diff --git a/examples/Makefile b/examples/Makefile index 15b6a8300..a3318aacd 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -25,40 +25,30 @@ # Define required environment variables #------------------------------------------------------------------------------------------------ +# Define target platform: PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB +PLATFORM ?= PLATFORM_DESKTOP + # Define required raylib variables PROJECT_NAME ?= raylib_examples RAYLIB_VERSION ?= 4.0.0 RAYLIB_PATH ?= .. -# One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB -PLATFORM ?= PLATFORM_DESKTOP +# Locations of raylib.h and libraylib.a/libraylib.so +# NOTE: Those variables are only used for PLATFORM_OS: LINUX, BSD +RAYLIB_INCLUDE_PATH ?= /usr/local/include +RAYLIB_LIBRARY_PATH ?= /usr/local/lib -# Locations of your newly installed library and associated headers. -# On Linux, if you have installed raylib but cannot compile the examples, check that -# the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations. -# To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED. -# To enable compile-time linking to a special version of libraylib.so, change these variables here. -# To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below. -# If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime, -# the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH. -# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths. -DESTDIR ?= /usr/local -RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib -# RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files. -RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include - -# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll) +# Library type compilation: STATIC (.a) or SHARED (.so/.dll) RAYLIB_LIBTYPE ?= STATIC # Build mode for project: DEBUG or RELEASE BUILD_MODE ?= RELEASE # Use external GLFW library instead of rglfw module -# TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3 USE_EXTERNAL_GLFW ?= FALSE -# Use Wayland display server protocol on Linux desktop -# by default it uses X11 windowing system +# Use Wayland display server protocol on Linux desktop (by default it uses X11 windowing system) +# NOTE: This variable is only used for PLATFORM_OS: LINUX USE_WAYLAND_DISPLAY ?= FALSE # Use cross-compiler for PLATFORM_RPI @@ -111,18 +101,16 @@ ifeq ($(PLATFORM),PLATFORM_DRM) endif endif -# RAYLIB_PATH adjustment for different platforms. -# If using GNU make, we can get the full path to the top of the tree. Windows? BSD? -# Required for ldconfig or other tools that do not perform path expansion. +# RAYLIB_PATH adjustment for LINUX platform +# TODO: Do we really need this? ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),LINUX) - RAYLIB_PREFIX ?= .. - RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX)) + RAYLIB_PREFIX ?= .. + RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX)) endif endif -# Default path for raylib on Raspberry Pi, if installed in different path, update it! -# This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki. -# TODO: update install: target in src/Makefile for RPI, consider relation to LINUX. + +# Default path for raylib on Raspberry Pi ifeq ($(PLATFORM),PLATFORM_RPI) RAYLIB_PATH ?= /home/pi/raylib endif @@ -130,6 +118,9 @@ ifeq ($(PLATFORM),PLATFORM_DRM) RAYLIB_PATH ?= /home/pi/raylib endif +# Define raylib release directory for compiled library +RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src + ifeq ($(PLATFORM),PLATFORM_WEB) # Emscripten required variables EMSDK_PATH ?= C:/emsdk @@ -140,24 +131,6 @@ ifeq ($(PLATFORM),PLATFORM_WEB) export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH):$$(PATH) endif -# Define raylib release directory for compiled library. -# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version -RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src - -# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries -# into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH -# so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux -# without formal installation from ../src/Makefile. It aids portability and is useful if you have -# multiple versions of raylib, have raylib installed to a non-standard location, or want to -# bundle libraylib.so with your game. Change it to your liking. -# NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, -# The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH, -# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) -# To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute. -# To see which libraries a built example is linking to, ldd core/core_basic_window; -# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing. -EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH) - # Define default C compiler: CC #------------------------------------------------------------------------------------------------ CC = gcc @@ -229,6 +202,10 @@ else endif # Additional flags for compiler (if desired) +# -Wextra enables some extra warning flags that are not enabled by -Wall +# -Wmissing-prototypes warn if a global function is defined without a previous prototype declaration +# -Wstrict-prototypes warn if a function is declared or defined without specifying the argument types +# -Werror=implicit-function-declaration catch function calls without prior declaration #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),LINUX) @@ -237,7 +214,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) endif ifeq ($(RAYLIB_LIBTYPE),SHARED) # Explicitly enable runtime link to libraylib.so - CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) + CFLAGS += -Wl,-rpath,$(RAYLIB_RELEASE_PATH) endif endif endif @@ -249,30 +226,27 @@ ifeq ($(PLATFORM),PLATFORM_DRM) endif # Define include paths for required headers: INCLUDE_PATHS -#------------------------------------------------------------------------------------------------ # NOTE: Some external/extras libraries could be required (stb, physac, easings...) +#------------------------------------------------------------------------------------------------ INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external -I$(RAYLIB_PATH)/src/extras # Define additional directories containing required header files +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),BSD) + INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH) + endif + ifeq ($(PLATFORM_OS),LINUX) + INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH) + endif +endif ifeq ($(PLATFORM),PLATFORM_RPI) - # RPI required libraries INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/include INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/include/interface/vmcs_host/linux INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/include/interface/vcos/pthreads endif ifeq ($(PLATFORM),PLATFORM_DRM) - # DRM required libraries INCLUDE_PATHS += -I/usr/include/libdrm endif -ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),BSD) - # Consider -L$(RAYLIB_H_INSTALL_PATH) - INCLUDE_PATHS += -I/usr/local/include - endif - ifeq ($(PLATFORM_OS),LINUX) - INCLUDE_PATHS += -I$(RAYLIB_H_INSTALL_PATH) - endif -endif # Define library paths containing required libs: LDFLAGS #------------------------------------------------------------------------------------------------ @@ -280,21 +254,18 @@ LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) - # resource file contains windows executable icon and properties + # NOTE: The resource .rc file contains windows executable icon and properties LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data # -Wl,--subsystem,windows hides the console window ifeq ($(BUILD_MODE), RELEASE) LDFLAGS += -Wl,--subsystem,windows endif endif - ifeq ($(PLATFORM_OS),BSD) - # Consider -L$(RAYLIB_INSTALL_PATH) - LDFLAGS += -Lsrc -L/usr/local/lib - endif ifeq ($(PLATFORM_OS),LINUX) - # Reset everything. - # Precedence: immediately local, installed version, raysan5 provided libs - LDFLAGS += -L$(RAYLIB_INSTALL_PATH) + LDFLAGS += -L$(RAYLIB_LIBRARY_PATH) + endif + ifeq ($(PLATFORM_OS),BSD) + LDFLAGS += -Lsrc -L$(RAYLIB_LIBRARY_PATH) endif endif ifeq ($(PLATFORM),PLATFORM_WEB) diff --git a/src/Makefile b/src/Makefile index 23eac580d..ddac896cb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,13 +34,15 @@ # #************************************************************************************************** -# Please read the wiki to know how to compile raylib, because there are different methods. +# NOTE: Highly recommended to read the raylib Wiki to know how to compile raylib for different platforms # https://github.com/raysan5/raylib/wiki .PHONY: all clean install uninstall # Define required environment variables #------------------------------------------------------------------------------------------------ +# Define target platform: PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB +PLATFORM ?= PLATFORM_DESKTOP # Define required raylib variables RAYLIB_VERSION = 4.0.0 @@ -70,10 +72,6 @@ RAYLIB_RES_FILE ?= ./raylib.dll.rc.data # if NONE, default config.h flags are used RAYLIB_CONFIG_FLAGS ?= NONE -# Define raylib platform -# Options: PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB -PLATFORM ?= PLATFORM_DESKTOP - # To define additional cflags: Use make CUSTOM_CFLAGS="" # Include raylib modules on compilation @@ -87,11 +85,11 @@ RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)/extras RAYLIB_MODULE_PHYSAC_PATH ?= $(RAYLIB_SRC_PATH)/extras # Use external GLFW library instead of rglfw module -USE_EXTERNAL_GLFW ?= FALSE +USE_EXTERNAL_GLFW ?= FALSE -# Use Wayland display server protocol on Linux desktop -# by default it uses X11 windowing system -USE_WAYLAND_DISPLAY ?= FALSE +# Use Wayland display server protocol on Linux desktop (by default it uses X11 windowing system) +# NOTE: This variable is only used for PLATFORM_OS: LINUX +USE_WAYLAND_DISPLAY ?= FALSE # Use cross-compiler for PLATFORM_RPI ifeq ($(PLATFORM),PLATFORM_RPI) @@ -102,9 +100,8 @@ ifeq ($(PLATFORM),PLATFORM_RPI) endif endif -# Determine if the file has root access (only for installing raylib) -# "whoami" prints the name of the user that calls him (so, if it is the root -# user, "whoami" prints "root"). +# Determine if the file has root access (only required to install raylib) +# "whoami" prints the name of the user that calls him (so, if it is the root user, "whoami" prints "root") ROOT = $(shell whoami) # By default we suppose we are working on Windows @@ -276,6 +273,7 @@ endif # -std=c99 defines C language mode (standard C from 1999 revision) # -std=gnu99 defines C language mode (GNU C from 1999 revision) # -Wno-missing-braces ignore invalid warning (GCC bug 53119) +# -Wno-unused-value ignore unused return values of some functions (i.e. fread()) # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec # -Werror=pointer-arith catch unportable code that does direct arithmetic on void pointers # -fno-strict-aliasing jar_xm.h does shady stuff (breaks strict aliasing) @@ -380,8 +378,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) endif # Define include paths for required headers: INCLUDE_PATHS -#------------------------------------------------------------------------------------------------ # NOTE: Several external required libraries (stb and others) +#------------------------------------------------------------------------------------------------ INCLUDE_PATHS = -I. -Iexternal/glfw/include -Iexternal/glfw/deps/mingw # Define additional directories containing required header files @@ -391,13 +389,11 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) endif endif ifeq ($(PLATFORM),PLATFORM_RPI) - # RPI required libraries INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/include INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/include/interface/vmcs_host/linux INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/include/interface/vcos/pthreads endif ifeq ($(PLATFORM),PLATFORM_DRM) - # DRM required libraries INCLUDE_PATHS += -I/usr/include/libdrm endif ifeq ($(PLATFORM),PLATFORM_ANDROID)