# Project    : ipv6calc
# File       : ipv6calc/Makefile[.in]
# Version    : $Id: ee2101a0fc98d2ca3af5146c8ce1540d8167ebf6 $
# Copyright  : 2002-2022 by Peter Bieringer <pb (at) bieringer.de>
#
# Information:
#  Makefile for ipv6calc
#

prefix		= @prefix@
exec_prefix	= @exec_prefix@
bindir		= @bindir@

# Compiler and Linker Options
DEFAULT_CFLAGS ?= -O2 -Wall -g @CFLAGS_EXTRA@

LDFLAGS += @LDFLAGS@

INCLUDES= @MD5_INCLUDE@ @GETOPT_INCLUDE@ @MMDB_INCLUDE_L1@ @IP2LOCATION_INCLUDE_L1@ -I../ -I../lib/ -I../databases/lib/

LIBS = @IPV6CALC_LIB@ @MMDB_LIB_L1@ @IP2LOCATION_LIB_L1@ @DYNLOAD_LIB@

GETOBJS = @LIBOBJS@

CC	= @CC@

LDFLAGS_EXTRA = @LDFLAGS_EXTRA@
LDFLAGS_EXTRA_STATIC = @LDFLAGS_EXTRA_STATIC@

OBJS	= ipv6calc.o showinfo.o ipv6calchelp_local.o

# splint
SPLINT_OPT_OUTSIDE = +posixlib -nullassign -uniondef -compdef -usedef -formatconst -exportlocal -preproc
#SPLINT_OPT_OUTSIDE = -uniondef +matchanyintegral --nullassign +ignoresigns -compdef -usedef -modobserver -formatconst -warnposix -exportlocal
SPLINT_TODO_LATER = -unrecog  -retvalint


all:		ipv6calc

.c.o:
		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)

$(OBJS):	ipv6calc.h ipv6calchelp_local.h showinfo.h ipv6calcoptions_local.h ../config.h ../lib/ipv6calctypes.h

libipv6calc:
		cd ../ && ${MAKE} lib-make

libipv6calc_db_wrapper:
		cd ../ && ${MAKE} lib-make

ipv6calc:	$(OBJS) libipv6calc libipv6calc_db_wrapper
		$(CC) -o ipv6calc $(OBJS) $(GETOBJS) $(LDFLAGS) $(LIBS) $(LDFLAGS_EXTRA) -lm

static:		ipv6calc
		$(CC) -o ipv6calc-static $(OBJS) $(GETOBJS) $(LDFLAGS) $(LIBS) $(LDFLAGS_EXTRA_STATIC) -lm -static

distclean:
		${MAKE} clean

autoclean:
		${MAKE} distclean

clean:
		rm -f ipv6calc ipv6calc-static *.o

test:		ipv6calc
		LD_LIBRARY_PATH=@LD_LIBRARY_PATH@ ./test_ipv6calc.sh || exit 1
		LD_LIBRARY_PATH=@LD_LIBRARY_PATH@ ./test_ipv6calc_filter.sh || exit 1
		LD_LIBRARY_PATH=@LD_LIBRARY_PATH@ ./test_ipv6calc_anonymization.sh || exit 1
		LD_LIBRARY_PATH=@LD_LIBRARY_PATH@ ./test_showinfo.sh || exit 1

test-minimal:	ipv6calc
		LD_LIBRARY_PATH=@LD_LIBRARY_PATH@ ./test_ipv6calc.sh || exit 1
		LD_LIBRARY_PATH=@LD_LIBRARY_PATH@ ./test_showinfo.sh minimal || exit 1

test-ldlibpath:	ipv6calc
		LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):@LD_LIBRARY_PATH_BASIC@ ./test_ipv6calc.sh || exit 1
		LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):@LD_LIBRARY_PATH_BASIC@ ./test_ipv6calc_filter.sh || exit 1
		LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):@LD_LIBRARY_PATH_BASIC@ ./test_ipv6calc_anonymization.sh || exit 1
		LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):@LD_LIBRARY_PATH_BASIC@ ./test_showinfo.sh || exit 1

codecheck:
		${MAKE} splint

splint:		
		splint *.c ../lib/*.c -I.. -I../lib $(SPLINT_OPT_OUTSIDE) $(SPLINT_TODO_LATER)

install:
		if [ ! -d $(DESTDIR)$(bindir) ]; then install -d -m 755 $(DESTDIR)$(bindir); fi
		install -m 755 ipv6calc $(DESTDIR)$(bindir)
