SHELL = /bin/sh
MAKE = make
SUPPORTED = solaris linux aix hpux freebsd
DATABASE=-DTEXTDATA

##########################################################################
# READ THIS FIRST
# 
# This Makefile has been "improved" to allow platform building more easily
# Check the entries for your platform below, specifically if you aren't 
# using gcc change the CC= entry for your compiler.
# 
# then run make yourplatform e.g. make linux
# 
#

all: what

#
# If you want to change the defaults do it here for each platform
#
linux: 
	@echo Making bcnu for $@
	$(MAKE) platform 'CC=gcc' 'CFLAGS=-O -DVERSION=\"`cat ../etc/bcnu_version`\" \
	$(DATABASE) -DLISTEN=10' 'PLATFORM=$(@)'

solaris: 
	@echo Making bcnu for $@
	$(MAKE) platform 'CC=gcc' 'CFLAGS=-O -DVERSION=\"`cat ../etc/bcnu_version`\" \
	$(DATABASE) -DLISTEN=10'  'PLATFORM=$(@)' 'LIBS=-lnsl -lsocket -ll'

hpux: 
	@echo Making bcnu for $@
	$(MAKE) platform 'CC=gcc' 'CFLAGS=-O -DVERSION=\"`cat ../etc/bcnu_version`\" \
	$(DATABASE) -DLISTEN=10' 'PLATFORM=$(@)'

aix: 
	@echo Making bcnu for $@
	$(MAKE) platform 'CC=gcc' 'CFLAGS=-O -DVERSION=\"`cat ../etc/bcnu_version`\" \
	$(DATABASE) -DLISTEN=10' 'PLATFORM=$(@)'

freebsd: 
	@echo Making bcnu for $@
	$(MAKE) platform 'CC=gcc' 'CFLAGS=-O -DVERSION=\"`cat ../etc/bcnu_version`\" \
	$(DATABASE) -DLISTEN=10 -DNOZOMBIE' 'PLATFORM=$(@)'

# for mysql on solaris replace the libs entry with
#LIBS= -L/usr/local/mysql/lib -lmysqlclient -lsocket -lnsl -lgen -ll
#DATABASE=-DMYSQLDATA -I/usr/local/mysql/include
#

drsnx: 
	@echo Making bcnu for $@
	$(MAKE) platform 'CC=cc' 'CFLAGS=-O -DVERSION=\"`cat ../etc/bcnu_version`\" \
	$(DATABASE)'  'PLATFORM=$(@)' 'LIBS = -lsocket -lnsl -L/usr/ucblib -lucb'

#
# Should not need to edit below here
#
bcnu: bcnu.h bcnu.o lib.o ../etc/bcnu_version
	${CC} ${CFLAGS} -o $@ bcnu.o lib.o ${LIBS}

bcnud: bcnu.h bcnud.o lib.o log.o process.o agent.o cmd.o ../etc/bcnu_version
	${CC} ${CFLAGS} ${INCLUDE} -o $@ bcnud.o lib.o log.o agent.o process.o cmd.o ${LIBS}

bcnumsg: bcnu.h bcnumsg.o lib.o ../etc/bcnu_version
	${CC} ${CFLAGS} -o $@ bcnumsg.o lib.o ${LIBS}

platform: bcnud bcnu bcnumsg
	cp bcnu ../bin/bcnu.$(PLATFORM)
	cp bcnud ../bin/bcnud.$(PLATFORM)
	cp bcnumsg ../bin/bcnumsg.$(PLATFORM)
	cd ../bin; touch bcnu bcnud bcnumsg
	cd ../bin; rm bcnu bcnud bcnumsg
	cd ../bin; ln -s bcnu.$(PLATFORM) bcnu
	cd ../bin; ln -s bcnud.$(PLATFORM) bcnud
	cd ../bin; ln -s bcnumsg.$(PLATFORM) bcnumsg
	cp ../bin/* ../platform

what:
	@echo You must specify the platform to make:
	@echo i.e. make linux
	@echo Supported [ $(SUPPORTED) ]
	@echo
	@echo This will compile the programs with the default settings
	@echo and copy them to the directories ../platform and ../bin

clean:	
	@echo Cleaning up
	rm -f *.o *~ bcnud bcnu bcnumsg

tar:
	@echo Making tar file /tmp/src.tar with bcnu sources
	cd ..; tar cvf /tmp/src.tar src/* etc/bcnu_version
