generated from rpuzonas/raylib-cpp-template
152 lines
4.0 KiB
Makefile
152 lines
4.0 KiB
Makefile
# ------------------------ Config -----------------------
|
|
|
|
# PLATFORM can be 'web' or 'desktop'
|
|
PLATFORM ?= desktop
|
|
|
|
SHELL := /bin/zsh
|
|
TOP_BUILD_DIR := build
|
|
EXECUTABLE := boids-playground
|
|
SUBMODULES_PATH := depends
|
|
|
|
# WEB_HEAP_SIZE default: 16777216 (16MiB)
|
|
WEB_HEAP_SIZE := 335544320
|
|
# WEB_STACK_SIZE default: 65536 (64KiB)
|
|
WEB_STACK_SIZE := 196608
|
|
WEB_SHELL := src/shell.html
|
|
|
|
COMPILER_FLAGS := -std=c++17 -Wno-enum-compare -O3 -g -flto -msse4.2 -mavx
|
|
COMPILER_FLAGS += -DRPROF_IMPLEMENTATION
|
|
COMPILER_FLAGS += -DRAYGUI_IMPLEMENTATION
|
|
# COMPILER_FLAGS += -DRLGL_IMPLEMENTATION
|
|
LINKER_FLAGS := -lraylib
|
|
|
|
# SOURCES := $(wildcard src/*.cpp)
|
|
SOURCES := src/main.cpp
|
|
|
|
COMPILER_FLAGS += -I$(SUBMODULES_PATH)/raygui/src/
|
|
|
|
# ----------------- Prepare variables for targets ------------------
|
|
|
|
EXT :=
|
|
EMSDK_PATH := $(SUBMODULES_PATH)/emsdk
|
|
RAYLIB_PLATFORM := PLATFORM_DESKTOP
|
|
|
|
COMPILER_FLAGS += -I$(SUBMODULES_PATH)/raylib/src
|
|
COMPILER_FLAGS += -I$(SUBMODULES_PATH)/raylib-cpp/include
|
|
|
|
ifeq ($(OS), Windows_NT)
|
|
CXX ?= g++
|
|
THEN := &&
|
|
MKDIR := -mkdir -p
|
|
RM := -del /q
|
|
COPY = -robocopy "$1" "$2" $3
|
|
EXT = .exe
|
|
MOVE := move
|
|
|
|
OS_NAME := windows
|
|
LINKER_FLAGS += -Wl,--allow-multiple-definition -pthread -lopengl32
|
|
LINKER_FLAGS += -lgdi32 -lwinmm -mwindows -static -static-libgcc -static-libstdc++
|
|
else
|
|
CXX ?= g++
|
|
THEN := ;
|
|
MKDIR := mkdir -p
|
|
RM := rm -rf
|
|
COPY = cp $1/$3 $2
|
|
MOVE := mv
|
|
|
|
OS_NAME := linux
|
|
LINKER_FLAGS += -lGL -lm -lpthread -ldl -lrt -lX11
|
|
endif
|
|
|
|
BUILD_NAME := $(OS_NAME)-$(PLATFORM)
|
|
BUILD_DIR := $(TOP_BUILD_DIR)/$(BUILD_NAME)
|
|
RAYLIB_RELEASE_PATH := $(TOP_BUILD_DIR)/raylib-$(BUILD_NAME)
|
|
|
|
OBJECTS := $(patsubst src/%, $(BUILD_DIR)/%, $(patsubst %.cpp, %.o, $(SOURCES)))
|
|
OBJECT_DEPENDS := $(patsubst %.o, %.d, $(OBJECTS))
|
|
|
|
LIB_DEPENDENCIES :=
|
|
ifeq ($(PLATFORM), web)
|
|
export EMSDK_QUIET=1
|
|
RAYLIB_PLATFORM := PLATFORM_WEB
|
|
CXX := source $(SUBMODULES_PATH)/emsdk/emsdk_env.sh $(THEN) emcc
|
|
EXT = .html
|
|
|
|
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
|
|
COMPILER_FLAGS += -I$(EMSCRIPTEN_PATH)/cache/sysroot/include
|
|
COMPILER_FLAGS += -D_DEFAULT_SOURCE
|
|
COMPILER_FLAGS += -msimd128
|
|
LINKER_FLAGS += -s USE_GLFW=3
|
|
LINKER_FLAGS += -s FORCE_FILESYSTEM=1
|
|
LINKER_FLAGS += $(RAYLIB_RELEASE_PATH)/libraylib.a
|
|
LINKER_FLAGS += --shell-file $(WEB_SHELL)
|
|
LINKER_FLAGS += -s TOTAL_MEMORY=$(WEB_HEAP_SIZE)
|
|
LINKER_FLAGS += -s STACK_SIZE=$(WEB_STACK_SIZE)
|
|
LIB_DEPENDENCIES += emsdk
|
|
else
|
|
COMPILER_FLAGS += -mavx2 -mfma -DSIMD256
|
|
endif
|
|
|
|
LINKER_FLAGS += -L$(RAYLIB_RELEASE_PATH)
|
|
MAIN_TARGET := $(BUILD_DIR)/$(EXECUTABLE)$(EXT)
|
|
|
|
# ------------------------ Targets -----------------------
|
|
|
|
# Add all rules from dependency files
|
|
-include $(OBJECT_DEPENDS)
|
|
|
|
.DEFAULT_GOAL := all
|
|
|
|
# Lists phony targets for Makefile
|
|
.PHONY: all setup submodules run clean emsdk app
|
|
|
|
app: $(MAIN_TARGET)
|
|
|
|
# Default target, compiles, runss and cleans
|
|
all: clean app run
|
|
|
|
# Sets up the project for compiling, generates includes and libs
|
|
setup: lib
|
|
|
|
# Pull and update the the build submodules
|
|
submodules:
|
|
git submodule update --init --recursive
|
|
|
|
# Build the raylib static library file and copy it into lib
|
|
lib: submodules $(LIB_DEPENDENCIES)
|
|
$(MKDIR) $(RAYLIB_RELEASE_PATH)
|
|
cd $(SUBMODULES_PATH)/raylib/src $(THEN) \
|
|
"$(MAKE)" \
|
|
PLATFORM=$(RAYLIB_PLATFORM) \
|
|
EMSDK_PATH=$(EMSDK_PATH) \
|
|
RAYLIB_RELEASE_PATH=../../../$(RAYLIB_RELEASE_PATH) -B
|
|
|
|
# Install and activate emscripten
|
|
emsdk: submodules
|
|
cd $(SUBMODULES_PATH)/emsdk $(THEN) ./emsdk install latest
|
|
cd $(SUBMODULES_PATH)/emsdk $(THEN) ./emsdk activate latest
|
|
|
|
# Link the program and create the executable
|
|
$(MAIN_TARGET): $(OBJECTS)
|
|
$(CXX) $(OBJECTS) -o $(MAIN_TARGET) $(LINKER_FLAGS) -D$(RAYLIB_PLATFORM)
|
|
ifeq ($(PLATFORM), web)
|
|
$(MOVE) $(MAIN_TARGET) $(BUILD_DIR)/index.html
|
|
endif
|
|
|
|
# Compile objects to the build directory
|
|
$(BUILD_DIR)/%.o: src/%.cpp Makefile
|
|
$(MKDIR) $(BUILD_DIR)
|
|
$(CXX) -MMD -MP -c $(COMPILER_FLAGS) $< -o $@ $(CXXFLAGS) -D$(RAYLIB_PLATFORM)
|
|
|
|
# Run the executable
|
|
run:
|
|
ifeq ($(PLATFORM), web)
|
|
python -m http.server 8080 -d $(BUILD_DIR)
|
|
else
|
|
$(MAIN_TARGET) $(ARGS)
|
|
endif
|
|
|
|
# Clean up all relevant files
|
|
clean:
|
|
$(RM) $(BUILD_DIR)
|