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.

319 lines
11 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #**************************************************************************************************
  2. #
  3. # raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten)
  4. #
  5. # Copyright (c) 2013-2017 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 raylib platform to compile for
  25. # possible platforms: PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB
  26. # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
  27. PLATFORM ?= PLATFORM_DESKTOP
  28. # define NO to use OpenAL Soft as static library (shared by default)
  29. SHARED_OPENAL ?= NO
  30. ifeq ($(PLATFORM),PLATFORM_WEB)
  31. SHARED_OPENAL = NO
  32. endif
  33. # define raylib directory for include and library
  34. RAYLIB_PATH ?= C:\raylib\raylib
  35. # determine PLATFORM_OS in case PLATFORM_DESKTOP selected
  36. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  37. # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
  38. ifeq ($(OS),Windows_NT)
  39. PLATFORM_OS=WINDOWS
  40. LIBPATH=win32
  41. else
  42. UNAMEOS:=$(shell uname)
  43. ifeq ($(UNAMEOS),Linux)
  44. PLATFORM_OS=LINUX
  45. LIBPATH=linux
  46. else
  47. ifeq ($(UNAMEOS),Darwin)
  48. PLATFORM_OS=OSX
  49. LIBPATH=osx
  50. endif
  51. endif
  52. endif
  53. endif
  54. # define compiler: gcc for C program, define as g++ for C++
  55. ifeq ($(PLATFORM),PLATFORM_WEB)
  56. # define emscripten compiler
  57. CC = emcc
  58. else
  59. ifeq ($(PLATFORM_OS),OSX)
  60. # define llvm compiler for mac
  61. CC = clang
  62. else
  63. # define default gcc compiler
  64. CC = gcc
  65. endif
  66. endif
  67. # define compiler flags:
  68. # -O2 defines optimization level
  69. # -Og enable debugging
  70. # -s strip unnecessary data from build
  71. # -Wall turns on most, but not all, compiler warnings
  72. # -std=c99 defines C language mode (standard C from 1999 revision)
  73. # -std=gnu99 defines C language mode (GNU C from 1999 revision)
  74. # -fgnu89-inline declaring inline functions support (GCC optimized)
  75. # -Wno-missing-braces ignore invalid warning (GCC bug 53119)
  76. # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
  77. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  78. ifeq ($(PLATFORM_OS),WINDOWS)
  79. CFLAGS = -O2 -s -Wall -std=c99
  80. endif
  81. ifeq ($(PLATFORM_OS),LINUX)
  82. CFLAGS = -O2 -s -Wall -std=c99 -D_DEFAULT_SOURCE
  83. endif
  84. ifeq ($(PLATFORM_OS),OSX)
  85. CFLAGS = -O2 -s -Wall -std=c99
  86. endif
  87. endif
  88. ifeq ($(PLATFORM),PLATFORM_WEB)
  89. CFLAGS = -O1 -Wall -std=c99 -D_DEFAULT_SOURCE -s USE_GLFW=3 -s ASSERTIONS=1 -s --profiling
  90. # -O2 # if used, also set --memory-init-file 0
  91. # --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
  92. # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
  93. # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
  94. # --preload-file file.res # embbed file.res resource into .data file
  95. endif
  96. ifeq ($(PLATFORM),PLATFORM_RPI)
  97. CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline
  98. endif
  99. #CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
  100. # define raylib release directory for compiled library
  101. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  102. ifeq ($(PLATFORM_OS),WINDOWS)
  103. RAYLIB_RELEASE = $(RAYLIB_PATH)/release/win32/mingw32
  104. endif
  105. ifeq ($(PLATFORM_OS),LINUX)
  106. RAYLIB_RELEASE = $(RAYLIB_PATH)/release/linux
  107. endif
  108. ifeq ($(PLATFORM_OS),OSX)
  109. RAYLIB_RELEASE = $(RAYLIB_PATH)/release/osx
  110. endif
  111. endif
  112. ifeq ($(PLATFORM),PLATFORM_WEB)
  113. RAYLIB_RELEASE = $(RAYLIB_PATH)/release/html5
  114. endif
  115. ifeq ($(PLATFORM),PLATFORM_RPI)
  116. RAYLIB_RELEASE = $(RAYLIB_PATH)/release/rpi
  117. endif
  118. # define any directories containing required header files
  119. INCLUDES = -I. -I$(RAYLIB_RELEASE) -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
  120. ifeq ($(PLATFORM),PLATFORM_RPI)
  121. INCLUDES += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
  122. endif
  123. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  124. ifeq ($(PLATFORM_OS),WINDOWS)
  125. # external libraries headers
  126. # GLFW3
  127. INCLUDES += -I$(RAYLIB_PATH)/src/external/glfw3/include
  128. # OpenAL Soft
  129. INCLUDES += -I$(RAYLIB_PATH)/src/external/openal_soft/include
  130. endif
  131. ifeq ($(PLATFORM_OS),LINUX)
  132. # you may optionally create this directory and install raylib
  133. # and related headers there. Edit ../src/Makefile appropriately.
  134. INCLUDES += -I/usr/local/include/raylib
  135. endif
  136. ifeq ($(PLATFORM_OS),OSX)
  137. # additional directories for MacOS
  138. endif
  139. endif
  140. # define library paths containing required libs
  141. LFLAGS = -L. -L$(RAYLIB_RELEASE) -L$(RAYLIB_PATH)/src
  142. ifeq ($(PLATFORM),PLATFORM_RPI)
  143. LFLAGS += -L/opt/vc/lib
  144. endif
  145. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  146. # add standard directories for GNU/Linux
  147. ifeq ($(PLATFORM_OS),WINDOWS)
  148. # external libraries to link with
  149. # GLFW3
  150. LFLAGS += -L$(RAYLIB_PATH)/src/external/glfw3/lib/$(LIBPATH)
  151. # OpenAL Soft
  152. LFLAGS += -L$(RAYLIB_PATH)/src/external/openal_soft/lib/$(LIBPATH)
  153. endif
  154. endif
  155. # define any libraries to link into executable
  156. # if you want to link libraries (libname.so or libname.a), use the -lname
  157. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  158. ifeq ($(PLATFORM_OS),LINUX)
  159. # libraries for Debian GNU/Linux desktop compiling
  160. # requires the following packages:
  161. # libglfw3-dev libopenal-dev libegl1-mesa-dev
  162. LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl
  163. # on XWindow requires also below libraries
  164. LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  165. else
  166. ifeq ($(PLATFORM_OS),OSX)
  167. # libraries for OSX 10.9 desktop compiling
  168. # requires the following packages:
  169. # libglfw3-dev libopenal-dev libegl1-mesa-dev
  170. LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAL -framework Cocoa
  171. else
  172. # libraries for Windows desktop compiling
  173. # NOTE: GLFW3 and OpenAL Soft libraries should be installed
  174. LIBS = -lraylib -lglfw3 -lopengl32 -lgdi32
  175. # if static OpenAL Soft required, define the corresponding libs
  176. ifeq ($(SHARED_OPENAL),NO)
  177. LIBS += -lopenal32 -lwinmm
  178. CFLAGS += -Wl,-allow-multiple-definition
  179. else
  180. LIBS += -lopenal32dll
  181. endif
  182. endif
  183. endif
  184. endif
  185. ifeq ($(PLATFORM),PLATFORM_RPI)
  186. # libraries for Raspberry Pi compiling
  187. # NOTE: OpenAL Soft library should be installed (libopenal1 package)
  188. LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
  189. endif
  190. ifeq ($(PLATFORM),PLATFORM_WEB)
  191. # NOTE: Set the correct path to libraylib.bc
  192. LIBS = $(RAYLIB_RELEASE)/libraylib.bc
  193. endif
  194. # define additional parameters and flags for windows
  195. ifeq ($(PLATFORM_OS),WINDOWS)
  196. # resources file contains windows exe icon
  197. # -Wl,--subsystem,windows hides the console window
  198. WINFLAGS = $(RAYLIB_PATH)/src/resources -Wl,--subsystem,windows
  199. endif
  200. ifeq ($(PLATFORM),PLATFORM_WEB)
  201. EXT = .html
  202. WEB_SHELL = --shell-file $(RAYLIB_PATH)\templates\web_shell\shell.html
  203. endif
  204. # define all object files required
  205. SAMPLES = \
  206. arkanoid \
  207. asteroids \
  208. asteroids_survival \
  209. floppy \
  210. gold_fever \
  211. gorilas \
  212. missile_commander \
  213. pang \
  214. snake \
  215. space_invaders \
  216. tetris \
  217. fix_dylib \
  218. # typing 'make' will invoke the default target entry
  219. default: samples
  220. # compile all game samples
  221. samples: $(SAMPLES)
  222. # compile game sample - arkanoid
  223. arkanoid: arkanoid.c
  224. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  225. # compile game sample - steroids
  226. asteroids: asteroids.c
  227. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  228. # compile game sample - asteroids_survival
  229. asteroids_survival: asteroids_survival.c
  230. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  231. # compile game sample - floppy
  232. floppy: floppy.c
  233. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  234. # compile game sample - gold_fever
  235. gold_fever: gold_fever.c
  236. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  237. # compile game sample - gorilas
  238. gorilas: gorilas.c
  239. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  240. # compile game sample - missile_commander
  241. missile_commander: missile_commander.c
  242. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  243. # compile game sample - pang
  244. pang: pang.c
  245. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  246. # compile game sample - snake
  247. snake: snake.c
  248. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  249. # compile game sample - space_invaders
  250. space_invaders: space_invaders.c
  251. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  252. # compile game sample - tetris
  253. tetris: tetris.c
  254. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL)
  255. # fix dylib install path name for each executable (MAC)
  256. fix_dylib:
  257. ifeq ($(PLATFORM_OS),OSX)
  258. find . -type f -perm +ugo+x -print0 | xargs -t -0 -R 1 -I file install_name_tool -change libglfw.3.0.dylib ../external/glfw3/lib/osx/libglfw.3.0.dylib file
  259. endif
  260. # clean everything
  261. clean:
  262. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  263. ifeq ($(PLATFORM_OS),OSX)
  264. find . -type f -perm +ugo+x -delete
  265. rm -f *.o
  266. else
  267. ifeq ($(PLATFORM_OS),LINUX)
  268. 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
  269. else
  270. del *.o *.exe /s
  271. endif
  272. endif
  273. endif
  274. ifeq ($(PLATFORM),PLATFORM_RPI)
  275. find . -type f -executable -delete
  276. rm -f *.o
  277. endif
  278. ifeq ($(PLATFORM),PLATFORM_WEB)
  279. del *.o *.html *.js
  280. endif
  281. @echo Cleaning done
  282. # instead of defining every module one by one, we can define a pattern
  283. # this pattern below will automatically compile every module defined on $(OBJS)
  284. #%.exe : %.c
  285. # $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM)