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.

451 lines
17 KiB

6 years ago
  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. PROJECT_NAME ?= raylib_examples
  26. RAYLIB_VERSION ?= 1.9.7
  27. RAYLIB_API_VERSION ?= 1
  28. RAYLIB_PATH ?= ..
  29. # Define default options
  30. # One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  31. PLATFORM ?= PLATFORM_DESKTOP
  32. # Locations of your newly installed library and associated headers. See ../src/Makefile
  33. # On Linux, if you have installed raylib but cannot compile the examples, check that
  34. # the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
  35. # To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
  36. # To enable compile-time linking to a special version of libraylib.so, change these variables here.
  37. # To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
  38. # If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
  39. # the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
  40. # RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
  41. DESTDIR ?= /usr/local
  42. RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
  43. # RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files.
  44. RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
  45. # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
  46. RAYLIB_LIBTYPE ?= STATIC
  47. # Build mode for project: DEBUG or RELEASE
  48. RAYLIB_BUILD_MODE ?= RELEASE
  49. # Use external GLFW library instead of rglfw module
  50. # TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
  51. USE_EXTERNAL_GLFW ?= FALSE
  52. # Use Wayland display server protocol on Linux desktop
  53. # by default it uses X11 windowing system
  54. USE_WAYLAND_DISPLAY ?= FALSE
  55. # NOTE: On PLATFORM_WEB OpenAL Soft backend is used by default (check raylib/src/Makefile)
  56. # Determine PLATFORM_OS in case PLATFORM_DESKTOP selected
  57. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  58. # No uname.exe on MinGW!, but OS=Windows_NT on Windows!
  59. # ifeq ($(UNAME),Msys) -> Windows
  60. ifeq ($(OS),Windows_NT)
  61. PLATFORM_OS=WINDOWS
  62. else
  63. UNAMEOS=$(shell uname)
  64. ifeq ($(UNAMEOS),Linux)
  65. PLATFORM_OS=LINUX
  66. endif
  67. ifeq ($(UNAMEOS),FreeBSD)
  68. PLATFORM_OS=FREEBSD
  69. endif
  70. ifeq ($(UNAMEOS),Darwin)
  71. PLATFORM_OS=OSX
  72. endif
  73. endif
  74. endif
  75. ifeq ($(PLATFORM),PLATFORM_RPI)
  76. UNAMEOS=$(shell uname)
  77. ifeq ($(UNAMEOS),Linux)
  78. PLATFORM_OS=LINUX
  79. endif
  80. endif
  81. # RAYLIB_PATH adjustment for different platforms.
  82. # If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
  83. # Required for ldconfig or other tools that do not perform path expansion.
  84. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  85. ifeq ($(PLATFORM_OS),LINUX)
  86. RAYLIB_PREFIX ?= ..
  87. RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
  88. endif
  89. endif
  90. # Default path for raylib on Raspberry Pi, if installed in different path, update it!
  91. # This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
  92. # TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
  93. ifeq ($(PLATFORM),PLATFORM_RPI)
  94. RAYLIB_PATH ?= /home/pi/raylib
  95. endif
  96. ifeq ($(PLATFORM),PLATFORM_WEB)
  97. # Emscripten required variables
  98. EMSDK_PATH = C:/emsdk
  99. EMSCRIPTEN_VERSION = 1.37.28
  100. CLANG_VERSION=e1.37.28_64bit
  101. PYTHON_VERSION=2.7.5.3_64bit
  102. NODE_VERSION=4.1.1_64bit
  103. 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)
  104. EMSCRIPTEN=$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION)
  105. endif
  106. # Define raylib release directory for compiled library.
  107. # RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version.
  108. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  109. ifeq ($(PLATFORM_OS),WINDOWS)
  110. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/win32/mingw32
  111. endif
  112. ifeq ($(PLATFORM_OS),LINUX)
  113. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/linux
  114. endif
  115. ifeq ($(PLATFORM_OS),OSX)
  116. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx
  117. endif
  118. ifeq ($(PLATFORM_OS),FREEBSD)
  119. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd
  120. endif
  121. endif
  122. ifeq ($(PLATFORM),PLATFORM_RPI)
  123. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/rpi
  124. endif
  125. ifeq ($(PLATFORM),PLATFORM_WEB)
  126. RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/html5
  127. endif
  128. # EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
  129. # into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
  130. # so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
  131. # without formal installation from ../src/Makefile. It aids portability and is useful if you have
  132. # multiple versions of raylib, have raylib installed to a non-standard location, or want to
  133. # bundle libraylib.so with your game. Change it to your liking.
  134. # Note: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
  135. # The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
  136. # Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  137. # To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
  138. # To see which libraries a built example is linking to, ldd core/core_basic_window;
  139. # Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
  140. EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH)
  141. # Define default C compiler: gcc
  142. # NOTE: define g++ compiler if using C++
  143. CC = gcc
  144. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  145. ifeq ($(PLATFORM_OS),OSX)
  146. # OSX default compiler
  147. CC = clang
  148. endif
  149. ifeq ($(PLATFORM_OS),FREEBSD)
  150. # FreeBSD default compiler
  151. CC = clang
  152. endif
  153. endif
  154. ifeq ($(PLATFORM),PLATFORM_RPI)
  155. ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
  156. # Define RPI cross-compiler
  157. #CC = armv6j-hardfloat-linux-gnueabi-gcc
  158. CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
  159. endif
  160. endif
  161. ifeq ($(PLATFORM),PLATFORM_WEB)
  162. # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
  163. # HTML5 emscripten compiler
  164. CC = emcc
  165. endif
  166. # Define default make program: Mingw32-make
  167. MAKE = mingw32-make
  168. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  169. ifeq ($(PLATFORM_OS),LINUX)
  170. MAKE = make
  171. endif
  172. endif
  173. # Define compiler flags:
  174. # -O1 defines optimization level
  175. # -g enable debugging
  176. # -s strip unnecessary data from build
  177. # -Wall turns on most, but not all, compiler warnings
  178. # -std=c99 defines C language mode (standard C from 1999 revision)
  179. # -std=gnu99 defines C language mode (GNU C from 1999 revision)
  180. # -Wno-missing-braces ignore invalid warning (GCC bug 53119)
  181. # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
  182. CFLAGS += -O1 -s -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
  183. # Additional flags for compiler (if desired)
  184. #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
  185. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  186. ifeq ($(PLATFORM_OS),WINDOWS)
  187. # resources file contains windows exe icon
  188. # -Wl,--subsystem,windows hides the console window
  189. CFLAGS += $(RAYLIB_PATH)/src/resources -Wl,--subsystem,windows
  190. endif
  191. ifeq ($(PLATFORM_OS),LINUX)
  192. ifeq ($(RAYLIB_BUILD_MODE),DEBUG)
  193. CFLAGS += -g
  194. #CC = clang
  195. endif
  196. ifeq ($(RAYLIB_LIBTYPE),STATIC)
  197. CFLAGS += -no-pie -D_DEFAULT_SOURCE
  198. endif
  199. ifeq ($(RAYLIB_LIBTYPE),SHARED)
  200. # Explicitly enable runtime link to libraylib.so
  201. CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  202. endif
  203. endif
  204. endif
  205. ifeq ($(PLATFORM),PLATFORM_RPI)
  206. CFLAGS += -std=gnu99
  207. endif
  208. ifeq ($(PLATFORM),PLATFORM_WEB)
  209. # -O2 # if used, also set --memory-init-file 0
  210. # --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
  211. # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
  212. # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
  213. # -s USE_PTHREADS=1 # multithreading support
  214. # -s WASM=1 # support Web Assembly (https://github.com/kripken/emscripten/wiki/WebAssembly)
  215. # --preload-file resources # specify a resources folder for data compilation
  216. CFLAGS += -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 --profiling --preload-file resources
  217. # Define a custom shell .html and output extension
  218. CFLAGS += --shell-file $(RAYLIB_PATH)\templates\web_shell\shell.html
  219. EXT = .html
  220. endif
  221. # Define include paths for required headers.
  222. # Precedence: immediately local, raysan5 provided sources
  223. # NOTE: Several external required libraries (stb and others)
  224. INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/release/include -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
  225. # Define additional directories containing required header files
  226. ifeq ($(PLATFORM),PLATFORM_RPI)
  227. # RPI required libraries
  228. INCLUDE_PATHS += -I/opt/vc/include
  229. INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
  230. INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
  231. endif
  232. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  233. ifeq ($(PLATFORM_OS),FREEBSD)
  234. # Consider -L$(RAYLIB_H_INSTALL_PATH)
  235. INCLUDE_PATHS += -I/usr/local/include
  236. endif
  237. ifeq ($(PLATFORM_OS),LINUX)
  238. # Reset everything.
  239. # Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include
  240. INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external
  241. endif
  242. endif
  243. # Define library paths containing required libs.
  244. # Precedence: immediately local, then raysan5 provided libs
  245. LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
  246. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  247. ifeq ($(PLATFORM_OS),FREEBSD)
  248. # Consider -L$(RAYLIB_INSTALL_PATH)
  249. LDFLAGS += -L. -Lsrc -L/usr/local/lib
  250. endif
  251. ifeq ($(PLATFORM_OS),LINUX)
  252. # Reset everything.
  253. # Precedence: immediately local, installed version, raysan5 provided libs
  254. LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
  255. endif
  256. endif
  257. ifeq ($(PLATFORM),PLATFORM_RPI)
  258. LDFLAGS += -L/opt/vc/lib
  259. endif
  260. # Define any libraries required on linking
  261. # if you want to link libraries (libname.so or libname.a), use the -lname
  262. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  263. ifeq ($(PLATFORM_OS),WINDOWS)
  264. # Libraries for Windows desktop compilation
  265. LDLIBS = -lraylib -lopengl32 -lgdi32
  266. # Required for physac examples
  267. LDLIBS += -static -lpthread
  268. endif
  269. ifeq ($(PLATFORM_OS),LINUX)
  270. # Libraries for Debian GNU/Linux desktop compiling
  271. # NOTE: Required packages: libegl1-mesa-dev
  272. LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
  273. # On X11 requires also below libraries
  274. LDLIBS += -lX11
  275. # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
  276. #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  277. # On Wayland windowing system, additional libraries requires
  278. ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
  279. LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
  280. endif
  281. # Explicit link to libc
  282. ifeq ($(RAYLIB_LIBTYPE),SHARED)
  283. LDLIBS += -lc
  284. endif
  285. endif
  286. ifeq ($(PLATFORM_OS),OSX)
  287. # Libraries for OSX 10.9 desktop compiling
  288. # NOTE: Required packages: libopenal-dev libegl1-mesa-dev
  289. LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa
  290. endif
  291. ifeq ($(PLATFORM_OS),FREEBSD)
  292. # Libraries for FreeBSD desktop compiling
  293. # NOTE: Required packages: mesa-libs
  294. LDLIBS = -lraylib -lGL -lpthread -lm
  295. # On XWindow requires also below libraries
  296. LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  297. endif
  298. ifeq ($(USE_EXTERNAL_GLFW),TRUE)
  299. # NOTE: It could require additional packages installed: libglfw3-dev
  300. LDLIBS += -lglfw
  301. endif
  302. endif
  303. ifeq ($(PLATFORM),PLATFORM_RPI)
  304. # Libraries for Raspberry Pi compiling
  305. # NOTE: Required packages: libasound2-dev (ALSA)
  306. LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
  307. endif
  308. ifeq ($(PLATFORM),PLATFORM_WEB)
  309. # Libraries for web (HTML5) compiling
  310. LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
  311. endif
  312. # Define all object files required
  313. EXAMPLES = \
  314. core/core_basic_window \
  315. core/core_input_keys \
  316. core/core_input_mouse \
  317. core/core_mouse_wheel \
  318. core/core_input_gamepad \
  319. core/core_random_values \
  320. core/core_color_select \
  321. core/core_drop_files \
  322. core/core_storage_values \
  323. core/core_gestures_detection \
  324. core/core_3d_mode \
  325. core/core_3d_picking \
  326. core/core_3d_camera_free \
  327. core/core_3d_camera_first_person \
  328. core/core_2d_camera \
  329. core/core_world_screen \
  330. core/core_vr_simulator \
  331. shapes/shapes_logo_raylib \
  332. shapes/shapes_basic_shapes \
  333. shapes/shapes_colors_palette \
  334. shapes/shapes_logo_raylib_anim \
  335. shapes/shapes_lines_bezier \
  336. textures/textures_logo_raylib \
  337. textures/textures_image_loading \
  338. textures/textures_rectangle \
  339. textures/textures_srcrec_dstrec \
  340. textures/textures_to_image \
  341. textures/textures_raw_data \
  342. textures/textures_particles_blending \
  343. textures/textures_image_processing \
  344. textures/textures_image_drawing \
  345. textures/textures_image_generation \
  346. textures/textures_image_text \
  347. text/text_sprite_fonts \
  348. text/text_bmfont_ttf \
  349. text/text_raylib_fonts \
  350. text/text_format_text \
  351. text/text_writing_anim \
  352. text/text_ttf_loading \
  353. text/text_bmfont_unordered \
  354. text/text_input_box \
  355. models/models_geometric_shapes \
  356. models/models_box_collisions \
  357. models/models_billboard \
  358. models/models_obj_loading \
  359. models/models_heightmap \
  360. models/models_cubicmap \
  361. models/models_mesh_picking \
  362. models/models_mesh_generation \
  363. models/models_material_pbr \
  364. models/models_skybox \
  365. models/models_yaw_pitch_roll \
  366. shaders/shaders_model_shader \
  367. shaders/shaders_shapes_textures \
  368. shaders/shaders_custom_uniform \
  369. shaders/shaders_postprocessing \
  370. audio/audio_sound_loading \
  371. audio/audio_music_stream \
  372. audio/audio_module_playing \
  373. audio/audio_raw_stream \
  374. physac/physics_demo \
  375. physac/physics_friction \
  376. physac/physics_movement \
  377. physac/physics_restitution \
  378. physac/physics_shatter \
  379. CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST))
  380. # Default target entry
  381. all: $(EXAMPLES)
  382. # Generic compilation pattern
  383. # NOTE: Examples must be ready for Android compilation!
  384. %: %.c
  385. ifeq ($(PLATFORM),PLATFORM_ANDROID)
  386. $(MAKE) -f Makefile.Android PROJECT_NAME=$@ PROJECT_SOURCE_FILES=$<
  387. else
  388. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
  389. endif
  390. # fix dylib install path name for each executable (MAC)
  391. fix_dylib:
  392. ifeq ($(PLATFORM_OS),OSX)
  393. 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
  394. endif
  395. # Clean everything
  396. clean:
  397. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  398. ifeq ($(PLATFORM_OS),WINDOWS)
  399. del *.o *.exe /s
  400. endif
  401. ifeq ($(PLATFORM_OS),LINUX)
  402. 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 -fv
  403. endif
  404. ifeq ($(PLATFORM_OS),OSX)
  405. find . -type f -perm +ugo+x -delete
  406. rm -f *.o
  407. endif
  408. endif
  409. ifeq ($(PLATFORM),PLATFORM_RPI)
  410. find . -type f -executable -delete
  411. rm -fv *.o
  412. endif
  413. ifeq ($(PLATFORM),PLATFORM_WEB)
  414. del *.o *.html *.js
  415. endif
  416. @echo Cleaning done