2022-06-22 14:59:21 -04:00
|
|
|
CXX ?= g++
|
|
|
|
CC ?= gcc
|
2022-05-11 13:18:24 -04:00
|
|
|
LD := lld
|
|
|
|
AR := ar
|
|
|
|
FORMAT := clang-format-11
|
|
|
|
ZAPD := ../ZAPDTR/ZAPD.out
|
2022-06-22 14:59:21 -04:00
|
|
|
UNAME := $(shell uname)
|
|
|
|
UNAMEM := $(shell uname -m)
|
2022-05-11 13:18:24 -04:00
|
|
|
|
|
|
|
LIBULTRASHIP := ../libultraship/libultraship.a
|
|
|
|
ZAPDUTILS := ../ZAPDTR/ZAPDUtils/ZAPDUtils.a
|
2022-06-20 13:38:08 -04:00
|
|
|
LIBSTORM := ../StormLib/build/libstorm.a
|
2022-05-11 13:18:24 -04:00
|
|
|
|
|
|
|
ASAN ?= 0
|
|
|
|
DEBUG ?= 1
|
|
|
|
OPTFLAGS ?= -O0
|
|
|
|
LTO ?= 0
|
|
|
|
|
|
|
|
WARN := \
|
|
|
|
-Wno-return-type \
|
2022-07-10 10:51:12 -04:00
|
|
|
-Wno-unused-command-line-argument \
|
|
|
|
-Wno-implicit-function-declaration \
|
|
|
|
-Wno-c++11-narrowing \
|
2022-05-11 13:18:24 -04:00
|
|
|
-funsigned-char \
|
2022-07-10 10:51:12 -04:00
|
|
|
-fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-strict-aliasing -fno-inline-functions -fno-inline-small-functions -ffreestanding -fwrapv \
|
2022-05-11 13:18:24 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
CXXFLAGS := $(WARN) -std=c++20 -D_GNU_SOURCE -fpermissive -no-pie -nostdlib
|
|
|
|
CFLAGS := $(WARN) -std=c99 -D_GNU_SOURCE -no-pie -nostdlib
|
2022-06-04 03:59:41 -04:00
|
|
|
LDFLAGS :=
|
2022-06-22 14:59:21 -04:00
|
|
|
|
|
|
|
ifeq ($(UNAME), Linux) #LINUX
|
|
|
|
CXXFLAGS += -mhard-float -msse2 -mfpmath=sse
|
|
|
|
CFLAGS += -mhard-float -msse2 -mfpmath=sse
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(UNAME), Darwin) #APPLE
|
|
|
|
CXXFLAGS += $(shell pkg-config --cflags sdl2) $(shell sdl2-config --cflags) $(shell pkg-config --cflags glew) -framework OpenGL
|
|
|
|
CFLAGS += $(shell pkg-config --cflags sdl2) $(shell sdl2-config --cflags) $(shell pkg-config --cflags glew) -framework OpenGL
|
|
|
|
endif
|
|
|
|
|
2022-05-11 13:18:24 -04:00
|
|
|
CPPFLAGS := -MMD
|
|
|
|
|
|
|
|
ifneq ($(DEBUG),0)
|
|
|
|
CXXFLAGS += -g
|
|
|
|
CFLAGS += -g
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(ASAN),0)
|
|
|
|
CXXFLAGS += -fsanitize=address
|
2022-06-04 05:56:31 -04:00
|
|
|
CFLAGS += -fsanitize=address
|
2022-05-11 13:18:24 -04:00
|
|
|
LDFLAGS += -fsanitize=address
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(LTO),0)
|
|
|
|
CXXFLAGS += -flto
|
2022-06-04 05:56:31 -04:00
|
|
|
CFLAGS += -flto
|
2022-05-11 13:18:24 -04:00
|
|
|
LDFLAGS += -flto
|
|
|
|
endif
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
ifeq ($(UNAME), Linux) #LINUX
|
2022-05-11 13:18:24 -04:00
|
|
|
TARGET := soh.elf
|
2022-06-22 14:59:21 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(UNAME), Darwin) #APPLE
|
|
|
|
TARGET := soh-$(UNAMEM)
|
|
|
|
endif
|
2022-05-11 13:18:24 -04:00
|
|
|
|
|
|
|
INC_DIRS := $(addprefix -I, \
|
|
|
|
. \
|
|
|
|
assets \
|
|
|
|
build \
|
|
|
|
include \
|
|
|
|
src \
|
|
|
|
../ZAPDTR/ZAPDUtils \
|
|
|
|
../libultraship/libultraship \
|
|
|
|
../libultraship/libultraship/Lib/spdlog/include \
|
|
|
|
../libultraship/libultraship/Lib/Fast3D/U64 \
|
|
|
|
../libultraship/libultraship/Lib/Fast3D/U64/PR \
|
|
|
|
)
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
ifeq ($(UNAME), Linux) #LINUX
|
|
|
|
INC_DIRS += $(addprefix -I, \
|
|
|
|
/opt/X11/include \
|
|
|
|
)
|
|
|
|
endif
|
|
|
|
|
2022-05-11 13:18:24 -04:00
|
|
|
LDDIRS := $(addprefix -L, \
|
|
|
|
../libultraship/ \
|
|
|
|
)
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
ifeq ($(UNAME), Linux) #LINUX
|
|
|
|
LDDIRS += $(addprefix -L, \
|
|
|
|
/opt/X11/lib \
|
|
|
|
)
|
|
|
|
endif
|
|
|
|
|
2022-05-11 13:18:24 -04:00
|
|
|
LDLIBS := \
|
|
|
|
$(ZAPDUTILS) \
|
2022-06-20 13:38:08 -04:00
|
|
|
$(LIBSTORM) \
|
2022-05-11 13:18:24 -04:00
|
|
|
$(addprefix -l, \
|
|
|
|
dl \
|
|
|
|
bz2 \
|
|
|
|
z \
|
|
|
|
pthread \
|
2022-06-22 14:59:21 -04:00
|
|
|
ultraship \
|
|
|
|
)
|
|
|
|
|
|
|
|
ifeq ($(UNAME), Linux) #LINUX
|
|
|
|
LDLIBS += \
|
|
|
|
$(addprefix -l, \
|
|
|
|
X11 \
|
2022-05-11 13:18:24 -04:00
|
|
|
SDL2 \
|
|
|
|
GL \
|
|
|
|
GLEW \
|
2022-06-22 14:59:21 -04:00
|
|
|
pulse \
|
|
|
|
)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(UNAME), Darwin) #APPLE
|
|
|
|
LDLIBS += \
|
2022-07-10 10:51:12 -04:00
|
|
|
$(addprefix -framework , \
|
2022-06-22 14:59:21 -04:00
|
|
|
OpenGL \
|
2022-05-11 13:18:24 -04:00
|
|
|
) \
|
2022-06-22 14:59:21 -04:00
|
|
|
$(shell sdl2-config --libs) $(shell pkg-config --libs glew)
|
|
|
|
endif
|
2022-05-11 13:18:24 -04:00
|
|
|
|
|
|
|
ASSET_BIN_DIRS := $(shell find assets/* -type d -not -path "assets/xml*")
|
|
|
|
ASSET_FILES_XML := $(foreach dir,$(ASSET_BIN_DIRS),$(wildcard $(dir)/*.xml))
|
|
|
|
ASSET_FILES_BIN := $(foreach dir,$(ASSET_BIN_DIRS),$(wildcard $(dir)/*.bin))
|
|
|
|
ASSET_FILES_OUT := $(foreach f,$(ASSET_FILES_XML:.xml=.c),$f) \
|
|
|
|
$(foreach f,$(ASSET_FILES_BIN:.bin=.bin.inc.c),build/$f)
|
|
|
|
|
|
|
|
TEXTURE_FILES_PNG := $(foreach dir,$(ASSET_BIN_DIRS),$(wildcard $(dir)/*.png))
|
|
|
|
TEXTURE_FILES_JPG := $(foreach dir,$(ASSET_BIN_DIRS),$(wildcard $(dir)/*.jpg))
|
|
|
|
TEXTURE_FILES_OUT := $(foreach f,$(TEXTURE_FILES_PNG:.png=.inc.c),build/$f) \
|
|
|
|
$(foreach f,$(TEXTURE_FILES_JPG:.jpg=.jpg.inc.c),build/$f) \
|
|
|
|
|
|
|
|
CXX_FILES := \
|
2022-06-04 03:59:41 -04:00
|
|
|
$(shell find soh -type f -name "*.cpp")
|
2022-05-11 13:18:24 -04:00
|
|
|
|
|
|
|
C_FILES := \
|
2022-06-04 03:59:41 -04:00
|
|
|
$(shell find soh -type f -name "*.c") \
|
|
|
|
$(shell find src/boot -type f -name "*.c") \
|
|
|
|
$(shell find src/buffers -type f -name "*.c") \
|
|
|
|
$(shell find src/code -type f -name "*.c") \
|
|
|
|
$(shell find src/overlays -type f -name "*.c") \
|
2022-05-11 13:18:24 -04:00
|
|
|
src/libultra/gu/coss.c \
|
|
|
|
src/libultra/gu/guLookAt.c \
|
|
|
|
src/libultra/gu/guLookAtHilite.c \
|
|
|
|
src/libultra/gu/guPerspectiveF.c \
|
|
|
|
src/libultra/gu/guPosition.c \
|
|
|
|
src/libultra/gu/guS2DInitBg.c \
|
|
|
|
src/libultra/gu/ortho.c \
|
|
|
|
src/libultra/gu/rotate.c \
|
|
|
|
src/libultra/gu/sins.c \
|
|
|
|
src/libultra/gu/sintable.c \
|
|
|
|
src/libultra/libc/sprintf.c
|
|
|
|
|
|
|
|
O_FILES := \
|
|
|
|
$(C_FILES:%.c=build/%.o) \
|
|
|
|
$(CXX_FILES:%.cpp=build/%.o)
|
|
|
|
D_FILES := $(O_FILES:%.o=%.d)
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
# Apple App Bundle
|
|
|
|
APPNAME=soh
|
|
|
|
APPBUNDLE=$(APPNAME).app
|
|
|
|
APPBUNDLECONTENTS=$(APPBUNDLE)/Contents
|
|
|
|
APPBUNDLEEXE=$(APPBUNDLECONTENTS)/MacOS
|
|
|
|
APPBUNDLERESOURCES=$(APPBUNDLECONTENTS)/Resources
|
|
|
|
APPBUNDLEICON=$(APPBUNDLECONTENTS)/Resources
|
|
|
|
|
2022-05-11 13:18:24 -04:00
|
|
|
# create build directory
|
|
|
|
SRC_DIRS := $(shell find . -type d -a -not -path "*build*")
|
|
|
|
$(shell mkdir -p $(SRC_DIRS:%=build/%))
|
|
|
|
|
|
|
|
all:
|
|
|
|
$(MAKE) -C ../libultraship
|
|
|
|
$(MAKE) $(TARGET)
|
|
|
|
|
|
|
|
setup:
|
|
|
|
cd ../OTRExporter && python3 extract_baserom.py
|
|
|
|
$(MAKE) mpq
|
|
|
|
|
|
|
|
mpq:
|
|
|
|
$(MAKE) -C ../libultraship
|
|
|
|
$(MAKE) -C ../OTRExporter/OTRExporter
|
|
|
|
$(MAKE) -C ../ZAPDTR
|
|
|
|
rm -rf ../OTRExporter/oot.otr
|
|
|
|
cd ../OTRExporter && python3 extract_assets.py
|
|
|
|
cp ../OTRExporter/oot.otr .
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
$(RM) -r baserom/
|
|
|
|
$(MAKE) clean -C ../libultraship
|
|
|
|
$(MAKE) clean -C ../OTRExporter/OTRExporter
|
|
|
|
$(MAKE) clean -C ../ZAPDTR
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf build $(TARGET)
|
|
|
|
|
|
|
|
.PHONY: all clean distclean setup mpq
|
|
|
|
|
|
|
|
build/%.o: %.cpp
|
|
|
|
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) $< -o $@
|
|
|
|
|
|
|
|
build/%.o: %.c
|
|
|
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) $< -o $@
|
|
|
|
|
|
|
|
# make soh depend on libultraship
|
|
|
|
$(TARGET): $(LIBULTRASHIP)
|
|
|
|
|
|
|
|
$(TARGET): $(O_FILES)
|
2022-07-10 10:51:12 -04:00
|
|
|
$(CXX) $^ -o $@ $(LDFLAGS) $(LDDIRS) $(LDLIBS)
|
2022-05-11 13:18:24 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
-include $(D_FILES)
|
|
|
|
|
|
|
|
appbundle: macosx/$(APPNAME).icns
|
|
|
|
rm -rf $(APPBUNDLE)
|
|
|
|
mkdir $(APPBUNDLE)
|
|
|
|
mkdir $(APPBUNDLE)/Contents
|
|
|
|
mkdir $(APPBUNDLE)/Contents/MacOS
|
|
|
|
mkdir $(APPBUNDLE)/Contents/Resources
|
|
|
|
cp macosx/Info.plist $(APPBUNDLECONTENTS)/
|
|
|
|
cp macosx/PkgInfo $(APPBUNDLECONTENTS)/
|
|
|
|
cp macosx/$(APPNAME).icns $(APPBUNDLEICON)/
|
|
|
|
cp $(TARGET) $(APPBUNDLEEXE)/soh
|
|
|
|
cp macosx/launcher.sh $(APPBUNDLEEXE)/launcher.sh
|
|
|
|
clang -ObjC macosx/appsupport.m -arch arm64 -arch x86_64 -framework Foundation -o macosx/appsupport
|
|
|
|
cp macosx/appsupport $(APPBUNDLEEXE)/appsupport
|
|
|
|
otool -l $(TARGET) | grep -A 2 LC_RPATH | tail -n 1 | awk '{print $2}' | dylibbundler -od -b -x $(APPBUNDLEEXE)/soh -d $(APPBUNDLECONTENTS)/libs
|
|
|
|
|
|
|
|
macosx/$(APPNAME).icns: macosx/$(APPNAME)Icon.png
|
|
|
|
rm -rf macosx/$(APPNAME).iconset
|
|
|
|
mkdir macosx/$(APPNAME).iconset
|
|
|
|
sips -z 16 16 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_16x16.png
|
|
|
|
sips -z 32 32 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_16x16@2x.png
|
|
|
|
sips -z 32 32 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_32x32.png
|
|
|
|
sips -z 64 64 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_32x32@2x.png
|
|
|
|
sips -z 128 128 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_128x128.png
|
|
|
|
sips -z 256 256 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_128x128@2x.png
|
|
|
|
sips -z 256 256 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_256x256.png
|
|
|
|
sips -z 512 512 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_256x256@2x.png
|
|
|
|
sips -z 512 512 macosx/$(APPNAME)Icon.png --out macosx/$(APPNAME).iconset/icon_512x512.png
|
|
|
|
cp macosx/$(APPNAME)Icon.png macosx/$(APPNAME).iconset/icon_512x512@2x.png
|
|
|
|
iconutil -c icns -o macosx/$(APPNAME).icns macosx/$(APPNAME).iconset
|
|
|
|
rm -r macosx/$(APPNAME).iconset
|
|
|
|
|
|
|
|
filledappbundle: appbundle
|
|
|
|
cp ./oot.otr $(APPBUNDLEEXE)/oot.otr
|
|
|
|
|