
WARN    = -Wall -W -Wshadow -Wpointer-arith \
			-Wbad-function-cast -Wcast-qual 
X86     = -malign-loops=4 -malign-functions=4 -malign-jumps=4 

# If you just have GCC:  See http://egcs.cygnus.com/ about EGCS!!
#CC     = gcc
#CFLAGS = -O6 -fomit-frame-pointer $(WARN) $(X86)
#CFLAGS = -ggdb -pg -O6  # if you're profiling

# If you're cool like me and have EGCS.
# note... 1.0.2 gave better performance than 1.1.0
CC     = egcs-haifa -Vegcs-2.90.27
CFLAGS = -O6 -fomit-frame-pointer $(WARN) $(X86) $(EGCS)
EGCS   = -mcpu=i686 # -fgcse -fstrict-aliasing


# If you're debugging:
#CFLAGS=-ggdb

PROGS=de_res re_res de_dcl re_dcl mk_tbl test_cpu
TABLES=	\
		fn_cond_br.T		\
		fn_dir_2op.T		\
		fn_imm_2op.T		\
		fn_impl_1op_a.T		\
		fn_impl_1op_b.T		\
		fn_ind_2op.T		\
		fn_reg_1op.T		\
		fn_reg_2op.T		\
		fn_rot_1op.T		\
		formats.T

CPU_OBJS = \
		cp_1610.o			\
		op_decode.o			\
		op_exec.o			\

OBJS = $(CPU_OBJS) \
		data_fmt.o			\
		de_dcl.o			\
		de_res.o			\
		file_util.o			\
		mk_tbl.o			\
		re_dcl.o			\
		re_res.o			\
		test_cpu.o			\
		dasm1600.o			\
		res_file.o

.SUFFIXES: .tbl .T

all: $(PROGS) $(TABLES) $(OBJS)

re_res: re_res.o res_file.o data_fmt.o file_util.o
	$(CC) -o re_res $(CFLAGS) re_res.o res_file.o data_fmt.o file_util.o

de_res: de_res.o res_file.o data_fmt.o file_util.o 
	$(CC) -o de_res $(CFLAGS) de_res.o res_file.o data_fmt.o file_util.o

re_dcl: re_dcl.o
	$(CC) -o re_dcl $(CFLAGS) re_dcl.o

de_dcl: de_dcl.o
	$(CC) -o de_dcl $(CFLAGS) de_dcl.o

mk_tbl: mk_tbl.o
	$(CC) -o mk_tbl $(CFLAGS) mk_tbl.o

test_cpu: $(CPU_OBJS) test_cpu.o dasm1600.o
	$(CC) -o test_cpu $(CFLAGS) test_cpu.o dasm1600.o $(CPU_OBJS)

zip: clean expand
	rm -f intv.zip
	zip -9r intv.zip *.c *.h *.tbl *.txt Makefile

expand:
	-[ ! -d bak ]  && mkdir bak 
	[ -d bak ]     && cp *.[ch] *.tbl *.txt bak
	-[ ! -d .exp ] && mkdir .exp 
	[ -d .exp ]    && for I in *.[ch] *.txt ; do \
	                   expand -4 $$I >.exp/$$I && mv .exp/$$I $$I ||exit;\
	                  done

clean:
	-[ ! -d bak ] && mkdir bak 
	[ -d bak ]    && cp *.[ch] *.tbl *.txt bak
	rm -f $(OBJS) $(PROGS) $(TABLES)

.tbl.T:
	./mk_tbl $< $@

de_res.o:    	res_file.h macros.h file_util.h
re_res.o:    	res_file.h macros.h file_util.h
res_file.o:  	res_file.h macros.h data_fmt.h
data_fmt.o:  	res_file.h macros.h 
file_util.o: 	res_file.h macros.h
cp_1610.o:		cp_1610.h op_decode.h op_exec.h
op_decode.o:	cp_1610.h op_decode.h op_exec.h $(TABLES)
op_exec.o:		cp_1610.h op_decode.h op_exec.h
test_cpu.o:		cp_1610.h op_decode.h 

op_decode.h:	cp_1610.h 

$(TABLES):		mk_tbl

$(PROGS) $(TABLES) $(OBJS): Makefile config.h
