#!/bin/sh
# requirements: python, cc, ld
COMMON_SOURCES="
libphysfs/src/physfs.c
libphysfs/src/physfs_archiver_7z.c
libphysfs/src/physfs_archiver_dir.c
libphysfs/src/physfs_archiver_grp.c
libphysfs/src/physfs_archiver_hog.c
libphysfs/src/physfs_archiver_iso9660.c
libphysfs/src/physfs_archiver_mvl.c
libphysfs/src/physfs_archiver_qpak.c
libphysfs/src/physfs_archiver_slb.c
libphysfs/src/physfs_archiver_unpacked.c
libphysfs/src/physfs_archiver_vdf.c
libphysfs/src/physfs_archiver_wad.c
libphysfs/src/physfs_archiver_zip.c
libphysfs/src/physfs_byteorder.c
libphysfs/src/physfs_platform_posix.c
libphysfs/src/physfs_unicode.c
libphysfs/src/physfs_platform_apple.m
libphysfs/extras/physfsrwops.c
common/2d/2dsline.cpp
common/2d/bitblt.cpp
common/2d/bitmap.cpp
common/2d/box.cpp
common/2d/canvas.cpp
common/2d/circle.cpp
common/2d/disc.cpp
common/2d/gpixel.cpp
common/2d/line.cpp
common/2d/pixel.cpp
common/2d/rect.cpp
common/2d/rle.cpp
common/2d/scalec.cpp
common/3d/draw.cpp
common/3d/globvars.cpp
common/3d/instance.cpp
common/3d/matrix.cpp
common/3d/points.cpp
common/3d/rod.cpp
common/3d/setup.cpp
common/arch/cocoa/messagebox.mm
common/arch/cocoa/SDLMain.m
common/arch/ogl/ogl_extensions.cpp
common/arch/ogl/ogl_sync.cpp
common/arch/sdl/digi_mixer_music.cpp
common/arch/sdl/event.cpp
common/arch/sdl/joy.cpp
common/arch/sdl/key.cpp
common/arch/sdl/mouse.cpp
common/arch/sdl/rbaudio.cpp
common/arch/sdl/timer.cpp
common/arch/sdl/window.cpp
common/editor/func.cpp
common/main/cli.cpp
common/main/cmd.cpp
common/main/cvar.cpp
common/maths/fixc.cpp
common/maths/rand.cpp
common/maths/tables.cpp
common/maths/vecmat.cpp
common/mem/mem.cpp
common/misc/error.cpp
common/misc/hash.cpp
common/misc/hmp.cpp
common/misc/ignorecase.cpp
common/misc/strutil.cpp
common/misc/vgrphys.cpp
common/misc/vgwphys.cpp
common/ui/button.cpp
common/ui/checkbox.cpp
common/ui/dialog.cpp
common/ui/file.cpp
common/ui/gadget.cpp
common/ui/icon.cpp
common/ui/inputbox.cpp
common/ui/keypad.cpp
common/ui/keypress.cpp
common/ui/listbox.cpp
common/ui/menu.cpp
common/ui/menubar.cpp
common/ui/message.cpp
common/ui/radio.cpp
common/ui/scroll.cpp
common/ui/ui.cpp
common/ui/uidraw.cpp
common/ui/userbox.cpp
similar/2d/font.cpp
similar/2d/palette.cpp
similar/2d/pcx.cpp
similar/3d/interp.cpp
similar/arch/ogl/gr.cpp
similar/arch/ogl/ogl.cpp
similar/arch/sdl/digi.cpp
similar/arch/sdl/digi_audio.cpp
similar/arch/sdl/digi_mixer.cpp
similar/arch/sdl/init.cpp
similar/arch/sdl/jukebox.cpp
similar/main/ai.cpp
similar/main/aipath.cpp
similar/main/automap.cpp
similar/main/bm.cpp
similar/main/cntrlcen.cpp
similar/main/collide.cpp
similar/main/config.cpp
similar/main/console.cpp
similar/main/controls.cpp
similar/main/credits.cpp
similar/main/digiobj.cpp
similar/main/dumpmine.cpp
similar/main/effects.cpp
similar/main/endlevel.cpp
similar/main/fireball.cpp
similar/main/fuelcen.cpp
similar/main/fvi.cpp
similar/main/game.cpp
similar/main/gamecntl.cpp
similar/main/gamefont.cpp
similar/main/gamemine.cpp
similar/main/gamerend.cpp
similar/main/gamesave.cpp
similar/main/gameseg.cpp
similar/main/gameseq.cpp
similar/main/gauges.cpp
similar/main/hostage.cpp
similar/main/hud.cpp
similar/main/iff.cpp
similar/main/inferno.cpp
similar/main/kconfig.cpp
similar/main/kmatrix.cpp
similar/main/laser.cpp
similar/main/lighting.cpp
similar/main/menu.cpp
similar/main/mglobal.cpp
similar/main/mission.cpp
similar/main/morph.cpp
similar/main/multi.cpp
similar/main/multibot.cpp
similar/main/net_udp.cpp
similar/main/newdemo.cpp
similar/main/newmenu.cpp
similar/main/object.cpp
similar/main/paging.cpp
similar/main/physics.cpp
similar/main/piggy.cpp
similar/main/player.cpp
similar/main/playsave.cpp
similar/main/polyobj.cpp
similar/main/powerup.cpp
similar/main/render.cpp
similar/main/robot.cpp
similar/main/scores.cpp
similar/main/segment.cpp
similar/main/slew.cpp
similar/main/songs.cpp
similar/main/state.cpp
similar/main/switch.cpp
similar/main/terrain.cpp
similar/main/texmerge.cpp
similar/main/text.cpp
similar/main/titles.cpp
similar/main/vclip.cpp
similar/main/vers_id.cpp
similar/main/wall.cpp
similar/main/weapon.cpp
similar/misc/args.cpp
similar/misc/physfsx.cpp
"
D1_SOURCES="${COMMON_SOURCES}
similar/main/bmread.cpp
d1x-rebirth/main/custom.cpp
d1x-rebirth/main/snddecom.cpp
"
D2_SOURCES="${COMMON_SOURCES}
d2x-rebirth/main/escort.cpp
d2x-rebirth/main/gamepal.cpp
d2x-rebirth/main/movie.cpp
d2x-rebirth/libmve/decoder16.cpp
d2x-rebirth/libmve/decoder8.cpp
d2x-rebirth/libmve/mve_audio.cpp
d2x-rebirth/libmve/mvelib.cpp
d2x-rebirth/libmve/mveplay.cpp
"
SYSTEM_FRAMEWORKS="Foundation AppKit IOKit OpenGL"
CUSTOM_FRAMEWORKS=`ls Frameworks|rev|cut -c 11-|rev`
DEFINES=""
CPPFLAGS="-O0 -g -I. -Icommon/include -Icommon/main -Ilibphysfs/src -Ilibphysfs/extras `for F in ${CUSTOM_FRAMEWORKS}; do echo " -IFrameworks/${F}.framework/Headers"; done` ${DEFINES}"
CFLAGS=""
CXXFLAGS="-std=c++17 -Wno-gnu-string-literal-operator-template"
MFLAGS="-FFrameworks -Wno-objc-protocol-method-implementation"
MXXFLAGS="-std=c++17 -FFrameworks -Wno-objc-protocol-method-implementation"
LDFLAGS="-dead_strip -lc++ -lSystem -lobjc `for F in ${SYSTEM_FRAMEWORKS}; do echo " -framework ${F}"; done` -FFrameworks `for F in ${CUSTOM_FRAMEWORKS}; do echo " -framework ${F}"; done`"
function build()
{
# usage: build "${SOURCES}" "${APPNAME}" "appspecificdir" [all]
echo "Compiling $2..."
echo "$1"|grep -v '^$'|grep -v '^#'|while read SRCFILE; do
OBJFILE="${SRCFILE}.o"
test ! "_$4" = "_all" -a "${OBJFILE}" -nt "${SRCFILE}" && continue
echo "+ ${SRCFILE}"
case "${SRCFILE}" in
similar/main/kconfig.cpp)
cc ${CPPFLAGS} ${DEFINES} -DDXX_KCONFIG_UI_ENUM=DXX_KCONFIG_UI_ENUM -DDXX_KCONFIG_UI_LABEL=DXX_KCONFIG_UI_LABEL -Dkc_item=kc_item ${CFLAGS} -E -c "similar/main/kconfig.ui-table.cpp" -o "similar/main/kconfig.ui-table.i"
similar/main/generate-kconfig-udlr.py "similar/main/kconfig.ui-table.i" > "$3/kconfig.udlr.h"
cc ${CPPFLAGS} ${CXXFLAGS} ${DEFINES} -c "${SRCFILE}" -o "${OBJFILE}";;
*.c) cc ${CPPFLAGS} ${CFLAGS} ${DEFINES} -c "${SRCFILE}" -o "${OBJFILE}";;
*.cpp) cc ${CPPFLAGS} ${CXXFLAGS} ${DEFINES} -c "${SRCFILE}" -o "${OBJFILE}";;
*.cxx) cc ${CPPFLAGS} ${CXXFLAGS} ${DEFINES} -c "${SRCFILE}" -o "${OBJFILE}";;
*.m) cc ${CPPFLAGS} ${MFLAGS} ${DEFINES} -c "${SRCFILE}" -o "${OBJFILE}";;
*.mm) cc ${CPPFLAGS} ${MXXFLAGS} ${DEFINES} -c "${SRCFILE}" -o "${OBJFILE}";;
*.mxx) cc ${CPPFLAGS} ${MXXFLAGS} ${DEFINES} -c "${SRCFILE}" -o "${OBJFILE}";;
esac
test $? -eq 0 || exit 1
done || exit 1
echo "Linking $2..."
OBJECTS="`echo "$1"|grep -v '^$'|grep -v '^#'|sed s/$/.o/g`"
ld -o "$2" ${OBJECTS} ${LDFLAGS} || exit 1
echo "Packaging $2..."
mkdir -p "$2.app/Contents"
echo -n "APPL????" > "$2.app/Contents/PkgInfo"
echo '<?xml version="1.0" encoding="UTF-8"?>' > "$2.app/Contents/Info.plist"
echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >> "$2.app/Contents/Info.plist"
echo '<plist version="1.0">' >> "$2.app/Contents/Info.plist"
echo '<dict>' >> "$2.app/Contents/Info.plist"
echo ' <key>CFBundleDevelopmentRegion</key>' >> "$2.app/Contents/Info.plist"
echo ' <string>English</string>' >> "$2.app/Contents/Info.plist"
echo ' <key>CFBundleExecutable</key>' >> "$2.app/Contents/Info.plist"
echo " <string>$2</string>" >> "$2.app/Contents/Info.plist"
echo ' <key>CFBundleIconFile</key>' >> "$2.app/Contents/Info.plist"
echo ' <string>descent</string>' >> "$2.app/Contents/Info.plist"
echo ' <key>CFBundleInfoDictionaryVersion</key>' >> "$2.app/Contents/Info.plist"
echo ' <string>6.0</string>' >> "$2.app/Contents/Info.plist"
echo ' <key>CFBundlePackageType</key>' >> "$2.app/Contents/Info.plist"
echo ' <string>APPL</string>' >> "$2.app/Contents/Info.plist"
echo ' <key>CFBundleSignature</key>' >> "$2.app/Contents/Info.plist"
echo ' <string>????</string>' >> "$2.app/Contents/Info.plist"
echo ' <key>CFBundleVersion</key>' >> "$2.app/Contents/Info.plist"
echo " <string>`cat dxxsconf.h|grep '#define DXX_VERSION_SEQ'|awk '{print $3}'|sed 's/,/./g'`</string>" >> "$2.app/Contents/Info.plist"
echo ' <key>NSMainNibFile</key>' >> "$2.app/Contents/Info.plist"
echo ' <string>MainMenu</string>' >> "$2.app/Contents/Info.plist"
echo ' <key>NSPrincipalClass</key>' >> "$2.app/Contents/Info.plist"
echo ' <string>NSApplication</string>' >> "$2.app/Contents/Info.plist"
echo '</dict>' >> "$2.app/Contents/Info.plist"
echo '</plist>' >> "$2.app/Contents/Info.plist"
mkdir -p "$2.app/Contents/Frameworks"
for FRAMEWORK in ${CUSTOM_FRAMEWORKS}; do
cp -r Frameworks/${FRAMEWORK}.framework "$2.app/Contents/Frameworks"
for HEADERDIR in `find "$2.app/Contents/Frameworks/${FRAMEWORK}.framework" -name Headers`; do
rm -rf "${HEADERDIR}"
done
done
mkdir -p "$2.app/Contents/MacOS"
mv "$2" "$2.app/Contents/MacOS"
mkdir -p "$2.app/Contents/Resources"
cp -r $3/Resources/* "$2.app/Contents/Resources"
echo "+ $2.app"
echo "Done."
}
function clean()
{
# usage: clean "${APPNAME}"
echo "Cleaning up..."
rm -rf "$1.app"
for F in `find . -type f|grep '\.o$'`; do
rm "${F}"
done
echo "+ $1.app"
echo "Done."
}
if [ "_$1" = "_clean" ]; then
clean Descent
clean Descent2
elif [ "_$1" = "_Descent" ]; then
DEFINES="-DDXX_BUILD_DESCENT_I=1 -DGL_SILENCE_DEPRECATION -Id1x-rebirth/main"
build "${D1_SOURCES}" Descent d1x-rebirth || exit 1
elif [ "_$1" = "_Descent2" ]; then
DEFINES="-DDXX_BUILD_DESCENT_II=1 -DGL_SILENCE_DEPRECATION -Id1x-rebirth/main"
build "${D2_SOURCES}" Descent2 d2x-rebirth || exit 1
else
for F in `find . -type f|grep '\.o$'`; do rm "${F}"; done
DEFINES="-DDXX_BUILD_DESCENT_I=1 -DGL_SILENCE_DEPRECATION -Id1x-rebirth/main"
build "${D1_SOURCES}" Descent d1x-rebirth $1 || exit 1
for F in `find . -type f|grep '\.o$'`; do rm "${F}"; done
DEFINES="-DDXX_BUILD_DESCENT_II=1 -DGL_SILENCE_DEPRECATION -Id2x-rebirth/main"
build "${D2_SOURCES}" Descent2 d2x-rebirth $1 || exit 1
fi