LESSONS = files

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
I = /usr/include

all:	learn tee lcount

learn:          $(OBJECTS)
	cc -n -o learn $(CFLAGS) $(OBJECTS) $(LIBRARY)
/bin/learn:     learn tee lcount
	/etc/instcmd learn /bin/learn
	/etc/instcmd tee $(LLIB)/tee
	/etc/instcmd lcount $(LLIB)/lcount
	rm $(OBJECTS)
	@echo "Now do 'make lessons' if you need to extract the lesson archives"
	@echo "Then do 'make play; make log' to make playpen and log directories"

tee:		tee.o
	cc -n $(CFLAGS) -o tee tee.o; rm tee.o
tee.o:		tee.c		


lcount:		lcount.o
	cc -n $(CFLAGS) -o lcount lcount.o; rm lcount.o
lcount.o:	lcount.c	$I/stdio.h 

copy.o:		copy.c		$I/stdio.h $I/signal.h lrnref 
dounit.o:	dounit.c	$I/stdio.h lrnref 
learn.o:	learn.c		$I/stdio.h lrndef $I/stdio.h \
				lrnref $I/signal.h 
list.o:		list.c		$I/stdio.h lrnref $I/signal.h 
makpipe.o:	makpipe.c	$I/stdio.h 
maktee.o:	maktee.c	$I/stdio.h $I/signal.h lrnref 
mem.o:		mem.c		$I/stdio.h lrnref 
mysys.o:	mysys.c		$I/stdio.h $I/signal.h 
selsub.o:	selsub.c	$I/stdio.h lrnref 
selunit.o:	selunit.c	$I/stdio.h lrnref 
start.o:	start.c		$I/stdio.h lrnref 
whatnow.o:	whatnow.c	$I/stdio.h lrnref 
wrapup.o:	wrapup.c	$I/signal.h $I/stdio.h lrnref 


lessons:	$(LESSONS)

$(LESSONS):
	-rm -r $(LLIB)/$@
	mkdir $(LLIB)/$@
	(cd $(LLIB)/$@; ar x ../$@.a)


play log:
	-rm -r $(LLIB)/$@; mkdir $(LLIB)/$@; chmod +w $(LLIB)/$@


check:
	-@test -r $(LLIB)/tee || echo 'tee not present; make tee'
	-@test -r $(LLIB)/lcount || echo 'lcount not present; make lcount'
	-@test -r $(LLIB)/play || echo 'play directory not present; make play'
	-@test -r $(LLIB)/log || echo 'log directory not present; make log'
	-@for i in $(LESSONS); do test -r $(LLIB)/$$i/L0 || echo $$i not unarchived, make $$i; done

