# Project    : ipv6calc
# File       : Makefile[.in]
# Version    : $Id: cb8f99510c18573121b4784ad54f34e0ec93d788 $
# Copyright  : 2001-2019 by Peter Bieringer <pb (at) bieringer.de>
#
# Information:
#  Main Makefile for ipv6calc project
#

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

ifeq (@ENABLE_BUNDLED_GETOPT@, 1)
  GETOPT_MAKE = getopt-make
  GETOPT_DIR  = getopt
endif

ifeq (@ENABLE_BUNDLED_MD5@, 1)
  MD5_MAKE = md5-make
  MD5_DIR  = md5
endif

ifeq (@ENABLE_MOD_IPV6CALC@, 1)
  MOD_IPV6CALC_MAKE = mod_ipv6calc-make
  MOD_IPV6CALC_DIR  = mod_ipv6calc
endif


CC	= @CC@

all:		$(MD5_MAKE) $(GETOPT_MAKE) ipv6calc ipv6logconv ipv6logstats ipv6loganon $(MOD_IPV6CALC_MAKE)

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


ipv6logconv:	$(GETOPT_MAKE) lib-make ipv6logconv-make

ipv6loganon:	$(GETOPT_MAKE) lib-make ipv6loganon-make ipv6logstats-make

ipv6logstats:	$(GETOPT_MAKE) lib-make ipv6logstats-make

ipv6calc:	$(GETOPT_MAKE) lib-make ipv6calc-make ipv6calcweb-make

updateclean:
		${MAKE} distclean
		for dir in databases/ieee-oui databases/ieee-iab databases/ipv4-assignment databases/ipv6-assignment; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			rm -rf autom4te.cache; \
			rm -rf autogen-all-variants.status; \
			cd $$ocwd; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1

distclean:
		${MAKE} clean
		rm -f config.cache config.status config.log
		rm -rf autom4te.cache
		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc mod_ipv6calc man lib md5 getopt databases/lib databases/ieee-oui36 databases/lib databases/ieee-oui28 databases/lib databases/ieee-oui databases/ieee-iab databases/ipv4-assignment databases/ipv6-assignment databases/registries databases/as-assignment databases/cc-assignment tools; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			rm -rf autom4te.cache; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1

autoclean:
		${MAKE} distclean
		rm -f Makefile
		rm -f contrib/ipv6calc.spec
		rm -f config.h
		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc mod_ipv6calc man lib databases/lib md5 getopt tools; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1

clean:
		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc mod_ipv6calc man lib databases/lib md5 getopt tools; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1

install:
		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc $(MOD_IPV6CALC_DIR) man lib databases/lib tools; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} install; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1

getopt-make:
		cd getopt && ${MAKE}

md5-make:
		cd md5 && ${MAKE}

lib-make:	$(MD5_MAKE) $(GETOPT_MAKE) db-ieee-oui-make db-ieee-iab-make db-ipv4-assignment-make db-ipv6-assignment-make db-wrapper-make db-lib-make
		cd lib && ${MAKE} GETOPT_INCLUDE=@GETOPT_INCLUDE@

ipv6logconv-make: lib-make
		cd ipv6logconv && ${MAKE}

ipv6loganon-make: lib-make
		cd ipv6loganon && ${MAKE}

ipv6logstats-make: lib-make
		cd ipv6logstats && ${MAKE}

ipv6calc-make:	lib-make
		cd ipv6calc && ${MAKE}

ipv6calcweb-make: ipv6calc-make
		cd ipv6calcweb && ${MAKE}

mod_ipv6calc-make: lib-make
		cd mod_ipv6calc && ${MAKE}

db-wrapper-make:
		cd databases/lib && ${MAKE}

db-ieee-oui-make:
		cd databases/ieee-oui && ${MAKE}

db-ieee-oui36-make:
		cd databases/ieee-oui36 && ${MAKE}

db-ieee-iab-make:
		cd databases/ieee-iab && ${MAKE}

db-ipv4-assignment-make:
		cd databases/ipv4-assignment && ${MAKE}

db-ipv6-assignment-make:
		cd databases/ipv6-assignment && ${MAKE}

db-cc-assignment-make:
		cd databases/cc-assignment && ${MAKE}

db-as-assignment-make:
		cd databases/as-assignment && ${MAKE}

db-lib-make:	db-ieee-oui-make db-ieee-iab-make db-ipv4-assignment-make db-ipv6-assignment-make db-wrapper-make db-lib-make db-cc-assignment-make db-as-assignment-make
		cd databases/lib && ${MAKE}

update:		update-ieee
		for dir in databases/registries; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ || exit 1; \
			cd $$ocwd ; \
		done || exit 1

update-ieee:
		for dir in databases/ieee-oui databases/ieee-oui28 databases/ieee-oui36 databases/ieee-iab; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} update || exit 1; \
			cd $$ocwd ; \
		done || exit 1

static:		ipv6logconv-make ipv6loganon-make ipv6logstats-make ipv6calc-make	
		for dir in ipv6logconv ipv6logstats ipv6loganon ipv6calc; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1

test:
		for dir in ipv6calc ipv6logconv ipv6logstats ipv6loganon ipv6calcweb $(MOD_IPV6CALC_DIR); do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1
		echo "ALL TESTS SUCCESSFUL"

test-minimal:
		for dir in ipv6calc ipv6logconv ipv6logstats ipv6loganon ipv6calcweb; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done

test-ldlibpath:
		for dir in ipv6calc ipv6logconv ipv6logstats ipv6loganon ipv6calcweb; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done

codecheck:
		# catch use of strncpy
		LC_ALL=C find . -type f -name '*.c' | xargs -r grep strncpy || exit 0
		# catch use of strcpy
		LC_ALL=C find . -type f -name '*.c' | xargs -r grep strcpy || exit 0

		for dir in ipv6calc ipv6logconv ipv6logstats ipv6loganon; do \
			ocwd=`pwd`; \
			cd $$dir || exit 1; \
			${MAKE} $@ ; r=$$?; \
			cd $$ocwd ; if [ $$r -ne 0 ]; then echo "Result: $$r"; exit $$r; fi; \
		done || exit 1
