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.

250 lines
8.3 KiB

9 years ago
9 years ago
9 years ago
8 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. # OpenAL Soft
  84. INCLUDES += -I../external/openal_soft/include
  85. endif
  86. # define library paths containing required libs
  87. ifeq ($(PLATFORM),PLATFORM_RPI)
  88. LFLAGS = -L. -L../src -L/opt/vc/lib
  89. else
  90. LFLAGS = -L. -L../src
  91. # external libraries to link with
  92. # GLFW3
  93. LFLAGS += -L../external/glfw3/lib/$(LIBPATH)
  94. ifneq ($(PLATFORM_OS),OSX)
  95. # OpenAL Soft
  96. LFLAGS += -L../external/openal_soft/lib/$(LIBPATH)
  97. endif
  98. endif
  99. # define any libraries to link into executable
  100. # if you want to link libraries (libname.so or libname.a), use the -lname
  101. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  102. ifeq ($(PLATFORM_OS),LINUX)
  103. # libraries for Debian GNU/Linux desktop compiling
  104. # requires the following packages:
  105. # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
  106. LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -lpthread -ldl
  107. # on XWindow could require also below libraries:
  108. LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  109. else
  110. ifeq ($(PLATFORM_OS),OSX)
  111. # libraries for OS X 10.9 desktop compiling
  112. # requires the following packages:
  113. # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
  114. LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa
  115. else
  116. # libraries for Windows desktop compiling
  117. # NOTE: GLFW3 and OpenAL Soft libraries should be installed
  118. LIBS = -lraylib -lglfw3 -lopengl32 -lopenal32 -lgdi32
  119. endif
  120. endif
  121. endif
  122. ifeq ($(PLATFORM),PLATFORM_RPI)
  123. # libraries for Raspberry Pi compiling
  124. # NOTE: OpenAL Soft library should be installed (libopenal1 package)
  125. LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
  126. endif
  127. ifeq ($(PLATFORM),PLATFORM_WEB)
  128. # NOTE: Set the correct path to libraylib.bc
  129. LIBS = ../src/libraylib.bc
  130. endif
  131. # define additional parameters and flags for windows
  132. ifeq ($(PLATFORM_OS),WINDOWS)
  133. # resources file contains windows exe icon
  134. # -Wl,--subsystem,windows hides the console window
  135. WINFLAGS = ../src/resources -Wl,--subsystem,windows
  136. endif
  137. ifeq ($(PLATFORM),PLATFORM_WEB)
  138. EXT = .html
  139. endif
  140. # define all object files required
  141. SAMPLES = \
  142. arkanoid \
  143. asteroids \
  144. asteroids_survival \
  145. floppy \
  146. gold_fever \
  147. gorilas \
  148. missile_commander \
  149. pang \
  150. snake \
  151. space_invaders \
  152. tetris \
  153. fix_dylib \
  154. # typing 'make' will invoke the first target entry in the file,
  155. # in this case, the 'default' target entry is raylib
  156. default: samples
  157. # compile all game samples
  158. samples: $(SAMPLES)
  159. # compile game sample - arkanoid
  160. arkanoid: arkanoid.c
  161. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  162. # compile game sample - steroids
  163. asteroids: asteroids.c
  164. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  165. # compile game sample - asteroids_survival
  166. asteroids_survival: asteroids_survival.c
  167. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  168. # compile game sample - floppy
  169. floppy: floppy.c
  170. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  171. # compile game sample - gold_fever
  172. gold_fever: gold_fever.c
  173. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  174. # compile game sample - gorilas
  175. gorilas: gorilas.c
  176. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  177. # compile game sample - missile_commander
  178. missile_commander: missile_commander.c
  179. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  180. # compile game sample - pang
  181. pang: pang.c
  182. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  183. # compile game sample - snake
  184. snake: snake.c
  185. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  186. # compile game sample - space_invaders
  187. space_invaders: space_invaders.c
  188. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  189. # compile game sample - tetris
  190. tetris: tetris.c
  191. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
  192. # fix dylib install path name for each executable (MAC)
  193. fix_dylib:
  194. ifeq ($(PLATFORM_OS),OSX)
  195. 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
  196. endif
  197. # clean everything
  198. clean:
  199. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  200. ifeq ($(PLATFORM_OS),OSX)
  201. find . -type f -perm +ugo+x -delete
  202. rm -f *.o
  203. else
  204. ifeq ($(PLATFORM_OS),LINUX)
  205. 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
  206. else
  207. del *.o *.exe
  208. endif
  209. endif
  210. endif
  211. ifeq ($(PLATFORM),PLATFORM_RPI)
  212. find . -type f -executable -delete
  213. rm -f *.o
  214. endif
  215. ifeq ($(PLATFORM),PLATFORM_WEB)
  216. del *.o *.html *.js
  217. endif
  218. @echo Cleaning done
  219. # instead of defining every module one by one, we can define a pattern
  220. # this pattern below will automatically compile every module defined on $(OBJS)
  221. #%.exe : %.c
  222. # $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM)