You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

407 lines
16 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #**************************************************************************************************
  2. #
  3. # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
  4. #
  5. # Copyright (c) 2013-2019 Ramon Santamaria (@raysan5)
  6. #
  7. # This software is provided "as-is", without any express or implied warranty. In no event
  8. # will the authors be held liable for any damages arising from the use of this software.
  9. #
  10. # Permission is granted to anyone to use this software for any purpose, including commercial
  11. # applications, and to alter it and redistribute it freely, subject to the following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not claim that you
  14. # wrote the original software. If you use this software in a product, an acknowledgment
  15. # in the product documentation would be appreciated but is not required.
  16. #
  17. # 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  18. # as being the original software.
  19. #
  20. # 3. This notice may not be removed or altered from any source distribution.
  21. #
  22. #**************************************************************************************************
  23. .PHONY: all clean
  24. # Define required raylib variables
  25. PROJECT_NAME ?= game
  26. RAYLIB_VERSION ?= 4.0.0
  27. RAYLIB_PATH ?= ..\..
  28. # Define compiler path on Windows
  29. COMPILER_PATH ?= C:/raylib/w64devkit/bin
  30. # Define default options
  31. # One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  32. PLATFORM ?= PLATFORM_DESKTOP
  33. # Locations of your newly installed library and associated headers. See ../src/Makefile
  34. # On Linux, if you have installed raylib but cannot compile the examples, check that
  35. # the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
  36. # To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
  37. # To enable compile-time linking to a special version of libraylib.so, change these variables here.
  38. # To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
  39. # If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
  40. # the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
  41. # RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
  42. DESTDIR ?= /usr/local
  43. RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
  44. # RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files.
  45. RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
  46. # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
  47. RAYLIB_LIBTYPE ?= STATIC
  48. # Build mode for project: DEBUG or RELEASE
  49. BUILD_MODE ?= RELEASE
  50. # Use external GLFW library instead of rglfw module
  51. # TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
  52. USE_EXTERNAL_GLFW ?= FALSE
  53. # Use Wayland display server protocol on Linux desktop
  54. # by default it uses X11 windowing system
  55. USE_WAYLAND_DISPLAY ?= FALSE
  56. # Determine PLATFORM_OS in case PLATFORM_DESKTOP selected
  57. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  58. # No uname.exe on MinGW!, but OS=Windows_NT on Windows!
  59. # ifeq ($(UNAME),Msys) -> Windows
  60. ifeq ($(OS),Windows_NT)
  61. PLATFORM_OS=WINDOWS
  62. export PATH := $(COMPILER_PATH):$(PATH)
  63. else
  64. UNAMEOS=$(shell uname)
  65. ifeq ($(UNAMEOS),Linux)
  66. PLATFORM_OS=LINUX
  67. endif
  68. ifeq ($(UNAMEOS),FreeBSD)
  69. PLATFORM_OS=BSD
  70. endif
  71. ifeq ($(UNAMEOS),OpenBSD)
  72. PLATFORM_OS=BSD
  73. endif
  74. ifeq ($(UNAMEOS),NetBSD)
  75. PLATFORM_OS=BSD
  76. endif
  77. ifeq ($(UNAMEOS),DragonFly)
  78. PLATFORM_OS=BSD
  79. endif
  80. ifeq ($(UNAMEOS),Darwin)
  81. PLATFORM_OS=OSX
  82. endif
  83. endif
  84. endif
  85. ifeq ($(PLATFORM),PLATFORM_RPI)
  86. UNAMEOS=$(shell uname)
  87. ifeq ($(UNAMEOS),Linux)
  88. PLATFORM_OS=LINUX
  89. endif
  90. endif
  91. # RAYLIB_PATH adjustment for different platforms.
  92. # If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
  93. # Required for ldconfig or other tools that do not perform path expansion.
  94. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  95. ifeq ($(PLATFORM_OS),LINUX)
  96. RAYLIB_PREFIX ?= ..
  97. RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
  98. endif
  99. endif
  100. # Default path for raylib on Raspberry Pi, if installed in different path, update it!
  101. # This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
  102. # TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
  103. ifeq ($(PLATFORM),PLATFORM_RPI)
  104. RAYLIB_PATH ?= /home/pi/raylib
  105. endif
  106. ifeq ($(PLATFORM),PLATFORM_WEB)
  107. # Emscripten required variables
  108. EMSDK_PATH ?= C:/emsdk
  109. EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
  110. CLANG_PATH = $(EMSDK_PATH)/upstream/bin
  111. PYTHON_PATH = $(EMSDK_PATH)/python/3.9.2-1_64bit
  112. NODE_PATH = $(EMSDK_PATH)/node/14.18.2_64bit/bin
  113. export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH):$$(PATH)
  114. endif
  115. # Define raylib release directory for compiled library.
  116. # RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version
  117. RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
  118. # EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
  119. # into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
  120. # so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
  121. # without formal installation from ../src/Makefile. It aids portability and is useful if you have
  122. # multiple versions of raylib, have raylib installed to a non-standard location, or want to
  123. # bundle libraylib.so with your game. Change it to your liking.
  124. # NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
  125. # The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
  126. # Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  127. # To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
  128. # To see which libraries a built example is linking to, ldd core/core_basic_window;
  129. # Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
  130. EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH)
  131. # Define default C compiler: gcc
  132. # NOTE: define g++ compiler if using C++
  133. CC = gcc
  134. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  135. ifeq ($(PLATFORM_OS),OSX)
  136. # OSX default compiler
  137. CC = clang
  138. endif
  139. ifeq ($(PLATFORM_OS),BSD)
  140. # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
  141. CC = clang
  142. endif
  143. endif
  144. ifeq ($(PLATFORM),PLATFORM_RPI)
  145. ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
  146. # Define RPI cross-compiler
  147. #CC = armv6j-hardfloat-linux-gnueabi-gcc
  148. CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
  149. endif
  150. endif
  151. ifeq ($(PLATFORM),PLATFORM_WEB)
  152. # HTML5 emscripten compiler
  153. # WARNING: To compile to HTML5, code must be redesigned
  154. # to use emscripten.h and emscripten_set_main_loop()
  155. CC = emcc
  156. endif
  157. # Define default make program: Mingw32-make
  158. MAKE = mingw32-make
  159. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  160. ifeq ($(PLATFORM_OS),LINUX)
  161. MAKE = make
  162. endif
  163. ifeq ($(PLATFORM_OS),OSX)
  164. MAKE = make
  165. endif
  166. endif
  167. # Define compiler flags:
  168. # -O0 defines optimization level (no optimization, better for debugging)
  169. # -O1 defines optimization level
  170. # -g include debug information on compilation
  171. # -s strip unnecessary data from build -> do not use in debug builds
  172. # -Wall turns on most, but not all, compiler warnings
  173. # -std=c99 defines C language mode (standard C from 1999 revision)
  174. # -std=gnu99 defines C language mode (GNU C from 1999 revision)
  175. # -Wno-missing-braces ignore invalid warning (GCC bug 53119)
  176. # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
  177. CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
  178. ifeq ($(BUILD_MODE),DEBUG)
  179. CFLAGS += -g -O0
  180. else
  181. CFLAGS += -s -O1
  182. endif
  183. # Additional flags for compiler (if desired)
  184. #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
  185. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  186. ifeq ($(PLATFORM_OS),WINDOWS)
  187. # resource file contains windows executable icon and properties
  188. # -Wl,--subsystem,windows hides the console window
  189. CFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data -Wl,--subsystem,windows
  190. endif
  191. ifeq ($(PLATFORM_OS),LINUX)
  192. ifeq ($(RAYLIB_LIBTYPE),STATIC)
  193. CFLAGS += -D_DEFAULT_SOURCE
  194. endif
  195. ifeq ($(RAYLIB_LIBTYPE),SHARED)
  196. # Explicitly enable runtime link to libraylib.so
  197. CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  198. endif
  199. endif
  200. endif
  201. ifeq ($(PLATFORM),PLATFORM_RPI)
  202. CFLAGS += -std=gnu99
  203. endif
  204. ifeq ($(PLATFORM),PLATFORM_WEB)
  205. # -Os # size optimization
  206. # -O2 # optimization level 2, if used, also set --memory-init-file 0
  207. # -s USE_GLFW=3 # Use glfw3 library (context/input management)
  208. # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL!
  209. # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
  210. # -s USE_PTHREADS=1 # multithreading support
  211. # -s WASM=0 # disable Web Assembly, emitted by default
  212. # -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow)
  213. # -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter
  214. # -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data
  215. # -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
  216. # --profiling # include information for code profiling
  217. # --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
  218. # --preload-file resources # specify a resources folder for data compilation
  219. CFLAGS += -Os -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 --preload-file resources
  220. ifeq ($(BUILD_MODE), DEBUG)
  221. CFLAGS += -s ASSERTIONS=1 --profiling
  222. endif
  223. # Define a custom shell .html and output extension
  224. CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
  225. EXT = .html
  226. endif
  227. # Define include paths for required headers
  228. # NOTE: Several external required libraries (stb and others)
  229. INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
  230. # Define additional directories containing required header files
  231. ifeq ($(PLATFORM),PLATFORM_RPI)
  232. # RPI required libraries
  233. INCLUDE_PATHS += -I/opt/vc/include
  234. INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
  235. INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
  236. endif
  237. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  238. ifeq ($(PLATFORM_OS),BSD)
  239. # Consider -L$(RAYLIB_H_INSTALL_PATH)
  240. INCLUDE_PATHS += -I/usr/local/include
  241. endif
  242. ifeq ($(PLATFORM_OS),LINUX)
  243. # Reset everything.
  244. # Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include
  245. INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external
  246. endif
  247. endif
  248. # Define library paths containing required libs.
  249. LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
  250. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  251. ifeq ($(PLATFORM_OS),BSD)
  252. # Consider -L$(RAYLIB_INSTALL_PATH)
  253. LDFLAGS += -L. -Lsrc -L/usr/local/lib
  254. endif
  255. ifeq ($(PLATFORM_OS),LINUX)
  256. # Reset everything.
  257. # Precedence: immediately local, installed version, raysan5 provided libs
  258. LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH)
  259. endif
  260. endif
  261. ifeq ($(PLATFORM),PLATFORM_RPI)
  262. LDFLAGS += -L/opt/vc/lib
  263. endif
  264. # Define any libraries required on linking
  265. # if you want to link libraries (libname.so or libname.a), use the -lname
  266. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  267. ifeq ($(PLATFORM_OS),WINDOWS)
  268. # Libraries for Windows desktop compilation
  269. # NOTE: WinMM library required to set high-res timer resolution
  270. LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
  271. # Required for physac examples
  272. #LDLIBS += -static -lpthread
  273. endif
  274. ifeq ($(PLATFORM_OS),LINUX)
  275. # Libraries for Debian GNU/Linux desktop compiling
  276. # NOTE: Required packages: libegl1-mesa-dev
  277. LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
  278. # On X11 requires also below libraries
  279. LDLIBS += -lX11
  280. # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
  281. #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  282. # On Wayland windowing system, additional libraries requires
  283. ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
  284. LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
  285. endif
  286. # Explicit link to libc
  287. ifeq ($(RAYLIB_LIBTYPE),SHARED)
  288. LDLIBS += -lc
  289. endif
  290. endif
  291. ifeq ($(PLATFORM_OS),OSX)
  292. # Libraries for OSX 10.9 desktop compiling
  293. # NOTE: Required packages: libopenal-dev libegl1-mesa-dev
  294. LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa
  295. endif
  296. ifeq ($(PLATFORM_OS),BSD)
  297. # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
  298. # NOTE: Required packages: mesa-libs
  299. LDLIBS = -lraylib -lGL -lpthread -lm
  300. # On XWindow requires also below libraries
  301. LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  302. endif
  303. ifeq ($(USE_EXTERNAL_GLFW),TRUE)
  304. # NOTE: It could require additional packages installed: libglfw3-dev
  305. LDLIBS += -lglfw
  306. endif
  307. endif
  308. ifeq ($(PLATFORM),PLATFORM_RPI)
  309. # Libraries for Raspberry Pi compiling
  310. # NOTE: Required packages: libasound2-dev (ALSA)
  311. LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
  312. endif
  313. ifeq ($(PLATFORM),PLATFORM_WEB)
  314. # Libraries for web (HTML5) compiling
  315. LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.a
  316. endif
  317. # Define a recursive wildcard function
  318. rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
  319. # Define all source files required
  320. SRC_DIR = src
  321. OBJ_DIR = obj
  322. # Define all object files from source files
  323. SRC = $(call rwildcard, *.c, *.h)
  324. #OBJS = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
  325. OBJS ?= main.c
  326. # For Android platform we call a custom Makefile.Android
  327. ifeq ($(PLATFORM),PLATFORM_ANDROID)
  328. MAKEFILE_PARAMS = -f Makefile.Android
  329. export PROJECT_NAME
  330. export SRC_DIR
  331. else
  332. MAKEFILE_PARAMS = $(PROJECT_NAME)
  333. endif
  334. # Default target entry
  335. # NOTE: We call this Makefile target or Makefile.Android target
  336. all:
  337. $(MAKE) $(MAKEFILE_PARAMS)
  338. # Project target defined by PROJECT_NAME
  339. $(PROJECT_NAME): $(OBJS)
  340. $(CC) -o $(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
  341. # Compile source files
  342. # NOTE: This pattern will compile every module defined on $(OBJS)
  343. #%.o: %.c
  344. $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
  345. $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
  346. # Clean everything
  347. clean:
  348. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  349. ifeq ($(PLATFORM_OS),WINDOWS)
  350. del *.o *.exe /s
  351. endif
  352. ifeq ($(PLATFORM_OS),LINUX)
  353. find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv
  354. endif
  355. ifeq ($(PLATFORM_OS),OSX)
  356. find . -type f -perm +ugo+x -delete
  357. rm -f *.o
  358. endif
  359. endif
  360. ifeq ($(PLATFORM),PLATFORM_RPI)
  361. find . -type f -executable -delete
  362. rm -fv *.o
  363. endif
  364. ifeq ($(PLATFORM),PLATFORM_WEB)
  365. del *.o *.html *.js
  366. endif
  367. @echo Cleaning done