2023-07-20 00:51:16 +02:00
AppName = $( notdir ${ CURDIR } )
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-10-30 12:27:41 +01:00
# Default build is always for the host system
2023-07-20 00:51:16 +02:00
i f n d e f T a r g e t
2023-10-07 16:51:29 +02:00
ifeq ( $( shell uname --operating-system) , Msys)
Target = WindowsPC
else
Target = LinuxPC
endif
2023-07-20 00:51:16 +02:00
e n d i f
i f d e f T a r g e t
2023-10-07 16:51:29 +02:00
ifeq ( $( Target) , LinuxPC)
2023-07-20 00:51:16 +02:00
ExeSuffix = .run
2023-10-07 16:51:29 +02:00
Defines += -DTarget_LinuxPC
MultiSpacc_Target = SDL20
else ifeq ( $( Target) , WindowsPC)
ExeSuffix = .exe
Defines += -DTarget_WindowsPC
2023-07-20 00:51:16 +02:00
MultiSpacc_Target = SDL20
2023-11-03 15:57:40 +01:00
else ifeq ( $( Target) , Windows9x)
ExeSuffix = .exe
Defines += -DTarget_Windows9x
MultiSpacc_Target = SDL12
LdFlags += -lmingw32 -static-libgcc
ToolsSyspath = /c/Files/Sdk/mingw32/bin
ToolsPrefix = $( ToolsSyspath) /
export PATH = $$ PATH:$( ToolsSyspath)
2023-10-07 16:51:29 +02:00
else ifeq ( $( Target) , NDS)
Defines += -DTarget_NDS
MultiSpacc_Target = NDS
2023-10-31 18:06:39 +01:00
else ifeq ( $( Target) , NES)
Defines += -DTarget_NES
MultiSpacc_Target = NES
2023-07-20 00:51:16 +02:00
endif
e n d i f
i f e q ( $( MultiSpacc_Target ) , S D L 1 2 )
2023-10-30 12:27:41 +01:00
Defines += -DMultiSpacc_Target_SDL12 -DMultiSpacc_Target_SDLCom
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-01 13:58:22 +01:00
BuildProcess = __Normal__
2023-07-20 00:51:16 +02:00
e l s e i f e q ( $( MultiSpacc_Target ) , S D L 2 0 )
2023-10-30 12:27:41 +01:00
Defines += -DMultiSpacc_Target_SDL20 -DMultiSpacc_Target_SDLCom
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-01 13:58:22 +01:00
BuildProcess = __Normal__
2023-10-07 16:51:29 +02:00
e l s e i f e q ( $( MultiSpacc_Target ) , N D S )
Defines += -DMultiSpacc_Target_NDS
2023-11-01 13:58:22 +01:00
BuildProcess = __NDS__
2023-10-31 18:06:39 +01:00
e l s e i f e q ( $( MultiSpacc_Target ) , N E S )
Defines += -DMultiSpacc_Target_NES
2023-11-01 13:58:22 +01:00
BuildProcess = __NES__
2023-07-20 00:51:16 +02:00
e n d i f
2023-10-07 16:51:29 +02:00
CC = $( ToolsPrefix) gcc $( CFlags) $( Defines)
2023-11-01 23:22:11 +01:00
BuildSources = $( AppSources) $( SpaccSources)
BuildObjects = $( BuildSources:.c= .o)
2023-07-20 00:51:16 +02:00
2023-10-08 02:09:09 +02:00
All all : $( BuildProcess )
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-01 13:58:22 +01:00
__Normal__ : $( BuildObjects )
2023-10-07 16:51:29 +02:00
$( CC) $^ $( LdFlags) -o $( AppName) $( ExeSuffix)
2023-07-20 00:51:16 +02:00
2023-11-01 13:58:22 +01:00
# TODO: Fix include substitutions properly in non-standard build processes
__NDS__ :
2023-10-08 02:09:09 +02:00
$( eval VirtualBuildDir = ./Build/NDS)
mkdir -p $( VirtualBuildDir) /source/.tmp
cp ../NDS.mk $( VirtualBuildDir) /Makefile
2023-10-31 18:06:39 +01:00
cp $( SpaccSources) $( SpaccHeaders) $( VirtualBuildDir) /source/.tmp/
cd $( VirtualBuildDir) /source/.tmp; for i in *; do mv ./$$ i ../LibMultiSpacc_$$ i; done
cp $( AppSources) $( AppHeaders) $( VirtualBuildDir) /source/
2023-11-01 23:22:11 +01:00
for i in $( VirtualBuildDir) /source/*.c $( VirtualBuildDir) /source/*.h; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$ i; done
for i in $( VirtualBuildDir) /source/*.c $( VirtualBuildDir) /source/*.h; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$ i; done
for i in $( VirtualBuildDir) /source/*.c $( VirtualBuildDir) /source/*.h; do sed -i 's|#include[ \t]"./|#include "LibMultiSpacc_|g' $$ i; done
2023-10-08 02:09:09 +02:00
cd $( VirtualBuildDir) ; make
2023-11-01 13:58:22 +01:00
__NES__ :
cd ../../neslib; make
$( eval VirtualBuildDir = ./Build/NES)
mkdir -p $( VirtualBuildDir) /.tmp
cp $( SpaccSources) $( SpaccHeaders) $( VirtualBuildDir) /.tmp/
cd $( VirtualBuildDir) /.tmp; for i in *; do mv ./$$ i ../LibMultiSpacc_$$ i; done
cp $( AppSources) $( AppHeaders) $( VirtualBuildDir) /
2023-11-01 23:22:11 +01:00
for i in $( VirtualBuildDir) /*.c $( VirtualBuildDir) /*.h; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$ i; done
for i in $( VirtualBuildDir) /*.c $( VirtualBuildDir) /*.h; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$ i; done
for i in $( VirtualBuildDir) /*.c $( VirtualBuildDir) /*.h; do sed -i 's|#include[ \t]"./|#include "LibMultiSpacc_|g' $$ i; done
cp ../../neslib/*.cfg ../../neslib/crt0.o ../../neslib/*.lib ../../neslib/*.h $( VirtualBuildDir) /
printf ".segment \"CHARS\"\n\t.incbin \"CHARS.chr\"" > $( VirtualBuildDir) /CHARS.s
echo " AppName=' $( AppName) '; Defines=' $( Defines) '; ProjectRoot=../..; " > $( VirtualBuildDir) /Make.sh
2023-11-01 13:58:22 +01:00
cat ../NES.mk.sh >> $( VirtualBuildDir) /Make.sh
2023-11-01 23:22:11 +01:00
cd $( VirtualBuildDir) ; sh ./Make.sh
2023-10-31 18:06:39 +01:00
2023-10-07 16:51:29 +02:00
Run run : All
2023-07-20 00:51:16 +02:00
./$( AppName) $( ExeSuffix)
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