#
# Makefile for DarcNES
#

# $Id: Makefile,v 1.36 1999/06/14 19:16:56 nyef Exp $

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

DEBUG=

OPTFLAGS=-O2 -fomit-frame-pointer

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

LDFLAGS=
CFLAGS=-g -Wall $(DEBUG) $(OPTFLAGS)
SFLAGS=-g -Wall $(DEBUG) $(OPTFLAGS)
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=-g -Wall $(DEBUG) $(OPTFLAGS)
SFLAGS=-g -Wall $(DEBUG) $(OPTFLAGS)
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=-g -Wall $(DEBUG) $(OPTFLAGS) `gtk-config --cflags`
SFLAGS=$(CFLAGS)
BINFILE=darcnes
LIBS=
endif

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

LDFLAGS=
CFLAGS=-g -Wall $(DEBUG) $(OPTFLAGS) -DASM_UNDERBARS
SFLAGS=-g -Wall $(DEBUG) $(OPTFLAGS) -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
#zarzon.c nes_blit.c io_pce.S io_nes.S

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
#zarzon.o nes_blit.o io_pce.o io_nes.o

COMMONSRCS=tool.c dt6502.c emu6502.S opc6502.S flags.c debug.c opc65c02.S \
	emu65c02.S emu6280.S dt6280.c opc6280.S emu6502a.S opc6502a.S cal.c \
	m6502.c emuz80.S opcz80.S mz80.c blitters.S emu68k.c
COMMONOBJS=tool.o dt6502.o emu6502.o opc6502.o flags.o debug.o opc65c02.o \
	emu65c02.o emu6280.o dt6280.o opc6280.o emu6502a.o opc6502a.o cal.o \
	m6502.o emuz80.o opcz80.o mz80.o blitters.o emu68k.o

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

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

LINUX_GTKSRCS=ui_gtk.c
LINUX_GTKOBJS=ui_gtk.o

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

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

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

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

ifeq ($(ENV),DJGPP)
SRCFILES=$(COMMONSRCS) $(GAMESRCS) $(DJGPPSRCS)
OBJFILES=$(COMMONOBJS) $(GAMEOBJS) $(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: 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) $<

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