#########################################################################
# Apple II emulator by Alexander Jean-Claude Bottema (C) 1994		#
#									#
# Makefile for Linux apple2 emulator					#
#									#
# $Id: Makefile,v 1.5.2.1 1997/03/01 19:49:01 chernabog Exp $		#
#									#
# MODIFICATION HISTORY							#
#   v0.3 by Aaron Culliney <chernabog@baldmountain.bbn.com>		#
#   Jan, 1997.								#
#									#
# ASSUMPTIONS:								#
#	GNU gcc, GNU make, GNU install					#
#									#
#########################################################################


default:	apple2
all:		depend default
install:	depend default _install

#################
# main settings #
#################

CC =		gcc
CFLAGS =	-I$(VGADIR) -Wall $(DEBUGGER) $(DEBUG)
LDFLAGS =	-L$(VGADIR) $(CFLAGS)
LDLIBS =	$(VGALIB) $(LEXLIB)
PROGS =		apple2
SRCS =		$(apple2.c) $(apple2.S)


#####################
# graphics settings #
#####################

VGADIR =	/usr/local/include
VGALIB =	-lvga

#################################################
# apple2 debugger settings			#
# comment these if you don't want the debugger	#
# if you have flex, you can regenerate tokens.c #
#################################################

#LEX =		flex -i
#DEBUGGER.l =	tokens.l
#DEBUGGER.c =	debugger.c $(DEBUGGER.l:.l=.c)
DEBUGGER.c =	debugger.c tokens.c
DEBUGGER =	-DDEBUGGER
#LEXLIB =	-lfl

####################################
# program debugging / optimization #
####################################

# optimization (-fomit-frame-pointer) causes debugger to choke
#OPTIMIZE =	-DNDEBUG -O2
#DEBUG =	-ggdb
#DEBUG +=	-pg


#####################
# compilation rules #
#####################

#.SUFFIXES:      .c .S .l .o
.SUFFIXES:      .c .S .o
.c.o:
		$(CC) $(CPPFLAGS) $(CFLAGS) -c $*.c
.S.o:
		$(CC) $(CPPFLAGS) $(CFLAGS) -c $*.S
#.l.c:
#		$(LEX) -o$*.c $*.l

##################
# apple2 program #
##################
apple2.l =	
apple2.c =	disk.c keys.c interface.c misc.c $(DEBUGGER.c)
apple2.S =	apple2.S diskio.S
apple2.o =	$(apple2.S:.S=.o) $(apple2.c:.c=.o)

apple2:		$(apple2.o)
		$(CC) $(LDFLAGS) -o $@ $(apple2.o) $(LDLIBS)


################
# installation
#
#	This is a bit of a hack 
################
INSTALL =	install
MANPAGES =
BINDIR =	/usr/local/bin
MANDIR =	/usr/local/man


_install:
		$(INSTALL) --mode=0711 \
		$(PROGS) $(BINDIR)

#		$(INSTALL) --mode=0711 \
#		$(MANPAGES) $(MANDIR)


#################
# other targets #
#################
.PHONY:		all clean realclean dep depend TAGS check remake

clean:
		$(RM) *.o core .depend Makefile.bak apple2
		$(RM) TAGS
		if [ -d checkdir ] ; then cd checkdir; $(MAKE) clean; fi

realclean:	clean
		$(RM) $(PROGS) .depend
		$(RM) -r autogen/*
		if [ -d checkdir ] ; then cd checkdir; $(MAKE) realclean; fi

dep:		depend
depend:		$(SRCS)
		$(CC) -MM *.c *.S > .depend
		if [ -d checkdir ] ; then cd checkdir; $(MAKE) depend; fi

TAGS:
		etags -t *.[hcly]
		if [ -d checkdir ] ; then cd checkdir; $(MAKE) TAGS; fi

remake:		realclean TAGS depend all


########################
# include dependencies #
########################
ifeq (.depend, $(wildcard .depend))
include .depend
endif
