2022-11-08 17:16:05 -05:00
# /\ +------------------------------------------------------+
# ____/ \____ /| - Open source game framework licensed to freely use, |
# \ / / | copy, modify and sell without restriction |
# +--\ ^__^ /--+ | |
# | ~/ \~ | | - created for <https://foam.shampoo.ooo> |
# | ~~~~~~~~~~~~ | +------------------------------------------------------+
# | SPACE ~~~~~ | /
# | ~~~~~~~ BOX |/
# +--------------+
#
2023-10-18 00:07:32 -04:00
# These are build targets for the box demo for Linux, Android, Windows, and web. There is also outdated code for OS X
# at the end of the file that is broken. The Android build also has not been tested in a bit.
#
# Modify variables as necessary to match the system this is running on and run make for the appropriate target, for
# example `make Box-linux.x86_64` for a Linux executable and `make Box-windows_32bit.exe" for Windows.
2022-11-08 17:16:05 -05:00
#######################
# Location parameters #
#######################
# Location of source files for the demo
2023-10-18 00:07:32 -04:00
SRC_DIR := .
2022-11-08 17:16:05 -05:00
# 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.
2023-10-18 00:07:32 -04:00
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
2022-11-08 17:16:05 -05:00
# 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
2023-10-18 00:07:32 -04:00
CREATE_FONT_SYMLINK := ln -nsf $( SB_DIR) /"BPmono.ttf" .
2022-11-08 17:16:05 -05:00
#############################
# Based on above parameters #
#############################
2023-10-18 00:07:32 -04:00
# Use SDL's utility program to get compilation and linker flags
2022-11-08 17:16:05 -05:00
SDL_CFLAGS = $( shell $( SDLCONFIG) --cflags)
SDL_LFLAGS := $( shell $( SDLCONFIG) --libs)
2023-10-18 00:07:32 -04:00
# Get all SPACEBOX header files, and get a list of object targets by replacing the .cpp suffix with .o
SB_H_FILES := $( wildcard $( addprefix $( SB_SRC_DIR) /,*.hpp) )
SB_O_FILES := $( patsubst %.cpp, %.o, $( wildcard $( addprefix $( SB_SRC_DIR) /,*.cpp) ) )
SRC_O_FILES := $( SRC_DIR) /BoxDemo.o
2022-11-08 17:16:05 -05:00
#################################################################
# Targets for building [SPACEBOX], dependencies and demo source #
#################################################################
2023-10-18 00:07:32 -04:00
$(SDLGFX2_DIR)/%.o : $( SDLGFX 2_DIR ) /%.c $( SDLGFX 2_DIR ) /%.h
$(GLEW_DIR)/%.o : $( GLEW_DIR ) /%.c $( GLEW_DIR ) /%.h
2022-11-08 17:16:05 -05:00
$( CC) $< $( CFLAGS) -c -o $@
2023-10-18 00:07:32 -04:00
$(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)/Game.o : $( addprefix $ ( SB_SRC_DIR ) /,extension .hpp Node .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 )
$(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)/BoxDemo.o : $( SB_H_FILES )
2022-11-08 17:16:05 -05:00
%.o : %.cpp %.hpp
$( CXX) $( CXXFLAGS) $< -c -o $@
#########
# Linux #
#########
2023-10-18 00:07:32 -04:00
Box-linux.x86_64 : CFLAGS = -Wall -Wextra -g -O 3 -c -I $( SB_LIB_DIR ) -I $( SB_SRC_DIR ) $( SDL_CFLAGS )
Box-linux.x86_64 : CXXFLAGS = $( CFLAGS ) --std =c ++17
Box-linux.x86_64 : LFLAGS = $( SDL_LFLAGS ) -Wl , --enable -new -dtags -lpthread -lGL -lGLESv 2 -lSDL 2_image -lSDL 2_ttf -lSDL 2_mixer -lstdc ++fs
Box-linux.x86_64 : $( GLEW_DIR ) /glew .o $( addprefix $ ( SDLGFX 2_DIR ) /,SDL 2_rotozoom .o SDL 2_gfxPrimitives .o ) $( SB_O_FILES ) $( SRC_O_FILES )
2022-11-08 17:16:05 -05:00
$( CREATE_FONT_SYMLINK)
2023-10-18 00:07:32 -04:00
$( CXX) $^ $( LFLAGS) -D__LINUX__ -o $@
2022-11-08 17:16:05 -05:00
#######
# Web #
#######
2023-04-10 18:06:07 -04:00
# Use Emscripten to output JavaScript file
2022-11-08 17:16:05 -05:00
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 $ ( SDLGFX 2_DIR ) ,SDL 2_rotozoom .o SDL 2_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.
2023-04-25 23:17:13 -04:00
SDL_SRC := $( HOME) /ext/software/SDL2-2.26.3
2022-11-08 17:16:05 -05:00
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)
2023-10-18 00:07:32 -04:00
###########
# Windows #
###########
# Set the paths to the directories for the SDL MinGW libraries. See the main README.md for details.
SDL_MINGW_ROOT := $( HOME) /ext/software/SDL2-mingw
SDL_MINGW := $( SDL_MINGW_ROOT) /SDL2-2.24.2/i686-w64-mingw32
SDL_IMG_MINGW := $( SDL_MINGW_ROOT) /SDL2_image-2.5.2/i686-w64-mingw32
SDL_TTF_MINGW := $( SDL_MINGW_ROOT) /SDL2_ttf-2.0.15/i686-w64-mingw32
SDL_MIXER_MINGW := $( SDL_MINGW_ROOT) /SDL2_mixer-2.5.2/i686-w64-mingw32
# Set the compiler to the MinGW compilers. See the main README.md for details.
Box-windows_32bit.exe : CC = i 686-w 64-mingw 32-gcc -posix
Box-windows_32bit.exe : CXX = i 686-w 64-mingw 32-g ++-posix
Box-windows_32bit.exe : CFLAGS = -Wall -Wextra -g -O 3 -c -DGLEW_STATIC -I $( SB_LIB_DIR ) -I $( SB_SRC_DIR ) \
-I$( SDL_MINGW) /include/SDL2 -I$( SDL_IMG_MINGW) /include/SDL2 -I$( SDL_TTF_MINGW) /include/SDL2 -I$( SDL_MIXER_MINGW) /include/SDL2
Box-windows_32bit.exe : CXXFLAGS = $( CFLAGS ) --std =c ++17
Box-windows_32bit.exe : LFLAGS = -lpthread -lstdc ++fs \
-L$( SDL_MINGW) /lib -L$( SDL_IMG_MINGW) /lib -L$( SDL_TTF_MINGW) /lib -L$( SDL_MIXER_MINGW) /lib -lmingw32 -lSDL2_image \
-lSDL2_ttf -lSDL2_mixer -lSDL2main -lSDL2 -lopengl32 -static-libstdc++ -static-libgcc
# Compile into the Windows build directory. Zip the executable, config files, shaders, resource folder, and DLLs together into a ZIP archive
# and move in into the build directory.
#
# The libwinpthread-1.dll path should be edited if necessary. The zip utility must be installed on the system. The /tmp directory must also exist.
Box-windows_32bit.exe : $( GLEW_DIR ) /glew .o $( addprefix $ ( SDLGFX 2_DIR ) /,SDL 2_rotozoom .o SDL 2_gfxPrimitives .o ) $( SB_O_FILES ) $( SRC_O_FILES ) config .json
$( CREATE_FONT_SYMLINK)
mkdir ${ basename $@ }
$( CXX) $( filter-out config.json, $^) $( LFLAGS) -o ${ basename $@ } /$@
cp $( SDL_MINGW) /bin/*.dll $( SDL_IMG_MINGW) /bin/*.dll $( SDL_TTF_MINGW) /bin/*.dll $( SDL_MIXER_MINGW) /bin/*.dll ${ basename $@ }
cp /usr/i686-w64-mingw32/lib/libwinpthread-1.dll ${ basename $@ }
cp -r resource/ shaders/ config.json ${ basename $@ }
zip -r ${ @ : exe =zip } ${ basename $@ }
mv ${ basename $@ } /tmp
rm -rf /tmp/${ basename $@ }
2022-11-08 17:16:05 -05:00
######################
# Clean object files #
######################
2023-10-18 00:07:32 -04:00
.PHONY = clean clean-all
2022-11-08 17:16:05 -05:00
clean :
-find $( SRC_DIR) -iname "*.o" -delete
rm -f BPmono.ttf
2023-10-18 00:07:32 -04:00
rm -f Box-linux.x86_64
rm -f Box-windows_32bit.zip
2022-11-08 17:16:05 -05:00
clean-all : clean
-find $( SB_SRC_DIR) -iname "*.o" -delete
-find $( SB_LIB_DIR) -iname "*.o" -delete
#############
# 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
PROJECTHOME := $( shell pwd )
SDLEMLIBSHOME := $( SDLHOME) /build/em/build/.libs
APPDIR := Main.app/Contents
SYSFWPATH := /Library/Frameworks
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