generated from rpuzonas/raylib-cpp-template
115 lines
3.7 KiB
Makefile
115 lines
3.7 KiB
Makefile
# Copyright (c) 2020 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
|
|
#
|
|
# This code is released under an unmodified zlib license.
|
|
# For conditions of distribution and use, please see:
|
|
# https://opensource.org/licenses/Zlib
|
|
|
|
# Define custom functions
|
|
rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
|
|
platformpth = $(subst /,$(PATHSEP),$1)
|
|
|
|
# Set global macros
|
|
buildDir := bin
|
|
executable := boids-playground
|
|
target := $(buildDir)/$(executable)
|
|
sources := $(call rwildcard,src/,*.cpp)
|
|
# objects := $(patsubst src/%, $(buildDir)/%, $(patsubst %.cpp, %.o, $(sources)))
|
|
objects := $(buildDir)/main.o
|
|
depends := $(patsubst %.o, %.d, $(objects))
|
|
compileFlags := -std=c++17 -I include
|
|
linkFlags = -lraylib
|
|
emsdk_path = /usr/lib/emscripten
|
|
ext =
|
|
|
|
# PLATFORM_DESKTOP or PLATFORM_WEB
|
|
PLATFORM ?= PLATFORM_DESKTOP
|
|
|
|
# Check for Windows
|
|
ifeq ($(OS), Windows_NT)
|
|
# Set Windows macros
|
|
osName := windows
|
|
CXX ?= g++
|
|
linkFlags += -Wl,--allow-multiple-definition -pthread -lopengl32 -lgdi32 -lwinmm -mwindows -static -static-libgcc -static-libstdc++
|
|
THEN := &&
|
|
PATHSEP := \$(BLANK)
|
|
MKDIR := -mkdir -p
|
|
RM := -del /q
|
|
COPY = -robocopy "$(call platformpth,$1)" "$(call platformpth,$2)" $3
|
|
else
|
|
# Set Linux macros
|
|
osName := linux
|
|
CXX ?= g++
|
|
linkFlags += -lGL -lm -lpthread -ldl -lrt -lX11
|
|
|
|
# Set UNIX macros
|
|
THEN := ;
|
|
PATHSEP := /
|
|
MKDIR := mkdir -p
|
|
RM := rm -rf
|
|
COPY = cp $1$(PATHSEP)$3 $2
|
|
endif
|
|
|
|
RAYLIB_RELEASE_PATH = lib/$(osName)
|
|
ifeq ($(PLATFORM), PLATFORM_WEB)
|
|
RAYLIB_RELEASE_PATH = lib/$(osName)-web
|
|
CXX := emcc
|
|
|
|
compileFlags += -I$(emscripten_path)/cache/sysroot/include
|
|
emscripten_path ?= $(emsdk_path)/upstream/emscripten
|
|
linkFlags += -s USE_GLFW=3 -s FORCE_FILESYSTEM=1 $(RAYLIB_RELEASE_PATH)/libraylib.a --shell-file src/shell.html
|
|
ext = .html
|
|
endif
|
|
linkFlags += -L$(RAYLIB_RELEASE_PATH)
|
|
|
|
# Lists phony targets for Makefile
|
|
.PHONY: all setup submodules run clean
|
|
|
|
# Default target, compiles, runss and cleans
|
|
all: $(target) run clean
|
|
|
|
# Sets up the project for compiling, generates includes and libs
|
|
setup: include lib
|
|
|
|
# Pull and update the the build submodules
|
|
submodules:
|
|
git submodule update --init --recursive
|
|
|
|
# Copy the relevant header files into includes
|
|
include: submodules
|
|
$(MKDIR) $(call platformpth, ./include)
|
|
$(call COPY,depends/raylib/src,./include,raylib.h)
|
|
$(call COPY,depends/raylib/src,./include,raymath.h)
|
|
$(call COPY,depends/raylib/src,./include,rlgl.h)
|
|
$(call COPY,depends/raylib-cpp/include,./include,*.hpp)
|
|
|
|
# Build the raylib static library file and copy it into lib
|
|
lib: submodules
|
|
$(MKDIR) $(call platformpth, $(RAYLIB_RELEASE_PATH))
|
|
cd depends/raylib/src $(THEN) "$(MAKE)" PLATFORM=$(PLATFORM) EMSDK_PATH=$(emsdk_path) RAYLIB_RELEASE_PATH=../../../$(RAYLIB_RELEASE_PATH) -B
|
|
|
|
# Link the program and create the executable
|
|
$(target): $(objects)
|
|
$(CXX) $(objects) -o $(target)$(ext) -DPLATFORM=$(PLATFORM) $(linkFlags)
|
|
|
|
# Add all rules from dependency files
|
|
-include $(depends)
|
|
|
|
# Compile objects to the build directory
|
|
$(buildDir)/%.o: src/%.cpp Makefile
|
|
$(MKDIR) $(call platformpth, $(@D))
|
|
$(CXX) -MMD -MP -c $(compileFlags) $< -o $@ $(CXXFLAGS) -D$(PLATFORM)
|
|
|
|
# Run the executable
|
|
run:
|
|
ifeq ($(PLATFORM), PLATFORM_WEB)
|
|
serve $(buildDir) $(ARGS)
|
|
else
|
|
$(target) $(ARGS)
|
|
endif
|
|
|
|
# Clean up all relevant files
|
|
clean:
|
|
$(RM) $(call platformpth, $(buildDir)/*)
|
|
|
|
# emcc -o bin/game.html bin/main.o bin/raycast.o -std=c99 -Wall -Wno-missing-braces -Wunused-result -D_DEFAULT_SOURCE -Os -I. -I../raylib/src -I../raylib/src/external -I../raylib/src/extras -I/cache/sysroot/include -L. -L../depends/raylib/src -L../depends/raylib/src -s USE_GLFW=3 -s TOTAL_MEMORY=134217728 -s FORCE_FILESYSTEM=1 ~/code/fun/raylib-game-template/raylib/src/libraylib.a -DPLATFORM_WEB -s ASYNCIFY
|