CC = gcc
CFLAGS = -g -Wall
LDFLAGS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo

# Architektur automatisch erkennen (arm64 oder x86_64)
ARCH := $(shell uname -m)

ifeq ($(ARCH),arm64)
	BINARIES = ./macos-arm64
else
	BINARIES = ./macos-x64
endif

raylib_folder = ./raylib
unityfolder = ./unity

# --------------------------
# eigenes Spiel bauen
# --------------------------
wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
	$(CC) $(CFLAGS) -o wordsalad_myversion main.c graphicalGame.c $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)

# --------------------------
# Normales Spiel bauen
# --------------------------
all: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
	$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)

main.o: main.c
	$(CC) -c $(CFLAGS) main.c

input.o: input.c
	$(CC) -c $(CFLAGS) input.c

game.o: game.c
	$(CC) -c $(CFLAGS) game.c

graphicalGame.o: graphicalGame.c
	$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c

# --------------------------
# Unit Tests
# --------------------------
TEST_BIN = runTests

test: input.o game.o unit_tests.c
	$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a

# --------------------------
# Clean
# --------------------------
clean:
	rm -f *.o wordsalad wordsalad_myversion $(TEST_BIN)