#-----------------------------------------------------------------------------#
# 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

#raw_text:
#---------
#SCREEN	= raw_text
#LIBS	=
#DEFINES += -DUSER_VIA -DSYSTEM_VIA -DNEED_TIMER

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

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

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

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

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

#-----------------------------------------------------------------------------#
# You shouldn't need to change anything below here.                           #
#-----------------------------------------------------------------------------#
OBJS	= manager.o 6502.o memory.o dis6502.o unix_io.o keyboard.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] *.inc\
		X11/*.[ch] X11/Makefile \
		simple/*.[ch] simple/Makefile \
		curses/*.[ch] curses/Makefile \
		raw_text/*.[ch] raw_text/Makefile \
		data | gzip > backup/`date +%d.%m.%y`.tar.gz

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