Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for macOS #441

Merged
merged 81 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
acb57f1
Fixed soh filters
KiritoDv May 16, 2022
f3496a0
add more makefile changes
crowell May 15, 2022
f5af934
almost ready
crowell May 16, 2022
97ba6a4
more updates
crowell May 19, 2022
91d89f7
update
crowell May 19, 2022
e495961
update
crowell May 19, 2022
3bf32d1
Update Makefiles to handle both platforms
dcvz May 30, 2022
44eb8d4
Allow for overriding the CXX and CC executables
dcvz May 30, 2022
f3a66ea
Restore original structure while supporting custom CXX flags
dcvz May 30, 2022
686e5b3
Remove some platform specific libs
dcvz May 30, 2022
acebb20
Dynamic target name
dcvz May 30, 2022
780ed6d
Make X11 paths package-agnostic
dcvz May 30, 2022
401a344
Remove changes to `gfx_opengl.cpp`
dcvz May 30, 2022
a87a5b9
Merge pull request #1 from crowell/chore/update-make
crowell May 30, 2022
91da461
Use OpenGL2 on MacOS instead of OpenGL3
crowell May 30, 2022
9e082fd
make it actually render something
crowell May 30, 2022
ba882b2
render at least the first texture, still need to figure out the second
crowell May 30, 2022
8ab2a0d
Let’s use OpenGL 3 again
dcvz May 30, 2022
dbacf38
maybe this works to get the right texture? link's eyes still look off…
crowell May 30, 2022
f7b7de7
did this work?
crowell May 30, 2022
4177721
set the platform to macos
crowell May 30, 2022
508b5c7
actual numbers are right, but logic is ugly XXX/TODO, i know
crowell May 30, 2022
447b28c
add zlib to ldflags for ZAPDUtils
crowell May 30, 2022
831cd63
A bit of cleanup
dcvz May 30, 2022
1232e00
Revert unneeded changes
dcvz May 30, 2022
8b58050
Remove GL_CHECK
dcvz May 30, 2022
0e0577d
Merge remote-tracking branch 'upstream/zelda64' into zelda64_mac
dcvz May 30, 2022
094c2b0
Fix issues with z64 branch
dcvz May 30, 2022
01d5e06
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 1, 2022
c17e3da
use an std::map instead of a giant array
crowell Jun 1, 2022
d533319
three point filter fix (#2)
dcvz Jun 2, 2022
d066fbf
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 2, 2022
54f1bbf
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 2, 2022
de4f2fb
Fix mac compilation
dcvz Jun 2, 2022
33bb174
fix audio for 64 bit
crowell Jun 3, 2022
b80d1f1
revert audio heap size, keep bigger pools
crowell Jun 3, 2022
5205363
Add more Apple specific checks to our modifications
dcvz Jun 3, 2022
8fd50af
Add building instructions for macOS
dcvz Jun 3, 2022
09025a3
Remove unecessary step from building instructions
dcvz Jun 3, 2022
9c6f10f
Add missing SDL2 & GLEW to Linux LDLIBS
dcvz Jun 4, 2022
8f635c2
Update BUILDING.md
dcvz Jun 4, 2022
5fbed02
Update soh/.gitignore to include other arch binaries
dcvz Jun 4, 2022
d22c6b1
Use right platform name for debugging window
dcvz Jun 4, 2022
941c09b
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 4, 2022
af6fc6f
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 5, 2022
0c8cc18
Fix stormlib on macos (arm64)
dcvz Jun 5, 2022
b7e7032
Simplify some of the ifdef checks
dcvz Jun 5, 2022
db59329
Revert an older no longer necessary fix
dcvz Jun 5, 2022
9b9ec2b
Remove remaining unecessary deviations
dcvz Jun 5, 2022
67a8ca0
Update building instructions after StormLib changes
dcvz Jun 5, 2022
361a2be
Feature: Use OpenGL 4.1 (#1)
dcvz Jun 9, 2022
86975fe
Further tweak the BUILDING
dcvz Jun 9, 2022
554e85d
Tidy up
dcvz Jun 9, 2022
5302776
reword -j message
dcvz Jun 9, 2022
15dbb06
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 13, 2022
fb7ce12
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 13, 2022
2bf7b3e
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 13, 2022
5bb2605
Add Jenkins CI Support (#2)
dcvz Jun 13, 2022
9694177
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 13, 2022
a109535
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 14, 2022
784bb74
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 15, 2022
cd89807
Fix type issues
dcvz Jun 15, 2022
7517785
add target <appbundle> and <filledappbundle>
crowell Jun 16, 2022
5205c25
pull gcc's rpath from otool output
crowell Jun 16, 2022
dd47590
move make target to the end so it's not default
crowell Jun 16, 2022
1be6ae7
Add Jenkins and make exe in par with other platforms
dcvz Jun 16, 2022
3900b6b
Actually save build artefacts
dcvz Jun 16, 2022
2260137
Fix artefact path
dcvz Jun 16, 2022
29a7820
Remove x11 mentions and linking (not used)
dcvz Jun 16, 2022
f2bd020
Update building instructions for generating app
dcvz Jun 16, 2022
253db5a
use appsupport directory
crowell Jun 17, 2022
e1cd6c9
Add new app icon
dcvz Jun 17, 2022
caf1c25
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 17, 2022
888c074
Update target to match macOS types
dcvz Jun 18, 2022
fba7a89
Update more audio types
dcvz Jun 18, 2022
7e149d6
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 19, 2022
a7c2d2c
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 19, 2022
5001da6
fix null deref in Audio_PlayFanfare
crowell Jun 20, 2022
7e20272
Merge branch 'zelda64' into zelda64_mac
dcvz Jun 22, 2022
3693992
Remove old import from z64
dcvz Jun 22, 2022
a514d23
address final nit with apple ifdefs
crowell Jun 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,9 @@ ZAPDUtils/build/
ZAPD/BuildInfo.h

DebugObj/*
ReleaseObj/*
ReleaseObj/*
.tags
tags
oot.otr
oot_save.sav
shipofharkinian.ini
21 changes: 21 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ make setup -j$(nproc) OPTFLAGS=-O2 DEBUG=0
make -j $(nproc) OPTFLAGS=-O2 DEBUG=0
```

## macOS

1. Requires `gcc@12, sdl2, libpng, glew, dylibbundler` (can be installed via brew, etc)
```bash
# Clone the repo
git clone https://github.com/HarbourMasters/Shipwright.git
cd ShipWright
# Copy the baserom to the OTRExporter folder
cp <path to your ROM> OTRExporter

cd soh
# Extract the assets/Compile the exporter/Run the exporter
# -jX defines number of cores to use for compilation - lower or remove entirely if having issues
make setup -j8 DEBUG=0 CC=gcc-12 CXX=g++-12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-jx no longer works for me for make setup. Does it work for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does! But no code that we change would affect that, that is a parameter to the make command

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it just worked now :-S

# Compile the code (watch the -j parameter as above)
make -j8 DEBUG=0 CC=gcc-12 CXX=g++-12
dcvz marked this conversation as resolved.
Show resolved Hide resolved
# Create macOS app bundle
make filledappbundle
```
9. Launch soh app in the soh folder!

# Compatible Roms
```
OOT_PAL_GC checksum 0x09465AC3
Expand Down
34 changes: 34 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,39 @@ pipeline {
}
}
}
stage ('Build macOS') {
Copy link
Contributor Author

@dcvz dcvz Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For merging purposes this just verifies that building works and does not do any distribution.
This will come in a later PR once this is merged into mainline

agent {
label "SoH-Mac-Builders"
}
steps {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions,
userRemoteConfigs: scm.userRemoteConfigs
])
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh '''
cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64

cd soh
make setup -j4 DEBUG=0 CC=gcc-12 CXX=g++-12
make -j4 DEBUG=0 CC=gcc-12 CXX=g++-12

make -j4 appbundle

mv ../README.md readme.txt
7z a soh-mac.7z soh.app readme.txt
'''
}
archiveArtifacts artifacts: 'soh/soh-mac.7z', followSymlinks: false, onlyIfSuccessful: true
}
post {
always {
step([$class: 'WsCleanup']) // Clean workspace
}
}
}
}
}
6 changes: 3 additions & 3 deletions OTRExporter/OTRExporter/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Only used for standalone compilation, usually inherits these from the main makefile

CXX := g++
CXX ?= g++
AR := ar
FORMAT := clang-format-11

Expand Down Expand Up @@ -31,7 +31,7 @@ ifneq ($(LTO),0)
CXXFLAGS += -flto
endif

SRC_DIRS := $(shell find -type d -not -path "*build*")
SRC_DIRS := $(shell find . -type d -not -path "*build*")
CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))

Expand Down Expand Up @@ -69,4 +69,4 @@ build/%.o: %.cpp
$(LIB): $(O_FILES)
$(AR) rcs $@ $^

-include $(D_FILES)
-include $(D_FILES)
2 changes: 1 addition & 1 deletion StormLib/src/SFileAddFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int FillWritableHandle(
pFileEntry->dwFlags = dwFlags | MPQ_FILE_EXISTS;

// Initialize the file time, CRC32 and MD5
assert(sizeof(hf->hctx) >= sizeof(hash_state));
//assert(sizeof(hf->hctx) >= sizeof(hash_state));
Copy link
Contributor Author

@dcvz dcvz Jun 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand the changes done to StormLib - but now [HASH_STATE_SIZE] is hardcoded, it doesn't seem to be correct for macos(arm64)? -- commenting this out doesn't seem to break anything for either platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NEstelami perhaps you have some insights here? I believe you were the one that made the changes to StormLib, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I didn't get a notification for this. There were only two real changes to StormLib - an optimization to make generating the OTRs several seconds faster, and additional checks when files are looked up in order to make \ and / interchangeable. I don't think I ever made any changes to the hash state size or anything like that.

memset(pFileEntry->md5, 0, MD5_DIGEST_SIZE);
md5_init((hash_state *)hf->hctx);
pFileEntry->dwCrc32 = crc32(0, Z_NULL, 0);
Expand Down
25 changes: 12 additions & 13 deletions ZAPDTR/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ DEBUG ?= 0
COPYCHECK_ARGS ?=
LLD ?= 0
WERROR ?= 0
UNAME := $(shell uname)

# Use clang++ if available, else use g++
ifeq ($(shell command -v clang++ >/dev/null 2>&1; echo $$?),0)
CXX := clang++
CXX ?= clang++
else
CXX := g++
CXX ?= g++
endif

INC := -I ZAPD -I lib/elfio -I lib/libgfxd -I lib/tinyxml2 -I ZAPDUtils
Expand Down Expand Up @@ -44,8 +45,15 @@ ifneq ($(DEPRECATION_ON),0)
endif
# CXXFLAGS += -DTEXTURE_DEBUG

LDFLAGS := -lm -ldl -lpng \
-L../StormLib/build -L../libultraship -lz -lbz2 -pthread -lpulse -lultraship -lstorm -lSDL2 -lGLEW -lGL -lX11
LDFLAGS := -lm -ldl \
-L../StormLib/build -L../libultraship -lbz2 -pthread -lultraship -lstorm

ifeq ($(UNAME), Darwin)
LDFLAGS += $(shell pkg-config --libs glew libpng zlib) $(shell sdl2-config --libs) -framework OpenGL
INC += $(shell pkg-config --cflags libpng)
else
LDFLAGS += -lpng -lGL -lGLEW -lX11 -lz -lSDL2 -lpulse
endif

# Use LLD if available. Set LLD=0 to not use it
ifeq ($(shell command -v ld.lld >/dev/null 2>&1; echo $$?),0)
Expand All @@ -56,21 +64,12 @@ ifneq ($(LLD),0)
LDFLAGS += -fuse-ld=lld
endif

UNAME := $(shell uname)
UNAMEM := $(shell uname -m)
ifneq ($(UNAME), Darwin)
LDFLAGS += -Wl,-export-dynamic -lstdc++fs
EXPORTERS := -Wl,--whole-archive ../OTRExporter/OTRExporter/OTRExporter.a -Wl,--no-whole-archive
else
EXPORTERS := -Wl,-force_load ../OTRExporter/OTRExporter/OTRExporter.a
ifeq ($(UNAMEM),arm64)
ifeq ($(shell brew list libpng > /dev/null 2>&1; echo $$?),0)
LDFLAGS += -L $(shell brew --prefix)/lib
INC += -I $(shell brew --prefix)/include
else
$(error Please install libpng via Homebrew)
endif
endif
endif


Expand Down
6 changes: 5 additions & 1 deletion ZAPDTR/ZAPD/ZRom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Utils/Directory.h"
#include "yaz0/yaz0.h"

#ifndef _MSC_VER
#ifdef __linux__
#include <byteswap.h>
#endif
#include <Globals.h>
Expand All @@ -17,6 +17,10 @@ namespace fs = std::filesystem;
#define __bswap_32 _byteswap_ulong
#define bswap_32 _byteswap_ulong
#endif
#if defined __APPLE__
#define __bswap32 __builtin_bswap32
#define bswap32 __builtin_bswap32
#endif

// ROM DMA Table Start
#define OOT_OFF_NTSC_10_RC 0x7430
Expand Down
3 changes: 2 additions & 1 deletion ZAPDTR/ZAPDUtils/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Only used for standalone compilation, usually inherits these from the main makefile
CXX ?= g++
CXXFLAGS ?= -Wall -Wextra -O2 -g -std=c++17

SRC_DIRS := $(shell find -type d -not -path "*build*")
SRC_DIRS := $(shell find . -type d -not -path "*build*")
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))

Expand Down
1 change: 1 addition & 0 deletions ZAPDTR/lib/libgfxd/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CC ?= gcc
CFLAGS = -Wall -O2 -g
UC_OBJ = uc_f3d.o uc_f3db.o uc_f3dex.o uc_f3dexb.o uc_f3dex2.o
OBJ = gfxd.o $(UC_OBJ)
Expand Down
17 changes: 12 additions & 5 deletions libultraship/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Only used for standalone compilation, usually inherits these from the main makefile

CXX := g++
CC := gcc
CXX ?= g++
CC ?= gcc
AR := ar
FORMAT := clang-format-11
UNAME := $(shell uname)

ASAN ?= 0
DEBUG ?= 1
Expand All @@ -16,7 +17,8 @@ WARN := -Wall -Wextra -Werror \
-Wno-unused-function \
-Wno-parentheses \
-Wno-narrowing \
-Wno-missing-field-initializers
-Wno-missing-field-initializers \
-Wno-error=multichar

CWARN :=
CXXWARN := -Wno-deprecated-enum-enum-conversion
Expand All @@ -25,6 +27,10 @@ CXXFLAGS := $(WARN) $(CXXWARN) -std=c++20 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG
CFLAGS := $(WARN) $(CWARN) -std=c99 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0
CPPFLAGS := -MMD

ifeq ($(UNAME), Darwin) #APPLE
CPPFLAGS += $(shell pkg-config --cflags sdl2 glew) -framework OpenGL
endif

ifneq ($(DEBUG),0)
CXXFLAGS += -g -D_DEBUG
CFLAGS += -g -D_DEBUG
Expand All @@ -40,7 +46,7 @@ ifneq ($(LTO),0)
CFLAGS += -flto
endif

SRC_DIRS := $(shell find -type d -not -path "*build*")
SRC_DIRS := $(shell find . -type d -not -path "*build*")

CXX_FILES := \
$(shell find libultraship/Factories -name "*.cpp") \
Expand Down Expand Up @@ -71,6 +77,7 @@ INC_DIRS := $(addprefix -I, \
libultraship/Lib/Fast3D/U64 \
libultraship/Lib/spdlog \
libultraship/Lib/spdlog/include \
libultraship/Lib/ImGui \
libultraship \
../StormLib/src \
)
Expand All @@ -97,4 +104,4 @@ build/%.o: %.c
$(LIB): $(O_FILES)
$(AR) rcs $@ $^

-include $(D_FILES)
-include $(D_FILES)
36 changes: 18 additions & 18 deletions libultraship/libultraship/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ namespace Ship

ResourceFile::ParseFileBinary(reader, res);

int seqDataSize = reader->ReadInt32();
uint32_t seqDataSize = reader->ReadInt32();

seq->seqData.reserve(seqDataSize);

for (int i = 0; i < seqDataSize; i++)
for (uint32_t i = 0; i < seqDataSize; i++)
seq->seqData.push_back(reader->ReadUByte());

seq->seqNumber = reader->ReadUByte();
seq->medium = reader->ReadUByte();
seq->cachePolicy = reader->ReadUByte();

int numFonts = reader->ReadInt32();
uint32_t numFonts = reader->ReadInt32();

for (int i = 0; i < numFonts; i++)
for (uint32_t i = 0; i < numFonts; i++)
seq->fonts.push_back(reader->ReadUByte());
}

Expand All @@ -36,26 +36,26 @@ namespace Ship
entry->unk_bit26 = reader->ReadByte();
entry->unk_bit25 = reader->ReadByte();

int dataSize = reader->ReadInt32();
uint32_t dataSize = reader->ReadInt32();

for (int i = 0; i < dataSize; i++)
for (uint32_t i = 0; i < dataSize; i++)
entry->data.push_back(reader->ReadUByte());

entry->loop.start = reader->ReadUInt32();
entry->loop.end = reader->ReadUInt32();
entry->loop.count = reader->ReadUInt32();

int loopStateCnt = reader->ReadUInt32();
uint32_t loopStateCnt = reader->ReadUInt32();

for (int i = 0; i < loopStateCnt; i++)
for (uint32_t i = 0; i < loopStateCnt; i++)
entry->loop.states.push_back(reader->ReadInt16());

entry->book.order = reader->ReadInt32();
entry->book.npredictors = reader->ReadInt32();

int bookSize = reader->ReadInt32();
uint32_t bookSize = reader->ReadInt32();

for (int i = 0; i < bookSize; i++)
for (uint32_t i = 0; i < bookSize; i++)
entry->book.books.push_back(reader->ReadInt16());
}

Expand All @@ -72,11 +72,11 @@ namespace Ship
soundFont->data2 = reader->ReadInt16();
soundFont->data3 = reader->ReadInt16();

int drumCnt = reader->ReadInt32();
int instrumentCnt = reader->ReadInt32();
int sfxCnt = reader->ReadInt32();
uint32_t drumCnt = reader->ReadInt32();
uint32_t instrumentCnt = reader->ReadInt32();
uint32_t sfxCnt = reader->ReadInt32();

for (int i = 0; i < drumCnt; i++)
for (uint32_t i = 0; i < drumCnt; i++)
{
DrumEntry drum;
drum.releaseRate = reader->ReadUByte();
Expand All @@ -92,7 +92,7 @@ namespace Ship
soundFont->drums.push_back(drum);
}

for (int i = 0; i < instrumentCnt; i++)
for (uint32_t i = 0; i < instrumentCnt; i++)
{
InstrumentEntry entry;

Expand Down Expand Up @@ -143,7 +143,7 @@ namespace Ship
soundFont->instruments.push_back(entry);
}

for (int i = 0; i < sfxCnt; i++)
for (uint32_t i = 0; i < sfxCnt; i++)
{
SoundFontEntry* entry = new SoundFontEntry();

Expand All @@ -164,9 +164,9 @@ namespace Ship
{
std::vector<AdsrEnvelope*> envelopes;

int envelopeCnt = reader->ReadInt32();
uint32_t envelopeCnt = reader->ReadInt32();

for (int i = 0; i < envelopeCnt; i++)
for (uint32_t i = 0; i < envelopeCnt; i++)
{
AdsrEnvelope* env = new AdsrEnvelope();
env->delay = reader->ReadInt16();
Expand Down
4 changes: 2 additions & 2 deletions libultraship/libultraship/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Ship

struct AdpcmBook
{
/* 0x00 */ int32_t order;
/* 0x04 */ int32_t npredictors;
/* 0x00 */ uint32_t order;
/* 0x04 */ uint32_t npredictors;
/* 0x08 */ std::vector<int16_t> books; // size 8 * order * npredictors. 8-byte aligned
};

Expand Down
Loading