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.

441 lines
17 KiB

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