LESSONS = files editor morefiles macros eqn C

FILES = lrndef lrnref \
	copy.c dounit.c learn.c list.c \
	makpipe.c maktee.c mem.c mysys.c selsub.c selunit.c \
	start.c whatnow.c wrapup.c \
	lcount.c tee.c \
	makefile

OBJECTS = copy.o dounit.o learn.o list.o mem.o \
	makpipe.o maktee.o mysys.o selsub.o selunit.o \
	start.o whatnow.o wrapup.o

CFLAGS = -O
LIBRARY =
LLIB	= /usr/lib/learn

cp:	all
	cp learn /bin
	cp tee $(LLIB)
	cp lcount $(LLIB)
	rm learn tee lcount *.o
	@echo "Now do 'make lessons' if you need to extract the lesson archives"

cmp:	all
	cmp learn /bin/learn
	cmp tee $(LLIB)/tee
	cmp lcount $(LLIB)/lcount
	rm learn tee lcount *.o

all:	learn tee lcount

learn: $(OBJECTS)
	cc -n -s -o learn $(CFLAGS) $(OBJECTS) $(LIBRARY)

$(OBJECTS): lrnref
learn.o: lrndef

tee:
	cc $(CFLAGS) -s -n tee.c -o tee $(LIBRARY)

lcount:
	cc $(CFLAGS) -s -n lcount.c -o lcount $(LIBRARY)

lessons:	$(LESSONS)

files:
	-if test ! -r $(LLIB)/files; then mkdir $(LLIB)/files; fi
	(cd $(LLIB)/files; ar x ../files.a)

morefiles:
	-if test ! -r $(LLIB)/morefiles; then mkdir $(LLIB)/morefiles; fi
	(cd $(LLIB)/morefiles; ar x ../morefiles.a)

editor:
	-if test ! -r $(LLIB)/editor; then mkdir $(LLIB)/editor; fi
	(cd $(LLIB)/editor; ar x ../editor.a)

macros:
	-if test ! -r $(LLIB)/macros; then mkdir $(LLIB)/macros; fi
	(cd $(LLIB)/macros; ar x ../macros.a)

eqn:
	-if test ! -r $(LLIB)/eqn; then mkdir $(LLIB)/eqn; fi
	(cd $(LLIB)/eqn; ar x ../eqn.a)

C:
	-if test ! -r $(LLIB)/C; then mkdir $(LLIB)/C; fi
	(cd $(LLIB)/C; ar x ../C.a)
