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