# $Id: Makefile.in,v 1.18 2006/01/04 06:11:04 nigel Exp $
# 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@
SLIRP_SRCS = @SLIRP_SRCS@

## 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 semaphore.h \
	  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

SLIRP_OBJ = $(patsubst ../slirp/%.c, build/%.o, $(SLIRP_SRCS))
SLIRP_LIB = libslirp.a

APP = $(OBJ_DIR)/BasiliskII.app

DEPS = $(OBJ_DIR) $(GEN) $(SLIRP_LIB) $(SRCS)

## Rules

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

all: $(APP)

ide: $(DEPS)
	open $(PROJECT)

test: $(APP)
	open $(APP)

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


$(APP): $(DEPS)
	$(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
	rm -fr autom4te.cache

clean: mostlyclean
	rm -f $(SLIRP_LIB)
	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 $@


$(SLIRP_OBJ) : build/%.o : ../slirp/%.c
	$(CC) -I../slirp $(CPPFLAGS) $(DEFS) $(CFLAGS) $(LDFLAGS) -c $< -o $@

$(SLIRP_LIB) : $(SLIRP_OBJ)
	libtool -static -o libslirp.a build/*.o

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