#  Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
#	The Regents of the University of California.  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that: (1) source code distributions
#  retain the above copyright notice and this paragraph in its entirety, (2)
#  distributions including binary code include the above copyright notice and
#  this paragraph in its entirety in the documentation or other materials
#  provided with the distribution, and (3) all advertising materials mentioning
#  features or use of this software display the following acknowledgement:
#  ``This product includes software developed by the University of California,
#  Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
#  the University nor the names of its contributors may be used to endorse
#  or promote products derived from this software without specific prior
#  written permission.
#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# @(#) $Id: Makefile.in 783 2011-09-28 01:23:30Z leres $ (LBL)

#
# Various configurable paths (remember to edit Makefile.in, not Makefile)
#

# Top level hierarchy
prefix = @prefix@
exec_prefix = @exec_prefix@
# Pathname of directory to install the binary
SBINDEST = @sbindir@
# Pathname of directory to install executables that other programs run
LIBEXECDIR = @libexecdir@
# Pathname of directory to install the man page
MANDEST = @mandir@
# The root of the directory tree for read-only
datarootdir = @datarootdir@
# Configuration files
sysconfdir = @sysconfdir@
# Pathname of directory to install the rc.d script
RCDDEST = ${exec_prefix}/etc/rc.d
# /etc/init.d
INITDDIR = /etc/init.d

# VPATH
srcdir = @srcdir@
VPATH = @srcdir@

#
# You shouldn't need to edit anything below here.
#

PROG = acld
ALL = ${PROG} @ACLC@
CC = @CC@
CCOPT = @V_CCOPT@
INCLS = @V_INCLS@
DEFS = @DEFS@

# Standard CFLAGS
CFLAGS = @CFLAGS@ @CPPFLAGS@ $(CCOPT) $(DEFS) $(INCLS)

# Optional build environment variables
ENVIRONMENT = @V_ENVIRONMENT@
BROCCOLI_VERSION = @BROCCOLI_VERSION@

# Standard LDFLAGS
LDFLAGS = @LDFLAGS@

# Standard LIBS
LIBS = @LIBS@

INSTALL = @INSTALL@

INSTALL_START = @INSTALL_START@

# Explicitly define compilation rule since SunOS 4's make doesn't like gcc.
# Also, gcc does not remove the .o before forking 'as', which can be a
# problem if you don't own the file but can write to the directory.
.c.o:
	@rm -f $@
	$(CC) $(CFLAGS) -c $(srcdir)/$*.c

SRCS = acld.c acl.c cf.c child.c client.c io.c util.c route.c \
	server.c setsignal.c stats.c timer.c whitelist.c \
	@CFORCESRCS@ @BRODSRCS@
CSRCS = aclc.c
GENSRC = version.c
LIBOBJS = @LIBOBJS@
LIBSRCS = $(LIBOBJS:.o=.c)
OBJS = $(SRCS:.c=.o) $(LIBOBJS) $(GENSRC:.c=.o)
HDRS = acld.h acl.h cf.h child.h client.h io.h util.h route.h server.h \
	setsignal.h stats.h timer.h util.h whitelist.h @V_LIBHDRS@
COBJS = $(CSRCS:.c=.o) $(LIBOBJS) $(GENSRC:.c=.o)

TAGFILES = $(SRCS) $(CSRCS) $(LIBOBJS:.o=.c) $(HDRS)

CLEANFILES = $(ALL) $(OBJS) $(COBJS) $(GENSRC) $(LIBOBJS) \
	purify $(OBJS:.o=_pure_*.o)

all: $(ALL)

acld: $(OBJS)
	@rm -f $@
	$(ENVIRONMENT) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

aclc: $(COBJS)
	@rm -f $@
	$(ENVIRONMENT) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COBJS) $(LIBS)

purify: $(OBJS)
	@rm -f $@
	purify $(CC) $(CFLAGS) $(LDFLAGS) -o purify $(OBJS) $(LIBS)
	#ln -s ln -s /home/cpacket/cForce/bin/cforce_linux.so libcforce_linux.so
	#purify $(CC) $(CFLAGS) $(LDFLAGS) -o purify $(OBJS) -L. -lcforce_linux

version.o: version.c
version.c: $(srcdir)/VERSION
	@rm -f $@
	(sed -e 's/.*/char version[] = "&";/' $(srcdir)/VERSION ; \
	echo 'char broccoli_version[] = "$(BROCCOLI_VERSION)";') > $@

install: $(ALL) $(INSTALL_START)
	@for f in $(ALL); do \
		$(INSTALL) -v -m 555 -o bin -g bin $${f} $(DESTDIR)$(SBINDEST); \
		done
	@diff acl.exp $(DESTDIR)$(LIBEXECDIR) >/dev/null 2>&1 || \
	    $(INSTALL) -v -m 555 -o bin -g bin acl.exp $(DESTDIR)$(LIBEXECDIR)
	@diff aclcompact.sh $(DESTDIR)$(LIBEXECDIR)/aclcompact >/dev/null 2>&1 || \
	    $(INSTALL) -v -m 555 -o bin -g bin aclcompact.sh $(DESTDIR)$(LIBEXECDIR)/aclcompact
	@diff check_acld.py $(DESTDIR)$(LIBEXECDIR)/check_acld >/dev/null 2>&1 || \
	    $(INSTALL) -v -m 555 -o bin -g bin check_acld.py $(DESTDIR)$(LIBEXECDIR)/check_acld
	@for f in cisco.expect force10.expect ipfw.expect; do \
		diff $(srcdir)/$${f} $(DESTDIR)$(sysconfdir) >/dev/null 2>&1 || \
		    $(INSTALL) -v -m 444 -o bin -g bin $(srcdir)/$${f} $(DESTDIR)$(sysconfdir); \
	done
	@mkdir -pv -m 775 /var/log/acld
	@mkdir -pv -m 775 /var/run/acld
	@for f in $(ALL); do \
		diff $(srcdir)/$${f}.8 $(DESTDIR)$(MANDEST)/man8 >/dev/null 2>&1 || \
		    $(INSTALL) -v -m 444 -o bin -g bin $(srcdir)/$${f}.8 $(DESTDIR)$(MANDEST)/man8; \
	done

# Startup scripts for /usr/local/etc/rc.d (e.g. FreeBSD)
install-localrcd:
	@for f in acld aclfw; do \
		diff $(srcdir)/$${f}.sh $(DESTDIR)$(RCDDEST)/$${f} >/dev/null 2>&1 || \
		    $(INSTALL) -v -m 555 -o bin -g bin $(srcdir)/$${f}.sh $(DESTDIR)$(RCDDEST)/$${f}; \
	done

# Startup scripts for update-rc.d (e.g. Ubuntu)
install-updatercd:
	@diff $(srcdir)/$(PROG)-init.d.sh $(INITDDIR)/$(PROG) >/dev/null 2>&1 || \
	    $(INSTALL) -v -m 555 -o bin -g bin $(srcdir)/$(PROG)-init.d.sh $(INITDDIR)/$(PROG)
	update-rc.d $(PROG) defaults

clean: force
	rm -f $(CLEANFILES)

distclean: force
	rm -rf $(CLEANFILES) Makefile config.cache config.log config.status \
	    autom4te.cache gnuc.h os-proto.h \
	    acl.exp aclcompact.sh acld.sh acld-init.d.sh aclfw.sh check_acld.py

tags:	$(TAGFILES)
	ctags -wtd $(TAGFILES)

dist tar: force
	@cwd=`pwd` ; name=${PROG}-`cat VERSION` ; \
	    list="" ; tar="tar chf" ; temp="$${name}.tar.gz" ; \
	    for i in `cat FILES` ; do list="$${list} $${name}/$${i}" ; done; \
	    echo \
	    "rm -f $${name}.tar.gz.asc $${name}; ln -s . $${name}" ; \
	     rm -f $${name}.tar.gz.asc $${name}; ln -s . $${name} ; \
	    echo \
	    "$${tar} - [lots of files] | gzip > $${temp}" ; \
	     $${tar} - $${list} | gzip > $${temp} ; \
	    echo \
	    "rm -f $${name}" ; \
	     rm -f $${name}

sign:
	@name=${PROG}-`cat VERSION`.tar.gz; \
	    set -x; \
	    rm -f $${name}.asc; \
	    gpg --armor --detach-sign $${name}


force:	/tmp
depend:	force $(GENSRC)
	./mkdep -c $(CC) $(DEFS) $(INCLS) $(SRCS) $(GENSRC) $(LIBSRCS)
