# -*- makefile -*-
#
# $Id: Makefile.in 1084 2005-02-12 20:17:04Z bmah $
#   based on:
# $ID: Makefile.in,v 1.20 1996/11/19 18:56:38 bmah Exp $
#
# Intergalactic Makefile
# Bruce A. Mah <bmah@acm.org>
#
# This work was first produced by an employee of Sandia National
# Laboratories under a contract with the U.S. Department of Energy.
# Sandia National Laboratories dedicates whatever right, title or
# interest it may have in this software to the public. Although no
# license from Sandia is needed to copy and use this software,
# copying and using the software might infringe the rights of
# others. This software is provided as-is. SANDIA DISCLAIMS ANY
# WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
#

#
# Locations of things
#
srcdir=@srcdir@
VPATH=@srcdir@
INCLUDE_DIR=@srcdir@

DESTDIR=
prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
mandir=@mandir@

# Locations of dependency files.  No reason to change these.
MAKEDEP_TMP=.makedep
MAKEFILE_DEPEND=Makefile.depend

#
# Configuration and stuff
#
host=@host@
host_alias=@host_alias@
host_cpu=@host_cpu@
host_vendor=@host_vendor@
host_os=@host_os@

#
# Compile-time options
#
DFLAGS=	@DEFS@

# Debian hardening
CPPEXTRA:=$(shell dpkg-buildflags --get CPPFLAGS)
CXXEXTRA:=$(shell dpkg-buildflags --get CXXFLAGS)
LDEXTRA:=$(shell dpkg-buildflags --get LDFLAGS)

#
# Compilation flags
#
LDFLAGS=@LDFLAGS@ $(LDEXTRA)
LIBS=@LIBS@
IFLAGS=@CPPFLAGS@ -I$(srcdir)

#
# Other cc options get defined here.
#
CXXFLAGS=@CXXFLAGS@ $(IFLAGS) $(DFLAGS) $(CPPEXTRA) $(CXXEXTRA)

#
# Specification of programs.
#
# Notes:  CC affects the generation of dependencies (at many sites,
# gcc has its own set of include files).
#
# SHELL is absolutely necessary for dependencies to work on Silicon
# Graphics Irix (at least version 3.3, not sure about 4.0 or later).
#
AWK=@AWK@
CXX=@CXX@
ECHO=echo
ECHOQNL=@echoqnl@
GZIP=gzip -9v
INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
LD=@CXX@
LN_S=@LN_S@
MKDIR=mkdir
MKINSTALLDIRS=${srcdir}/mkinstalldirs
PGP=gpg
RM=rm
SHELL=/bin/sh
TAR=tar
TOUCH=touch

A.OUT=pchar
VERSION=@PC_VERSION@

TARDIR=$(A.OUT)-$(VERSION)
TARFILE=$(TARDIR).tar
TARGZFILE=$(TARFILE).gz
SIGFILE=$(TARGZFILE).asc

#
# Various files
#
# OBJ lists the pathnames of the object files in the build tree as
# defined by $(srcdir).
#
# Other file lists are used in generation distribution tarballs.
#
OBJ	=@obj_subsets@
OBJ_BASE= \
	main.o \
	Kendall.o \
	Pctest.o PctestIpv4.o PctestIpv4File.o PctestIpv4Udp.o PctestIpv4Raw.o\
	PctestIpv4Tcp.o PctestIpv4Icmp.o \
	ResultTable.o \
	TestRecord.o \
	version.o
OBJ_IPV6= \
	PctestIpv6.o PctestIpv6File.o PctestIpv6Icmp.o PctestIpv6Tcp.o \
	PctestIpv6Udp.o 
OBJ_SNMP= \
	GetIfInfo.o

GENSRC= \
	version.cc

SRCFILES= \
	main.cc \
	GetIfInfo.cc GetIfInfo.h \
	Kendall.cc Kendall.h \
	Pctest.cc Pctest.h \
	PctestIpv4.cc PctestIpv4.h \
	PctestIpv4File.cc PctestIpv4File.h \
	PctestIpv4Udp.cc PctestIpv4Udp.h \
	PctestIpv4Raw.cc PctestIpv4Raw.h \
	PctestIpv4Tcp.cc PctestIpv4Tcp.h \
	PctestIpv4Icmp.cc PctestIpv4Icmp.h \
	PctestIpv6.cc PctestIpv6.h \
	PctestIpv6File.cc PctestIpv6File.h \
	PctestIpv6Icmp.cc PctestIpv6Icmp.h \
	PctestIpv6Tcp.cc PctestIpv6Tcp.h \
	PctestIpv6Udp.cc PctestIpv6Udp.h \
	ResultTable.cc ResultTable.h \
	TestRecord.cc TestRecord.h \
	pc.h

OTHERFILES= \
	README CHANGES FAQ pchar.8 \
	Makefile.in Makefile.depend.in \
	VERSION \
	aclocal.m4 \
	config.guess config.sub configure configure.in install-sh mkinstalldirs

CONFIGFILES= \
	Makefile $(MAKEFILE_DEPEND) $(MAKEDEP_TMP)\
	config.cache config.log config.status

#
# Main target dependencies
#
all: $(A.OUT)

$(A.OUT): $(OBJ)
	$(LD) $(OBJ) $(LDFLAGS) $(LIBS) -o $(A.OUT) 

version.o: version.cc
version.cc: VERSION
	@$(RM) -f $@
	@$(TOUCH) $@
	@echo "# Generating $@ for this build..."
	@echo "static char version[] = \"$(A.OUT) `cat $(srcdir)/VERSION`\";" >> $@
	@echo "static char copyright[] = " >> $@
	@echo '"This work was first produced by an employee of Sandia National"' >> $@
	@${ECHOQNL} >> $@
	@echo '"Laboratories under a contract with the U.S. Department of Energy."' >> $@
	@${ECHOQNL} >> $@
	@echo '"Sandia National Laboratories dedicates whatever right, title or"' >> $@
	@${ECHOQNL} >> $@
	@echo '"interest it may have in this software to the public. Although no"' >> $@
	@${ECHOQNL} >> $@
	@echo '"license from Sandia is needed to copy and use this software,"' >> $@
	@${ECHOQNL} >> $@
	@echo '"copying and using the software might infringe the rights of"' >> $@
	@${ECHOQNL} >> $@
	@echo '"others. This software is provided as-is. SANDIA DISCLAIMS ANY"' >> $@
	@${ECHOQNL} >> $@
	@echo '"WARRANTY OF ANY KIND, EXPRESS OR IMPLIED."' >> $@
	@${ECHOQNL} >> $@
	@echo ';' >> $@
	@echo "static char dflags[] = \"$(DFLAGS)\";" >> $@
	@echo "char *Version = version;" >> $@
	@echo "char *Copyright = copyright;" >> $@
	@echo "char *DFlags = dflags;" >> $@

FORCE:

#
# install
#
TRANSFORM=@program_transform_name@
install: install-program install-man

install-program: all
	$(MKINSTALLDIRS) $(DESTDIR)${sbindir}
	$(INSTALL_PROGRAM) $(A.OUT) $(DESTDIR)$(sbindir)/`echo $(A.OUT) | sed '$(TRANSFORM)'`

install-man:
	$(MKINSTALLDIRS) $(DESTDIR)${mandir}/man8
	$(INSTALL_DATA) ${srcdir}/pchar.8 $(DESTDIR)${mandir}/man8/pchar.8

#
# clean
#
# Remove all object and executable files.
#
clean:
	$(RM) -f $(OBJ) $(A.OUT) $(GENSRC)

#
# pristine
#
# Like clean target, but also removes "meta-files" and distribution
# tarballs that we might have lying around
#
pristine: clean
	$(RM) -f $(CONFIGFILES)
	$(RM) -f $(TARDIR) $(TARFILE) $(TARGZFILE) $(SIGFILE)
	$(RM) -f core $(A.OUT).core
distclean: pristine

#
# dist
#
# Create a tarball in the current directory
#
dist: $(TARGZFILE)
$(TARGZFILE):
	$(RM) -rf $(TARDIR) $(TARFILE) $(TARGZFILE)	
	$(MKDIR) $(TARDIR)
	for f in `echo $(SRCFILES) $(OTHERFILES)`; do \
		(cd $(TARDIR); $(LN_S) ../$(srcdir)/$$f $$f); \
	done;
	(export POSIXLY_CORRECT=yes; $(TAR) -cvhlf $(TARFILE) $(TARDIR))
	$(GZIP) $(GZIPFLAGS) $(TARFILE)
	$(RM) -rf $(TARDIR)

#
# sign
#
# PGP-sign a distribution
#
sign: $(SIGFILE)
$(SIGFILE): $(TARGZFILE)
	@$(PGP) -sba $(TARGZFILE)

#
# depend
#
# Create source file dependency rules at the end of this file.
# 
depend:
	@$(RM) -f $(MAKEDEP_TMP)
	@echo "# make depend started on" `hostname` "on" `date` > $(MAKEDEP_TMP)
	@echo "Building dependencies ..."; \
	for src in `echo $(OBJ) $(SRC) " " | sed -e 's/\.o[ \t\n]/.cc /g'`; do \
	    echo -n " " $$src ": "; \
	    if [ -r $(srcdir)/$$src ]; then \
		$(CXX) -M $(CXXFLAGS) $(srcdir)/$$src >> $(MAKEDEP_TMP); \
		echo "done"; \
	    else \
		echo "nonexistent"; \
	    fi; \
	done;
	@echo "# make depend completed on" `hostname` "on" `date` >> $(MAKEDEP_TMP)
	@echo "Commiting dependencies to" $(MAKEFILE_DEPEND) "..."
	@$(RM) -f $(MAKEFILE_DEPEND)
	@mv $(MAKEDEP_TMP) $(MAKEFILE_DEPEND)
	@echo "Done."

#
# Modified default rules.  They are roughly the same as the defaults,
# but compilation commands are modified to put the compiler output at
# the location specified by the makefile target instead of the current
# directory.
#
# .cc		C++ source file
# .tcl		Tcl source file
# .cdf		Cumulative distribution function file
# .pdf		Probability density function file
#
.SUFFIXES: .cc .tcl .cdf .pdf
.cc.o:
	$(CXX) $(CXXFLAGS) -c $< -o $@
.tcl.cc:
	@$(RM) -f $@
	@$(TOUCH) $@
	@echo "# Generating $@ from $<..."
	@echo "// $@ generated from $<" > $@
	@echo "// on `date` by $$USER" >> $@
	@echo "" >> $@
	@echo 'static char foo[] = {' >> $@
	@sed -e '/^$$/d'             \
	    -e 's/	/ /g'        \
	    -e 's/^ *//g'            \
	    -e "s/\\(.\\)/'\\1',/g"  \
	    -e 's/\\/\\\\/g'         \
	    -e 's/$$/0x0a,/'         \
	    $< >> $@
	@echo '0x0 };' >> $@
	@echo "" >> $@
	@echo "// Indirection is needed to fool damaged linker" >> $@
	@echo "" >> $@
	@echo 'char *$(*F) = foo;' >> $@

#
# Grab dependencies.  Note that the file $(MAKEFILE_DEPEND) *must*
# exist, even if empty.
#
include $(MAKEFILE_DEPEND)
