#
# Makefile for DarcNES
#

# $Id: Makefile,v 1.51 2000/01/09 18:23:46 nyef Exp $

#ENV=Linux_svgalib
ENV=Linux_X
#ENV=DJGPP
#ENV=Linux_GTK

#C_ONLY=-DC_ONLY

MACH_TYPES=-DMACH_TYPES=\"types-i386.h\"

#BYTE_ORDER=-DMSB_FIRST
BYTE_ORDER=-DLSB_FIRST

DEBUG=

OPTFLAGS=-O2 -fomit-frame-pointer

BASE_CFLAGS=-Wall $(DEBUG) $(OPTFLAGS) $(C_ONLY) $(BYTE_ORDER) $(MACH_TYPES)
BASE_SFLAGS=-Wall $(DEBUG) $(OPTFLAGS)

#
# Flags for Linux_svgalib
#
ifeq ($(ENV),Linux_svgalib)
CC=gcc
AS=gcc
LD=gcc

LDFLAGS=
CFLAGS=$(BASE_CFLAGS)
SFLAGS=$(BASE_SFLAGS)
BINFILE=sdarcnes
LIBS=-lvgagl -lvga
endif

#
# Flags for Linux_X
#
ifeq ($(ENV),Linux_X)
CC=gcc
AS=gcc
LD=gcc

LDFLAGS=-L/usr/X11R6/lib
CFLAGS=$(BASE_CFLAGS) -I/usr/X11R6/include
SFLAGS=$(BASE_SFLAGS) -I/usr/X11R6/include
BINFILE=darcnes
LIBS=-lXext -lXaw -lXmu -lXt -lX11
endif

#
# Flags for Linux_GTK
#
ifeq ($(ENV),Linux_GTK)
CC=gcc
AS=gcc
LD=gcc

LDFLAGS=`gtk-config --libs`
CFLAGS=$(BASE_CFLAGS) `gtk-config --cflags`
SFLAGS=$(BASE_SFLAGS)
BINFILE=darcnes
LIBS=
endif

#
# Flags for DJGPP
#
ifeq ($(ENV),DJGPP)
CC=gcc
AS=gcc
LD=gcc

LDFLAGS=
CFLAGS=$(BASE_CFLAGS) -DASM_UNDERBARS
SFLAGS=$(BASE_SFLAGS) -DASM_UNDERBARS
BINFILE=darcnes.exe
LIBS=-lalleg
endif

GAMESRCS=mappers.c nes_ppu.c nes.c pce.c pce_vdp.c nes_psg.c sms.c sms9918.c \
	genesis.c gen_vdp.c sms_psg.c coleco.c tms9918.c sg1000.c apple2.c \
	apple2_vdp.c

GAMEOBJS=mappers.o nes_ppu.o nes.o pce.o pce_vdp.o nes_psg.o sms.o sms9918.o \
	genesis.o gen_vdp.o sms_psg.o coleco.o tms9918.o sg1000.o apple2.o \
	apple2_vdp.o

ifdef C_ONLY
ASMSRCS=
ASMOBJS=
CSRCS=blit_c.c
COBJS=blit_c.o
else
ASMSRCS=blitters.S
ASMOBJS=blitters.o
CSRCS=
COBJS=
endif

COMMONSRCS=tool.c cal.c m6502.c mz80.c emu68k.c m6280.c torr_cpu.c tiledraw.c
COMMONOBJS=tool.o cal.o m6502.o mz80.o emu68k.o m6280.o torr_cpu.o tiledraw.o

LINUX_SVGASRCS=video_svga.c ui_svga.c snd_unix.c
LINUX_SVGAOBJS=video_svga.o ui_svga.o snd_unix.o

LINUX_XSRCS=video_x.c ui_x.c snd_unix.c
LINUX_XOBJS=video_x.o ui_x.o snd_unix.o

LINUX_GTKSRCS=ui_gtk.c snd_unix.c
LINUX_GTKOBJS=ui_gtk.o snd_unix.o

DJGPPSRCS=video_allegro.c ui_allegro.c snd_allegro.c
DJGPPOBJS=video_allegro.o ui_allegro.o snd_allegro.o

ifeq ($(ENV),Linux_svgalib)
SRCFILES=$(COMMONSRCS) $(GAMESRCS) $(ASMSRCS) $(CSRCS) $(LINUX_SVGASRCS)
OBJFILES=$(COMMONOBJS) $(GAMEOBJS) $(ASMOBJS) $(COBJS) $(LINUX_SVGAOBJS)
endif

ifeq ($(ENV),Linux_X)
SRCFILES=$(COMMONSRCS) $(GAMESRCS) $(ASMSRCS) $(CSRCS) $(LINUX_XSRCS)
OBJFILES=$(COMMONOBJS) $(GAMEOBJS) $(ASMOBJS) $(COBJS) $(LINUX_XOBJS)
endif

ifeq ($(ENV),Linux_GTK)
SRCFILES=$(COMMONSRCS) $(GAMESRCS) $(ASMSRCS) $(CSRCS) $(LINUX_GTKSRCS)
OBJFILES=$(COMMONOBJS) $(GAMEOBJS) $(ASMOBJS) $(COBJS) $(LINUX_GTKOBJS)
endif

ifeq ($(ENV),DJGPP)
SRCFILES=$(COMMONSRCS) $(GAMESRCS) $(ASMSRCS) $(CSRCS) $(DJGPPSRCS)
OBJFILES=$(COMMONOBJS) $(GAMEOBJS) $(ASMOBJS) $(COBJS) $(DJGPPOBJS)
endif

# non-*.[chS] files to include in distribution
#MISC_FILES=Makefile notes ppu_notes readme sound_notes timing.txt
MISC_FILES=Makefile readme files.txt

# make rules

all:	default
ifeq (_depend,$(wildcard _depend))
default: $(BINFILE)
else
default: depend
endif

$(BINFILE): $(OBJFILES)
	$(LD) $(LDFLAGS) -o $(BINFILE) $(OBJFILES) $(LIBS)

.PHONY: tests
tests: test_68k
	cat tests/68k_test_*[0-9] | ./test_68k

test_68k: test_68k.o emu68k.o
	$(LD) $(LDFLAGS) -o test_68k test_68k.o emu68k.o

.PHONY: clean
clean:
	rm -f *.o *~ "#"*"#" $(BINFILE)

.PHONY: realclean
realclean: clean
	rm -f _depend

.PHONY: distr
distr:
	tar cvzf darcnes.tgz *.[chS] $(MISC_FILES)
	grep -h \$$Id Makefile *.[chS] | grep -v darcnes.ids -> darcnes.ids

.PHONY: depend
depend:
	gcc $(CFLAGS) -MM $(SRCFILES) > _depend
	@echo dependancy data generated.
	@echo run 'make' again to build the program.

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

.c.s:	
	$(CC) -S $(CFLAGS) $<

.S.o:
	$(AS) -c $(SFLAGS) $<

.s.o:
	$(AS) -c $(SFLAGS) $(addsuffix .S,$(basename $<))

# Dependancy data
ifeq (_depend,$(wildcard _depend))
include _depend
endif

#
# $Log: Makefile,v $
# Revision 1.51  2000/01/09 18:23:46  nyef
# added a target to run the unit tests automatically
#
# Revision 1.50  2000/01/01 04:13:06  nyef
# added apple2.c and apple2_vdp.c to the compile lists
#
# Revision 1.49  1999/12/24 16:53:04  nyef
# added include directory for XWindows on FreeBSD
#
# Revision 1.48  1999/12/12 18:20:31  nyef
# added a target for test_68k
#
# Revision 1.47  1999/12/07 02:01:51  nyef
# added the MACH_TYPES silliness (too bad it's the best solution I found)
#
# Revision 1.46  1999/12/04 04:57:41  nyef
# removed debug.c, dt6502.c, dt65c02.c and dt6280.c from the compile lists
#
# Revision 1.45  1999/12/04 04:05:59  nyef
# removed all ASM CPU cores from the compile lists
#
# Revision 1.44  1999/11/27 20:08:10  nyef
# added sg1000.[co] to the compile lists
#
# Revision 1.43  1999/11/23 01:41:59  nyef
# added tiledraw.c to the compile lists
#
# Revision 1.42  1999/11/14 01:30:25  nyef
# added a .c.s rule to make it easier to check the compiler's behavior
#
# Revision 1.41  1999/10/31 02:38:24  nyef
# added snd_allegro.c and snd_unix.c to the compile lists
#
# Revision 1.40  1999/08/23 01:44:37  nyef
# removed -g debug option
#
# Revision 1.39  1999/08/15 02:27:20  nyef
# added C_ONLY support
# added partial support for new "Torrigion" CPU core
# added BYTE_ORDER support
#
# Revision 1.38  1999/08/07 16:20:03  nyef
# added -DLSB_FIRST to CFLAGS in all system types
#
# Revision 1.37  1999/08/02 00:21:36  nyef
# added m6280.[co] to the compile lists
#
# Revision 1.36  1999/06/14 19:16:56  nyef
# removed (unused) GRAPHICS options
# added OPTFLAGS (optimization), with -fomit-frame-pointer
#
# Revision 1.35  1999/06/08 01:49:56  nyef
# added coleco.[co] to the compile lists
# added tms9918.[co] to the compile lists
#
# Revision 1.34  1999/04/28 16:49:22  nyef
# added sms_psg.[co] to the compile lists
#
# Revision 1.33  1999/04/17 23:04:29  nyef
# added genesis.[co], gen_vdp.[co], and emu68k.[co] to compile lists.
#
# Revision 1.32  1999/02/21 23:32:52  nyef
# switched from using blitters.c to blitter.S
#
# Revision 1.31  1999/02/15 03:40:50  nyef
# added patch from Michael Vance for GTK support
#
# Revision 1.30  1999/02/14 18:34:35  nyef
# removed io_nes.[So] from the compile lists
#
# Revision 1.29  1999/01/22 03:04:16  nyef
# added files.txt to the MISC_FILES list.
#
# Revision 1.28  1999/01/18 22:16:58  nyef
# added changes required for SVGALib support
#
# Revision 1.27  1999/01/17 02:13:13  nyef
# added pce_vdp.[co] to the compile lists.
#
# Revision 1.26  1999/01/13 04:15:41  nyef
# removed io_pce.[So] from the compile lists.
#
# Revision 1.25  1999/01/11 02:24:02  nyef
# removed nes_blit.[co] from compile lists.
# added blitters.[co] to compile lists.
#
# Revision 1.24  1999/01/08 02:45:46  nyef
# removed zarzon code from compile lists.
#
# Revision 1.23  1999/01/07 03:16:55  nyef
# added sms9918.[co] to the compile lists.
#
# Revision 1.22  1999/01/03 02:29:51  nyef
# added maratz80.[co] to the compile lists.
#
# Revision 1.21  1999/01/01 07:01:38  nyef
# added sms.c, emuz80.S and opcz80.S to compile lists.
#
# Revision 1.20  1998/12/31 19:30:45  nyef
# added some admin stuff to make distr.
#
# Revision 1.19  1998/12/24 04:33:46  nyef
# split all of the game-specific files out of the common compile lists.
# added zarzon.[co] to the game compile lists.
#
# Revision 1.18  1998/12/20 04:03:37  nyef
# changed header comment and all binfiles to say "darcnes".
#
# Revision 1.17  1998/12/20 04:01:54  nyef
# removed a few files from MISC_FILES.
#
# Revision 1.16  1998/12/12 21:38:50  nyef
# added m6502.c to compile lists
#
# Revision 1.15  1998/11/29 18:29:20  nyef
# added cal.c to the compile lists.
#
# Revision 1.14  1998/10/21 02:38:58  nyef
# added targets for 'realclean' and 'distr'
#
# Revision 1.13  1998/10/11 21:37:02  nyef
# added {emu,opc}6502a.[So] the the common compile lists.
#
# Revision 1.12  1998/08/22 00:25:46  nyef
# added nes_psg.[co] to the common compile lists.
#
# Revision 1.11  1998/08/02 16:52:59  nyef
# added ui_allegro.[co] to DJGPP{SRC,OBJ}S.
#
# Revision 1.10  1998/08/01 22:31:02  nyef
# added ui_x.[co] to the LINUX_X{SRC,OBJ}S lines.
#
# Revision 1.9  1998/08/01 01:15:10  nyef
# added a bunch of libs to the Linux_X configuration for GUI support.
#
# Revision 1.8  1998/07/31 23:52:47  nyef
# added .s.o rule for DJGPP support.
#
# Revision 1.7  1998/07/29 01:39:42  nyef
# added ASM_UNDERBARS to [CS]FLAGS for DJGPP.
# removed commented out commands on [CS]FLAGS for Linux/Svgalib.
# added -lalleg to LIBS line for DJGPP.
#
# Revision 1.6  1998/07/28 23:48:18  nyef
# changed all references to '.depend' to '_depend' for DOS compatability.
#
# Revision 1.5  1998/07/25 16:58:04  nyef
# added the blit compiler to the common compile lists.
#
# Revision 1.4  1998/07/14 02:08:59  nyef
# added opc6280.S to the compile lists
#
# Revision 1.3  1998/07/14 01:50:30  nyef
# added dt6280.c to the file lists.
#
# Revision 1.2  1998/07/12 20:51:17  nyef
# re-added pce-specific files to compile lists
#
# Revision 1.1  1998/07/11 22:16:01  nyef
# Initial revision
#
#
