#  Copyright (c) 1990, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2009, 2010, 2011, 2012, 2013, 2016, 2017, 2019, 2020
#  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 the following conditions are met:
#      * Redistributions of source code must retain the above copyright
#        notice, this list of conditions and the following disclaimer.
#      * Redistributions in binary form must reproduce the above copyright
#        notice, this list of conditions and the following disclaimer in the
#        documentation and/or other materials provided with the distribution.
#      * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#  ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#  SUCH DAMAGE.
#
# @(#) $Id: Makefile.in 1539 2023-12-03 00:48:53Z 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
BINDEST = @sbindir@
# Pathname of directory to install the man page
MANDEST = @mandir@
# The root of the directory tree for read-only
datarootdir = @datarootdir@
# Pathname of directory to install database file
ARPDIR ?= @prefix@/arpwatch

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

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

PROG = arpwatch
ALL = $(PROG) arpsnmp
CC = @CC@
CCOPT = @V_CCOPT@
INCLS = -I. @V_INCLS@
DEFS = @DEFS@ -DARPDIR=\"$(ARPDIR)\" -DPATH_SENDMAIL=\"$(SENDMAIL)\"

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

# Standard LDFLAGS
LDFLAGS = @LDFLAGS@

# Standard LIBS
LIBS = @LIBS@
# Standard LIBS without libpcap.a
SLIBS = @LBL_LIBS@

INSTALL = @INSTALL@
CPPCHECK = cppcheck -q --enable=all --inline-suppr --suppress=variableScope -Dlint -D__FreeBSD__ -I/usr/include
PYLINT= pylint -sn -d C0103,C0302,C0330,R0902,R0903,R0911,R0912,R0913,R0914,R0915,W0141,W0312,W0511,W0603 "--dummy-variables-rgx=(_[a-z_][a-z0-9_]*)"
SENDMAIL = @V_SENDMAIL@

# 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

CSRC =	db.c dns.c ec.c file.c intoa.c machdep.c util.c report.c setsignal.c
WSRC =	arpwatch.c
SSRC =	arpsnmp.c
GENSRC = version.c

SRC =	$(WSRC) $(SSRC) $(CSRC) $(GENSRC)

# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
# hack the extra indirection
OBJ =	$(WSRC:.c=.o) $(SSRC:.c=.o) $(CSRC:.c=.o) $(GENSRC:.c=.o) @LIBOBJS@
WOBJ =	$(WSRC:.c=.o) $(CSRC:.c=.o) $(GENSRC:.c=.o) @LIBOBJS@
SOBJ =	$(SSRC:.c=.o) $(CSRC:.c=.o) $(GENSRC:.c=.o) @LIBOBJS@
HDR =	arpwatch.h db.h dns.h ec.h file.h machdep.h report.h setsignal.h

TAGHDR = \
	/usr/include/net/if.h \
	/usr/include/netinet/if_ether.h \
	/usr/include/netinet/in.h \
	/usr/include/sys/socket.h

TAGFILES = $(SRC) $(HDR) $(TAGHDR)

CLEANFILES = $(ALL) $(OBJ) $(GENSRC) purify $(OBJ:.o=_pure_*.o) \
	massagevendor.py update-ethercodes.sh

all: $(ALL)

$(PROG): $(WOBJ) @V_PCAPDEP@
	@rm -f $@
	$(CC) $(LDFLAGS) -o $@ $(WOBJ) $(LIBS)

arpsnmp: $(SOBJ)
	@rm -f $@
	$(CC) $(LDFLAGS) -o $@ $(SOBJ) $(SLIBS)

purify: $(SOBJ)
	@rm -f $@
	purify $(CC) -static $(LDFLAGS) -o $@ $(SOBJ) $(SLIBS)

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

install: $(ALL)
	$(INSTALL) -v -m 555 $(PROG) $(DESTDIR)$(BINDEST)
	$(INSTALL) -v -m 555 arpsnmp $(DESTDIR)$(BINDEST)
	@diff $(srcdir)/$(PROG).8 $(DESTDIR)$(MANDEST)/man8 >/dev/null 2>&1 || \
	    $(INSTALL) -v -m 444 $(srcdir)/$(PROG).8 $(DESTDIR)$(MANDEST)/man8
	@diff $(srcdir)/arpsnmp.8 $(DESTDIR)$(MANDEST)/man8 >/dev/null 2>&1 || \
	    $(INSTALL) -v -m 444 $(srcdir)/arpsnmp.8 $(DESTDIR)$(MANDEST)/man8
@HAVE_FREEBSD_TRUE@	@$(INSTALL) -v -m 555 arpwatch.sh $(DESTDIR)$(prefix)/etc/rc.d/arpwatch

clean:
	rm -f $(CLEANFILES)

distclean:
	rm -rf $(CLEANFILES) Makefile config.cache config.log config.status \
	    gnuc.h os-proto.h arpwatch.sh arpwatch.8 arpsnmp.8 autom4te.cache

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

ethers.new: arp.dat
	./arp2ethers > ethers.new

man man1:
	./config.status && man ./arpwatch.8

man2:
	./config.status && man ./arpsnmp.8

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; ln -s . $$name" ; \
	     rm -f $$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}

lint:
	@$(CPPCHECK) $(DEFS) $(INCLS) $(WSRC) $(SSRC) $(CSRC)

pylint: pylint1

pylint1: massagevendor.py
	@$(PYLINT) massagevendor.py || true

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