CFLAGS= -g -O
all:	libusp.a libusp_p.a

SRCS=	block.c get.c internal.c main.c put.c usp_et.et
INCLUDES=	usp.h notice.h gen.h

libusp.a: usp_et.h usp_et.o usp.h gen.h main.o block.o get.o put.o internal.o
	ar r libusp.a main.o block.o get.o put.o internal.o usp_et.o
	ranlib libusp.a

libusp_p.a: usp_et.h usp_et.o usp.h gen.h main.o block.o get.o put.o internal.o
	cd profiled; ar r ../libusp_p.a main.o block.o get.o put.o internal.o usp_et.o
	ranlib libusp_p.a

install:

clean:
	rm -f *.o libusp.a *~ core

dist:	$(SRCS) $(INCLUDES) Makefile
	-mkdir ../../dist/source/usp
	-chmod g+w ../../dist/source/usp
	-mkdir ../../dist/source/usp/profiled
	-chmod g+w ../../dist/source/usp/profiled
	cp -p $(SRCS) ../../dist/source/usp/
	cp -p $(INCLUDES) ../../dist/source/usp/
	cp -p Makefile ../../dist/source/usp/
	chmod 644 ../../dist/source/usp/Makefile
	cp -p usp_et.et ../../dist/source/usp/

.c.o:
	-rm -f $*.o profiled/$*.o
	${CC} -c -pg ${CFLAGS} $*.c
	mv -f $*.o profiled/$*.o
	${CC} -c ${CFLAGS} $*.c

.SUFFIXES:	.h .et

.et.c:
	rm -f $*.o $*.h
	../et/compile_et $*.et

usp_et.o : usp_et.c
usp_et.c : usp_et.et

.et.h:
	rm -f $*.o $*.h
	../et/compile_et $*.et

# 'make depend' code
depend: ${SRCS} usp_et.h
	${CC} -M ${CFLAGS} ${SRCS} | \
	sed -e ':loop' \
	    -e 's/\.\.\/[^ /]*\/\.\./../' \
	    -e 't loop' | \
	awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
		else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
		       else rec = rec " " $$2 } } \
	      END { print rec } ' > makedep
	echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	rm -f Makefile.bak
	cp Makefile Makefile.bak
	ed - Makefile < eddep
	rm eddep makedep
#
# the last line in the makefile should be...
# DO NOT DELETE THIS LINE

block.o: block.c /usr/include/sys/types.h /usr/include/stdio.h ./gen.h ./usp.h
block.o: ./usp_et.h /usr/include/netinet/in.h
get.o: get.c /usr/include/sys/types.h /usr/include/stdio.h ./gen.h ./usp.h
get.o: ./usp_et.h /usr/include/netinet/in.h
internal.o: internal.c /usr/include/sys/types.h /usr/include/errno.h
internal.o: /usr/include/stdio.h ./gen.h ./usp.h ./usp_et.h
internal.o: /usr/include/netinet/in.h
main.o: main.c /usr/include/stdio.h /usr/include/errno.h /usr/include/strings.h
main.o: /usr/include/sys/types.h /usr/include/sys/socket.h /usr/include/netdb.h
main.o: /usr/include/netinet/in.h ./gen.h ./usp.h ./usp_et.h
put.o: put.c /usr/include/sys/types.h /usr/include/stdio.h ./gen.h ./usp.h
put.o: ./usp_et.h /usr/include/netinet/in.h
