incomplete support for macOS builds

This commit is contained in:
Zack Buhman 2026-04-07 12:49:39 -05:00
parent c4053cd8b7
commit e08e842764
3 changed files with 28 additions and 6 deletions

5
.gitignore vendored
View File

@ -2,4 +2,7 @@
*.spv
*.o
main
*.pack
*.pack
tool/pack_file
*.zip
*.tar

View File

@ -5,7 +5,9 @@ AS=$(PREFIX)as
OBJARCH = elf64-x86-64
OPT = -O0 -march=x86-64-v3
UNAME := $(shell uname -s)
OPT += -O0 -march=x86-64-v3
DEBUG = -g
@ -25,9 +27,13 @@ CFLAGS += -fpic
FLAGS += -fstack-protector -fstack-protector-all -fno-omit-frame-pointer -fsanitize=address
LDFLAGS += -lm
ifeq ($(shell uname),Linux)
ifeq ($(UNAME),Linux)
LDFLAGS += -Wl,-z noexecstack
endif
ifeq ($(UNAME),Darwin)
LDFLAGS += -framework Foundation -framework Cocoa -framework IOKit -framework AVFoundation -framework CoreVideo -framework CoreAudio -framework CoreMedia -framework CoreHaptics -framework AudioToolbox -framework GameController -framework ForceFeedback -framework Carbon -framework Metal -framework QuartzCore -framework UniformTypeIdentifiers
LDFLAGS += -lstdc++
endif
OBJS = \
src/main.o \
@ -35,8 +41,13 @@ OBJS = \
src/file.o \
src/pack.o
ifeq ($(UNAME),Darwin)
LIBS = \
../SDL3-dist/lib/libSDL3.a
else
LIBS = \
../SDL3-dist/lib64/libSDL3.a
endif
all: main

View File

@ -8,8 +8,17 @@
#include "file.h"
extern "C" {
#ifdef __APPLE__
extern uint8_t const files_pack_start[];
extern uint8_t const files_pack_end[];
#define files_pack_start files_pack_start
#define files_pack_end files_pack_end
#else
extern uint8_t const _files_pack_start[];
extern uint8_t const _files_pack_end[];
#define files_pack_start _files_pack_start
#define files_pack_end _files_pack_end
#endif
};
namespace file {
@ -18,12 +27,12 @@ namespace file {
{
fprintf(stderr, "(pack) filename: %s\n", r_filename);
pack::header const * header = (pack::header const *)&_files_pack_start[0];
pack::header const * header = (pack::header const *)&files_pack_start[0];
if (header->magic != pack::magic_value) {
fprintf(stderr, "invalid header magic: %08x expected magic value: %08x\n", header->magic, pack::magic_value);
exit(EXIT_FAILURE);
}
ptrdiff_t data = (ptrdiff_t)&_files_pack_start[header->header_size];
ptrdiff_t data = (ptrdiff_t)&files_pack_start[header->header_size];
for (unsigned int i = 0; i < header->entry_count; i++) {
if (strcmp(header->entry[i].filename, r_filename) == 0) {
@ -35,5 +44,4 @@ namespace file {
fprintf(stderr, "filename not found in pack file %s\n", r_filename);
exit(EXIT_FAILURE);
}
}