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.

344 lines
12 KiB

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