#
# libem/Makefile
#
include	../Makefile.config

CFLAGS= -I.. $(COPT)
LIBEMFW_OBJS=assert.o cpbidir.o ipaddr.o \
	cfgroupid.o cfuserid.o cfhosts.o cfint.o cfstr.o setug.o \
	emi.o emo.o fastdaemon.o fastheap.o findcmd.o \
	findhash.o findhash2.o hash.o pidfile.o \
	lwrcmpn.o lwrcmpz.o lwrcopy.o lwrmatch.o lwrtable.o \
	uprcopy.o uprtable.o \
	version.o versionchk.o xmalloc.o xstrndup.o chksnprintf.o

LIBEMTN_OBJS=tncore.o tndfa.o tngetc.o tngets.o tnhelp.o tnprintf.o \
	tnputc.o tnputs.o

all:	../libemfw.a ../libemtn.a

../libemfw.a: $(LIBEMFW_OBJS)
	ar rcv ../libemfw.a $(LIBEMFW_OBJS)
	$(RANLIB) ../libemfw.a

../libemtn.a: $(LIBEMTN_OBJS)
	ar rcv ../libemtn.a $(LIBEMTN_OBJS)
	$(RANLIB) ../libemtn.a

cpbidir.o: cpbidir.c emio.h
emi.o:	emi.c emio.h
emo.o:	emo.c emio.h
fastheap.o: fastheap.c fastheap.h
lwrtable.o: lwrtable.c lwrtable.h
uprtable.o: uprtable.c uprtable.h

lwrtable.h: maketable
	./maketable -l >lwrtable.h

uprtable.h: maketable
	./maketable -u >uprtable.h

MAKETABLE_OBJ=maketable.o hash.o xmalloc.o xstrndup.o

maketable: $(MAKETABLE_OBJ)
	$(CC) $(LDFL) -o maketable $(MAKETABLE_OBJ) -lm

clean:
	rm -f ../libemfw.a ../libemtn.a *.o fastdaemon.c
	rm -f lwrtable.h uprtable.h maketable

# Build fastdaemon.c from TIS' lib/daemon.c
#
# We make the following changes:
#
# - remove all code but do_daemon()
# - rename do_daemon() to do_fastdaemon()
# - call write_pid_file()
# - don't install hup_exit() for SIGHUP
# - call got_signal() when accept() is interrupted by a signal
# - ignore SIGHUP after forking (killall -HUP squid-gw)

fastdaemon.c: ../lib/daemon.c fastdaemon.sed
	sed -f fastdaemon.sed <../lib/daemon.c >fastdaemon.c
