Advertisement
imposerfromamongsus

Untitled

Nov 30th, 2021
1,464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 16.47 KB | None | 0 0
  1. #**************************************************************************************************
  2. #
  3. #   raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
  4. #
  5. #   Copyright (c) 2013-2021 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.  
  24. .PHONY: all clean
  25.  
  26. # Define required variables
  27. PROJECT_NAME       ?= metaballs
  28. RAYLIB_VERSION     ?= 3.8.0
  29. RAYLIB_PATH        ?= /home/user
  30.  
  31. # Define default options
  32.  
  33. # One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  34. PLATFORM           ?= PLATFORM_WEB
  35.  
  36. # Locations of your newly installed library and associated headers.
  37. # On Linux, if you have installed raylib but cannot compile the examples, check that
  38. # the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
  39. # To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
  40. # To enable compile-time linking to a special version of libraylib.so, change these variables here.
  41. # To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
  42. # If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
  43. # the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
  44.  
  45. # Desired full path to libraylib. No relative paths.
  46. DESTDIR               ?= /usr/local
  47. RAYLIB_INSTALL_PATH   ?= $(DESTDIR)/lib
  48.  
  49. # raylib header and associated source files
  50. RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
  51.  
  52. # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
  53. RAYLIB_LIBTYPE        ?= SHARED
  54.  
  55. # Build mode for project: DEBUG or RELEASE
  56. BUILD_MODE            ?= RELEASE
  57.  
  58. # Use external GLFW library instead of rglfw module
  59. # TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
  60. USE_EXTERNAL_GLFW     ?= FALSE
  61.  
  62. # Use Wayland display server protocol on Linux desktop
  63. # by default it uses X11 windowing system
  64. USE_WAYLAND_DISPLAY   ?= FALSE
  65.  
  66. # Determine PLATFORM_OS in case PLATFORM_DESKTOP selected
  67. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  68.     # No uname.exe on MinGW!, but OS=Windows_NT on Windows!
  69.     # ifeq ($(UNAME),Msys) -> Windows
  70.     ifeq ($(OS),Windows_NT)
  71.         PLATFORM_OS=WINDOWS
  72.     else
  73.         UNAMEOS=$(shell uname)
  74.         ifeq ($(UNAMEOS),Linux)
  75.             PLATFORM_OS=LINUX
  76.         endif
  77.         ifeq ($(UNAMEOS),FreeBSD)
  78.             PLATFORM_OS=BSD
  79.         endif
  80.         ifeq ($(UNAMEOS),OpenBSD)
  81.             PLATFORM_OS=BSD
  82.         endif
  83.         ifeq ($(UNAMEOS),NetBSD)
  84.             PLATFORM_OS=BSD
  85.         endif
  86.         ifeq ($(UNAMEOS),DragonFly)
  87.             PLATFORM_OS=BSD
  88.         endif
  89.         ifeq ($(UNAMEOS),Darwin)
  90.             PLATFORM_OS=OSX
  91.         endif
  92.     endif
  93. endif
  94. ifeq ($(PLATFORM),PLATFORM_RPI)
  95.     UNAMEOS=$(shell uname)
  96.     ifeq ($(UNAMEOS),Linux)
  97.         PLATFORM_OS=LINUX
  98.     endif
  99. endif
  100. ifeq ($(PLATFORM),PLATFORM_DRM)
  101.     UNAMEOS=$(shell uname)
  102.     ifeq ($(UNAMEOS),Linux)
  103.         PLATFORM_OS=LINUX
  104.     endif
  105. endif
  106.  
  107. # RAYLIB_PATH adjustment for different platforms.
  108. # If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
  109. # Required for ldconfig or other tools that do not perform path expansion.
  110. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  111.     ifeq ($(PLATFORM_OS),LINUX)
  112.         RAYLIB_PREFIX ?= ..
  113.         RAYLIB_PATH    = $(realpath $(RAYLIB_PREFIX))
  114.     endif
  115. endif
  116. # Default path for raylib on Raspberry Pi, if installed in different path, update it!
  117. # This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
  118. # TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
  119. ifeq ($(PLATFORM),PLATFORM_RPI)
  120.     RAYLIB_PATH        ?= /home/pi/raylib
  121. endif
  122. ifeq ($(PLATFORM),PLATFORM_DRM)
  123.     RAYLIB_PATH        ?= /home/pi/raylib
  124. endif
  125.  
  126. ifeq ($(PLATFORM),PLATFORM_WEB)
  127.     # Emscripten required variables
  128.     EMSDK_PATH         ?= /home/user/emsdk/
  129.     EMSCRIPTEN_PATH    ?= $(EMSDK_PATH)/upstream/emscripten
  130.     CLANG_PATH          = $(EMSDK_PATH)/upstream/bin
  131.     PYTHON_PATH         = $(EMSDK_PATH)/python/3.9.2-1_64bit
  132.     NODE_PATH           = $(EMSDK_PATH)/node/14.15.5_64bit/bin
  133.     export PATH         = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH)
  134. endif
  135.  
  136. # Define raylib release directory for compiled library.
  137. # RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version
  138. RAYLIB_RELEASE_PATH     ?= $(RAYLIB_PATH)/src
  139.  
  140. # EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
  141. # into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
  142. # so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
  143. # without formal installation from ../src/Makefile. It aids portability and is useful if you have
  144. # multiple versions of raylib, have raylib installed to a non-standard location, or want to
  145. # bundle libraylib.so with your game. Change it to your liking.
  146. # NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
  147. # The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
  148. # Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  149. # To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
  150. # To see which libraries a built example is linking to, ldd core/core_basic_window;
  151. # Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
  152. EXAMPLE_RUNTIME_PATH   ?= $(RAYLIB_RELEASE_PATH)
  153.  
  154. # Define default C compiler: gcc
  155. # NOTE: define g++ compiler if using C++
  156. CC = gcc
  157.  
  158. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  159.     ifeq ($(PLATFORM_OS),OSX)
  160.         # OSX default compiler
  161.         CC = clang
  162.     endif
  163.     ifeq ($(PLATFORM_OS),BSD)
  164.         # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
  165.         CC = clang
  166.     endif
  167. endif
  168. ifeq ($(PLATFORM),PLATFORM_RPI)
  169.     ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
  170.         # Define RPI cross-compiler
  171.         #CC = armv6j-hardfloat-linux-gnueabi-gcc
  172.         CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
  173.     endif
  174. endif
  175. ifeq ($(PLATFORM),PLATFORM_WEB)
  176.     # HTML5 emscripten compiler
  177.     # WARNING: To compile to HTML5, code must be redesigned
  178.     # to use emscripten.h and emscripten_set_main_loop()
  179.     CC = emcc
  180. endif
  181.  
  182. # Define default make program
  183. MAKE    ?= make
  184.  
  185. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  186.     ifeq ($(PLATFORM_OS),WINDOWS)
  187.         MAKE = mingw32-make
  188.     endif
  189. endif
  190. ifeq ($(PLATFORM),PLATFORM_ANDROID)
  191.     MAKE = mingw32-make
  192. endif
  193.  
  194. # Define compiler flags:
  195. #  -O1                  defines optimization level
  196. #  -g                   include debug information on compilation
  197. #  -s                   strip unnecessary data from build
  198. #  -Wall                turns on most, but not all, compiler warnings
  199. #  -std=c99             defines C language mode (standard C from 1999 revision)
  200. #  -std=gnu99           defines C language mode (GNU C from 1999 revision)
  201. #  -Wno-missing-braces  ignore invalid warning (GCC bug 53119)
  202. #  -D_DEFAULT_SOURCE    use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
  203. CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
  204.  
  205. ifeq ($(BUILD_MODE),DEBUG)
  206.     CFLAGS += -g
  207.     ifeq ($(PLATFORM),PLATFORM_WEB)
  208.         CFLAGS += -s ASSERTIONS=1 --profiling
  209.     endif
  210. else
  211.     ifeq ($(PLATFORM),PLATFORM_WEB)
  212.         CFLAGS += -Os
  213.     else
  214.         CFLAGS += -s -O1
  215.     endif
  216. endif
  217.  
  218. # Additional flags for compiler (if desired)
  219. #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
  220. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  221.     ifeq ($(PLATFORM_OS),LINUX)
  222.         ifeq ($(RAYLIB_LIBTYPE),STATIC)
  223.             CFLAGS += -D_DEFAULT_SOURCE
  224.         endif
  225.         ifeq ($(RAYLIB_LIBTYPE),SHARED)
  226.             # Explicitly enable runtime link to libraylib.so
  227.             CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
  228.         endif
  229.     endif
  230. endif
  231. ifeq ($(PLATFORM),PLATFORM_RPI)
  232.     CFLAGS += -std=gnu99
  233. endif
  234. ifeq ($(PLATFORM),PLATFORM_DRM)
  235.     CFLAGS += -std=gnu99 -DEGL_NO_X11
  236. endif
  237. ifeq ($(PLATFORM),PLATFORM_WEB)
  238.     # -Os                        # size optimization
  239.     # -O2                        # optimization level 2, if used, also set --memory-init-file 0
  240.     # -s USE_GLFW=3              # Use glfw3 library (context/input management)
  241.     # -s ALLOW_MEMORY_GROWTH=1   # to allow memory resizing -> WARNING: Audio buffers could FAIL!
  242.     # -s TOTAL_MEMORY=16777216   # to specify heap memory size (default = 16MB) (67108864 = 64MB)
  243.     # -s USE_PTHREADS=1          # multithreading support
  244.     # -s WASM=0                  # disable Web Assembly, emitted by default
  245.     # -s ASYNCIFY                # lets synchronous C/C++ code interact with asynchronous JS
  246.     # -s FORCE_FILESYSTEM=1      # force filesystem to load/save files data
  247.     # -s ASSERTIONS=1            # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
  248.     # --profiling                # include information for code profiling
  249.     # --memory-init-file 0       # to avoid an external memory initialization code file (.mem)
  250.     # --preload-file resources   # specify a resources folder for data compilation
  251.     # --source-map-base          # allow debugging in browser with source map
  252.     CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --preload-file resources
  253.  
  254.     # Define a custom shell .html and output extension
  255.     CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
  256.     EXT = .html
  257. endif
  258.  
  259. # Define include paths for required headers
  260. # NOTE: Several external required libraries (stb and others)
  261. INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
  262.  
  263. # Define additional directories containing required header files
  264. ifeq ($(PLATFORM),PLATFORM_RPI)
  265.     # RPI required libraries
  266.     INCLUDE_PATHS += -I/opt/vc/include
  267.     INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
  268.     INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
  269. endif
  270. ifeq ($(PLATFORM),PLATFORM_DRM)
  271.     # DRM required libraries
  272.     INCLUDE_PATHS += -I/usr/include/libdrm
  273. endif
  274. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  275.     ifeq ($(PLATFORM_OS),BSD)
  276.         # Consider -L$(RAYLIB_H_INSTALL_PATH)
  277.         INCLUDE_PATHS += -I/usr/local/include
  278.     endif
  279.     ifeq ($(PLATFORM_OS),LINUX)
  280.         INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
  281.     endif
  282. endif
  283.  
  284. # Define library paths containing required libs.
  285. LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
  286.  
  287. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  288.     ifeq ($(PLATFORM_OS),WINDOWS)
  289.         # resource file contains windows executable icon and properties
  290.         LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
  291.         # -Wl,--subsystem,windows hides the console window
  292.         ifeq ($(BUILD_MODE), RELEASE)
  293.             LDFLAGS += -Wl,--subsystem,windows
  294.         endif
  295.     endif
  296.     ifeq ($(PLATFORM_OS),BSD)
  297.         # Consider -L$(RAYLIB_INSTALL_PATH)
  298.         LDFLAGS += -L. -Lsrc -L/usr/local/lib
  299.     endif
  300.     ifeq ($(PLATFORM_OS),LINUX)
  301.         # Reset everything.
  302.         # Precedence: immediately local, installed version, raysan5 provided libs
  303.         LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)
  304.     endif
  305. endif
  306.  
  307. ifeq ($(PLATFORM),PLATFORM_RPI)
  308.     LDFLAGS += -L/opt/vc/lib
  309. endif
  310.  
  311. # Define any libraries required on linking
  312. # if you want to link libraries (libname.so or libname.a), use the -lname
  313. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  314.     ifeq ($(PLATFORM_OS),WINDOWS)
  315.         # Libraries for Windows desktop compilation
  316.         # NOTE: WinMM library required to set high-res timer resolution
  317.         LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
  318.         # Required for physac examples
  319.         LDLIBS += -static -lpthread
  320.     endif
  321.     ifeq ($(PLATFORM_OS),LINUX)
  322.         # Libraries for Debian GNU/Linux desktop compiling
  323.         # NOTE: Required packages: libegl1-mesa-dev
  324.         LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
  325.  
  326.         # On X11 requires also below libraries
  327.         LDLIBS += -lX11
  328.         # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
  329.         #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  330.  
  331.         # On Wayland windowing system, additional libraries requires
  332.         ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
  333.             LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
  334.         endif
  335.         # Explicit link to libc
  336.         ifeq ($(RAYLIB_LIBTYPE),SHARED)
  337.             LDLIBS += -lc
  338.         endif
  339.     endif
  340.     ifeq ($(PLATFORM_OS),OSX)
  341.         # Libraries for OSX 10.9 desktop compiling
  342.         # NOTE: Required packages: libopenal-dev libegl1-mesa-dev
  343.         LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
  344.     endif
  345.     ifeq ($(PLATFORM_OS),BSD)
  346.         # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
  347.         # NOTE: Required packages: mesa-libs
  348.         LDLIBS = -lraylib -lGL -lpthread -lm
  349.  
  350.         # On XWindow requires also below libraries
  351.         LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
  352.     endif
  353.     ifeq ($(USE_EXTERNAL_GLFW),TRUE)
  354.         # NOTE: It could require additional packages installed: libglfw3-dev
  355.         LDLIBS += -lglfw
  356.     endif
  357. endif
  358. ifeq ($(PLATFORM),PLATFORM_RPI)
  359.     # Libraries for Raspberry Pi compiling
  360.     # NOTE: Required packages: libasound2-dev (ALSA)
  361.     LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
  362. endif
  363. ifeq ($(PLATFORM),PLATFORM_DRM)
  364.     # Libraries for DRM compiling
  365.     # NOTE: Required packages: libasound2-dev (ALSA)
  366.     LDLIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lgbm -ldrm -ldl
  367. endif
  368. ifeq ($(PLATFORM),PLATFORM_WEB)
  369.     # Libraries for web (HTML5) compiling
  370.     LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.a
  371. endif
  372.  
  373. # Define all source files required
  374. PROJECT_SOURCE_FILES ?= \
  375.     raylib_game.c \
  376.     screen_logo.c \
  377.     screen_title.c \
  378.     screen_options.c \
  379.     screen_gameplay.c \
  380.     screen_ending.c
  381.  
  382. # Define all object files from source files
  383. OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES))
  384.  
  385. # For Android platform we call a custom Makefile.Android
  386. ifeq ($(PLATFORM),PLATFORM_ANDROID)
  387.     MAKEFILE_PARAMS = -f Makefile.Android
  388.     export PROJECT_NAME
  389.     export PROJECT_SOURCE_FILES
  390. else
  391.     MAKEFILE_PARAMS = $(PROJECT_NAME)
  392. endif
  393.  
  394. # Default target entry
  395. # NOTE: We call this Makefile target or Makefile.Android target
  396. all:
  397.     which make;
  398.     $(MAKE) $(MAKEFILE_PARAMS)
  399.  
  400. # Project target defined by PROJECT_NAME
  401. $(PROJECT_NAME): $(OBJS)
  402.     $(CC) -o $(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
  403.  
  404. # Compile source files
  405. # NOTE: This pattern will compile every module defined on $(OBJS)
  406. %.o: %.c
  407.     $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
  408.  
  409. # Clean everything
  410. clean:
  411. ifeq ($(PLATFORM),PLATFORM_DESKTOP)
  412.     ifeq ($(PLATFORM_OS),WINDOWS)
  413.         del *.o *.exe /s
  414.     endif
  415.     ifeq ($(PLATFORM_OS),LINUX)
  416.         find . -type f -executable -delete
  417.         rm -fv *.o
  418.     endif
  419.     ifeq ($(PLATFORM_OS),OSX)
  420.         find . -type f -perm +ugo+x -delete
  421.         rm -f *.o
  422.     endif
  423. endif
  424. ifeq ($(PLATFORM),PLATFORM_RPI)
  425.     find . -type f -executable -delete
  426.     rm -fv *.o
  427. endif
  428. ifeq ($(PLATFORM),PLATFORM_DRM)
  429.     find . -type f -executable -delete
  430.     rm -fv *.o
  431. endif
  432. ifeq ($(PLATFORM),PLATFORM_WEB)
  433.     del *.o *.html *.js
  434. endif
  435.     @echo Cleaning done
  436.  
  437.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement