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.

331 line
12 KiB

  1. #**************************************************************************************************
  2. #
  3. # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
  4. #
  5. # Copyright (c) 2013-2018 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. # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
  26. PLATFORM ?= PLATFORM_DESKTOP
  27. RAYLIB_PATH = ../..
  28. PROJECT_NAME ?= advance_game
  29. # Default path for raylib on Raspberry Pi, if installed in different path, update it!
  30. ifeq ($(PLATFORM),PLATFORM_RPI)
  31. RAYLIB_PATH ?= /home/pi/raylib
  32. endif
  33. # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
  34. RAYLIB_LIBTYPE ?= STATIC
  35. # Use external GLFW library instead of rglfw module
  36. USE_EXTERNAL_GLFW ?= FALSE
  37. # Use Wayland display server protocol on Linux desktop
  38. # by default it uses X11 windowing system
  39. USE_WAYLAND_DISPLAY ?= FALSE
  40. # NOTE: On PLATFORM_WEB OpenAL Soft backend is used by default (check raylib/src/Makefile)
  41. # Determine PLATFORM_OS in case PLATFORM_DESKTOP selected
  42. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  43. # No uname.exe on MinGW!, but OS=Windows_NT on Windows!
  44. # ifeq ($(UNAME),Msys) -> Windows
  45. ifeq ($(OS),Windows_NT)
  46. PLATFORM_OS=WINDOWS
  47. else
  48. UNAMEOS=$(shell uname)
  49. ifeq ($(UNAMEOS),Linux)
  50. PLATFORM_OS=LINUX
  51. endif
  52. ifeq ($(UNAMEOS),FreeBSD)
  53. PLATFORM_OS=BSD
  54. endif
  55. ifeq ($(UNAMEOS),OpenBSD)
  56. PLATFORM_OS=BSD
  57. endif
  58. ifeq ($(UNAMEOS),NetBSD)
  59. PLATFORM_OS=BSD
  60. endif
  61. ifeq ($(UNAMEOS),DragonFly)
  62. PLATFORM_OS=BSD
  63. endif
  64. ifeq ($(UNAMEOS),Darwin)
  65. PLATFORM_OS=OSX
  66. endif
  67. endif
  68. endif
  69. ifeq ($(PLATFORM),PLATFORM_RPI)
  70. UNAMEOS=$(shell uname)
  71. ifeq ($(UNAMEOS),Linux)
  72. PLATFORM_OS=LINUX
  73. endif
  74. endif
  75. ifeq ($(PLATFORM),PLATFORM_WEB)
  76. # Emscripten required variables
  77. EMSDK_PATH = C:/emsdk
  78. EMSCRIPTEN_VERSION = 1.38.8
  79. CLANG_VERSION = e1.38.8_64bit
  80. PYTHON_VERSION = 2.7.13.1_64bit\python-2.7.13.amd64
  81. NODE_VERSION = 8.9.1_64bit
  82. 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)
  83. EMSCRIPTEN = $(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION)
  84. endif
  85. RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/release/libs
  86. # Define raylib release directory for compiled library
  87. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  88. ifeq ($(PLATFORM_OS),WINDOWS)
  89. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/win32/mingw32
  90. endif
  91. ifeq ($(PLATFORM_OS),LINUX)
  92. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/linux
  93. endif
  94. ifeq ($(PLATFORM_OS),OSX)
  95. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx
  96. endif
  97. ifeq ($(PLATFORM_OS),BSD)
  98. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd
  99. endif
  100. endif
  101. ifeq ($(PLATFORM),PLATFORM_RPI)
  102. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/rpi
  103. endif
  104. ifeq ($(PLATFORM),PLATFORM_WEB)
  105. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/html5
  106. endif
  107. # Define default C compiler: gcc
  108. # NOTE: define g++ compiler if using C++
  109. CC = gcc
  110. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  111. ifeq ($(PLATFORM_OS),OSX)
  112. # OSX default compiler
  113. CC = clang
  114. endif
  115. ifeq ($(PLATFORM_OS),BSD)
  116. # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
  117. CC = clang
  118. endif
  119. endif
  120. ifeq ($(PLATFORM),PLATFORM_RPI)
  121. ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
  122. # Define RPI cross-compiler
  123. #CC = armv6j-hardfloat-linux-gnueabi-gcc
  124. CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
  125. endif
  126. endif
  127. ifeq ($(PLATFORM),PLATFORM_WEB)
  128. # HTML5 emscripten compiler
  129. CC = emcc
  130. endif
  131. # Define default make program: Mingw32-make
  132. MAKE = mingw32-make
  133. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  134. ifeq ($(PLATFORM_OS),LINUX)
  135. MAKE = make
  136. endif
  137. endif
  138. # Define compiler flags:
  139. # -O1 defines optimization level
  140. # -g enable debugging
  141. # -s strip unnecessary data from build
  142. # -Wall turns on most, but not all, compiler warnings
  143. # -std=c99 defines C language mode (standard C from 1999 revision)
  144. # -std=gnu99 defines C language mode (GNU C from 1999 revision)
  145. # -Wno-missing-braces ignore invalid warning (GCC bug 53119)
  146. # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
  147. CFLAGS += -O1 -s -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
  148. # Additional flags for compiler (if desired)
  149. #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
  150. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  151. ifeq ($(PLATFORM_OS),WINDOWS)
  152. # resources file contains windows exe icon
  153. # -Wl,--subsystem,windows hides the console window
  154. CFLAGS += $(RAYLIB_PATH)/raylib.rc.o -Wl,--subsystem,windows
  155. endif
  156. ifeq ($(PLATFORM_OS),LINUX)
  157. CFLAGS += -D_DEFAULT_SOURCE
  158. endif
  159. endif
  160. ifeq ($(PLATFORM),PLATFORM_RPI)
  161. CFLAGS += -std=gnu99
  162. endif
  163. ifeq ($(PLATFORM),PLATFORM_WEB)
  164. # -O2 # if used, also set --memory-init-file 0
  165. # --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
  166. # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
  167. # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
  168. # -s USE_PTHREADS=1 # multithreading support
  169. # -s WASM=1 # support Web Assembly (https://github.com/kripken/emscripten/wiki/WebAssembly)
  170. # --preload-file resources # specify a resources folder for data compilation
  171. CFLAGS += -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 --profiling --preload-file resources
  172. # Define a custom shell .html and output extension
  173. CFLAGS += --shell-file $(RAYLIB_PATH)\templates\web_shell\shell.html
  174. EXT = .html
  175. endif
  176. # Define include paths for required headers
  177. # NOTE: Several external required libraries (stb and others)
  178. INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/release/include -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
  179. # Define additional directories containing required header files
  180. ifeq ($(PLATFORM),PLATFORM_RPI)
  181. # RPI requried libraries
  182. INCLUDE_PATHS += -I/opt/vc/include
  183. INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
  184. INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
  185. endif
  186. # Define library paths containing required libs
  187. LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
  188. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  189. ifeq ($(PLATFORM_OS),FREEBSD)
  190. INCLUDE_PATHS += -I/usr/local/include
  191. LDFLAGS += -L. -Lsrc -L/usr/local/lib
  192. endif
  193. endif
  194. ifeq ($(PLATFORM),PLATFORM_RPI)
  195. LDFLAGS += -L/opt/vc/lib
  196. endif
  197. # Define any libraries required on linking
  198. # if you want to link libraries (libname.so or libname.a), use the -lname
  199. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  200. ifeq ($(PLATFORM_OS),WINDOWS)
  201. # Libraries for Windows desktop compilation
  202. LDLIBS = -lraylib -lopengl32 -lgdi32
  203. # Required for physac examples
  204. #LDLIBS += -static -lpthread
  205. endif
  206. ifeq ($(PLATFORM_OS),LINUX)
  207. # Libraries for Debian GNU/Linux desktop compiling
  208. # NOTE: Required packages: libegl1-mesa-dev
  209. LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
  210. # On X11 requires also below libraries
  211. LDLIBS += -lX11
  212. # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
  213. #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  214. # On Wayland windowing system, additional libraries requires
  215. ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
  216. LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
  217. endif
  218. endif
  219. ifeq ($(PLATFORM_OS),OSX)
  220. # Libraries for OSX 10.9 desktop compiling
  221. # NOTE: Required packages: libopenal-dev libegl1-mesa-dev
  222. LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa
  223. endif
  224. ifeq ($(PLATFORM_OS),FREEBSD)
  225. # Libraries for FreeBSD desktop compiling
  226. # NOTE: Required packages: mesa-libs
  227. LDLIBS = -lraylib -lGL -lpthread -lm
  228. # On XWindow requires also below libraries
  229. LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  230. endif
  231. ifeq ($(USE_EXTERNAL_GLFW),TRUE)
  232. # NOTE: It could require additional packages installed: libglfw3-dev
  233. LDLIBS += -lglfw
  234. endif
  235. endif
  236. ifeq ($(PLATFORM),PLATFORM_RPI)
  237. # Libraries for Raspberry Pi compiling
  238. # NOTE: Required packages: libasound2-dev (ALSA)
  239. LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
  240. endif
  241. ifeq ($(PLATFORM),PLATFORM_WEB)
  242. # Libraries for web (HTML5) compiling
  243. LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
  244. endif
  245. # Define all source files required
  246. PROJECT_SOURCE_FILES ?= advance_game.c \
  247. screens/screen_logo.c \
  248. screens/screen_title.c \
  249. screens/screen_options.c \
  250. screens/screen_gameplay.c \
  251. screens/screen_ending.c
  252. # Define all object files from source files
  253. OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES))
  254. # For Android platform we call a custom Makefile.Android
  255. ifeq ($(PLATFORM),PLATFORM_ANDROID)
  256. MAKEFILE_PARAMS = -f Makefile.Android
  257. export PROJECT_NAME
  258. export PROJECT_SOURCE_FILES
  259. else
  260. MAKEFILE_PARAMS = $(PROJECT_NAME)
  261. endif
  262. # Default target entry
  263. # NOTE: We call this Makefile target or Makefile.Android target
  264. all:
  265. $(MAKE) $(MAKEFILE_PARAMS)
  266. # Project target defined by PROJECT_NAME
  267. $(PROJECT_NAME): $(OBJS)
  268. $(CC) -o $(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
  269. # Compile source files
  270. # NOTE: This pattern will compile every module defined on $(OBJS)
  271. %.o: %.c
  272. $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
  273. # Clean everything
  274. clean:
  275. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  276. ifeq ($(PLATFORM_OS),WINDOWS)
  277. del *.o *.exe /s
  278. endif
  279. ifeq ($(PLATFORM_OS),LINUX)
  280. 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 -f
  281. endif
  282. ifeq ($(PLATFORM_OS),OSX)
  283. find . -type f -perm +ugo+x -delete
  284. rm -f *.o
  285. endif
  286. endif
  287. ifeq ($(PLATFORM),PLATFORM_RPI)
  288. find . -type f -executable -delete
  289. rm -f *.o
  290. endif
  291. ifeq ($(PLATFORM),PLATFORM_WEB)
  292. del *.o *.html *.js
  293. endif
  294. @echo Cleaning done