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.

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