# Filter Compiler Makefile
#
# You may need to change some of the following to match the target system.
# These settings work for FreeBSD, Linux, Solaris, SunOS, and probably others.
# I no longer have access to an AIX system but it will probably need CC=cc
# and CFLAGS=-Wall -x

INSTALLDIR=/sbin
MANDIR=/usr/share/man/man8

CC=gcc
CFLAGS=-Wall -O4
YACC=yacc
#YACC=bison -y
ARCHLIBS=

# --------------------------------------------------------------------

# If this system is Solaris, include -lsocket and -lnsl libraries.
ARCHLIBS:sh=[ x"`uname -sr | cut -c1-7`" = x"SunOS 5" ] \
		&& echo -lsocket -lnsl || true

HEADERS=chario.h groups.h macros.h protocols.h version.h classes.h \
	hosts.h ports.h services.h 
OBJS=y.tab.o dbfc.o lex.o groups.o hosts.o services.o classes.o chario.o
SRCS=$(OBJS:%.c=%.o)

all: dbfc

package: dbfc
	@[ -d ../pkg ] || (echo ../pkg directory does not exist; false)
	@mkdir -p ../pkg/files/sbin
	cp dbfc ../pkg/files/sbin
	@strip ../pkg/files/sbin/dbfc

dbfc: ${OBJS}
	${CC} ${CFLAGS} -o dbfc ${OBJS} ${ARCHLIBS}

${OBJS}: ${HEADERS}

lex.c: y.tab.h

y.tab.c y.tab.h: grammar.y
	${YACC} -d grammar.y

y.tab.o: y.tab.c
	${CC} $(CFLAGS:-Wall=) -c y.tab.c

install: dbfc
	install -c -o root -g bin -m 555 -s dbfc $(INSTALLDIR)
	install -c -o bin -g bin -m 444 dbfc.8 $(MANDIR)
	gzip $(MANDIR)/dbfc.8

clean:
	rm -f ${OBJS} dbfc y.tab.c y.tab.h ../pkg/files/sbin/dbfc
	@[ -d ../pkg/files/sbin ] && rmdir ../pkg/files/sbin || true
