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.

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