SRCS = term_atr.c term_axi.c term_bar.c term_box.c term_bxf.c term_col.c \
	term_fld.c term_fn1.c term_fun.c term_key.c term_lme.c term_lod.c \
	term_men.c term_mo2.c term_mou.c term_pr.c term_rec.c term_res.c \
	term_typ.c term_vid.c term_win.c 
OBJS = $(SRCS:%.c=%.o)
CC = cc
CFLAGS = -w3 -Otax -g1 -zld -zl -zc -Wc,-r -Ih/
CWD = $(shell basename `pwd`)

all: lib/termlibc.lib lib/termlibh.lib lib/termlibl.lib lib/termlibm.lib \
	lib/termlibs.lib lib/termlib3r.lib lib/termlib3s.lib

clean:
	rm -f lib/*.lib o/*/*.o *.err

test: all
	(cd test; make)

dist: all
	rm -f o/*/*.o *.err
	(cd c ; rcsclean)
	(cd h/sys ; rcsclean)
	(cd test ; make clean)
	(cd .. ; tar -cvf - $(CWD)) | gzip -9c >../termlib.tar.gz

lib/termlibc.lib: $(addprefix o/16c/,$(OBJS))
	$(CC) -a $@ $^

o/16c/%.o: c/%.c
	$(CC) -2 -mc -c $(CFLAGS) -o $@ $^

lib/termlibh.lib: $(addprefix o/16h/,$(OBJS))
	$(CC) -a $@ $^

o/16h/%.o: c/%.c
	$(CC) -2 -mh -c $(CFLAGS) -o $@ $^

lib/termlibl.lib: $(addprefix o/16l/,$(OBJS))
	$(CC) -a $@ $^

o/16l/%.o: c/%.c
	$(CC) -2 -ml -c $(CFLAGS) -o $@ $^

lib/termlibm.lib: $(addprefix o/16m/,$(OBJS))
	$(CC) -a $@ $^

o/16m/%.o: c/%.c
	$(CC) -2 -mm -c $(CFLAGS) -o $@ $^

lib/termlibs.lib: $(addprefix o/16s/,$(OBJS))
	$(CC) -a $@ $^

o/16s/%.o: c/%.c
	$(CC) -2 -ms -c $(CFLAGS) -o $@ $^

lib/termlib3r.lib: $(addprefix o/32r/,$(OBJS))
	$(CC) -a $@ $^

o/32r/%.o: c/%.c
	$(CC) -3r -c $(CFLAGS) -o $@ $^

lib/termlib3s.lib: $(addprefix o/32s/,$(OBJS))
	$(CC) -a $@ $^

o/32s/%.o: c/%.c
	$(CC) -3s -c $(CFLAGS) -o $@ $^

