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.

393 lines
15 KiB

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