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.

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