248 lines
12 KiB
Makefile
248 lines
12 KiB
Makefile
# /\ +------------------------------------------------------+
|
|
# ____/ \____ /| - Open source game framework licensed to freely use, |
|
|
# \ / / | copy, modify and sell without restriction |
|
|
# +--\ ^__^ /--+ | |
|
|
# | ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
|
# | ~~~~~~~~~~~~ | +------------------------------------------------------+
|
|
# | SPACE ~~~~~ | /
|
|
# | ~~~~~~~ BOX |/
|
|
# +--------------+
|
|
#
|
|
# These are build targets for the box demo for Linux, Android, and web. Other platforms haven't been tested in a while
|
|
# and won't work without significant editing. Modify variables as necessary to match the system this is running on and
|
|
# run `make box`, `make build/android/ooo.shampoo.box/app_debug.apk`, or `make box_demo.js` in the current directory.
|
|
|
|
#######################
|
|
# Location parameters #
|
|
#######################
|
|
|
|
# Location of source files for the demo
|
|
SRC_DIR := ./
|
|
|
|
# Locations of [SPACEBOX] source and dependencies required to be compiled from source. These locations are configured to match
|
|
# the structure of the [SPACEBOX] repository but can be modified as necessary.
|
|
SB_DIR := ../../
|
|
SB_SRC_DIR := $(SB_DIR)src/
|
|
SB_LIB_DIR := $(SB_DIR)lib/
|
|
SDLGFX2_DIR := $(SB_LIB_DIR)sdl2-gfx/
|
|
GLEW_DIR := $(SB_LIB_DIR)glew/
|
|
|
|
# C and C++ compiler commands
|
|
CC := clang
|
|
CXX := clang++
|
|
|
|
# Location of SDL config program
|
|
SDLCONFIG := ~/local/sdl/bin/sdl2-config
|
|
|
|
# Edit to point to the location of BPmono.ttf
|
|
CREATE_FONT_SYMLINK := ln -nsf $(SB_DIR)"BPmono.ttf" .
|
|
|
|
#############################
|
|
# Based on above parameters #
|
|
#############################
|
|
|
|
SDL_CFLAGS = $(shell $(SDLCONFIG) --cflags)
|
|
SDL_LFLAGS := $(shell $(SDLCONFIG) --libs)
|
|
SB_H_FILES := $(wildcard $(addprefix $(SB_SRC_DIR),*.hpp))
|
|
SB_O_FILES := $(filter-out $(addprefix $(SB_SRC_DIR),filesystem.o),$(SB_H_FILES:.hpp=.o))
|
|
SRC_H_FILES := $(wildcard $(addprefix $(SRC_DIR),*.hpp))
|
|
SRC_O_FILES := BoxDemo.o $(SRC_H_FILES:.hpp=.o)
|
|
|
|
#################################################################
|
|
# Targets for building [SPACEBOX], dependencies and demo source #
|
|
#################################################################
|
|
|
|
$(SDLGFX2_DIR)%.o: $(SDLGFX2_DIR)%.c $(SDLGFX2_DIR)%.h
|
|
$(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
|
|
$(CC) $< $(CFLAGS) -c -o $@
|
|
|
|
$(SB_SRC_DIR)extension.o: $(addprefix $(SB_SRC_DIR),Box.hpp Segment.hpp Color.hpp filesystem.hpp Pixels.hpp Log.hpp)
|
|
$(SB_SRC_DIR)Node.o: $(addprefix $(SB_SRC_DIR),Game.hpp Configuration.hpp Delegate.hpp Display.hpp Input.hpp Box.hpp Audio.hpp Log.hpp)
|
|
$(SB_SRC_DIR)Sprite.o: $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Animation.hpp Color.hpp extension.hpp Pixels.hpp Log.hpp)
|
|
$(SB_SRC_DIR)Game.o: $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Sprite.hpp Recorder.hpp Input.hpp Configuration.hpp \
|
|
Delegate.hpp Audio.hpp Log.hpp)
|
|
$(SB_SRC_DIR)Animation.o: $(addprefix $(SB_SRC_DIR),Node.hpp Timer.hpp)
|
|
$(SB_SRC_DIR)Recorder.o: $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Configuration.hpp Delegate.hpp Animation.hpp extension.hpp)
|
|
$(SB_SRC_DIR)Input.o: $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Configuration.hpp Delegate.hpp)
|
|
$(SB_SRC_DIR)Configuration.o: $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Log.hpp)
|
|
$(SB_SRC_DIR)Delegate.o: $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Input.hpp)
|
|
$(SB_SRC_DIR)Display.o: $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Configuration.hpp Delegate.hpp Log.hpp)
|
|
$(SB_SRC_DIR)Box.o: $(addprefix $(SB_SRC_DIR),extension.hpp Segment.hpp)
|
|
$(SB_SRC_DIR)Segment.o: $(addprefix $(SB_SRC_DIR),extension.hpp Box.hpp)
|
|
$(SB_SRC_DIR)Pixels.o: $(addprefix $(SB_SRC_DIR),Box.hpp extension.hpp Log.hpp utility.hpp)
|
|
$(SB_SRC_DIR)Audio.o: $(addprefix $(SB_SRC_DIR),Node.hpp Display.hpp Configuration.hpp Box.hpp filesystem.hpp extension.hpp)
|
|
$(SB_SRC_DIR)GLObject.o: $(addprefix $(SB_SRC_DIR),Log.hpp)
|
|
$(SB_SRC_DIR)Texture.o: $(addprefix $(SB_SRC_DIR),GLObject.hpp filesystem.hpp Log.hpp)
|
|
$(SB_SRC_DIR)VBO.o: $(addprefix $(SB_SRC_DIR),Log.hpp GLObject.hpp Attributes.hpp extension.hpp)
|
|
$(SB_SRC_DIR)Attributes.o: $(addprefix $(SB_SRC_DIR),Log.hpp extension.hpp)
|
|
$(SRC_DIR)Model.o: $(addprefix $(SB_SRC_DIR),extension.hpp Attributes.hpp Texture.hpp utility.hpp)
|
|
$(SRC_DIR)BoxDemo.o: $(SRC_H_FILES) $(SB_H_FILES)
|
|
%.o: %.cpp %.hpp
|
|
$(CXX) $(CXXFLAGS) $< -c -o $@
|
|
|
|
#########
|
|
# Linux #
|
|
#########
|
|
|
|
box: CFLAGS = -Wall -Wextra -g -O3 -c -I$(SB_LIB_DIR) -I$(SB_SRC_DIR) $(SDL_CFLAGS)
|
|
box: CXXFLAGS = $(CFLAGS) --std=c++17
|
|
box: LFLAGS = $(SDL_LFLAGS) -Wl,--enable-new-dtags -lpthread -lGL -lGLESv2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lstdc++fs
|
|
box: $(GLEW_DIR)glew.o $(addprefix $(SDLGFX2_DIR),SDL2_rotozoom.o SDL2_gfxPrimitives.o) $(SB_O_FILES) $(SRC_O_FILES)
|
|
$(CREATE_FONT_SYMLINK)
|
|
$(CXX) $^ $(LFLAGS) -D__LINUX__ -o box
|
|
|
|
#######
|
|
# Web #
|
|
#######
|
|
|
|
# Use Emscripten to output JavaScript and an HTML index page for running in the browser
|
|
|
|
EMSCRIPTENHOME = $(HOME)/ext/software/emsdk/upstream/emscripten
|
|
EMSCRIPTEN_CFLAGS = -O1 -Wall -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS="['png', 'jpg']" -s USE_SDL_TTF=2 -s USE_SDL_MIXER=2 \
|
|
-I $(SB_LIB_DIR) -I $(SB_SRC_DIR)
|
|
EMSCRIPTEN_LFLAGS = -s MIN_WEBGL_VERSION=2 -s EXPORTED_FUNCTIONS="['_main']" -s ALLOW_MEMORY_GROWTH=1 -s FULL_ES3=1 -s LLD_REPORT_UNDEFINED
|
|
EMSCRIPTEN_PRELOADS = --preload-file "BPmono.ttf"@/ --preload-file "shaders/"@/"shaders/" --preload-file "config.json"@/ --preload-file "resource/"@/"resource/"
|
|
|
|
box_demo.js: CC = $(EMSCRIPTENHOME)/emcc
|
|
box_demo.js: CXX = $(EMSCRIPTENHOME)/em++
|
|
box_demo.js: CFLAGS = $(EMSCRIPTEN_CFLAGS)
|
|
box_demo.js: CXXFLAGS = $(CFLAGS) --std=c++17
|
|
box_demo.js: $(addprefix $(SDLGFX2_DIR),SDL2_rotozoom.o SDL2_gfxPrimitives.o) $(SB_O_FILES) $(SRC_O_FILES) index.html config.json resource/* shaders/*
|
|
$(CREATE_FONT_SYMLINK)
|
|
$(CXX) $(filter %.o,$^) $(CXXFLAGS) $(EMSCRIPTEN_LFLAGS) $(EMSCRIPTEN_PRELOADS) -o box_demo.js
|
|
|
|
###########
|
|
# Android #
|
|
###########
|
|
|
|
# Detailed info on how this build target was created is in README.md at the root of the repository. It requires the Android SDK and the source packages
|
|
# for SDL, SDL_image, SDL_mixer, and SDL_ttf. The paths below should be customized. The icon creation requires Imagemagick's convert tool from
|
|
# <https://imagemagick.org/>. The project source files are assumed to be just `$(SRC_DIR)/*.cpp`. If that is not the case, the revise_skeleton.sh script
|
|
# must be edited.
|
|
|
|
SDL_SRC := $(HOME)/ext/software/SDL2-2.24.0-android
|
|
SDL_IMAGE_SRC := $(HOME)/ext/software/SDL2_image-2.6.2-android
|
|
SDL_MIXER_SRC := $(HOME)/ext/software/SDL2_mixer-2.6.2-android
|
|
SDL_TTF_SRC := $(HOME)/ext/software/SDL2_ttf-2.20.1-android
|
|
SDL_ANDROID_PROJECT := $(SDL_SRC)/android-project
|
|
ANDROID_MK := app/jni/src/Android.mk
|
|
ANDROID_APP_MK := app/jni/Application.mk
|
|
ANDROID_MANIFEST := app/src/main/AndroidManifest.xml
|
|
ANDROID_SDK := $(HOME)/local/Android
|
|
ANDROID_PACKAGE := ooo.shampoo.spacebox
|
|
ANDROID_BUILD_DIR := build/android/$(ANDROID_PACKAGE)
|
|
ANDROID_CLASS := BoxDemo
|
|
ANDROID_CLASS_DIR := app/src/main/java/$(subst .,/,$(ANDROID_PACKAGE))
|
|
|
|
# The skeleton for the Android build is based on the SDL android-project. The libraries are symlinked in. If the script that rewrites the skeleton
|
|
# has changed, start with a fresh skeleton.
|
|
$(ANDROID_BUILD_DIR): $(SDL_SRC)/android-project/ $(SB_SRC_DIR)/android/revise_skeleton.sh
|
|
-mkdir -p $(ANDROID_BUILD_DIR)
|
|
rsync -ar $(SDL_SRC)/android-project/ $(ANDROID_BUILD_DIR)
|
|
ln -nsf $(SDL_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL
|
|
ln -nsf $(SDL_IMAGE_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL2_image
|
|
ln -nsf $(SDL_MIXER_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL2_mixer
|
|
ln -nsf $(SDL_TTF_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL2_ttf
|
|
$(SB_SRC_DIR)/android/revise_skeleton.sh $(ANDROID_PACKAGE) $(ANDROID_BUILD_DIR) $(ANDROID_MANIFEST) $(ANDROID_APP_MK) $(ANDROID_MK) $(ANDROID_CLASS) \
|
|
$(ANDROID_APP_NAME) $(ANDROID_MIN_TARGET) $(ANDROID_NDK) "Box Demo" "18" "22.1.7171670" $(SB_SRC_DIR) $(SB_LIB_DIR) $(SRC_DIR)
|
|
|
|
# Extend the SDLActivity class
|
|
$(ANDROID_BUILD_DIR)/$(ANDROID_CLASS_DIR)/$(ANDROID_CLASS).java: $(SB_SRC_DIR)/android/main_class.sh
|
|
$(SB_SRC_DIR)/android/main_class.sh $(ANDROID_PACKAGE) $(ANDROID_CLASS) $(ANDROID_BUILD_DIR)/$(ANDROID_CLASS_DIR)
|
|
|
|
# Generate icon
|
|
$(ANDROID_BUILD_DIR)/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: $(SB_SRC_DIR)/android/generate_icon.sh $(SB_DIR)/icon
|
|
$(SB_SRC_DIR)/android/generate_icon.sh $(ANDROID_BUILD_DIR) "../../icon/foreground.png" "../../icon/background.png"
|
|
|
|
# Custom assets
|
|
$(ANDROID_BUILD_DIR)/app/src/main/assets: config.json resource/* shaders/*
|
|
-mkdir -p $(ANDROID_BUILD_DIR)/app/src/main/assets
|
|
rsync -ar resource shaders config.json $(ANDROID_BUILD_DIR)/app/src/main/assets
|
|
|
|
# Run gradle and generate an APK
|
|
$(ANDROID_BUILD_DIR)/app-debug.apk: $(ANDROID_BUILD_DIR) $(ANDROID_BUILD_DIR)/$(ANDROID_CLASS_DIR)/$(ANDROID_CLASS).java \
|
|
$(ANDROID_BUILD_DIR)/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml $(ANDROID_BUILD_DIR)/app/src/main/assets
|
|
ANDROID_SDK_ROOT=$(ANDROID_SDK) $(ANDROID_BUILD_DIR)/gradlew -p $(ANDROID_BUILD_DIR) build
|
|
ln -nsf app/build/outputs/apk/debug/app-debug.apk $(ANDROID_BUILD_DIR)
|
|
ln -nsf app/build/outputs/apk/debug/app-release-unsigned.apk $(ANDROID_BUILD_DIR)
|
|
|
|
######################
|
|
# Clean object files #
|
|
######################
|
|
|
|
clean:
|
|
-find $(SRC_DIR) -iname "*.o" -delete
|
|
rm -f BPmono.ttf
|
|
rm -f box
|
|
|
|
clean-all: clean
|
|
-find $(SB_SRC_DIR) -iname "*.o" -delete
|
|
-find $(SB_LIB_DIR) -iname "*.o" -delete
|
|
|
|
.PHONY = clean clean-all
|
|
|
|
#############
|
|
# compiledb #
|
|
#############
|
|
|
|
# Generate a clang JSON compilation database file. This can be useful for example for code completion. It requires a
|
|
# compiledb binary (https://pypi.org/project/compiledb/). It should be generated manually every time a file is added,
|
|
# renamed, or the compilation flags change. The generated database is based on the Linux build.
|
|
|
|
PATH_TO_COMPILEDB = $(HOME)/.local/bin/compiledb
|
|
compile_commands.json:
|
|
-$(PATH_TO_COMPILEDB) -n make box -k
|
|
|
|
############################################################################################
|
|
# WARNING: these targets are out of date and only here for reference until they're updated #
|
|
############################################################################################
|
|
|
|
BUILDDIR := build
|
|
SOFTWARE_ROOT := /home/frank/ext/software
|
|
SDLHOME := $(SOFTWARE_ROOT)/SDL2-2.0.14
|
|
SDL_IMG_HOME := $(SOFTWARE_ROOT)/SDL2_image-2.0.5
|
|
SDL_TTF_HOME := $(SOFTWARE_ROOT)/SDL2_ttf-2.0.15
|
|
GLEW_WIN32_HOME := $(SOFTWARE_ROOT)/glew-2.1.0-win32
|
|
PROJECTHOME := $(shell pwd)
|
|
SDLEMLIBSHOME := $(SDLHOME)/build/em/build/.libs
|
|
WINBUILDDIR := win
|
|
SDLMINGWHOME := $(SDLHOME)/i686-w64-mingw32
|
|
SDL_IMG_MINGW_HOME := $(SDL_IMG_HOME)/i686-w64-mingw32
|
|
SDL_TTF_MINGW_HOME := $(SDL_TTF_HOME)/i686-w64-mingw32
|
|
APPDIR := Main.app/Contents
|
|
SYSFWPATH := /Library/Frameworks
|
|
|
|
mingw :
|
|
if [ ! -d $(BUILDDIR)/$(WINBUILDDIR) ]; then mkdir -p $(BUILDDIR)/$(WINBUILDDIR); fi;
|
|
cd $(BUILDDIR)/$(WINBUILDDIR) && \
|
|
i686-w64-mingw32-g++ -std=c++17 $(PROJECTHOME)/main.cpp -I$(SDLMINGWHOME)/include/SDL2 \
|
|
-I$(SDL_IMG_MINGW_HOME)/include/SDL2 -I$(SDL_TTF_MINGW_HOME)/include/SDL2 $(INC) \
|
|
$(PROJECTHOME)/sdl2-gfx/SDL2_gfxPrimitives.c $(PROJECTHOME)/sdl2-gfx/SDL2_rotozoom.c $(PROJECTHOME)/glew/glew.c \
|
|
-L$(SDLMINGWHOME)/lib -L$(SDL_IMG_MINGW_HOME)/lib -L$(SDL_TTF_MINGW_HOME)/lib \
|
|
-lmingw32 -lSDL2_image \
|
|
-lSDL2_ttf -lstdc++fs \
|
|
-lSDL2main -lSDL2 -lopengl32 -Wall -O2 -o main.exe && \
|
|
cp $(SDLMINGWHOME)/bin/SDL2.dll $(SDL_IMG_MINGW_HOME)/bin/SDL2_image.dll \
|
|
$(SDL_TTF_MINGW_HOME)/bin/SDL2_ttf.dll .
|
|
|
|
osx :
|
|
g++ -I $(SYSFWPATH)/SDL2.framework/Headers $(INC) \
|
|
-I $(SYSFWPATH)/SDL2_image.framework/Headers -Wl,-rpath,$(SYSFWPATH) \
|
|
-framework SDL2 -framework SDL2_image -framework OpenGL main.cpp sdl2-gfx/SDL2_rotozoom.c \
|
|
-o main
|
|
|
|
osx-bundle :
|
|
if [ ! -d "$(APPDIR)" ]; then mkdir -p $(APPDIR); fi;
|
|
if [ ! -d "$(APPDIR)" ]; then mkdir $(APPDIR); fi;
|
|
if [ ! -d "$(APPDIR)/MacOS" ]; then mkdir $(APPDIR)/MacOS; fi;
|
|
if [ ! -d "$(APPDIR)/Frameworks" ]; then mkdir $(APPDIR)/Frameworks; fi;
|
|
if [ ! -d "$(APPDIR)/Resources" ]; then mkdir $(APPDIR)/Resources; fi;
|
|
touch $(APPDIR)/Info.plist
|
|
cp -r $(SYSFWPATH)/SDL2.framework $(APPDIR)/Frameworks
|
|
cp -r $(SYSFWPATH)/SDL2_image.framework $(APPDIR)/Frameworks
|
|
g++ -I $(SYSFWPATH)/SDL2.framework/Headers -I $(SYSFWPATH)/SDL2_image.framework/Headers \
|
|
-Wl,-rpath,@executable_path/../Frameworks -Wl,-rpath,$(SYSFWPATH) \
|
|
-framework SDL2 -framework SDL2_image -framework OpenGL main.cpp -o $(APPDIR)/MacOS/main
|
|
|
|
cross : linux android emscripten mingw
|