# NOTE! This may need gmake (certainly on the DEC Alpha)

#-----------------------------------------------------------------------------#
# Defines:
#
# SCREEN	Which style of IO to use for the display. Choices are:
#		simple - simple no nonsense output
#               curses - the curses package (requires curses/termcap libs
#		X11 - graphical interface
#
# LIBS		Libraries need specific to the SCREEN definition
#
# ASSUME	Assume certain low level things, such as instruction fetches
#		are never from memory mapped IO etc. Hence not 100% accurate,
#		but correct for nearly all code and MUCH faster.
#
# SUPERFAST	Always use fastest IO - ie no allowance for any mmap IO
#
# DEBUG		Add -d option to enable debugging. This slows things down by
#		(currently) around 5%.
#
# USER_VIA	The user port 6522. Also define NEED_TIMER
#
# SYSTEM_VIA	The system 6522. Required by the X11 interface. Also define
#		NEED_TIMER.
#
# NEED_TIMER	Adds the itimer support. This is required by the VIA and X11
#		support.
#-----------------------------------------------------------------------------#

# Most basic
#DEFINES = -DSUPERFAST #-DDEBUG
DEFINES = -DASSUME #-DDEBUG

#DEFINES += -DUSER_VIA -DSYSTEM_VIA -DNEED_TIMER

#simple:
#-------
#SCREEN = simple
#LIBS   =

#curses:
#-------
#SCREEN = curses
#LIBS   = -lcurses -ltermcap

#X11:
#----
SCREEN = X11
LIBS   = -L/usr/X386/lib -lXext -lX11 -lots
DEFINES += -DUSER_VIA -DSYSTEM_VIA -DNEED_TIMER

#-----------------------------------------------------------------------------#
# Compiler/linker defs.                                                       #
#-----------------------------------------------------------------------------#
#CC	= gcc
CC	= c89

#DEBUG	= -O2 -fforce-mem -fforce-addr -fcaller-saves -ffast-math -fomit-frame-pointer -ffloat-store
DEBUG	= -g

CFLAGS	= $(DEBUG) -DSCREEN_$(SCREEN) $(DEFINES)

LD	= $(CC)
LDFLAGS	= $(DEBUG)

#-----------------------------------------------------------------------------#
# You shouldn't need to change anything below here.                           #
#-----------------------------------------------------------------------------#
OBJS	= manager.o 6502.o opcodes.o memory.o dis6502.o unix_io.o \
	  sysvia.o usrvia.o timer.o $(SCREEN)/screen.a

beeb:	$(OBJS)
	$(LD) $(LDFLAGS) $(OBJS) -o beeb $(LIBS)

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

sysvia.o: 6522.c
	$(CC) $(CFLAGS) -Di_6522=i_6522_system -DVIAS -c 6522.c -o sysvia.o

usrvia.o: 6522.c
	$(CC) $(CFLAGS) -Di_6522=i_6522_user -DVIAU -c 6522.c -o usrvia.o

$(SCREEN)/screen.a: FORCE
	cd $(SCREEN); \
	$(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" "LD=$(LD)" "LD=$(LDFLAGS)"
FORCE:

backup: FORCE
	tar cvf - README Makefile ChangeLog Acknowledgements *.[ch] \
		X11/*.[ch] X11/Makefile \
		simple/*.[ch] simple/Makefile \
		curses/*.[ch] curses/Makefile \
		data | gzip > backup/`date +%d.%m.%y`.tar.gz
