# $Id$
# MacOS X makefile for Basilisk II. Slightly based on the Unix one

## System specific configuration
@SET_MAKE@
SHELL = /bin/sh


CC = @CC@
CXX = @CXX@
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
CPPFLAGS = @CPPFLAGS@ -I../include -I. @CPUINCLUDES@
DEFS = @DEFS@ @DEFINES@ -D_REENTRANT
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
BLESS = @BLESS@
IDE = @IDE@
PROJECT = @PROJECT@
IDEARGS = @IDEARGS@

## Files
OBJ_DIR = build
GENSRCS = cpudefs.cpp cpuemu.cpp cpustbl.cpp cputbl.h

# Wrappers which split the very large cpuemu.cpp into smaller compile units
GENEMUS = cpuemu1.cpp cpuemu2.cpp cpuemu3.cpp cpuemu4.cpp \
	  cpuemu5.cpp cpuemu6.cpp cpuemu7.cpp cpuemu8.cpp

# Symlinks to, or copies of, files in other directories
GENLINK = README.txt INSTALL.txt install-sh \
	  Darwin config.guess config.sub \
	  sys_unix.cpp timer_unix.cpp user_strings_unix.h

GEN  = $(GENEMUS) $(GENSRCS)

SRCS =  BasiliskII.icns Controller.h Controller.mm Credits.html \
	Emulator.h Emulator.mm EmulatorView.h EmulatorView.mm English.lproj \
	NNThread.h NNThread.m PrefsEditor.h PrefsEditor.mm \
	ToDo.html Versions.html \
	audio_macosx.mm extfs_macosx.mm macos_util_macosx.h main_macosx.h \
	main_macosx.mm misc_macosx.h misc_macosx.mm nowrite.icns prefs_macosx.cpp \
	sysdeps.h video_macosx.mm video_macosx.h
APP = $(OBJ_DIR)/BasiliskII.app

## Rules

.PHONY: mostlyclean clean distclean depend dep
.SUFFIXES:
.SUFFIXES: .c .cpp .s .o .h

all: $(APP)

ide: $(OBJ_DIR) $(GEN) $(SRCS)
	open $(PROJECT)

test: $(APP)
	open $(APP)

$(OBJ_DIR)::
	@[ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1


$(APP): $(OBJ_DIR) $(GEN) $(SRCS)
	$(IDE) -buildstyle Deployment $(IDEARGS) \
		&& $(BLESS) $(APP)/Contents/MacOS/BasiliskII \
		|| rm -fr $(APP)

BasiliskII.icns :
	touch $@

nowrite.icns :
#	ln -sf /System/Library/CoreServices/Finder.app/Contents/Resources/nowrite.icns .
	touch $@

mostlyclean:
	rm -fr English.lproj/*~* $(OBJ_DIR)/* core* *.core *~ *.bak

clean: mostlyclean
	rm -f $(GEN)
	rm -f cpudefs.cpp cputmp*.s cpufast*.s cpustbl.cpp

distclean: clean
	rm -rf $(OBJ_DIR)
	rm -rf autom4te.cache
	rm -f Makefile
	rm -f config.cache config.log config.status config.h config.h.in
	rm -f Darwin/lowmem Darwin/pagezero
	rm -f $(GENLINK)
	rm -f configure
	rm -f .DS_Store




$(OBJ_DIR)/build68k: ../uae_cpu/build68k.c
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(LDFLAGS) $< -o $@

$(OBJ_DIR)/cpuopti: ../uae_cpu/cpuopti.c
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(LDFLAGS) $< -o $@

$(OBJ_DIR)/gencpu: cpudefs.cpp ../uae_cpu/gencpu.c ../uae_cpu/readcpu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS) $^ -o $@



cpudefs.cpp: $(OBJ_DIR)/build68k ../uae_cpu/table68k
	$(OBJ_DIR)/build68k < ../uae_cpu/table68k > $@

cpuemu.cpp cpustbl.cpp cputbl.h: $(OBJ_DIR)/gencpu
	$<


$(GENEMUS) : cpuemu.cpp
	for i in 1 2 3 4 5 6 7 8; \
	do \
	printf "#define  PART_%d\n#include \"%s\"\n" $$i $<  >cpuemu$$i.cpp; \
	done


cpufast.s: cpuemu.s $(OBJ_DIR)/cpuopti
	$(OBJ_DIR)/cpuopti <cpuemu.s >$@ || mv cputmp.s $@

cpuemu.s: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -S $(CXXFLAGS) $< -o $@

#-------------------------------------------------------------------------
# DO NOT DELETE THIS LINE -- make depend depends on it.
