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.

470 lines
18 KiB

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