| 1 | #************************************************************************************************** |
| 2 | # |
| 3 | # raylib makefile for Desktop platforms, Web (Wasm), Raspberry Pi (DRM mode) and Android |
| 4 | # |
| 5 | # Copyright (c) 2013-2026 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 environment variables |
| 27 | #------------------------------------------------------------------------------------------------ |
| 28 | # Define target platform: PLATFORM_DESKTOP, PLATFORM_WEB, PLATFORM_DRM, PLATFORM_ANDROID |
| 29 | PLATFORM ?= PLATFORM_DESKTOP |
| 30 | |
| 31 | # Define project variables |
| 32 | PROJECT_NAME ?= rexm |
| 33 | PROJECT_VERSION ?= 1.0 |
| 34 | PROJECT_BUILD_PATH ?= . |
| 35 | PROJECT_SOURCE_FILES ?= rexm.c |
| 36 | |
| 37 | # raylib library variables |
| 38 | RAYLIB_SRC_PATH ?= ../../src |
| 39 | RAYLIB_INCLUDE_PATH ?= $(RAYLIB_SRC_PATH) |
| 40 | RAYLIB_LIB_PATH ?= $(RAYLIB_SRC_PATH) |
| 41 | |
| 42 | # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll) |
| 43 | RAYLIB_LIBTYPE ?= STATIC |
| 44 | |
| 45 | # Define compiler path on Windows |
| 46 | COMPILER_PATH ?= C:\raylib\w64devkit\bin |
| 47 | |
| 48 | # Build mode for project: DEBUG or RELEASE |
| 49 | BUILD_MODE ?= RELEASE |
| 50 | |
| 51 | # PLATFORM_WEB: Default properties |
| 52 | BUILD_WEB_ASYNCIFY ?= FALSE |
| 53 | BUILD_WEB_SHELL ?= minshell.html |
| 54 | BUILD_WEB_HEAP_SIZE ?= 128MB |
| 55 | BUILD_WEB_STACK_SIZE ?= 1MB |
| 56 | BUILD_WEB_ASYNCIFY_STACK_SIZE ?= 1048576 |
| 57 | BUILD_WEB_RESOURCES ?= FALSE |
| 58 | BUILD_WEB_RESOURCES_PATH ?= resources |
| 59 | |
| 60 | # Determine PLATFORM_OS in case PLATFORM_DESKTOP selected |
| 61 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) |
| 62 | # No uname.exe on MinGW!, but OS=Windows_NT on Windows! |
| 63 | # ifeq ($(UNAME),Msys) -> Windows |
| 64 | ifeq ($(OS),Windows_NT) |
| 65 | PLATFORM_OS = WINDOWS |
| 66 | export PATH := $(COMPILER_PATH):$(PATH) |
| 67 | else |
| 68 | UNAMEOS = $(shell uname) |
| 69 | ifeq ($(UNAMEOS),Linux) |
| 70 | PLATFORM_OS = LINUX |
| 71 | endif |
| 72 | ifeq ($(UNAMEOS),FreeBSD) |
| 73 | PLATFORM_OS = BSD |
| 74 | endif |
| 75 | ifeq ($(UNAMEOS),OpenBSD) |
| 76 | PLATFORM_OS = BSD |
| 77 | endif |
| 78 | ifeq ($(UNAMEOS),NetBSD) |
| 79 | PLATFORM_OS = BSD |
| 80 | endif |
| 81 | ifeq ($(UNAMEOS),DragonFly) |
| 82 | PLATFORM_OS = BSD |
| 83 | endif |
| 84 | ifeq ($(UNAMEOS),Darwin) |
| 85 | PLATFORM_OS = OSX |
| 86 | endif |
| 87 | endif |
| 88 | endif |
| 89 | ifeq ($(PLATFORM),PLATFORM_DRM) |
| 90 | UNAMEOS = $(shell uname) |
| 91 | ifeq ($(UNAMEOS),Linux) |
| 92 | PLATFORM_OS = LINUX |
| 93 | endif |
| 94 | endif |
| 95 | |
| 96 | ifeq ($(PLATFORM_OS),WINDOWS) |
| 97 | ifeq ($(PLATFORM),PLATFORM_WEB) |
| 98 | # Emscripten required variables |
| 99 | EMSDK_PATH ?= C:/raylib/emsdk |
| 100 | EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten |
| 101 | CLANG_PATH = $(EMSDK_PATH)/upstream/bin |
| 102 | PYTHON_PATH = $(EMSDK_PATH)/python/3.13.3_64bit |
| 103 | NODE_PATH = $(EMSDK_PATH)/node/22.16.0_64bit/bin |
| 104 | export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH):$$(PATH) |
| 105 | endif |
| 106 | endif |
| 107 | |
| 108 | # Define default C compiler: CC |
| 109 | #------------------------------------------------------------------------------------------------ |
| 110 | CC = gcc |
| 111 | |
| 112 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) |
| 113 | ifeq ($(PLATFORM_OS),OSX) |
| 114 | # OSX default compiler |
| 115 | CC = clang |
| 116 | endif |
| 117 | ifeq ($(PLATFORM_OS),BSD) |
| 118 | # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler |
| 119 | CC = clang |
| 120 | endif |
| 121 | endif |
| 122 | ifeq ($(PLATFORM),PLATFORM_WEB) |
| 123 | # HTML5 emscripten compiler |
| 124 | # WARNING: To compile to HTML5, code must be redesigned |
| 125 | # to use emscripten.h and emscripten_set_main_loop() |
| 126 | CC = emcc |
| 127 | endif |
| 128 | ifeq ($(PLATFORM),PLATFORM_DRM) |
| 129 | ifeq ($(USE_RPI_CROSS_COMPILER),TRUE) |
| 130 | # Define RPI cross-compiler |
| 131 | #CC = armv6j-hardfloat-linux-gnueabi-gcc |
| 132 | CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc |
| 133 | endif |
| 134 | endif |
| 135 | |
| 136 | |
| 137 | # Define default make program: MAKE |
| 138 | #------------------------------------------------------------------------------------------------ |
| 139 | MAKE ?= make |
| 140 | |
| 141 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) |
| 142 | ifeq ($(PLATFORM_OS),WINDOWS) |
| 143 | MAKE = mingw32-make |
| 144 | endif |
| 145 | endif |
| 146 | |
| 147 | # Define compiler flags: CFLAGS |
| 148 | #------------------------------------------------------------------------------------------------ |
| 149 | # -O1 defines optimization level |
| 150 | # -g include debug information on compilation |
| 151 | # -s strip unnecessary data from build |
| 152 | # -Wall turns on most, but not all, compiler warnings |
| 153 | # -std=c99 defines C language mode (standard C from 1999 revision) |
| 154 | # -std=gnu99 defines C language mode (GNU C from 1999 revision) |
| 155 | # -Wno-missing-braces ignore invalid warning (GCC bug 53119) |
| 156 | # -Wno-unused-value ignore unused return values of some functions (i.e. fread()) |
| 157 | # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec |
| 158 | CFLAGS = -std=c99 -Wall -Wno-missing-braces -Wno-unused-value -Wno-pointer-sign -D_DEFAULT_SOURCE $(PROJECT_CUSTOM_FLAGS) |
| 159 | #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes |
| 160 | |
| 161 | ifeq ($(BUILD_MODE),DEBUG) |
| 162 | CFLAGS += -g -D_DEBUG |
| 163 | else |
| 164 | ifeq ($(PLATFORM),PLATFORM_WEB) |
| 165 | ifeq ($(BUILD_WEB_ASYNCIFY),TRUE) |
| 166 | CFLAGS += -O3 |
| 167 | else |
| 168 | CFLAGS += -Os |
| 169 | endif |
| 170 | else |
| 171 | ifeq ($(PLATFORM_OS),OSX) |
| 172 | CFLAGS += -O2 |
| 173 | else |
| 174 | CFLAGS += -s -O2 |
| 175 | endif |
| 176 | endif |
| 177 | endif |
| 178 | ifeq ($(PLATFORM),PLATFORM_DRM) |
| 179 | CFLAGS += -std=gnu99 -DEGL_NO_X11 |
| 180 | endif |
| 181 | |
| 182 | # Define include paths for required headers: INCLUDE_PATHS |
| 183 | #------------------------------------------------------------------------------------------------ |
| 184 | INCLUDE_PATHS += -I. -Iexternal -I$(RAYLIB_INCLUDE_PATH) |
| 185 | |
| 186 | # Define additional directories containing required header files |
| 187 | ifeq ($(PLATFORM),PLATFORM_DRM) |
| 188 | # DRM required libraries |
| 189 | INCLUDE_PATHS += -I/usr/include/libdrm |
| 190 | endif |
| 191 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) |
| 192 | ifeq ($(PLATFORM_OS),BSD) |
| 193 | # Consider -L$(RAYLIB_H_INSTALL_PATH) |
| 194 | INCLUDE_PATHS += -I/usr/local/include |
| 195 | endif |
| 196 | endif |
| 197 | |
| 198 | # Define library paths containing required libs: LDFLAGS |
| 199 | #------------------------------------------------------------------------------------------------ |
| 200 | LDFLAGS = -L. -L$(RAYLIB_LIB_PATH) |
| 201 | |
| 202 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) |
| 203 | ifeq ($(PLATFORM_OS),WINDOWS) |
| 204 | # NOTE: The resource .rc file contains windows executable icon and properties |
| 205 | LDFLAGS += $(PROJECT_NAME).rc.data |
| 206 | # -Wl,--subsystem,windows hides the console window |
| 207 | ifeq ($(BUILD_MODE), RELEASE) |
| 208 | #LDFLAGS += -Wl,--subsystem,windows |
| 209 | endif |
| 210 | endif |
| 211 | ifeq ($(PLATFORM_OS),BSD) |
| 212 | # Consider -L$(RAYLIB_INSTALL_PATH) |
| 213 | LDFLAGS += -Lsrc -L/usr/local/lib |
| 214 | endif |
| 215 | ifeq ($(PLATFORM_OS),LINUX) |
| 216 | # Reset everything. |
| 217 | # Precedence: immediately local, installed version, raysan5 provided libs |
| 218 | #LDFLAGS += -L$(RAYLIB_RELEASE_PATH) |
| 219 | endif |
| 220 | endif |
| 221 | ifeq ($(PLATFORM),PLATFORM_WEB) |
| 222 | # -Os # size optimization |
| 223 | # -O2 # optimization level 2, if used, also set --memory-init-file 0 |
| 224 | # -sUSE_GLFW=3 # Use glfw3 library (context/input management) |
| 225 | # -sALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL! |
| 226 | # -sTOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) (67108864 = 64MB) |
| 227 | # -sUSE_PTHREADS=1 # multithreading support |
| 228 | # -sWASM=0 # disable Web Assembly, emitted by default |
| 229 | # -sASYNCIFY # lets synchronous C/C++ code interact with asynchronous JS |
| 230 | # -sFORCE_FILESYSTEM=1 # force filesystem to load/save files data |
| 231 | # -sASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off) |
| 232 | # -sMINIFY_HTML=0 # minify generated html from shell.html |
| 233 | # --profiling # include information for code profiling |
| 234 | # --memory-init-file 0 # to avoid an external memory initialization code file (.mem) |
| 235 | # --preload-file resources # specify a resources folder for data compilation |
| 236 | # --source-map-base # allow debugging in browser with source map |
| 237 | # --shell-file shell.html # define a custom shell .html and output extension |
| 238 | LDFLAGS += -sUSE_GLFW=3 -sTOTAL_MEMORY=$(BUILD_WEB_HEAP_SIZE) -sSTACK_SIZE=$(BUILD_WEB_STACK_SIZE) -sFORCE_FILESYSTEM=1 -sMINIFY_HTML=0 |
| 239 | |
| 240 | # Build using asyncify |
| 241 | ifeq ($(BUILD_WEB_ASYNCIFY),TRUE) |
| 242 | LDFLAGS += -sASYNCIFY -sASYNCIFY_STACK_SIZE=$(BUILD_WEB_ASYNCIFY_STACK_SIZE) |
| 243 | endif |
| 244 | |
| 245 | # Add resources building if required |
| 246 | ifeq ($(BUILD_WEB_RESOURCES),TRUE) |
| 247 | LDFLAGS += --preload-file $(BUILD_WEB_RESOURCES_PATH) |
| 248 | endif |
| 249 | |
| 250 | # Add debug mode flags if required |
| 251 | ifeq ($(BUILD_MODE),DEBUG) |
| 252 | LDFLAGS += -sASSERTIONS=1 --profiling |
| 253 | endif |
| 254 | |
| 255 | # Define a custom shell .html and output extension |
| 256 | LDFLAGS += --shell-file $(BUILD_WEB_SHELL) |
| 257 | EXT = .html |
| 258 | endif |
| 259 | |
| 260 | # Define libraries required on linking: LDLIBS |
| 261 | # NOTE: To link libraries (lib<name>.so or lib<name>.a), use -l<name> |
| 262 | #------------------------------------------------------------------------------------------------ |
| 263 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) |
| 264 | ifeq ($(PLATFORM_OS),WINDOWS) |
| 265 | # Libraries for Windows desktop compilation |
| 266 | # NOTE: WinMM library required to set high-res timer resolution |
| 267 | LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm |
| 268 | # Required for physac examples |
| 269 | #LDLIBS += -static -lpthread |
| 270 | endif |
| 271 | ifeq ($(PLATFORM_OS),LINUX) |
| 272 | # Libraries for Debian GNU/Linux desktop compiling |
| 273 | # NOTE: Required packages: libegl1-mesa-dev |
| 274 | LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt |
| 275 | |
| 276 | # On Wayland windowing system, additional libraries requires |
| 277 | ifeq ($(USE_WAYLAND_DISPLAY),TRUE) |
| 278 | LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon |
| 279 | else |
| 280 | # On X11 requires also below libraries |
| 281 | LDLIBS += -lX11 |
| 282 | # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them |
| 283 | #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor |
| 284 | endif |
| 285 | # Explicit link to libc |
| 286 | ifeq ($(RAYLIB_LIBTYPE),SHARED) |
| 287 | LDLIBS += -lc |
| 288 | endif |
| 289 | endif |
| 290 | ifeq ($(PLATFORM_OS),OSX) |
| 291 | # Libraries for OSX 10.9 desktop compiling |
| 292 | # NOTE: Required packages: libopenal-dev libegl1-mesa-dev |
| 293 | LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo |
| 294 | endif |
| 295 | ifeq ($(PLATFORM_OS),BSD) |
| 296 | # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling |
| 297 | # NOTE: Required packages: mesa-libs |
| 298 | LDLIBS = -lraylib -lGL -lpthread -lm |
| 299 | |
| 300 | # On XWindow requires also below libraries |
| 301 | LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor |
| 302 | endif |
| 303 | endif |
| 304 | ifeq ($(PLATFORM),PLATFORM_WEB) |
| 305 | # Libraries for web (HTML5) compiling |
| 306 | LDLIBS = $(RAYLIB_LIB_PATH)/libraylib.a |
| 307 | endif |
| 308 | ifeq ($(PLATFORM),PLATFORM_DRM) |
| 309 | # Libraries for DRM compiling |
| 310 | # NOTE: Required packages: libasound2-dev (ALSA) |
| 311 | LDLIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lgbm -ldrm -ldl |
| 312 | endif |
| 313 | |
| 314 | |
| 315 | # Define all object files from source files |
| 316 | #------------------------------------------------------------------------------------------------ |
| 317 | OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES)) |
| 318 | |
| 319 | # Define processes to execute |
| 320 | #------------------------------------------------------------------------------------------------ |
| 321 | # For Android platform we call a custom Makefile.Android |
| 322 | ifeq ($(PLATFORM),PLATFORM_ANDROID) |
| 323 | MAKEFILE_TARGET = -f Makefile.Android |
| 324 | export PROJECT_NAME |
| 325 | export PROJECT_SOURCE_FILES |
| 326 | else |
| 327 | MAKEFILE_TARGET = $(PROJECT_NAME) |
| 328 | endif |
| 329 | |
| 330 | # Default target entry |
| 331 | # NOTE: We call this Makefile target or Makefile.Android target |
| 332 | all: |
| 333 | $(MAKE) $(MAKEFILE_TARGET) |
| 334 | |
| 335 | # Project target defined by PROJECT_NAME |
| 336 | $(PROJECT_NAME): $(OBJS) |
| 337 | $(CC) -o $(PROJECT_BUILD_PATH)/$(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) |
| 338 | |
| 339 | # Compile source files |
| 340 | # NOTE: This pattern will compile every module defined on $(OBJS) |
| 341 | %.o: %.c |
| 342 | $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) |
| 343 | |
| 344 | # Clean everything |
| 345 | clean: |
| 346 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) |
| 347 | ifeq ($(PLATFORM_OS),WINDOWS) |
| 348 | del *.o *.exe /s |
| 349 | endif |
| 350 | ifeq ($(PLATFORM_OS),LINUX) |
| 351 | find . -type f -executable -delete |
| 352 | rm -fv *.o |
| 353 | endif |
| 354 | ifeq ($(PLATFORM_OS),OSX) |
| 355 | rm -f *.o external/*.o $(PROJECT_NAME) |
| 356 | endif |
| 357 | endif |
| 358 | ifeq ($(PLATFORM),PLATFORM_DRM) |
| 359 | find . -type f -executable -delete |
| 360 | rm -fv *.o |
| 361 | endif |
| 362 | ifeq ($(PLATFORM),PLATFORM_WEB) |
| 363 | del *.o *.html *.js |
| 364 | endif |
| 365 | @echo Cleaning done |