#
#	Makefile for TTL_PAPERS and TTL_VAPERS
#
CC=gcc
CFLAGS= -O


#
#	The following define the library .h, .c, and .o files,
#	and then the flags to be given when compiling library code
#
PLIBH=psound.h timer.h types.h papers.h intern.h inline.h version.h gather.h reduce.h scan.h putget.h vote.h
PLIBC=psound.c papers.c gather.c reduce.c scan.c putget.c vote.c timer.c
PLIBO=psound.o papers.o gather.o reduce.o scan.o putget.o vote.o timer.o
#
#	Remove the -DP_VAPERS in the line below if you are compiling
#	for the actual TTL_PAPERS hardware
#
PLIBCFLAGS= -O6 -DP_VAPERS


#
#	The applications groups
#
PCHECK=check.c
PPEN=psetenv.c cold.c
PSOUND=musical.c music.c
PDEMO=pi.c libdemo.c
PPRIV=psetenv cold musical music check libdemo pi


#
#	Other stuff... a packing list
#
RUN=run killrsh
DOC=README vapers.doc library.doc
XVAPERS=xvapers vapersicon.xbm vaperswood.xbm
PACKLIST=$(PLIBH) $(PLIBC) $(PCHECK) $(PPEN) $(PSOUND) $(PDEMO) \
	$(RUN) $(DOC) $(XVAPERS) paperslib.h


all:	paperslib.a psetenv cold musical music check libdemo pi


priv:	$(PPRIV)
	echo "If you are not root, this doesn't work."
	chown root $(PPRIV)
	chmod +s $(PPRIV)


#
#	Now, the library make rules...
#
paperslib.a:	$(PLIBO)
	ar -r paperslib.a $(PLIBO)

papers.h:	types.h
	touch papers.h

intern.h:	papers.h inline.h
	touch intern.h

papers.o:	papers.c intern.h version.h
	$(CC) $(PLIBCFLAGS) papers.c -c

gather.h:	types.h
	touch gather.h

gather.o:	gather.c gather.h intern.h
	$(CC) $(PLIBCFLAGS) gather.c -c

reduce.h:	types.h
	touch reduce.h

reduce.o:	reduce.c reduce.h intern.h
	$(CC) $(PLIBCFLAGS) reduce.c -c

scan.h:	types.h
	touch scan.h

scan.o:	scan.c scan.h gather.h intern.h
	$(CC) $(PLIBCFLAGS) scan.c -c

putget.h:	types.h
	touch putget.h

putget.o:	putget.c putget.h intern.h
	$(CC) $(PLIBCFLAGS) putget.c -c

vote.h:	types.h
	touch vote.h

vote.o:	vote.c intern.h
	$(CC) $(PLIBCFLAGS) vote.c -c

timer.o:	timer.c timer.h
	$(CC) $(PLIBCFLAGS) timer.c -c

psound.o:	psound.c psound.h
	$(CC) $(PLIBCFLAGS) psound.c -c


#
#	Check isn't part of the library...  it is a hardware check
#	program.  When compiled for VAPERS it does nothing useful.
#
check:	check.c paperslib.a
	$(CC) $(PLIBCFLAGS) check.c -o check paperslib.a


#
#	The following are "special" programs that currently fake the
#	parallel OS environment...  when PEN is released, these will
#	probably go away.
#
psetenv:	psetenv.c intern.h version.h
	$(CC) $(PLIBCFLAGS) psetenv.c -o psetenv

cold:	cold.c papers.c
	$(CC) $(PLIBCFLAGS) cold.c -o cold


#
#	The next two programs are used to play music using the built-in
#	speaker of a PC.  Forget 'em if this is the simulator.
#
musical:	musical.c paperslib.a
	$(CC) $(PLIBCFLAGS) musical.c -o musical -O paperslib.a

music:	music.c paperslib.a
	$(CC) $(PLIBCFLAGS) music.c -o music paperslib.a


#
#	The following are real demo programs that you can use with
#	either version of the library, PAPERS or VAPERS.
#
pi:	pi.c paperslib.a
	$(CC) $(CFLAGS) pi.c -o pi paperslib.a paperslib.a

libdemo:	libdemo.c paperslib.a
	$(CC) $(CFLAGS) libdemo.c -o libdemo paperslib.a


#
#	Some utility make options....
#
clean:	
	rm -f $(PLIBO)

tar:	$(PACKLIST) Makefile
	tar -cvf TTL_LIB_950614.tar $(PACKLIST) Makefile
