# File: makefile
#
# $Header: Makefile,v 1.1.212.3 95/12/04 16:32:37 indnetwk Exp $
#
# This is the makefile that builds the DHCP Client executable and associated
# objects.
#

##### MACRO SECTION

ANSI	= -D_HPUX_SOURCE

# Include file macros
ALLINC	= dhcpclient.h trace.h dhcpdb.h dhcp.h intf_proto.h

# This makefile
MAKEFILE= Makefile

PRODUCT=/usr/lbin/dhcpclient

TARGET	= dhcpclient
USR_TARGET = /usr/lbin/$(TARGET)

TARGOBJS= ci.o \
	  dhcp_utils.o \
	  intf.o \
	  dlpi.o \
	  sock.o \
	  trace.o

DBLIB	= libdhcpdb.a
TARGLIBS= $(DBLIB)


#####
# BBA Macros
#
# NOTE: The file .NORMAL exists if the last compile did not use bba.
#       The file .BBA    exists if the last compile used bba.
#####

BBACMD	= -tp,/usr/hp64000/lib/bbacpp
BBAOPT	= -DBBA_OPTO=A -DBBA_OPTa
BBAGEN	= /usr/hp64000/bin/bbagen
BBALIB	= bba.a
BBALIBX	=
BBAGENOPTS= -d /home/bba/bbadump.data -o $(BBALIB)

BBAGENX	= @echo >/dev/null
BFA	= -DBFA
BBACFLAGS=${BFA} ${BBAOPT} ${CFLAGS} ${BBACMD}


# Commands
COPY	= cp -p

# Misc
DONE	= @echo "$@ COMPLETE"


##### TARGET SECTION

#####
# 'make' primer
#   $@ - target of makefile run
#   $< - source file prerequisite for target (only for suffix rules)
#   $? - the dependancy(s) that is newer than the target.
#####

# Defaults file containing the shell, compiler options, etc

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

#LOC_CFLAGS= -Aa $(CFLAGS) +Onolimit $(ANSI)
LOC_CFLAGS= -Aa $(CFLAGS) $(ANSI)

#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 target, this is the highest level target and must occur prior to any
# other.

all:  clean build install

dhcpc:	.NORMAL install_client

.NORMAL:
	$(RM) -f *.o .BBA $(TARGLIBS)
	touch $@

bba:    .BBA bbatarget

bbatarget:  
	${MAKE} -f $(MAKEFILE) \
		CFLAGS="${BBACFLAGS}" BBAGENX="${BBAGEN}" BBALIBX="${BBALIB}" \
		install_client


.BBA:
	$(RM) -f *.o .NORMAL $(TARGLIBS)
	touch $@

build:	$(TARGLIBS) $(TARGET)

clean:
	$(RM) -f $(TARGOBJS) $(TARGLIBS) $(TARGET)
	$(DONE)

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

install:
	$(INSTALLSCPT) $(PRODUCT) $(INSTALLDB)

install_client: $(TARGET)
	$(COPY) $(TARGET) $(USR_TARGET)
	chmod 544 $(USR_TARGET);chgrp bin $(USR_TARGET);chown bin $(USR_TARGET)
	touch $@

# dhcpclient binary
$(TARGET): $(TARGOBJS) $(TARGLIBS)
	${BBAGENX} ${BBAGENOPTS} ${TARGOBJS}
	$(CC) -o $@ $(LDFLAGS) $(LOC_CFLAGS) $(TARGOBJS) $(TARGLIBS) ${BBALIBX}


## Detailed OBJECT Targets

# detailed ci object
ci.o: ci.c $(ALLINC)
	$(CC) -c -o $@ $(LOC_CFLAGS) ci.c

# detailed intf object
intf.o: intf.c dhcpclient.h trace.h
	$(CC) -c -o $@ $(LOC_CFLAGS) intf.c

# detailed dlpi object
dlpi.o: dlpi.c dhcpclient.h trace.h
	$(CC) -c -o $@ $(LOC_CFLAGS) dlpi.c

# detailed sock object
sock.o: sock.c dhcpclient.h trace.h
	$(CC) -c -o $@ $(LOC_CFLAGS) sock.c

# detailed dhcpdb shared-library object
$(DBLIB): dhcpdb.c dhcpdb.h dhcp.h
	$(CC) -c -o dhcpdb.o $(LOC_CFLAGS) dhcpdb.c
	ar -rv $(DBLIB) dhcpdb.o
	$(RM) -f dhcpdb.o

# detailed dhcp_utils object
dhcp_utils.o: dhcp_utils.c $(ALLINC)
	$(CC) -c -o $@ $(LOC_CFLAGS) dhcp_utils.c

# detailed trace object
trace.o: trace.c trace.h
	$(CC) -c -o $@ $(LOC_CFLAGS) trace.c


##########################################################################
#

tags: *.c *.h
	ctags -t *.c *.h


#bbatarget:  
#	${MAKE} -f $(MAKEFILE) \
#		CFLAGS="${BBACFLAGS}" BBAGENX="${BBAGEN}" BBALIBX="${BBALIB}" \
#		$(TARGET)

# Standard macros
#DEBUG	= -g
#CFLAGS	= $(ANSI)
#CFLAGS	= $(DEBUG) $(ANSI)
#CC	= c89
