#
#  Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003
#	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,v 1.95 2003/08/31 00:38:11 vern Exp $
#

SHELL = /bin/sh
PKG = bro

prefix = @prefix@
exec_prefix = @exec_prefix@
SBINDEST = @sbindir@
MANDEST = @mandir@
LIBDEST = @libdir@/$(PKG)

CC = @CC@
CCOPT = @V_CCOPT@
INCLS = @V_INCLS@
CPLUS = @CXX@
# CPLUS=${ccmalloc_dir}/bin/ccmalloc c++ ${ccmalloc_dir}/obj/ccmalloc-g++.o -L${ccmalloc_dir}/lib

CPPFLAGS = -I. $(LIBEDIT_INCL)
# CPPFLAGS = -I. -DEXPIRE_DFA_STATES
MEMDEBUG_FLAGS=-Dmalloc=debug_malloc -Drealloc=debug_realloc -Dfree=debug_free
# CFLAGS = $(CPPFLAGS) $(CCOPT) $(INCLS) -g -O0 -Wall -Wwrite-strings -W -DDEBUG_BRO
CFLAGS = $(CPPFLAGS) $(CCOPT) $(INCLS)
LDFLAGS = @LDFLAGS@

LIBEDIT_INCL = -I$(LIBEDIT_LIB_DIR)
LIBEDIT_LIB_DIR = libedit
LIBEDIT_LIB = libedit/libedit.a
LIBEDIT_LIBS = -Llibedit -ltermcap -ledit

LFLAGS = -s
LIBS = $(LIBEDIT_LIBS) @LIBS@ -lm

# Purify barfs when c++ is used for $(CPLUS).
PURIFY_CPLUS = g++
PURE_FLAGS = -chain-length=20

YACC = @YACC@
YFLAGS = -d -t -v
LEX = @LEX@
INSTALL = @INSTALL@ -d
INSTALL_DATA = @INSTALL_DATA@
@SET_MAKE@
COMPRESS = @COMPRESS@

EXEC = $(PKG)
OBJ =   main.o net_util.o util.o \
	parse.o scan.o re-parse.o re-scan.o rule-parse.o rule-scan.o \
	Active.o Anon.o Attr.o BackDoor.o BroString.o CCL.o \
	ChunkedIO.o CompHash.o Conn.o DFA.o DNS.o DNS_Mgr.o \
	DbgBreakpoint.o DbgHelp.o DbgWatch.o Debug.o DebugCmds.o \
	Desc.o Dict.o Discard.o EquivClass.o Event.o \
	EventHandler.o EventRegistry.o Expr.o FTP.o File.o \
	Finger.o Frag.o Frame.o Func.o HTTP.o Hash.o ICMP.o \
	ID.o Ident.o IntSet.o InterConn.o List.o Logger.o \
	Login.o MIME.o NFA.o NTP.o NVT.o Net.o NetVar.o \
	NetbiosSSN.o Obj.o PacketFilter.o PacketSort.o PktSrc.o \
	PolicyFile.o Portmap.o PrefixTable.o PriorityQueue.o \
	Queue.o RE.o RPC.o Reassem.o Rlogin.o Rule.o \
	RuleAction.o RuleCondition.o RuleMatcher.o SMTP.o \
	SSH.o Scope.o SerializationFormat.o Serializer.o \
	Sessions.o SteppingStone.o Stmt.o TCP.o TCP_Rewriter.o \
	Telnet.o Timer.o Type.o UDP.o Val.o Var.o XDR.o \
	cq.o md5.o patricia.o setsignal.o version.o @LIBOBJS@

# when we overload CPLUS when using ccmalloc ...
BIF_CPLUS = @CXX@
BIFCL = ./bifcl
BIFS =	bro.bif event.bif const.bif \
	common-rw.bif finger-rw.bif ident-rw.bif \
	ftp-rw.bif smtp-rw.bif http-rw.bif
BIF_FUNC_H = $(BIFS:.bif=.bif.func_h)
BIF_FUNC_DEF = $(BIFS:.bif=.bif.func_def)
BIF_FUNC_INIT = $(BIFS:.bif=.bif.func_init)
BIF_NETVAR_H = $(BIFS:.bif=.bif.netvar_h)
BIF_NETVAR_DEF = $(BIFS:.bif=.bif.netvar_def)
BIF_NETVAR_INIT = $(BIFS:.bif=.bif.netvar_init)
BIFOBJ = bif_arg.o bif_lex.o bif_parse.o
BIFCLEAN = bifcl $(BIFOBJ) $(BIF_FUNC_DEF) $(BIF_NETVAR_DEF)

TARGET = @target@
POLICY = policy/bro.init policy/*.bro

PRIV = priv

GENSRC = version.c scan.cc parse.cc y.tab.c broparse.h re-parse.cc re-scan.cc \
	y.output broparse.h re-parse.h rule-parse.cc rule-parse.h rule-scan.cc \
	config.log \
	$(BIF_FUNC_H) $(BIF_FUNC_DEF) $(BIF_FUNC_INIT) \
	$(BIF_NETVAR_H) $(BIF_NETVAR_DEF) $(BIF_NETVAR_INIT) $(BIF_NETVAR_H)

#	bro.bif.h bro.bif.builtin_init \
#	finger-rw.bif.func_h finger-rw.bif.func finger-rw.bif.builtin_init \
#	ftp-rw.bif.func_h ftp-rw.bif.func ftp-rw.bif.builtin_init \
#	http-rw.bif.func_h http-rw.bif.func http-rw.bif.builtin_init \
#	ident-rw.bif.func_h ident-rw.bif.func ident-rw.bif.builtin_init \
#	smtp-rw.bif.func_h smtp-rw.bif.func smtp-rw.bif.builtin_init \
#	common-rw.bif.func_h common-rw.bif.func common-rw.bif.builtin_init

CLEANFILES = $(EXEC) $(OBJ) $(BIFCLEAN) $(GENSRC) core

all: $(PKG)

$(PKG): $(LIBEDIT_LIB) $(OBJ)
	$(CPLUS) -o $(EXEC) $(OBJ) $(LDFLAGS) $(LIBS)
opt:
	@$(MAKE) $(MFLAGS) CCOPT="`echo $(CCOPT) | sed -e 's/-O2//;s/$$/ -O3/'`"

depend:
	makedepend -- $(CFLAGS) -- *.cc

version.o: version.c
version.c: VERSION
	@rm -f $@
	sed -e 's/.*/char version[] = "&";/' VERSION > $@

Active.o: Active.cc Active.h
	$(CPLUS) $(CFLAGS) -c Active.cc

Anon.o: Anon.cc Anon.h
	$(CPLUS) $(CFLAGS) -c Anon.cc

Attr.o: Attr.cc Attr.h
	$(CPLUS) $(CFLAGS) -c Attr.cc

BackDoor.o: BackDoor.cc BackDoor.h
	$(CPLUS) $(CFLAGS) -c BackDoor.cc

BroString.o: BroString.cc BroString.h
	$(CPLUS) $(CFLAGS) -c BroString.cc

CCL.o: CCL.cc CCL.h
	$(CPLUS) $(CFLAGS) -c CCL.cc

ChunkedIO.o: ChunkedIO.cc ChunkedIO.h
	$(CPLUS) $(CFLAGS) -c ChunkedIO.cc

CompHash.o: CompHash.cc CompHash.h
	$(CPLUS) $(CFLAGS) -c CompHash.cc

Conn.o: Conn.cc Conn.h
	$(CPLUS) $(CFLAGS) -c Conn.cc

DFA.o: DFA.cc DFA.h
	$(CPLUS) $(CFLAGS) -c DFA.cc

Debug.o: Debug.cc Debug.h DebugCmdConstants.h DebugCmdInfoConstants.cc
	$(CPLUS) $(CFLAGS) -c Debug.cc

DebugCmds.o: DebugCmds.cc DebugCmds.h DebugCmdInfoConstants.cc Debug.h
	$(CPLUS) $(CFLAGS) -c DebugCmds.cc

DebugCmdInfoConstants.cc: DebugCmdInfoConstants.in
	perl make_dbg_constants.pl $< $>

DebugCmdConstants.h: DebugCmdInfoConstants.in
	perl make_dbg_constants.pl $< $>

DbgBreakpoint.o: DbgBreakpoint.cc DbgBreakpoint.h Debug.h
	$(CPLUS) $(CFLAGS) -c DbgBreakpoint.cc

DbgWatch.o: DbgWatch.cc DbgWatch.h Debug.h
	$(CPLUS) $(CFLAGS) -c DbgWatch.cc

DbgHelp.o: DbgHelp.cc
	$(CPLUS) $(CFLAGS) -c DbgHelp.cc

Desc.o: Desc.cc Desc.h
	$(CPLUS) $(CFLAGS) -c Desc.cc

Dict.o: Dict.cc Dict.h
	$(CPLUS) $(CFLAGS) -c Dict.cc

Discard.o: Discard.cc Discard.h
	$(CPLUS) $(CFLAGS) -c Discard.cc

DNS.o: DNS.cc DNS.h
	$(CPLUS) $(CFLAGS) -c DNS.cc

DNS_Mgr.o: DNS_Mgr.cc DNS_Mgr.h
	$(CPLUS) $(CFLAGS) -c DNS_Mgr.cc

EquivClass.o: EquivClass.cc EquivClass.h
	$(CPLUS) $(CFLAGS) -c EquivClass.cc

Event.o: Event.cc Event.h
	$(CPLUS) $(CFLAGS) -c Event.cc

EventHandler.o: EventHandler.cc EventHandler.h
	$(CPLUS) $(CFLAGS) -c EventHandler.cc

EventRegistry.o: EventRegistry.cc EventRegistry.h
	$(CPLUS) $(CFLAGS) -c EventRegistry.cc

Expr.o: Expr.cc Expr.h
	$(CPLUS) $(CFLAGS) -c Expr.cc

File.o: File.cc File.h
	$(CPLUS) $(CFLAGS) -c File.cc

finger-rw.bif.func_h finger-rw.bif.func_def finger-rw.bif.func_init: finger-rw.bif bifcl
	$(BIFCL) finger-rw.bif
	@mv finger-rw.bif.bro policy/

Finger.o: Finger.cc Finger.h finger-rw.bif.func_def
	$(CPLUS) $(CFLAGS) -c Finger.cc

Frag.o: Frag.cc Frag.h Reassem.h
	$(CPLUS) $(CFLAGS) -c Frag.cc

Frame.o: Frame.cc Frame.h
	$(CPLUS) $(CFLAGS) -c Frame.cc

ftp-rw.bif.func_h ftp-rw.bif.func_def ftp-rw.bif.func_init: ftp-rw.bif bifcl
	$(BIFCL) ftp-rw.bif
	@mv ftp-rw.bif.bro policy/

FTP.o: FTP.cc FTP.h ftp-rw.bif.func_def
	$(CPLUS) $(CFLAGS) -c FTP.cc

bro.bif.func_h bro.bif.func_def bro.bif.func_init: bro.bif bifcl
	$(BIFCL) bro.bif
	@mv bro.bif.bro policy/

Func.o: Func.cc Func.h bro.bif.func_def $(BIF_FUNC_INIT)
	$(CPLUS) $(CFLAGS) -c Func.cc

Hash.o: Hash.cc Hash.h
	$(CPLUS) $(CFLAGS) -c Hash.cc

http-rw.bif.func_h http-rw.bif.func_def http-rw.bif.func_init: http-rw.bif bifcl
	$(BIFCL) http-rw.bif
	@mv http-rw.bif.bro policy/

HTTP.o: HTTP.cc HTTP.h http-rw.bif.func_def
	$(CPLUS) $(CFLAGS) -c HTTP.cc

ICMP.o: ICMP.cc ICMP.h
	$(CPLUS) $(CFLAGS) -c ICMP.cc

ID.o: ID.cc ID.h
	$(CPLUS) $(CFLAGS) -c ID.cc

ident-rw.bif.func_h ident-rw.bif.func_def ident-rw.bif.func_init: ident-rw.bif bifcl
	$(BIFCL) ident-rw.bif
	@mv ident-rw.bif.bro policy/

Ident.o: Ident.cc Ident.h ident-rw.bif.func_def
	$(CPLUS) $(CFLAGS) -c Ident.cc

InterConn.o: InterConn.cc InterConn.h
	$(CPLUS) $(CFLAGS) -c InterConn.cc

IntSet.o: IntSet.cc IntSet.h
	$(CPLUS) $(CFLAGS) -c IntSet.cc

List.o: List.cc List.h
	$(CPLUS) $(CFLAGS) -c List.cc

Logger.o: Logger.cc Logger.h
	$(CPLUS) $(CFLAGS) -c Logger.cc

Login.o: Login.cc Login.h
	$(CPLUS) $(CFLAGS) -c Login.cc

MIME.o: MIME.cc MIME.h
	$(CPLUS) $(CFLAGS) -c MIME.cc

NFA.o: NFA.cc NFA.h
	$(CPLUS) $(CFLAGS) -c NFA.cc

NTP.o: NTP.cc NTP.h
	$(CPLUS) $(CFLAGS) -c NTP.cc

NVT.o: NVT.cc NVT.h
	$(CPLUS) $(CFLAGS) -c NVT.cc

Net.o: Net.cc Net.h PacketSort.h
	$(CPLUS) $(CFLAGS) -c Net.cc

NetbiosSSN.o: NetbiosSSN.cc NetbiosSSN.h
	$(CPLUS) $(CFLAGS) -c NetbiosSSN.cc

event.bif.netvar_h event.bif.netvar_def event.bif.netvar_init: event.bif bifcl
	$(BIFCL) event.bif
	@mv event.bif.bro policy/

const.bif.netvar_h const.bif.netvar_def const.bif.netvar_init: const.bif bifcl
	$(BIFCL) const.bif
	@mv const.bif.bro policy/

$(OBJ): event.bif.netvar_h const.bif.netvar_h

NetVar.o: NetVar.cc NetVar.h event.bif.netvar_def const.bif.netvar_def
	$(CPLUS) $(CFLAGS) -c NetVar.cc

Obj.o: Obj.cc Obj.h
	$(CPLUS) $(CFLAGS) -c Obj.cc

PacketSort.o: PacketSort.cc PacketSort.h
	$(CPLUS) $(CFLAGS) -c PacketSort.cc

patricia.o: patricia.c patricia.h
	$(CC) $(CFLAGS) -c patricia.c

PacketFilter.o: PacketFilter.cc PacketFilter.h
	$(CPLUS) $(CFLAGS) -c PacketFilter.cc

PktSrc.o: PktSrc.cc PktSrc.h
	$(CPLUS) $(CFLAGS) -c PktSrc.cc

PolicyFile.o: PolicyFile.cc PolicyFile.h
	$(CPLUS) $(CFLAGS) -c PolicyFile.cc

Portmap.o: Portmap.cc Portmap.h
	$(CPLUS) $(CFLAGS) -c Portmap.cc

PrefixTable.o: PrefixTable.cc PrefixTable.h
	$(CPLUS) $(CFLAGS) -c PrefixTable.cc

PriorityQueue.o: PriorityQueue.cc PriorityQueue.h
	$(CPLUS) $(CFLAGS) -c PriorityQueue.cc

Queue.o: Queue.cc Queue.h
	$(CPLUS) $(CFLAGS) -c Queue.cc

RE.o: RE.cc RE.h
	$(CPLUS) $(CFLAGS) -c RE.cc

Reassem.o: Reassem.cc Reassem.h
	$(CPLUS) $(CFLAGS) -c Reassem.cc

Rlogin.o: Rlogin.cc Rlogin.h
	$(CPLUS) $(CFLAGS) -c Rlogin.cc

RPC.o: RPC.cc RPC.h
	$(CPLUS) $(CFLAGS) -c RPC.cc

Rule.o: Rule.cc Rule.h RuleMatcher.h
	$(CPLUS) $(CFLAGS) -c Rule.cc

RuleAction.o: RuleAction.cc RuleAction.h RuleMatcher.h
	$(CPLUS) $(CFLAGS) -c RuleAction.cc

RuleCondition.o: RuleCondition.cc RuleCondition.h RuleMatcher.h
	$(CPLUS) $(CFLAGS) -c RuleCondition.cc

RuleMatcher.o: RuleMatcher.cc RuleMatcher.h RuleMatcher.h
	$(CPLUS) $(CFLAGS) -c RuleMatcher.cc

Scope.o: Scope.cc Scope.h
	$(CPLUS) $(CFLAGS) -c Scope.cc

Sessions.o: Sessions.cc Sessions.h IP.h
	$(CPLUS) $(CFLAGS) -c Sessions.cc

Serializer.o: Serializer.cc Serializer.h
	$(CPLUS) $(CFLAGS) -c Serializer.cc

SerializationFormat.o: SerializationFormat.cc SerializationFormat.h
	$(CPLUS) $(CFLAGS) -c SerializationFormat.cc

smtp-rw.bif.func_h smtp-rw.bif.func_def smtp-rw.bif.func_init: smtp-rw.bif bifcl
	$(BIFCL) smtp-rw.bif
	@mv smtp-rw.bif.bro policy/

SMTP.o: SMTP.cc SMTP.h SMTP_cmd.def MIME.h smtp-rw.bif.func_def
	$(CPLUS) $(CFLAGS) -c SMTP.cc

SSH.o: SSH.cc SSH.h
	$(CPLUS) $(CFLAGS) -c SSH.cc

SteppingStone.o: SteppingStone.cc SteppingStone.h
	$(CPLUS) $(CFLAGS) -c SteppingStone.cc

Stmt.o: Stmt.cc Stmt.h StmtEnums.h
	$(CPLUS) $(CFLAGS) -c Stmt.cc

TCP.o: TCP.cc TCP.h Reassem.h
	$(CPLUS) $(CFLAGS) -c TCP.cc

common-rw.bif.func_h common-rw.bif.func_def common-rw.bif.func_init: common-rw.bif bifcl
	$(BIFCL) common-rw.bif
	@mv common-rw.bif.bro policy/

TCP_Rewriter.o: TCP_Rewriter.cc TCP_Rewriter.h common-rw.bif.func_def
	$(CPLUS) $(CFLAGS) -c TCP_Rewriter.cc

Telnet.o: Telnet.cc Telnet.h
	$(CPLUS) $(CFLAGS) -c Telnet.cc

Timer.o: Timer.cc Timer.h
	$(CPLUS) $(CFLAGS) -c Timer.cc

Type.o: Type.cc Type.h
	$(CPLUS) $(CFLAGS) -c Type.cc

UDP.o: UDP.cc UDP.h
	$(CPLUS) $(CFLAGS) -c UDP.cc

Val.o: Val.cc Val.h
	$(CPLUS) $(CFLAGS) -c Val.cc

Var.o: Var.cc Var.h
	$(CPLUS) $(CFLAGS) -c Var.cc

XDR.o: XDR.cc XDR.h
	$(CPLUS) $(CFLAGS) -c XDR.cc

main.o: main.cc
	$(CPLUS) $(CFLAGS) -c main.cc

net_util.o: net_util.cc net_util.h
	$(CPLUS) $(CFLAGS) -c net_util.cc

parse.o: parse.cc broparse.h
	$(CPLUS) $(CFLAGS) -c parse.cc
broparse.h parse.cc: parse.y
	$(YACC) $(YFLAGS) parse.y
	@sed '/extern char.*getenv/d;s/yylex/brolex/' <y.tab.c >parse.cc
	@mv y.tab.h broparse.h
	@rm y.tab.c
parse.y: parse.in make_parser.pl
	@rm -f parse.y
	perl -w make_parser.pl "$(YACC)"

scan.o: scan.cc broparse.h
	$(CPLUS) $(CFLAGS) -c scan.cc
scan.cc: scan.l
	$(LEX) $(LFLAGS) -Pbro -oscan.cc scan.l

re-parse.o: re-parse.cc re-parse.h
	$(CPLUS) $(CFLAGS) -c re-parse.cc
re-parse.h re-parse.cc: re-parse.y
	$(YACC) $(YFLAGS) re-parse.y
	@sed '/extern char.*getenv/d;s/yylex/re_lex/;s/yy/RE_/g' <y.tab.c >re-parse.cc
	@mv y.tab.h re-parse.h
	@rm y.tab.c

re-scan.o: re-scan.cc
	$(CPLUS) $(CFLAGS) -c re-scan.cc
re-scan.cc: re-scan.l
	$(LEX) $(LFLAGS) -Pre_ -ore-scan.cc re-scan.l

rule-parse.o: rule-parse.cc rule-parse.h
	$(CPLUS) $(CFLAGS) -c rule-parse.cc

rule-parse.h rule-parse.cc: rule-parse.y
	$(YACC) $(YFLAGS) rule-parse.y
	@sed '/extern char.*getenv/d;s/yylex/rules_lex/;s/yy/rules_/g' <y.tab.c >rule-parse.cc
	@sed '/extern char.*getenv/d;s/yylex/rules_lex/;s/yy/rules_/g' <y.tab.h >rule-parse.h
	@rm y.tab.c y.tab.h

rule-scan.o: rule-scan.cc
	$(CPLUS) $(CFLAGS) -c rule-scan.cc
rule-scan.cc: rule-scan.l
	$(LEX) $(LFLAGS) -Prules_ -orule-scan.cc rule-scan.l

util.o: util.cc util.h
	$(CPLUS) $(CFLAGS) -DLIBDEST=\"$(LIBDEST)\" -c util.cc

cq.o: cq.c cq.h
	$(CC) $(CFLAGS) -c cq.c

md5.o: md5.c md5.h
	$(CC) $(CFLAGS) -c md5.c

nb_dns.o: nb_dns.c nb_dns.h
	$(CC) $(CFLAGS) -c nb_dns.c

setsignal.o: setsignal.c setsignal.h
	$(CC) $(CFLAGS) -c setsignal.c

# $(BIF_FUNC_INIT) $(BIF_FUNC): bifcl

# $(BIF_FUNC_INIT): %.bif.func_init: %.bif
#	$(BIFCL) $<

# $(BIF_FUNC_DEF): %.bif.func_def: %.bif
#	$(BIFCL) $<

bifcl: bif_lex.o bif_parse.o bif_arg.o
	$(BIF_CPLUS) $(CFLAGS) -o $@ bif_lex.o bif_parse.o bif_arg.o

bif_lex.o: bif_lex.cc bif_parse.h
	$(BIF_CPLUS) -o $@ -c $<

bif_lex.cc: builtin-func.l bif_parse.h
	$(LEX) -o$@ builtin-func.l

bif_parse.o: bif_parse.cc bif_parse.h
	$(BIF_CPLUS) -o $@ -c $<

bif_parse.h bif_parse.cc: builtin-func.y bif_arg.h bif_type.def
	$(YACC) $(YFLAGS) builtin-func.y
	@mv y.tab.h bif_parse.h
	@mv y.tab.c bif_parse.cc

bif_arg.o: bif_arg.cc bif_arg.h bif_type.def
	$(BIF_CPLUS) -o $@ -c $<

$(LIBEDIT_LIB): libedit.src.tar.gz
	@echo "Unpacking libedit sources"
	@gzip -d <libedit.src.tar.gz | tar xf -
	@echo "Building libedit.a"
	@cd libedit; ./configure; make
	@chmod -R 755 libedit

purify: $(OBJ)
	purify $(PURE_FLAGS) $(PURIFY_CPLUS) $(OBJ) $(LIBS)

CHANGES: VERSION
	@echo "You need to update CHANGES"

# pub-tar - source distribution with public version of policy files
pub-tar: tar CHANGES
tar:
	@echo Building public tar ...
	@rm -f FILES.temp NAME.temp
	@cat FILES FILES.pub > FILES.temp
	@echo "pub" > NAME.temp
	@$(MAKE) build-tar
	@rm -f FILES.temp NAME.temp

# pre-pub-tar - preliminary version of public distribution, for building diffs
pre-pub-tar: tar
	@cd CURRENT; \
		tar xfz ../`cat ../latest-dist`.tar.gz ; \
		diff -wcr --ignore-matching-lines="Id:" `cat current-dist` `cat ../latest-dist` | unify >latest-diffs ; \
		cp ../latest-dist current-dist

# priv-tar - source distribution with private version of policy files
priv-tar:
	@echo Building private tar ...
	@rm -f FILES.temp NAME.temp
	@cat FILES FILES.pub > FILES.temp
	@if [ "$(PRIV)" = "priv" ] ; then ./FILES.$(PRIV).sh >>FILES.temp ; \
	    else cat FILES.$(PRIV) >> FILES.temp ; fi
	@echo "priv" > NAME.temp
	@$(MAKE) build-tar
	@rm -f FILES.temp NAME.temp

# bin-tar - binary distribution with private version of policy files
bin-tar: $(PKG)
	@echo Building binary tar ...
	@rm -f FILES.temp NAME.temp
	@cat FILES.bin FILES.pub > FILES.temp
	@if [ "$(PRIV)" = "priv" ] ; then ./FILES.$(PRIV).sh >>FILES.temp ; \
	    else cat FILES.$(PRIV) >> FILES.temp ; fi
	@echo "bin.$(PRIV)" > NAME.temp
	@$(MAKE) build-tar
	@rm -f FILES.temp NAME.temp

build-tar: FILES.temp NAME.temp
	@cwd=`pwd` ; name=$(PKG)-`cat NAME.temp`-`cat VERSION` ; \
	    if [ "$(COMPRESS)" = "gzip" ] ; then ext=gz ; else ext=Z; fi ; \
	    list="" ; tar="tar chf" ; temp="$$name.tar.$$ext" ; \
	    for i in `cat FILES.temp` ; do list="$$list $$name/$$i" ; done; \
	    echo \
	    "rm -f $$name; ln -s . $$name" ; \
	     rm -f $$name; ln -s . $$name ; \
	    echo \
	    "$$tar - [lots of files] | $(COMPRESS) > $$temp" ; \
	     $$tar - $$list | $(COMPRESS) > $$temp ; \
	    echo \
	    "echo $$name >latest-dist" ; \
	     echo $$name >latest-dist ; \
	    echo \
	    "rm -f $$name" ; \
	     rm -f $$name ;

install:
	$(INSTALL) $(EXEC) $(SBINDEST)
	$(INSTALL_DATA) $(POLICY) $(LIBDEST)

clean:
	rm -f $(CLEANFILES)

distclean:
	rm -f $(CLEANFILES) Makefile \
	    config.cache config.log config.status config.h
	rm -rf libedit
