# Windows Makefile for Basilisk II

## System specific configuration

SHELL = /bin/sh

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
datadir = @datadir@
mandir = @mandir@
man1dir = $(mandir)/man1

KEYCODES = ../SDL/keycodes

DESTDIR =

SDL_CFLAGS = @SDL_CFLAGS@
SDL_LIBS = @SDL_LIBS@
WANT_GTK = @WANT_GTK@
GTK_CFLAGS = @GTK_CFLAGS@
GTK_LIBS = @GTK_LIBS@

SLIRP_CFLAGS = @SLIRP_CFLAGS@
SLIRP_SRCS = \
    ../slirp/bootp.c     ../slirp/ip_output.c  ../slirp/tcp_input.c  \
    ../slirp/cksum.c     ../slirp/mbuf.c       ../slirp/tcp_output.c \
    ../slirp/debug.c     ../slirp/misc.c       ../slirp/tcp_subr.c   \
    ../slirp/if.c        ../slirp/sbuf.c       ../slirp/tcp_timer.c  \
    ../slirp/ip_icmp.c   ../slirp/slirp.c      ../slirp/tftp.c       \
    ../slirp/ip_input.c  ../slirp/socket.c     ../slirp/udp.c
SLIRP_OBJS = $(SLIRP_SRCS:../slirp/%.c=$(OBJ_DIR)/slirp-%.o)

USE_BINCUE = @USE_BINCUE@

LN_S = @LN_S@
WINDRES = @WINDRES@
CC = @CC@
CXX = @CXX@
CFLAGS = @CFLAGS@ $(SDL_CFLAGS)
CXXFLAGS = @CXXFLAGS@ $(SDL_CFLAGS)
CPPFLAGS = @CPPFLAGS@ -I../include -I. -I../CrossPlatform @CPUINCLUDES@ -I../slirp
DEFS = @DEFS@ @DEFINES@
LDFLAGS = @LDFLAGS@ -Wl,-Bstatic
LIBS = @LIBS@ -lws2_32 -lwsock32 -liphlpapi
CPUSRCS = @CPUSRCS@
EXTRASRCS = @EXTRASRCS@

HOST_CC = gcc
HOST_CXX = g++
HOST_CFLAGS = -O2
HOST_CXXFLAGS = -O2
HOST_LDFLAGS =

## Files
XPLATSRCS = vm_alloc.cpp vm_alloc.h sigsegv.cpp sigsegv.h video_vosf.h video_blit.cpp video_blit.h

CDENABLESRCS = cdenable/cache.cpp cdenable/eject_nt.cpp cdenable/ntcd.cpp

ROUTERSRCS =  router/arp.cpp router/dump.cpp router/dynsockets.cpp router/ftp.cpp \
	router/icmp.cpp router/mib/interfaces.cpp router/iphelp.cpp router/ipsocket.cpp \
	router/mib/mibaccess.cpp router/router.cpp router/tcp.cpp router/udp.cpp b2ether/packet32.cpp

SRCS = ../main.cpp main_windows.cpp ../prefs.cpp ../prefs_items.cpp prefs_windows.cpp \
    sys_windows.cpp ../rom_patches.cpp ../slot_rom.cpp ../rsrc_patches.cpp \
    ../emul_op.cpp ../macos_util.cpp ../xpram.cpp xpram_windows.cpp ../timer.cpp \
    timer_windows.cpp ../adb.cpp ../serial.cpp serial_windows.cpp \
    ../ether.cpp ether_windows.cpp ../sony.cpp ../disk.cpp ../cdrom.cpp \
    ../scsi.cpp ../dummy/scsi_dummy.cpp ../video.cpp \
    ../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp ../SDL/video_sdl3.cpp \
    video_blit.cpp ../audio.cpp ../SDL/audio_sdl.cpp ../SDL/audio_sdl3.cpp clip_windows.cpp \
	../extfs.cpp extfs_windows.cpp ../user_strings.cpp user_strings_windows.cpp \
    vm_alloc.cpp sigsegv.cpp posix_emu.cpp util_windows.cpp \
    ../dummy/prefs_editor_dummy.cpp BasiliskII.rc \
    $(CDENABLESRCS) $(ROUTERSRCS) $(CPUSRCS) $(EXTRASRCS) $(SLIRP_OBJS)

UI_SRCS = ../prefs.cpp prefs_windows.cpp prefs_editor_gtk.cpp xpram_windows.cpp \
	../prefs_items.cpp ../user_strings.cpp user_strings_windows.cpp util_windows.cpp \
	b2ether/Packet32.cpp BasiliskIIGUI.rc

UI_APP = BasiliskIIGUI.exe

APP = BasiliskII.exe

PROGS = $(APP)

ifeq ($(WANT_GTK),yes)
PROGS += $(UI_APP)
endif

## Rules
.PHONY: modules install installdirs uninstall mostlyclean clean distclean depend dep
.SUFFIXES:
.SUFFIXES: .c .cpp .s .o .h

all: $(PROGS)

$(XPLATSRCS): %: ../CrossPlatform/%
	$(LN_S) $< $@

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

define SRCS_LIST_TO_OBJS
	$(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(foreach file, $(SRCS), \
	$(basename $(notdir $(file))))))
endef
OBJS = $(SRCS_LIST_TO_OBJS)

define UI_SRCS_LIST_TO_OBJS
	$(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(foreach file, $(UI_SRCS), \
	$(basename $(notdir $(file))))))
endef
UI_OBJS = $(UI_SRCS_LIST_TO_OBJS)

SRC_PATHS += $(sort $(foreach file, $(SRCS), $(dir $(file))))
VPATH :=
VPATH += $(addprefix :, $(subst  ,:, $(filter-out $($(subst, :, ,$(VPATH))), $(SRC_PATHS))))

$(APP): $(XPLATSRCS) $(OBJ_DIR) $(OBJS)
	$(CXX) -o $@ $(LDFLAGS) $(OBJS) $(LIBS) $(SDL_LIBS)

$(UI_APP): $(XPLATSRCS) $(OBJ_DIR) $(UI_OBJS)
	$(CXX) -o $@ $(LDFLAGS) $(UI_OBJS) $(LIBS) -Wl,-Bdynamic $(GTK_LIBS) -Wl,-Bstatic -mwindows -static-libgcc

mostlyclean:
	rm -f $(APP) $(UI_APP) $(OBJ_DIR)/* core* *.core *~ *.bak

clean: mostlyclean
	rm -f $(XPLATSRCS)
	rm -f cpuemu.cpp cpudefs.cpp cputmp*.s cpufast*.s cpustbl.cpp cputbl.h compemu.cpp compstbl.cpp comptbl.h

distclean: clean
	rm -rf $(OBJ_DIR)
	rm -rf autom4te.cache
	rm -f Makefile
	rm -f config.cache config.log config.status config.h

depend dep:
	makedepend $(CPPFLAGS) -Y. $(SRCS) 2>/dev/null

$(OBJ_DIR)/%.ho : %.c
	$(HOST_CC) $(CPPFLAGS) $(DEFS) $(HOST_CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.ho : %.cpp
	$(HOST_CXX) $(CPPFLAGS) $(DEFS) $(HOST_CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/slirp-%.o : ../slirp/%.c
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(SLIRP_CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o : %.c
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o : %.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o : %.s
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/prefs_editor_gtk.o: prefs_editor_gtk.cpp
	$(CXX) -O2 -mms-bitfields $(CPPFLAGS) $(DEFS) $(GTK_CFLAGS) -c $< -o $@

# Windows resources
$(OBJ_DIR)/%.o: %.rc
	$(WINDRES) --include-dir ../Windows -i $< -o $@
$(OBJ_DIR)/build68k.exe: $(OBJ_DIR)/build68k.ho
	$(HOST_CC) $(HOST_LDFLAGS) -o $@ $<
$(OBJ_DIR)/gencpu.exe: $(OBJ_DIR)/gencpu.ho $(OBJ_DIR)/readcpu.ho $(OBJ_DIR)/cpudefs.ho
	$(HOST_CXX) $(HOST_LDFLAGS) -o $@ $(OBJ_DIR)/gencpu.ho $(OBJ_DIR)/readcpu.ho $(OBJ_DIR)/cpudefs.ho
$(OBJ_DIR)/gencomp.exe: $(OBJ_DIR)/gencomp.ho $(OBJ_DIR)/readcpu.ho $(OBJ_DIR)/cpudefs.ho
	$(HOST_CXX) $(HOST_LDFLAGS) -o $@ $(OBJ_DIR)/gencomp.ho $(OBJ_DIR)/readcpu.ho $(OBJ_DIR)/cpudefs.ho

cpudefs.cpp: $(OBJ_DIR)/build68k.exe ../uae_cpu/table68k
	$(OBJ_DIR)/build68k.exe ../uae_cpu/table68k >cpudefs.cpp
cpustbl.cpp: cpuemu.cpp
cpustbl_nf.cpp: cpustbl.cpp
compstbl.cpp: compemu.cpp
cputbl.h: cpuemu.cpp
comptbl.h: compemu.cpp

cpuemu.cpp: $(OBJ_DIR)/gencpu.exe
	$(OBJ_DIR)/gencpu.exe

compemu.cpp: $(OBJ_DIR)/gencomp.exe
	$(OBJ_DIR)/gencomp.exe

$(OBJ_DIR)/cpustbl_nf.o: cpustbl.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) $(CXXFLAGS) -DNOFLAGS -c $< -o $@

$(OBJ_DIR)/compemu_support.o: compemu_support.cpp comptbl.h
	$(CXX) $(CPPFLAGS) $(DEFS) $(CXXFLAGS) -c $< -o $@

$(OBJ_DIR)/cpuemu1.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_1 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu2.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_2 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu3.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_3 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu4.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_4 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu5.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_5 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu6.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_6 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu7.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_7 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu8.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_8 $(CXXFLAGS) -c $< -o $@

$(OBJ_DIR)/cpuemu1_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_1 -DNOFLAGS $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu2_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_2 -DNOFLAGS $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu3_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_3 -DNOFLAGS $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu4_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_4 -DNOFLAGS $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu5_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_5 -DNOFLAGS $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu6_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_6 -DNOFLAGS $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu7_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_7 -DNOFLAGS $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu8_nf.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_8 -DNOFLAGS $(CXXFLAGS) -c $< -o $@

$(OBJ_DIR)/compemu1.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_1 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/compemu2.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_2 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/compemu3.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_3 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/compemu4.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_4 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/compemu5.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_5 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/compemu6.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_6 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/compemu7.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_7 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/compemu8.o: compemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_8 $(CXXFLAGS) -c $< -o $@

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