OPTIONS=-O3 -Wall -I .

REDEF=-D_DOSBase=___DOSBase

CC=gcc

%.o: %.c
	$(CC) $(OPTIONS) -S $^ -o $*.S 2>&1|tee $*.err
	$(CC) -E -traditional $(REDEF) $*.S -o $*2.S
	$(CC) $(OPTIONS) $*2.S -c -o $*.o
	-rm $*.S $*2.S
	-if test ! -s $*.err; then rm $*.err; fi

all: libstack.a bigtest bigtest-c bigtest-x stackextend.guide

veryclean:
	-rm *.a *.o *.guide bigtest bigtest-?

libstack.a: init_stk.o link_a5_0_f.o link_a5_d0_f.o longjmp.o stkchk_d0.o stkext.o
libstack.a: stkovf.o stkrst.o stkrst_f.o stk_argbytes.o stk_minframe.o stk_safezone.o
libstack.a: sub_d0_sp.o xcovf.o
	-rm $@
	ar -q $@ $^
	ranlib $@

bigtest-c: bigtest-c.S libstack.a
	$(CC) -noixemul -O3 $^ -o $@

bigtest-x: bigtest-x.S libstack.a
	$(CC) -noixemul -O3 $^ -o $@

bigtest: bigtest.c libstack.a
	$(CC) -noixemul -O3 $^ -o $@

stackextend.guide: stackextend.doc
	makeinfo --amiga $^
