#############################################################################
#                                                                           #
#                            Third Year Project                             #
#                                                                           #
#                            An IBM PC Emulator                             #
#                          For Unix and X Windows                           #
#                                                                           #
#                             By David Hedley                               #
#                                                                           #
#                                                                           #
# This program is Copyrighted.  Consult the file COPYRIGHT for more details #
#                                                                           #
#############################################################################

# Valid options are as follow:
# -DINLINE_FUNCTIONS if your compiler support inline functions (most do)
# -DDEBUG            prints lots of debugging messages.
# -DDEBUGGER         compiles in the debugger
# -DKBUK             if you have a UK style 102 key keyboard
# -DBIG_ENDIAN       if your computer is big-endian (Sparc, 68000 etc)
# -DLITTLE_ENDIAN    if your computer is little-endian (80x86 etc)
# -DALIGNED_ACCESS   if your computer requires words to be on even boundaries
# -DBIGCASE          If your compiler/computer can handle 256 case switches
#
# -D_HPUX_SOURCE     If you are compiling on an HP
# -DSOLARIS          If you are using Solaris (only 2.3 has been tested)
# -DSGI              If you are using an SGI
# -DRS6000           If you are using an RS6000
#
# Note that when compiling on the RS6000 and SGI using the standard cc compiler
# specifying -O2 to optimise the code results in the emulator crashing. I
# believe this is due to compiler bugs (as the programs run OK without
# optimisation). If anyone can shed light on what the problem is I would be
# eternally grateful.
#
# Not specifying the following will mean the defaults are used. They can be
# overridden in the .pcemurc file
#
# -DBOOT360          Boot from a 360k disk image  file
# -DBOOT720          Boot from a 720k disk image file
# -DBOOT1_44         Boot from a 1.44Mb disk image file
# -DBOOT1_2          Boot from a 1.2Mb disk image file
#
# -DBOOTFILE="xyz"   Boot from disk image "xyz" (default "DriveA")
# -DCURSORSPEED=n    Set cursor flash speed to n frames per flash (default 30)
# -DUPDATESPEED=n    Set screen update speed to n frames per update (default 5)
# 
# Including -fomit-frame-pointer should increase speed a little, but it has
# been known to crash the emulator when running on certain machines (80x86
# based PCs under Linux, and HPs running HPUX). 

OPTIONS = define=BOOT1_44 define=BIG_ENDIAN define=ALIGNED_ACCESS \
          define=BIGCASE define=INLINE_FUNCTIONS  define=AMIGA \
          define=strcasecmp=stricmp define=strncasecmp=strnicmp \
          define=inline=__inline

CC      = sc
CFLAGS = CPU=68060 MATH=68881 PARM=REG OPTIMIZE OPTTIME OPTSCHED NODEBUG CODE=FAR DATA=FAR STRINGMERGE NOSTACKCHECK
#CFLAGS = CPU=68060 MATH=68881 PARM=REG OPTIMIZE OPTTIME OPTSCHED DEBUG=FULL CODE=FAR DATA=FAR STRINGMERGE NOSTACKCHECK
#CFLAGS = CPU=68060 MATH=68881 PARM=REG NOOPTIMIZE DEBUG=FULL CODE=FAR DATA=FAR STRINGMERGE STACKCHECK

CCPPC   = scppc
CFLAGSPPC = PARM=REG OPTIMIZE OPTTIME OPTSCHED NODEBUG STRINGMERGE NOSTACKCHECK
#CFLAGSPPC = PARM=REG NOOPTIMIZE DEBUG=FULL STRINGMERGE STACKCHECK

# You may need to add -N to the LFLAGS if you get sporadic segmentation
# faults. So far I have only needed to do this when compiling under Linux
# as Xlib seems to be mysteriously writing to its text segment

OFILES  = main.o cpu.o bios.o vga.o vgahard.o debugger.o astuff.o \
          hardware.o mfs.o
OFILESPPC  = main.oPPC cpu.oPPC bios.oPPC vga.oPPC vgahard.oPPC debugger.oPPC \
          astuff.oPPC hardware.oPPC mfs.oPPC amiga_timer.oPPC
PROGNAME    = pcemu
PROGNAMEPPC = pcemuppc
GLOBAL_DEP  = smakefile global.h mytypes.h

all: $(PROGNAME) $(PROGNAMEPPC)

cpu.o:	$(GLOBAL_DEP) cpu.c cpu.h instr.h debugger.h hardware.h
main.o: $(GLOBAL_DEP) main.c bios.h astuff.h hardware.h
bios.o: $(GLOBAL_DEP) bios.c bios.h cpu.h vga.h vgahard.h debugger.h hardware.h \
        keytabs.h mfs_link.h
vga.o:	$(GLOBAL_DEP) vga.c bios.h cpu.h vga.h vgahard.h hardware.h
vgahard.o: $(GLOBAL_DEP) vgahard.c vgahard.h astuff.h hardware.h
debugger.o: $(GLOBAL_DEP) debugger.c cpu.h debugger.h disasm.h vgahard.h
astuff.o: $(GLOBAL_DEP) astuff.c vgahard.h astuff.h icon.h hardware.h
hardware.o: $(GLOBAL_DEP) hardware.c cpu.h vgahard.h debugger.h hardware.h
mfs.o: $(GLOBAL_DEP) mfs.c cpu.h mfs.h mfs_link.h

cpu.oPPC:	$(GLOBAL_DEP) cpu.c cpu.h instr.h debugger.h hardware.h
main.oPPC: $(GLOBAL_DEP) main.c bios.h astuff.h hardware.h
bios.oPPC: $(GLOBAL_DEP) bios.c bios.h cpu.h vga.h vgahard.h debugger.h hardware.h \
        keytabs.h mfs_link.h
vga.oPPC:	$(GLOBAL_DEP) vga.c bios.h cpu.h vga.h vgahard.h hardware.h
vgahard.oPPC: $(GLOBAL_DEP) vgahard.c vgahard.h astuff.h hardware.h
debugger.oPPC: $(GLOBAL_DEP) debugger.c cpu.h debugger.h disasm.h vgahard.h
astuff.oPPC: $(GLOBAL_DEP) astuff.c vgahard.h astuff.h icon.h hardware.h
hardware.oPPC: $(GLOBAL_DEP) hardware.c cpu.h vgahard.h debugger.h hardware.h
mfs.oPPC: $(GLOBAL_DEP) mfs.c cpu.h mfs.h mfs_link.h

.c.o:
	$(CC) $(CFLAGS) $(OPTIONS) $<

.c.oPPC:
	$(CCPPC) $(CFLAGSPPC) $(OPTIONS) OBJECTNAME=$*.oPPC $<

$(PROGNAME): $(OFILES)
	$(CC) $(CFLAGS) link programname=$(PROGNAME) $(OFILES)

$(PROGNAMEPPC): $(OFILESPPC)
	ppc-amigaos-ld -r -o $(PROGNAMEPPC) lib:c_ppc.o $(OFILESPPC) lib:scppc.a lib:end.o
	protect $(PROGNAMEPPC) +e
#	slinkppc ppc to $(PROGNAMEPPC) from lib:c.o $(OFILESPPC) lib lib:scppc.lib

amiga_timer.oPPC: amiga_timer.s
	pasm -o amiga_timer.oPPC amiga_timer.s

clean:
	rm $(PROGNAME) *.o *.oPPC
