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.

254 lines
8.5 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. #**************************************************************************************************
  2. #
  3. # raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten)
  4. #
  5. # Copyright (c) 2015 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. # define raylib platform to compile for
  24. # possible platforms: PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB
  25. # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
  26. PLATFORM ?= PLATFORM_DESKTOP
  27. # determine PLATFORM_OS in case PLATFORM_DESKTOP selected
  28. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  29. # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
  30. ifeq ($(OS),Windows_NT)
  31. PLATFORM_OS=WINDOWS
  32. LIBPATH=win32
  33. else
  34. UNAMEOS:=$(shell uname)
  35. ifeq ($(UNAMEOS),Linux)
  36. PLATFORM_OS=LINUX
  37. LIBPATH=linux
  38. else
  39. ifeq ($(UNAMEOS),Darwin)
  40. PLATFORM_OS=OSX
  41. LIBPATH=osx
  42. endif
  43. endif
  44. endif
  45. endif
  46. # define compiler: gcc for C program, define as g++ for C++
  47. ifeq ($(PLATFORM),PLATFORM_WEB)
  48. # define emscripten compiler
  49. CC = emcc
  50. else
  51. ifeq ($(PLATFORM_OS),OSX)
  52. # define llvm compiler for mac
  53. CC = clang
  54. else
  55. # define default gcc compiler
  56. CC = gcc
  57. endif
  58. endif
  59. # define compiler flags:
  60. # -O2 defines optimization level
  61. # -Wall turns on most, but not all, compiler warnings
  62. # -std=c99 use standard C from 1999 revision
  63. ifeq ($(PLATFORM),PLATFORM_RPI)
  64. CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
  65. else
  66. CFLAGS = -O2 -Wall -std=c99
  67. endif
  68. ifeq ($(PLATFORM),PLATFORM_WEB)
  69. CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 --shell-file ../../templates/web_shell/shell.html
  70. #-s ASSERTIONS=1 # to check for memory allocation errors (-O1 disables it)
  71. #-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
  72. #-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
  73. endif
  74. #CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
  75. # define any directories containing required header files
  76. ifeq ($(PLATFORM),PLATFORM_RPI)
  77. INCLUDES = -I. -I../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
  78. else
  79. INCLUDES = -I. -I../src
  80. # external libraries headers
  81. # GLFW3
  82. INCLUDES += -I../external/glfw3/include
  83. # GLEW - Not required any more, replaced by GLAD
  84. #INCLUDES += -I../external/glew/include
  85. # OpenAL Soft
  86. INCLUDES += -I../external/openal_soft/include
  87. endif
  88. # define library paths containing required libs
  89. ifeq ($(PLATFORM),PLATFORM_RPI)
  90. LFLAGS = -L. -L../src -L/opt/vc/lib
  91. else
  92. LFLAGS = -L. -L../src
  93. # external libraries to link with
  94. # GLFW3
  95. LFLAGS += -L../external/glfw3/lib/$(LIBPATH)
  96. ifneq ($(PLATFORM_OS),OSX)
  97. # OpenAL Soft
  98. LFLAGS += -L../external/openal_soft/lib/$(LIBPATH)
  99. # GLEW: Not used, replaced by GLAD
  100. #LFLAGS += -L../../external/glew/lib/$(LIBPATH)
  101. endif
  102. endif
  103. # define any libraries to link into executable
  104. # if you want to link libraries (libname.so or libname.a), use the -lname
  105. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  106. ifeq ($(PLATFORM_OS),LINUX)
  107. # libraries for Debian GNU/Linux desktop compiling
  108. # requires the following packages:
  109. # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
  110. LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread
  111. # on XWindow could require also below libraries, just uncomment
  112. #LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  113. else
  114. ifeq ($(PLATFORM_OS),OSX)
  115. # libraries for OS X 10.9 desktop compiling
  116. # requires the following packages:
  117. # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
  118. LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa
  119. else
  120. # libraries for Windows desktop compiling
  121. # NOTE: GLFW3 and OpenAL Soft libraries should be installed
  122. LIBS = -lraylib -lglfw3 -lopengl32 -lopenal32 -lgdi32
  123. endif
  124. endif
  125. endif
  126. ifeq ($(PLATFORM),PLATFORM_RPI)
  127. # libraries for Raspberry Pi compiling
  128. # NOTE: OpenAL Soft library should be installed (libopenal1 package)
  129. LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
  130. endif
  131. ifeq ($(PLATFORM),PLATFORM_WEB)
  132. # NOTE: Set the correct path to libraylib.bc
  133. LIBS = ../src/libraylib.bc
  134. endif
  135. # define additional parameters and flags for windows
  136. ifeq ($(PLATFORM_OS),WINDOWS)
  137. # resources file contains windows exe icon
  138. # -Wl,--subsystem,windows hides the console window
  139. WINFLAGS = ../src/resources -Wl,--subsystem,windows
  140. endif
  141. ifeq ($(PLATFORM),PLATFORM_WEB)
  142. EXT = .html
  143. endif
  144. # define all object files required
  145. SAMPLES = \
  146. arkanoid \
  147. asteroids \
  148. asteroids_survival \
  149. floppy \
  150. gold_fever \
  151. gorilas \
  152. missile_commander \
  153. pang \
  154. snake \
  155. space_invaders \
  156. tetris \
  157. fix_dylib \
  158. # typing 'make' will invoke the first target entry in the file,
  159. # in this case, the 'default' target entry is raylib
  160. default: samples
  161. # compile all game samples
  162. samples: $(SAMPLES)
  163. # compile game sample - arkanoid
  164. arkanoid: arkanoid.c
  165. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  166. # compile game sample - steroids
  167. asteroids: asteroids.c
  168. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  169. # compile game sample - asteroids_survival
  170. asteroids_survival: asteroids_survival.c
  171. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  172. # compile game sample - floppy
  173. floppy: floppy.c
  174. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  175. # compile game sample - gold_fever
  176. gold_fever: gold_fever.c
  177. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  178. # compile game sample - gorilas
  179. gorilas: gorilas.c
  180. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  181. # compile game sample - missile_commander
  182. missile_commander: missile_commander.c
  183. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  184. # compile game sample - pang
  185. pang: pang.c
  186. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  187. # compile game sample - snake
  188. snake: snake.c
  189. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  190. # compile game sample - space_invaders
  191. space_invaders: space_invaders.c
  192. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  193. # compile game sample - tetris
  194. tetris: tetris.c
  195. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  196. # fix dylib install path name for each executable (MAC)
  197. fix_dylib:
  198. ifeq ($(PLATFORM_OS),OSX)
  199. 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
  200. endif
  201. # clean everything
  202. clean:
  203. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  204. ifeq ($(PLATFORM_OS),OSX)
  205. find . -type f -perm +ugo+x -delete
  206. rm -f *.o
  207. else
  208. ifeq ($(PLATFORM_OS),LINUX)
  209. 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
  210. else
  211. del *.o *.exe
  212. endif
  213. endif
  214. endif
  215. ifeq ($(PLATFORM),PLATFORM_RPI)
  216. find . -type f -executable -delete
  217. rm -f *.o
  218. endif
  219. ifeq ($(PLATFORM),PLATFORM_WEB)
  220. del *.o *.html *.js
  221. endif
  222. @echo Cleaning done
  223. # instead of defining every module one by one, we can define a pattern
  224. # this pattern below will automatically compile every module defined on $(OBJS)
  225. #%.exe : %.c
  226. # $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM)