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.

453 lines
17 KiB

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