Guest User

Makefile

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