2023-11-06 23:23:22 +01:00
|
|
|
AppName = $(notdir $(CURDIR))
|
2023-11-17 13:53:12 +01:00
|
|
|
AppAssets = ../CHARS.xcf
|
2023-10-31 18:06:39 +01:00
|
|
|
AppSources = $(wildcard *.c)
|
|
|
|
AppHeaders = $(wildcard *.h)
|
|
|
|
SpaccSources = $(wildcard ../../LibMultiSpacc/*.c)
|
|
|
|
SpaccHeaders = $(wildcard ../../LibMultiSpacc/*.h)
|
2023-11-01 13:58:22 +01:00
|
|
|
CFlags = -Os -Werror -Wpedantic -Wdeclaration-after-statement
|
2023-07-20 00:51:16 +02:00
|
|
|
|
2023-11-16 00:52:20 +01:00
|
|
|
# Defaults
|
|
|
|
BuildProcess = Normal
|
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
# TODO: handle other unixes
|
|
|
|
ifeq ($(shell uname --operating-system), Msys)
|
|
|
|
Host = Windows
|
|
|
|
else
|
|
|
|
Host = Linux
|
|
|
|
endif
|
|
|
|
|
|
|
|
# When no user-specified target, build for the host system
|
2023-07-20 00:51:16 +02:00
|
|
|
ifndef Target
|
2023-11-04 16:49:35 +01:00
|
|
|
ifeq ($(Host), Windows)
|
2023-10-07 16:51:29 +02:00
|
|
|
Target = WindowsPC
|
2023-11-04 16:49:35 +01:00
|
|
|
else ifeq ($(Host), Linux)
|
2023-10-07 16:51:29 +02:00
|
|
|
Target = LinuxPC
|
|
|
|
endif
|
2023-07-20 00:51:16 +02:00
|
|
|
endif
|
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
ifeq ($(Target), LinuxPC)
|
|
|
|
ExeSuffix = .run
|
2023-11-09 19:26:53 +01:00
|
|
|
Defines += -DTarget_LinuxPC -DMultiSpacc_Target_PC -DMultiSpacc_Target_Linux
|
2023-11-04 16:49:35 +01:00
|
|
|
MultiSpacc_Target = SDL20
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
else ifeq ($(Target), WindowsPC)
|
|
|
|
ExeSuffix = .exe
|
2023-11-09 19:26:53 +01:00
|
|
|
Defines += -DTarget_WindowsPC -DMultiSpacc_Target_PC -DMultiSpacc_Target_Windows
|
2023-11-04 16:49:35 +01:00
|
|
|
MultiSpacc_Target = SDL20
|
|
|
|
ifneq ($(Host), Windows)
|
|
|
|
ToolsSuffix = -mingw-w64
|
|
|
|
endif
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
else ifeq ($(Target), Windows9x)
|
|
|
|
ExeSuffix = .exe
|
2023-11-17 13:53:12 +01:00
|
|
|
Defines += -DTarget_Windows9x -DMultiSpacc_Target_Windows9x -DMultiSpacc_Target_PC -DMultiSpacc_Target_Windows
|
2023-11-04 16:49:35 +01:00
|
|
|
MultiSpacc_Target = SDL12
|
|
|
|
LdFlags += -lmingw32 -static-libgcc
|
|
|
|
ifeq ($(Host), Windows)
|
|
|
|
ToolsSyspath = /c/Files/Sdk/mingw32/bin
|
2023-11-17 13:53:12 +01:00
|
|
|
# TODO: Find a workaround to the path hardcoding here
|
|
|
|
export PATH=/usr/bin:/c/Files/Applications:$(ToolsSyspath)
|
2023-11-04 16:49:35 +01:00
|
|
|
else
|
|
|
|
ToolsSyspath = /opt/Sdk/mingw32/bin
|
|
|
|
ToolsWrapper = wine
|
2023-11-06 23:23:22 +01:00
|
|
|
LdFlags += -LZ:/opt/Sdk/mingw32/lib
|
2023-07-20 00:51:16 +02:00
|
|
|
endif
|
2023-11-04 16:49:35 +01:00
|
|
|
ToolsPrefix = $(ToolsSyspath)/
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
else ifeq ($(Target), Web)
|
|
|
|
Defines += -DTarget_Web
|
|
|
|
MultiSpacc_Target = Web
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-11-16 00:52:20 +01:00
|
|
|
else ifeq ($(Target), Switch)
|
|
|
|
Defines += -DTarget_Switch
|
|
|
|
MultiSpacc_Target = Switch
|
|
|
|
|
|
|
|
else ifeq ($(Target), 3DS)
|
|
|
|
Defines += -DTarget_3DS
|
|
|
|
MultiSpacc_Target = 3DS
|
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
else ifeq ($(Target), NDS)
|
|
|
|
Defines += -DTarget_NDS
|
|
|
|
MultiSpacc_Target = NDS
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
else ifeq ($(Target), NES)
|
|
|
|
Defines += -DTarget_NES
|
|
|
|
MultiSpacc_Target = NES
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-07-20 00:51:16 +02:00
|
|
|
endif
|
|
|
|
|
2023-11-17 13:53:12 +01:00
|
|
|
ConstSdlDefines = -DMultiSpacc_Target_SDLCom -DMultiSpacc_Target_SDLCommon -DMultiSpacc_Backend_SDLCommon
|
|
|
|
ConstSdl12Defines = $(ConstSdlDefines) -DMultiSpacc_Target_SDL12 -DMultiSpacc_Backend_SDL12
|
|
|
|
ConstSdl20Defines = $(ConstSdlDefines) -DMultiSpacc_Target_SDL20 -DMultiSpacc_Backend_SDL20
|
|
|
|
|
2023-07-20 00:51:16 +02:00
|
|
|
ifeq ($(MultiSpacc_Target), SDL12)
|
2023-11-17 13:53:12 +01:00
|
|
|
Defines += $(ConstSdl12Defines) -DMultiSpacc_Target_SDLStandard
|
2023-10-07 16:51:29 +02:00
|
|
|
CFlags += $(shell sdl-config --cflags)
|
2023-11-03 15:57:40 +01:00
|
|
|
LdFlags += $(shell sdl-config --libs) -lSDLmain -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-07-20 00:51:16 +02:00
|
|
|
else ifeq ($(MultiSpacc_Target), SDL20)
|
2023-11-17 13:53:12 +01:00
|
|
|
Defines += $(ConstSdl20Defines) -DMultiSpacc_Target_SDLStandard
|
2023-10-07 16:51:29 +02:00
|
|
|
CFlags += $(shell sdl2-config --cflags)
|
2023-11-03 15:57:40 +01:00
|
|
|
LdFlags += $(shell sdl2-config --libs) -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-11-04 16:49:35 +01:00
|
|
|
else ifeq ($(MultiSpacc_Target), Web)
|
2023-11-17 13:53:12 +01:00
|
|
|
Defines += -DMultiSpacc_Target_Web $(ConstSdl20Defines) -DMultiSpacc_Target_SDLWeb
|
2023-11-06 23:23:22 +01:00
|
|
|
LdFlags += -sWASM=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS='["png"]' -sUSE_SDL_TTF=2 -sUSE_SDL_MIXER=2
|
2023-11-16 00:52:20 +01:00
|
|
|
BuildProcess = Web
|
|
|
|
|
|
|
|
else ifeq ($(MultiSpacc_Target), Switch)
|
|
|
|
ExeSuffix = .nro
|
2023-11-17 13:53:12 +01:00
|
|
|
Defines += -DMultiSpacc_Target_Switch $(ConstSdl20Defines)
|
2023-11-16 00:52:20 +01:00
|
|
|
Libs += -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lpng -ljpeg -lwebp -lm -lz -lminizip -lbz2
|
|
|
|
BuildProcess = Switch
|
|
|
|
|
|
|
|
else ifeq ($(MultiSpacc_Target), 3DS)
|
|
|
|
ExeSuffix = .3dsx
|
|
|
|
Defines += -DMultiSpacc_Target_3DS
|
|
|
|
BuildProcess = 3DS
|
|
|
|
OutLauncher = citra
|
2023-11-14 18:51:12 +01:00
|
|
|
|
2023-10-07 16:51:29 +02:00
|
|
|
else ifeq ($(MultiSpacc_Target), NDS)
|
2023-11-14 18:51:12 +01:00
|
|
|
ExeSuffix = .nds
|
2023-10-07 16:51:29 +02:00
|
|
|
Defines += -DMultiSpacc_Target_NDS
|
2023-11-16 00:52:20 +01:00
|
|
|
BuildProcess = NDS
|
2023-11-14 18:51:12 +01:00
|
|
|
OutLauncher = melonDS
|
|
|
|
|
2023-10-31 18:06:39 +01:00
|
|
|
else ifeq ($(MultiSpacc_Target), NES)
|
2023-11-14 18:51:12 +01:00
|
|
|
ExeSuffix = .nes
|
2023-10-31 18:06:39 +01:00
|
|
|
Defines += -DMultiSpacc_Target_NES
|
2023-11-16 00:52:20 +01:00
|
|
|
BuildProcess = NES
|
2023-11-14 18:51:12 +01:00
|
|
|
OutLauncher = fceux
|
|
|
|
|
2023-07-20 00:51:16 +02:00
|
|
|
endif
|
|
|
|
|
2023-11-01 23:22:11 +01:00
|
|
|
BuildSources = $(AppSources) $(SpaccSources)
|
|
|
|
BuildObjects = $(BuildSources:.c=.o)
|
2023-07-20 00:51:16 +02:00
|
|
|
|
2023-11-16 00:52:20 +01:00
|
|
|
ifeq ($(BuildProcess), Normal)
|
2023-11-04 16:49:35 +01:00
|
|
|
CC = $(ToolsWrapper) $(ToolsPrefix)gcc$(ToolsSuffix) $(CFlags) $(Defines)
|
2023-11-16 00:52:20 +01:00
|
|
|
BuildDir = .
|
|
|
|
else
|
|
|
|
BuildDir = ./Build/$(BuildProcess)
|
2023-11-04 16:49:35 +01:00
|
|
|
endif
|
|
|
|
|
2023-11-16 00:52:20 +01:00
|
|
|
# TODO: Fix include substitutions properly in this, and make all custom build processes lest wasteful of operations
|
|
|
|
define PrepareTargetBuildDir
|
|
|
|
mkdir -p $(BuildDir)/.tmp $(BuildDirSources)/.tmp
|
|
|
|
|
|
|
|
echo > $(BuildDir)/Makefile
|
|
|
|
echo "TARGET = $(AppName)" >> $(BuildDir)/Makefile
|
|
|
|
echo "MultiSpacc_Defines = $(Defines)" >> $(BuildDir)/Makefile
|
|
|
|
echo "MultiSpacc_LdFlags = $(LdFlags)" >> $(BuildDir)/Makefile
|
|
|
|
echo "MultiSpacc_Libs = $(Libs)" >> $(BuildDir)/Makefile
|
|
|
|
if [ -f ../$(BuildProcess).mk ]; then cat ../$(BuildProcess).mk >> $(BuildDir)/Makefile; fi
|
|
|
|
|
|
|
|
cp $(SpaccSources) $(SpaccHeaders) $(BuildDirSources)/.tmp/
|
|
|
|
cd $(BuildDirSources)/.tmp; for i in *; do mv ./$$i ../LibMultiSpacc_$$i; done
|
|
|
|
cp $(AppSources) $(AppHeaders) $(BuildDirSources)/
|
|
|
|
|
2023-11-14 18:51:12 +01:00
|
|
|
for i in $(BuildDirSources)/*.c $(BuildDirSources)/*.h; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$i; done
|
|
|
|
for i in $(BuildDirSources)/*.c $(BuildDirSources)/*.h; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$i; done
|
|
|
|
for i in $(BuildDirSources)/*.c $(BuildDirSources)/*.h; do sed -i 's|#include[ \t]"./|#include "LibMultiSpacc_|g' $$i; done
|
|
|
|
endef
|
|
|
|
|
2023-11-17 13:53:12 +01:00
|
|
|
# For C++ build systems, main() must be in a .cpp file, to be compiled by the CXX
|
2023-11-16 00:52:20 +01:00
|
|
|
define TargetBuildAppToCpp
|
|
|
|
$(shell mv $(BuildDirSources)/MultiSpacc_* $(BuildDirSources)/.tmp/)
|
|
|
|
for File in $(BuildDirSources)/*.c; do mv $${File} $${File}pp; done
|
|
|
|
$(shell mv $(BuildDirSources)/.tmp/* $(BuildDirSources)/)
|
|
|
|
endef
|
|
|
|
|
2023-11-17 13:53:12 +01:00
|
|
|
All all: __Assets__ __$(BuildProcess)__
|
|
|
|
|
|
|
|
__Assets__:
|
|
|
|
mkdir -p ./Build/Assets
|
|
|
|
for SrcFile in $(AppAssets); \
|
|
|
|
do \
|
|
|
|
SrcExt="$${SrcFile##*.}"; \
|
|
|
|
DstName="$${SrcFile##*/}"; \
|
|
|
|
DstName="$${DstName%.*}"; \
|
|
|
|
if [ "$${SrcExt}" = xcf ]; then \
|
|
|
|
magick convert "$${SrcFile}" "./Build/Assets/$${DstName}.png"; \
|
|
|
|
mv "./Build/Assets/$${DstName}-0.png" "./Build/Assets/$${DstName}.4.png"; \
|
|
|
|
mv "./Build/Assets/$${DstName}-1.png" "./Build/Assets/$${DstName}.png"; \
|
|
|
|
fi; \
|
|
|
|
done
|
2023-07-20 00:51:16 +02:00
|
|
|
|
2023-11-03 15:57:40 +01:00
|
|
|
# TODO: use virtual build dirs even for normals to allow linking against different libraries without recleaning
|
2023-11-17 13:53:12 +01:00
|
|
|
# TODO: copy required DLLs on PC for Dist
|
2023-11-01 13:58:22 +01:00
|
|
|
__Normal__: $(BuildObjects)
|
2023-11-16 00:52:20 +01:00
|
|
|
$(CC) $^ $(LdFlags) $(Libs) -o $(AppName)$(ExeSuffix)
|
2023-07-20 00:51:16 +02:00
|
|
|
|
2023-11-17 13:53:12 +01:00
|
|
|
# TODO: bundle JS, WASM, and assets package in HTML file for Dist
|
|
|
|
# TODO: remove asset hardcoding from here
|
2023-11-04 16:49:35 +01:00
|
|
|
__Web__:
|
2023-11-14 18:51:12 +01:00
|
|
|
mkdir -p $(BuildDir)
|
|
|
|
emcc $(BuildSources) $(CFlags) $(Defines) $(LdFlags) --preload-file $(AppAssets)@CHARS.png -o $(BuildDir)/Emscripten.js
|
|
|
|
cp ../Emscripten.html $(BuildDir)/$(AppName).html
|
2023-11-04 16:49:35 +01:00
|
|
|
|
2023-11-16 00:52:20 +01:00
|
|
|
__Switch__:
|
|
|
|
$(eval BuildDirSources = $(BuildDir)/source)
|
|
|
|
$(PrepareTargetBuildDir)
|
|
|
|
$(TargetBuildAppToCpp)
|
2023-11-17 13:53:12 +01:00
|
|
|
#mkdir -p $(BuildDir)/romfs/.dummy
|
|
|
|
#touch $(BuildDir)/romfs/.dummy/.dummy
|
|
|
|
mkdir -p $(BuildDir)/romfs
|
|
|
|
cp -r ./Build/Assets $(BuildDir)/romfs/Assets
|
|
|
|
cd $(BuildDir); make -j$$(nproc --all)
|
2023-11-01 13:58:22 +01:00
|
|
|
|
2023-11-16 00:52:20 +01:00
|
|
|
__3DS__ __NDS__:
|
2023-11-14 18:51:12 +01:00
|
|
|
$(eval BuildDirSources = $(BuildDir)/source)
|
2023-11-16 00:52:20 +01:00
|
|
|
$(PrepareTargetBuildDir)
|
2023-11-17 13:53:12 +01:00
|
|
|
cd $(BuildDir); make -j$$(nproc --all)
|
2023-11-14 18:51:12 +01:00
|
|
|
|
|
|
|
__NES__: __neslib__
|
|
|
|
$(eval BuildDirSources = $(BuildDir))
|
2023-11-16 00:52:20 +01:00
|
|
|
$(PrepareTargetBuildDir)
|
2023-11-14 18:51:12 +01:00
|
|
|
cp ../../neslib/*.cfg ../../neslib/crt0.o ../../neslib/*.lib ../../neslib/*.h $(BuildDir)/
|
|
|
|
printf ".segment \"CHARS\"\n\t.incbin \"CHARS.chr\"" > $(BuildDir)/CHARS.s
|
|
|
|
echo "ProjectRoot=../..; AppName='$(AppName)'; AppAssets='$(AppAssets)'; Defines='$(Defines)';" > $(BuildDir)/Make.sh
|
|
|
|
cat ../NES.mk.sh >> $(BuildDir)/Make.sh
|
|
|
|
cd $(BuildDir); sh ./Make.sh
|
|
|
|
|
|
|
|
__neslib__:
|
2023-11-17 13:53:12 +01:00
|
|
|
cd ../../neslib; make -j$$(nproc --all)
|
2023-10-31 18:06:39 +01:00
|
|
|
|
2023-10-07 16:51:29 +02:00
|
|
|
Run run: All
|
2023-11-17 13:53:12 +01:00
|
|
|
cd ./Build; $(OutLauncher) ../$(BuildDir)/$(AppName)$(ExeSuffix); cd ..
|
2023-07-20 00:51:16 +02:00
|
|
|
|
2023-10-08 02:09:09 +02:00
|
|
|
Clean clean Clear clear:
|
2023-07-20 00:51:16 +02:00
|
|
|
find -L . -name "*.o" -type f -delete
|
2023-10-07 16:51:29 +02:00
|
|
|
find -L ../../LibMultiSpacc -name "*.o" -type f -delete
|
2023-11-01 13:58:22 +01:00
|
|
|
rm -f ./$(AppName)$(ExeSuffix)
|
2023-10-08 02:09:09 +02:00
|
|
|
rm -rf ./Build
|
2023-11-14 18:51:12 +01:00
|
|
|
|
|
|
|
.PHONY: All all Run run Clean clean Clear clear
|