#---------------------------------------------------------------------
# Make file for bootp directory
# $Header: Makefile,v 1.12.212.5 96/03/11 11:21:40 bhm Exp $
#
# Things you might want to change.  Pass them in on the command line:
# ROOT - should point to the root where the commands will be installed
#        (e.g. /deliver/INETSVCS/indnetwk)
#---------------------------------------------------------------------

ROOT=

# Need to add libdhcp.sl and dhcptools to product list
PRODUCTS=/usr/lbin/bootpd     \
	 /usr/sbin/bootpquery \
         /usr/sbin/dhcptools  \
	 /usr/newconfig/etc/bootptab \
	 /usr/newconfig/etc/dhcptab  \
         /usr/lib/libdhcp.1 \
         /usr/lib/libdhcp.sl

HDRS=  		bootp.h bootpd.h hash.h dhcpapp.h dhcpvars.h sort.h
BOOTPDSRCS=     bootpd.c build_offer.c readfile.c hash.c sort.c
BOOTPDOBJS=     bootpd.o build_offer.o readfile.o hash.o sort.o
BOOTPDOPT=-DDEBUG -DVEND_CMU -DSYSLOG -DPRIVATE=static -DPRE_STREAMS

DHCPTOOLS_HDRS= dhcpapp.h dhcpvars.h
DHCPTOOLS_SRCS= dhcptools.c
DHCPTOOLS_LIBS=-ldhcp

LDLIBRARIES=../util/libutil.a
INCLUDES=-I. -I../include -I/usr/include

# Defaults file containing the shell, compiler options, etc

BUILDRULES=/source/INETSVCS/$(LOGNAME)/config/defaults
include ${BUILDRULES}

LOC_CFLAGS=$(INCLUDES) $(BOOTPDOPT) -Aa $(CFLAGS) +Onolimit -D_HPUX_SOURCE

#Install database name
INSTALLDB=/source/INETSVCS/$(LOGNAME)/config/installdb

#Script called to parse the install deliverable
INSTALLSCPT=/source/INETSVCS/$(LOGNAME)/config/install_script

########################  MAKEFILE TARGETS
default: all

all: clean build install

clean:
	$(RM) -f *.o
	$(RM) -f bootpd bootpquery dhcptools version.c libdhcp.1 libdhcp.sl

########################  COMPILATION TARGETS
.c.o:
	$(CC) -c $(LOC_CFLAGS) $*.c

bootpquery.o: 	bootpquery.c bootp.h
bootpd.o: 	bootpd.c bootpd.h bootp.h dhcpapp.h dhcpvars.h sort.h
build_offer.o: 	build_offer.c bootp.h hash.h bootpd.h dhcpapp.h sort.h
readfile.o: 	readfile.c bootp.h hash.h bootpd.h sort.h
hash.o: 	hash.c hash.h
sort.o: 	sort.c sort.h
libdhcp.o:  	libdhcp.c bootpd.h bootp.h hash.h dhcpapp.h sort.h
		${CC} ${LOC_CFLAGS} -c +z libdhcp.c
lib_validate.o:	lib_validate.c bootpd.h bootp.h hash.h dhcpapp.h sort.h
		${CC} ${LOC_CFLAGS} -c +z lib_validate.c
hashsl.o: 	hash.c hash.h
		${CC} ${LOC_CFLAGS} -c -o hashsl.o +z hash.c
sortsl.o: 	sort.c sort.h
		${CC} ${LOC_CFLAGS} -c -o sortsl.o +z sort.c

dhcptools.o: 	dhcptools.c

########################  BUILD TARGETS

build: bootpd libdhcp.1 bootpquery dhcptools 

bootpd: version.o $(BOOTPDOBJS)
	$(ECHO) "Building bootpd..."
	$(CC) -o bootpd version.o \
		 $(BOOTPDOBJS) $(LDLIBRARIES) $(LOC_CFLAGS) $(LDFLAGS)

bootpquery: bootpquery.o
	$(ECHO) "Building bootpquery..."
	$(CC) -Aa -o bootpquery bootpquery.o $(LDLIBRARIES) $(LDFLAGS)

version.o: 
	$(SHELL) newvers.sh
	$(CC) $(LOC_CFLAGS) -c version.c

libdhcp.1:  libdhcp.o lib_validate.o hashsl.o sortsl.o
	${LD} -b -E -o libdhcp.1 libdhcp.o lib_validate.o hashsl.o sortsl.o
	ln -s libdhcp.1 libdhcp.sl

dhcptools:	${DHCPTOOLS_SRCS} ${DHCPTOOLS_HDRS}
	${CC} ${LOC_CFLAGS} -o dhcptools ${DHCPTOOLS_SRCS} ${LDFLAGS} -L /usr/lib -L. ${DHCPTOOLS_LIBS} -Wl,+b /usr/lib

install:
	for file in $(PRODUCTS) ; do \
		$(INSTALLSCPT) $$file $(INSTALLDB) ;  \
	done

versionlog:
	$(RM) -f version.log
	VERSION=`cat version` ; \
	$(ECHO) "Revision $$VERSION contains the following bootpd sources:\n" >version.log
	for i in $(BOOTPDSRCS) $(HDRS) ; do \
		ident $$i | grep Header | \
		awk 'BEGIN { spaces="                ";\
			     tablen=15-length(FILE)+1;\
		       	     tab=substr(spaces,1,tablen);\
			   }\
		     {print FILE tab $$3}' FILE=$$i ; \
	done | sort | pr -2 -t >>version.log

