Makefile 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. #**************************************************************************************************
  2. #
  3. # raylib makefile for Desktop platform and HTML5
  4. #
  5. # Copyright (c) 2019 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. RAYLIB_PATH ?= ../../raylib
  26. RAYGUI_PATH ?= ../src
  27. # Define default options
  28. # One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  29. PLATFORM ?= PLATFORM_DESKTOP
  30. # Locations of your newly installed library and associated headers. See ../src/Makefile
  31. # On Linux, if you have installed raylib but cannot compile the examples, check that
  32. # the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
  33. # To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
  34. # To enable compile-time linking to a special version of libraylib.so, change these variables here.
  35. # To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
  36. # If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
  37. # the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
  38. # RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
  39. DESTDIR ?= /usr/local
  40. RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
  41. # RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files.
  42. RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
  43. # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
  44. RAYLIB_LIBTYPE ?= STATIC
  45. # Build mode for project: DEBUG or RELEASE
  46. BUILD_MODE ?= RELEASE
  47. # Use external GLFW library instead of rglfw module
  48. # TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
  49. USE_EXTERNAL_GLFW ?= FALSE
  50. # Use Wayland display server protocol on Linux desktop
  51. # by default it uses X11 windowing system
  52. USE_WAYLAND_DISPLAY ?= FALSE
  53. # Determine PLATFORM_OS in case PLATFORM_DESKTOP selected
  54. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  55. # No uname.exe on MinGW!, but OS=Windows_NT on Windows!
  56. # ifeq ($(UNAME),Msys) -> Windows
  57. ifeq ($(OS),Windows_NT)
  58. PLATFORM_OS=WINDOWS
  59. else
  60. UNAMEOS=$(shell uname)
  61. ifeq ($(UNAMEOS),Linux)
  62. PLATFORM_OS=LINUX
  63. endif
  64. ifeq ($(UNAMEOS),FreeBSD)
  65. PLATFORM_OS=BSD
  66. endif
  67. ifeq ($(UNAMEOS),OpenBSD)
  68. PLATFORM_OS=BSD
  69. endif
  70. ifeq ($(UNAMEOS),NetBSD)
  71. PLATFORM_OS=BSD
  72. endif
  73. ifeq ($(UNAMEOS),DragonFly)
  74. PLATFORM_OS=BSD
  75. endif
  76. ifeq ($(UNAMEOS),Darwin)
  77. PLATFORM_OS=OSX
  78. endif
  79. endif
  80. endif
  81. ifeq ($(PLATFORM),PLATFORM_RPI)
  82. UNAMEOS=$(shell uname)
  83. ifeq ($(UNAMEOS),Linux)
  84. PLATFORM_OS=LINUX
  85. endif
  86. endif
  87. # RAYLIB_PATH adjustment for different platforms.
  88. # If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
  89. # Required for ldconfig or other tools that do not perform path expansion.
  90. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  91. ifeq ($(PLATFORM_OS),LINUX)
  92. RAYLIB_PREFIX ?= ..
  93. RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
  94. endif
  95. endif
  96. # Default path for raylib on Raspberry Pi, if installed in different path, update it!
  97. # This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
  98. # TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
  99. ifeq ($(PLATFORM),PLATFORM_RPI)
  100. RAYLIB_PATH ?= /home/pi/raylib
  101. endif
  102. ifeq ($(PLATFORM),PLATFORM_WEB)
  103. # Emscripten required variables
  104. EMSDK_PATH ?= C:/raylib/emsdk
  105. EMSCRIPTEN_VERSION ?= 1.38.32
  106. CLANG_VERSION = e$(EMSCRIPTEN_VERSION)_64bit
  107. PYTHON_VERSION = 2.7.13.1_64bit\python-2.7.13.amd64
  108. NODE_VERSION = 8.9.1_64bit
  109. 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)
  110. EMSCRIPTEN = $(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION)
  111. endif
  112. # Define raylib release directory for compiled library.
  113. # RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version
  114. RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
  115. # EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
  116. # into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
  117. # so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
  118. # without formal installation from ../src/Makefile. It aids portability and is useful if you have
  119. # multiple versions of raylib, have raylib installed to a non-standard location, or want to
  120. # bundle libraylib.so with your game. Change it to your liking.
  121. # NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
  122. # The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
  123. # Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  124. # To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
  125. # To see which libraries a built example is linking to, ldd core/core_basic_window;
  126. # Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
  127. EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH)
  128. # Define default C compiler: gcc
  129. # NOTE: define g++ compiler if using C++
  130. CC = gcc
  131. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  132. ifeq ($(PLATFORM_OS),OSX)
  133. # OSX default compiler
  134. CC = clang
  135. endif
  136. ifeq ($(PLATFORM_OS),BSD)
  137. # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
  138. CC = clang
  139. endif
  140. endif
  141. ifeq ($(PLATFORM),PLATFORM_RPI)
  142. ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
  143. # Define RPI cross-compiler
  144. #CC = armv6j-hardfloat-linux-gnueabi-gcc
  145. CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
  146. endif
  147. endif
  148. ifeq ($(PLATFORM),PLATFORM_WEB)
  149. # HTML5 emscripten compiler
  150. # WARNING: To compile to HTML5, code must be redesigned
  151. # to use emscripten.h and emscripten_set_main_loop()
  152. CC = emcc
  153. endif
  154. # Define default make program: Mingw32-make
  155. MAKE = mingw32-make
  156. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  157. ifeq ($(PLATFORM_OS),LINUX)
  158. MAKE = make
  159. endif
  160. endif
  161. # Define compiler flags:
  162. # -O1 defines optimization level
  163. # -g include debug information on compilation
  164. # -s strip unnecessary data from build
  165. # -Wall turns on most, but not all, compiler warnings
  166. # -std=c99 defines C language mode (standard C from 1999 revision)
  167. # -std=gnu99 defines C language mode (GNU C from 1999 revision)
  168. # -Wno-missing-braces ignore invalid warning (GCC bug 53119)
  169. # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
  170. CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
  171. ifeq ($(BUILD_MODE),DEBUG)
  172. CFLAGS += -g
  173. endif
  174. ifeq ($(RAYLIB_BUILD_MODE),RELEASE)
  175. CFLAGS += -O1 -s
  176. endif
  177. # Additional flags for compiler (if desired)
  178. #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
  179. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  180. ifeq ($(PLATFORM_OS),WINDOWS)
  181. # resource file contains windows executable icon and properties
  182. # -Wl,--subsystem,windows hides the console window
  183. CFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data -Wl,--subsystem,windows
  184. endif
  185. ifeq ($(PLATFORM_OS),LINUX)
  186. ifeq ($(RAYLIB_LIBTYPE),STATIC)
  187. CFLAGS += -D_DEFAULT_SOURCE
  188. endif
  189. ifeq ($(RAYLIB_LIBTYPE),SHARED)
  190. # Explicitly enable runtime link to libraylib.so
  191. CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  192. endif
  193. endif
  194. endif
  195. ifeq ($(PLATFORM),PLATFORM_RPI)
  196. CFLAGS += -std=gnu99
  197. endif
  198. ifeq ($(PLATFORM),PLATFORM_WEB)
  199. # -Os # size optimization
  200. # -O2 # optimization level 2, if used, also set --memory-init-file 0
  201. # -sUSE_GLFW=3 # Use glfw3 library (context/input management)
  202. # -sALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL!
  203. # -sTOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) (67108864 = 64MB)
  204. # -sUSE_PTHREADS=1 # multithreading support
  205. # -sWASM=0 # disable Web Assembly, emitted by default
  206. # -sASYNCIFY # lets synchronous C/C++ code interact with asynchronous JS
  207. # -sFORCE_FILESYSTEM=1 # force filesystem to load/save files data
  208. # -sASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
  209. # -sMINIFY_HTML=0 # minify generated html from shell.html
  210. # --profiling # include information for code profiling
  211. # --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
  212. # --preload-file resources # specify a resources folder for data compilation
  213. # --source-map-base # allow debugging in browser with source map
  214. # --shell-file shell.html # define a custom shell .html and output extension
  215. CFLAGS += -Os -sUSE_GLFW=3 -sFORCE_FILESYSTEM=1 -sASYNCIFY --preload-file $(dir $<)resources@resources -sMINIFY_HTML=0
  216. ifeq ($(BUILD_MODE), DEBUG)
  217. CFLAGS += -sASSERTIONS=1 --profiling
  218. endif
  219. # NOTE: Simple raylib examples are compiled to be interpreter by emterpreter, that way,
  220. # we can compile same code for ALL platforms with no change required, but, working on bigger
  221. # projects, code needs to be refactored to avoid a blocking while() loop, moving Update and Draw
  222. # logic to a self contained function: UpdateDrawFrame(), check core_basic_window_web.c for reference.
  223. # Define a custom shell .html and output extension
  224. CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
  225. EXT = .html
  226. endif
  227. # Define include paths for required headers
  228. # NOTE: Several external required libraries (stb and others)
  229. INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external -I$(RAYGUI_PATH)
  230. # Define additional directories containing required header files
  231. ifeq ($(PLATFORM),PLATFORM_RPI)
  232. # RPI required libraries
  233. INCLUDE_PATHS += -I/opt/vc/include
  234. INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
  235. INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
  236. endif
  237. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  238. ifeq ($(PLATFORM_OS),BSD)
  239. # Consider -L$(RAYLIB_H_INSTALL_PATH)
  240. INCLUDE_PATHS += -I/usr/local/include
  241. endif
  242. ifeq ($(PLATFORM_OS),LINUX)
  243. # Reset everything.
  244. # Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include
  245. INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external
  246. endif
  247. endif
  248. # Define library paths containing required libs.
  249. LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
  250. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  251. ifeq ($(PLATFORM_OS),BSD)
  252. # Consider -L$(RAYLIB_INSTALL_PATH)
  253. LDFLAGS += -L. -Lsrc -L/usr/local/lib
  254. ifeq ($(shell uname),OpenBSD)
  255. LDFLAGS += -L/usr/X11R6/lib
  256. endif
  257. endif
  258. ifeq ($(PLATFORM_OS),LINUX)
  259. # Reset everything.
  260. # Precedence: immediately local, installed version, raysan5 provided libs
  261. LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH)
  262. endif
  263. endif
  264. ifeq ($(PLATFORM),PLATFORM_RPI)
  265. LDFLAGS += -L/opt/vc/lib
  266. endif
  267. # Define any libraries required on linking
  268. # if you want to link libraries (libname.so or libname.a), use the -lname
  269. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  270. ifeq ($(PLATFORM_OS),WINDOWS)
  271. # Libraries for Windows desktop compilation
  272. # NOTE: WinMM library required to set high-res timer resolution
  273. LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
  274. # Required for physac examples
  275. LDLIBS += -static -lpthread
  276. endif
  277. ifeq ($(PLATFORM_OS),LINUX)
  278. # Libraries for Debian GNU/Linux desktop compiling
  279. # NOTE: Required packages: libegl1-mesa-dev
  280. LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
  281. # On X11 requires also below libraries
  282. LDLIBS += -lX11
  283. # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
  284. #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  285. # On Wayland windowing system, additional libraries requires
  286. ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
  287. LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
  288. endif
  289. # Explicit link to libc
  290. ifeq ($(RAYLIB_LIBTYPE),SHARED)
  291. LDLIBS += -lc
  292. endif
  293. endif
  294. ifeq ($(PLATFORM_OS),OSX)
  295. # Libraries for OSX 10.9 desktop compiling
  296. # NOTE: Required packages: libopenal-dev libegl1-mesa-dev
  297. LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
  298. endif
  299. ifeq ($(PLATFORM_OS),BSD)
  300. # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
  301. # NOTE: Required packages: mesa-libs
  302. LDLIBS = -lraylib -lGL -lpthread -lm
  303. # On XWindow requires also below libraries
  304. LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  305. endif
  306. ifeq ($(USE_EXTERNAL_GLFW),TRUE)
  307. # NOTE: It could require additional packages installed: libglfw3-dev
  308. LDLIBS += -lglfw
  309. endif
  310. endif
  311. ifeq ($(PLATFORM),PLATFORM_RPI)
  312. # Libraries for Raspberry Pi compiling
  313. # NOTE: Required packages: libasound2-dev (ALSA)
  314. LDLIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -ldrm -lgbm -ldl
  315. endif
  316. ifeq ($(PLATFORM),PLATFORM_WEB)
  317. # Libraries for web (HTML5) compiling
  318. LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
  319. endif
  320. # Define all source files required
  321. EXAMPLES = \
  322. controls_test_suite/controls_test_suite \
  323. custom_file_dialog/custom_file_dialog \
  324. custom_input_box/custom_input_box\
  325. image_exporter/image_exporter \
  326. image_importer_raw/image_importer_raw \
  327. property_list/property_list \
  328. portable_window/portable_window \
  329. scroll_panel/scroll_panel \
  330. style_selector/style_selector \
  331. custom_sliders/custom_sliders \
  332. animation_curve/animation_curve \
  333. floating_window/floating_window \
  334. CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST))
  335. # Default target entry
  336. all: $(EXAMPLES)
  337. # Generic compilation pattern
  338. # NOTE: Examples must be ready for Android compilation!
  339. %: %.c
  340. $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
  341. # Clean everything
  342. clean:
  343. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  344. ifeq ($(PLATFORM_OS),WINDOWS)
  345. del *.o *.exe /s
  346. endif
  347. ifeq ($(PLATFORM_OS),LINUX)
  348. rm -f $(EXAMPLES)
  349. endif
  350. ifeq ($(PLATFORM_OS),OSX)
  351. find . -type f -perm +ugo+x -delete
  352. rm -f *.o
  353. endif
  354. ifeq ($(shell uname),OpenBSD)
  355. find . -type f -perm 0755 -delete
  356. rm -f *.o
  357. endif
  358. endif
  359. ifeq ($(PLATFORM),PLATFORM_RPI)
  360. find . -type f -executable -delete
  361. rm -fv *.o
  362. endif
  363. ifeq ($(PLATFORM),PLATFORM_WEB)
  364. del *.o *.html *.js
  365. endif
  366. @echo Cleaning done