##############################################################################
## Source-level Makefile for jzintv
##
## The whole make process is driven from the top-level Makefile.  In contrast
## to the (poor) advice given in the Make documentation, I do _not_ call make
## recursively to build the source of this project.
##############################################################################

##############################################################################
## Project directory structure
##############################################################################
B=../bin
L=../lib

##############################################################################
## Project-wide build flags
##############################################################################
P          = export PATH;

SDL_DIR    = /usr/local
SDL_CFLAGS = -I$(SDL_DIR)/include -D_REENTRANT 
SDL_LFLAGS = -L$(SDL_DIR)/lib $(SDL_DIR)/lib/libSDL.a -lpthread -ldl


WARN    = -Wall -W -Wshadow -Wpointer-arith \
			-Wbad-function-cast -Wcast-qual 

#CC = $(P) egcs
 CC = $(P) gcc

 DEF_FLAGS = -DDIRECT_HCIF #-DSDL_08 

#OPT_FLAGS = -O
 OPT_FLAGS = -O2 -ggdb $(WARN)
#OPT_FLAGS = -O6 -fomit-frame-pointer $(WARN)
#OPT_FLAGS = -O2 -pg -ggdb $(WARN)

CFLAGS = $(OPT_FLAGS) -I. -I.. $(DEF_FLAGS)
LFLAGS = -L../lib


OBJS=jzintv.o
PROG=$(B)/jzintv
TOCLEAN=$(B)/jzintv core

PROGS=$(PROG)

CFLAGS += $(SDL_CFLAGS) 
LFLAGS += $(SDL_LFLAGS)

##############################################################################
## Generic build-rules
##############################################################################

all: $(OBJS) $(PROG)

$(PROG): $(OBJS)
	$(CC) -o $(PROG) $(OBJS) $(CFLAGS) $(LFLAGS)

clean:
	rm -f $(OBJS) 
	rm -f $(TOCLEAN)

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

##############################################################################
## Include module-specific Makefiles.  
##############################################################################
 include cfg/subMakefile	# Machine configuration
 include plat/subMakefile	# Platform-specific initialization
 include event/subMakefile	# Event subsystem
 include gfx/subMakefile	# Graphics support routines
 include snd/subMakefile	# Sound support routines
 include debug/subMakefile	# Debugger
 include periph/subMakefile	# Peripheral bus
 include cp1600/subMakefile	# CP-1600 CPU simulator
 include mem/subMakefile	# Memories (RAMs and ROMs)
 include stic/subMakefile	# Standard Television Interface Circuit
 include pads/subMakefile	# Game pad input
 include ay8910/subMakefile	# AY-891x Sound Chip
 include ivoice/subMakefile	# Intellivoice Support
 include speed/subMakefile	# Speed controller object
 include file/subMakefile	# File I/O routines
 include util/subMakefile	# Utility programs
 include asm/subMakefile	# Assembler (as1600)


$(PROG): $(OBJS)

all: $(PROGS)

jzintv.o: config.h periph/periph.h cp1600/cp1600.h mem/mem.h
jzintv.o: pads/pads.h debug/debug.h cp1600/op_decode.h cp1600/op_exec.h
jzintv.o: stic/stic.h speed/speed.h gfx/gfx.h snd/snd.h ay8910/ay8910.h
jzintv.o: plat/plat.h cfg/cfg.h event/event.h event/event_tbl.h file/file.h
