ADDED: Support for SDL building on Makefile

This commit is contained in:
Ray 2023-10-29 20:44:18 +01:00
parent 601e391b06
commit 4625c41431
2 changed files with 128 additions and 30 deletions

View File

@ -1,6 +1,25 @@
#**************************************************************************************************
#
# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
# raylib makefile for multiple platforms
#
# This file supports building raylib examples for the following platforms:
#
# - PLATFORM_DESKTOP (GLFW backend):
# > Windows (Win32, Win64)
# > Linux (X11/Wayland desktop mode)
# > macOS/OSX (x64, arm64)
# > FreeBSD, OpenBSD, NetBSD, DragonFly (X11 desktop)
# - PLATFORM_DESKTOP_SDL (SDL backend):
# > Windows (Win32, Win64)
# > Linux (X11/Wayland desktop mode)
# > Others (not tested)
# - PLATFORM_WEB:
# > HTML5 (WebAssembly)
# - PLATFORM_DRM:
# > Raspberry Pi 0-5 (no X11/Wayland)
# > Linux native mode (KMS driver)
# - PLATFORM_ANDROID:
# > Android (ARM, ARM64)
#
# Copyright (c) 2013-2023 Ramon Santamaria (@raysan5)
#
@ -25,7 +44,7 @@
# Define required environment variables
#------------------------------------------------------------------------------------------------
# Define target platform: PLATFORM_DESKTOP, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
# Define target platform: PLATFORM_DESKTOP, PLATFORM_DESKTOP_SDL, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
PLATFORM ?= PLATFORM_DESKTOP
# Define required raylib variables
@ -47,6 +66,11 @@ BUILD_MODE ?= RELEASE
# Use external GLFW library instead of rglfw module
USE_EXTERNAL_GLFW ?= FALSE
# PLATFORM_DESKTOP_SDL: It requires SDL library to be provided externally
# WARNING: Library is not included in raylib, it MUST be configured by users
SDL_INCLUDE_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2-2.28.4/include
SDL_LIBRARY_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2-2.28.4/lib/x64
# Use Wayland display server protocol on Linux desktop (by default it uses X11 windowing system)
# NOTE: This variable is only used for PLATFORM_OS: LINUX
USE_WAYLAND_DISPLAY ?= FALSE
@ -58,8 +82,8 @@ BUILD_WEB_HEAP_SIZE ?= 134217728
BUILD_WEB_RESOURCES ?= TRUE
BUILD_WEB_RESOURCES_PATH ?= $(dir $<)resources@resources
# Determine PLATFORM_OS in case PLATFORM_DESKTOP or PLATFORM_WEB selected
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_WEB))
# Determine PLATFORM_OS when required
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLATFORM_WEB))
# No uname.exe on MinGW!, but OS=Windows_NT on Windows!
# ifeq ($(UNAME),Msys) -> Windows
ifeq ($(OS),Windows_NT)
@ -224,6 +248,9 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH)
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
INCLUDE_PATHS += -I$(SDL_INCLUDE_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH)
INCLUDE_PATHS += -I/usr/include/libdrm
@ -254,6 +281,17 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDFLAGS += -Lsrc -L$(RAYLIB_LIB_PATH)
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(PLATFORM_OS),WINDOWS)
# NOTE: The resource .rc file contains windows executable icon and properties
LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
# -Wl,--subsystem,windows hides the console window
ifeq ($(BUILD_MODE), RELEASE)
LDFLAGS += -Wl,--subsystem,windows
endif
endif
LDFLAGS += -L$(SDL_LIBRARY_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
# -Os # size optimization
# -O2 # optimization level 2, if used, also set --memory-init-file 0
@ -346,6 +384,34 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDLIBS += -lglfw
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(PLATFORM_OS),WINDOWS)
# Libraries for Windows desktop compilation
LDLIBS = -lraylib -lSDL2 -lSDL2main -lopengl32 -lgdi32
endif
ifeq ($(PLATFORM_OS),LINUX)
# Libraries for Debian GNU/Linux desktop compiling
# NOTE: Required packages: libegl1-mesa-dev
LDLIBS = -lraylib -lSDL2 -lSDL2main -lGL -lm -lpthread -ldl -lrt
# On X11 requires also below libraries
LDLIBS += -lX11
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
# On Wayland windowing system, additional libraries requires
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
endif
# Explicit link to libc
ifeq ($(RAYLIB_LIBTYPE),SHARED)
LDLIBS += -lc
endif
# NOTE: On ARM 32bit arch, miniaudio requires atomics library
LDLIBS += -latomic
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
# Libraries for DRM compiling
# NOTE: Required packages: libasound2-dev (ALSA)

View File

@ -1,18 +1,28 @@
#******************************************************************************
#
# raylib makefile
# raylib makefile
#
# Platforms supported:
# PLATFORM_DESKTOP: Windows (Win32, Win64)
# PLATFORM_DESKTOP: Linux (arm64, i386, x64)
# PLATFORM_DESKTOP: OSX/macOS (arm64, x86_64)
# PLATFORM_DESKTOP: FreeBSD, OpenBSD, NetBSD, DragonFly
# PLATFORM_ANDROID: Android (arm, i686, arm64, x86_64)
# PLATFORM_DRM: Linux native mode, including Raspberry Pi (RPI OS Bullseye)
# PLATFORM_WEB: HTML5 (Chrome, Firefox)
# This file supports building raylib library for the following platforms:
#
# Many thanks to Milan Nikolic (@gen2brain) for implementing Android platform pipeline.
# Many thanks to Emanuele Petriglia for his contribution on GNU/Linux pipeline.
# - PLATFORM_DESKTOP (GLFW backend):
# > Windows (Win32, Win64)
# > Linux (X11/Wayland desktop mode)
# > macOS/OSX (x64, arm64)
# > FreeBSD, OpenBSD, NetBSD, DragonFly (X11 desktop)
# - PLATFORM_DESKTOP_SDL (SDL backend):
# > Windows (Win32, Win64)
# > Linux (X11/Wayland desktop mode)
# > Others (not tested)
# - PLATFORM_WEB:
# > HTML5 (WebAssembly)
# - PLATFORM_DRM:
# > Raspberry Pi 0-5 (no X11/Wayland)
# > Linux native mode (KMS driver)
# - PLATFORM_ANDROID:
# > Android (ARM, ARM64)
#
# Many thanks to Milan Nikolic (@gen2brain) for implementing Android platform pipeline.
# Many thanks to Emanuele Petriglia for his contribution on GNU/Linux pipeline.
#
# Copyright (c) 2013-2023 Ramon Santamaria (@raysan5)
#
@ -86,6 +96,11 @@ RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)/../../raygui/src
# Use external GLFW library instead of rglfw module
USE_EXTERNAL_GLFW ?= FALSE
# PLATFORM_DESKTOP_SDL: It requires SDL library to be provided externally
# WARNING: Library is not included in raylib, it MUST be configured by users
SDL_INCLUDE_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2-2.28.4/include
SDL_LIBRARY_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2-2.28.4/lib/x64
# Use Wayland display server protocol on Linux desktop (by default it uses X11 windowing system)
# NOTE: This variable is only used for PLATFORM_OS: LINUX
USE_WAYLAND_DISPLAY ?= FALSE
@ -98,8 +113,8 @@ ROOT = $(shell whoami)
HOST_PLATFORM_OS ?= WINDOWS
PLATFORM_OS ?= WINDOWS
# Determine PLATFORM_OS in case PLATFORM_DESKTOP selected
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
# Determine PLATFORM_OS when required
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLATFORM_WEB))
# No uname.exe on MinGW!, but OS=Windows_NT on Windows!
# ifeq ($(UNAME),Msys) -> Windows
ifeq ($(OS),Windows_NT)
@ -142,16 +157,7 @@ ifeq ($(PLATFORM),PLATFORM_DRM)
endif
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(OS),Windows_NT)
PLATFORM_OS = WINDOWS
ifndef PLATFORM_SHELL
PLATFORM_SHELL = cmd
endif
else
UNAMEOS = $(shell uname)
ifeq ($(UNAMEOS),Linux)
PLATFORM_OS = LINUX
endif
ifeq ($(PLATFORM_OS),LINUX)
ifndef PLATFORM_SHELL
PLATFORM_SHELL = sh
endif
@ -214,7 +220,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
#GRAPHICS = GRAPHICS_API_OPENGL_43 # Uncomment to use OpenGL 4.3
#GRAPHICS = GRAPHICS_API_OPENGL_ES2 # Uncomment to use OpenGL ES 2.0 (ANGLE)
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
# By default use OpenGL 3.3 on desktop platform with SDL backend
GRAPHICS ?= GRAPHICS_API_OPENGL_33
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
# On DRM OpenGL ES 2.0 must be used
GRAPHICS = GRAPHICS_API_OPENGL_ES2
@ -413,14 +422,21 @@ endif
# Define include paths for required headers: INCLUDE_PATHS
# NOTE: Several external required libraries (stb and others)
#------------------------------------------------------------------------------------------------
INCLUDE_PATHS = -I. -Iexternal/glfw/include -Iexternal/glfw/deps/mingw
INCLUDE_PATHS = -I.
# Define additional directories containing required header files
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
INCLUDE_PATHS += -Iexternal/glfw/include -Iexternal/glfw/deps/mingw
ifeq ($(PLATFORM_OS),BSD)
INCLUDE_PATHS += -I/usr/local/include
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
INCLUDE_PATHS += -I$(SDL_INCLUDE_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
INCLUDE_PATHS += -Iexternal/glfw/include -Iexternal/glfw/deps/mingw
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
INCLUDE_PATHS += -I/usr/include/libdrm
ifeq ($(USE_RPI_CROSSCOMPILER), TRUE)
@ -470,10 +486,14 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDFLAGS += -Wl,-soname,lib$(RAYLIB_LIB_NAME).$(RAYLIB_API_VERSION).so -Lsrc -L/usr/local/lib
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
LDFLAGS += -Wl,-soname,lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_API_VERSION)
LDFLAGS += -L$(SDL_LIBRARY_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
LDFLAGS += -Wl,-soname,lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_API_VERSION)
ifeq ($(USE_RPI_CROSSCOMPILER), TRUE)
INCLUDE_PATHS += -L$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/lib -L$(RPI_TOOLCHAIN_SYSROOT)/usr/lib
LDFLAGS += -L$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/lib -L$(RPI_TOOLCHAIN_SYSROOT)/usr/lib
endif
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
@ -518,6 +538,18 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDLIBS = -lglfw
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(PLATFORM_OS),WINDOWS)
LDLIBS = -static-libgcc -lopengl32 -lgdi32
endif
ifeq ($(PLATFORM_OS),LINUX)
LDLIBS = -lGL -lc -lm -lpthread -ldl -lrt
ifeq ($(USE_WAYLAND_DISPLAY),FALSE)
LDLIBS += -lX11
endif
endif
LDLIBS += -lSDL2 -lSDL2main
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
LDLIBS = -lGLESv2 -lEGL -ldrm -lgbm -lpthread -lrt -lm -ldl
ifeq ($(RAYLIB_MODULE_AUDIO),TRUE)