# Project    : ipv6calc
# File       : lib/Makefile
# Version    : $Id: 6b0031c76e681a0f7ea3eb90373698ba962f8cee $
# Copyright  : 2002-2020 by Peter Bieringer <pb (at) bieringer.de>
#
# Information:
#  Makefile for ipv6calc libraries
#

libdir	= @libdir@

# Compiler and Linker Options
#  -D__EXTENSIONS__ is for Solaris & strtok_r
DEFAULT_CFLAGS ?= -O2 -Wall
CFLAGS += -D__EXTENSIONS__ -fPIC

LDFLAGS += @LDFLAGS@

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

ifeq ($(shell uname), Darwin)
	SO_NAME_FLAGS=-install_name
else
	SO_NAME_FLAGS=-soname
endif

SHARED_LIBRARY=@SHARED_LIBRARY@

CC	= @CC@
AR	= ar
RANLIB	= @RANLIB@

OBJS	=	libipv6calc.o  \
		libipv6addr.o  \
		libipv4addr.o  \
		libipaddr.o    \
		libieee.o      \
		libeui64.o     \
		libmac.o       \
		librfc1884.o   \
		librfc1886.o   \
		librfc1924.o   \
		librfc2874.o   \
		librfc3041.o   \
		librfc3056.o   \
		librfc5569.o   \
		librfc6052.o   \
		libifinet6.o   \
		ipv6calchelp.o \
		ipv6calcoptions.o \
		ipv6calctypes.o

all:		
		${MAKE} libipv6calc.a
		${MAKE} libipv6calc.so.@PACKAGE_VERSION@

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

$(OBJS):	libipv6calcdebug.h  \
		libipv6calc.h       \
		libipv6calc_filter.h \
		libipv6addr.h       \
		libipv4addr.h       \
		libipaddr.h         \
		libieee.h           \
		libeui64.h          \
		libmac.h            \
		librfc1884.h        \
		librfc1886.h        \
		librfc1924.h        \
		librfc2874.h        \
		librfc3041.h        \
		librfc3056.h        \
		librfc5569.h        \
		librfc6052.h        \
		libifinet6.h        \
		ipv6calchelp.h      \
		ipv6calctypes.h     \
		ipv6calcoptions.h   \
		ipv6calcoptions_common.h \
		ipv6calccommands.h  \
		ipv6calc_inttypes.h \

libipv6calc.a:	$(OBJS)
		cd ../ && ${MAKE} db-ieee-oui-make
		cd ../ && ${MAKE} db-ipv4-assignment-make
		cd ../ && ${MAKE} db-ipv6-assignment-make
		echo "Create library (.a)"
		$(AR) r libipv6calc.a $(OBJS)
		$(RANLIB) libipv6calc.a

libipv6calc.so.@PACKAGE_VERSION@: $(OBJS)
ifeq ($(SHARED_LIBRARY), yes)
		cd ../ && ${MAKE} db-ieee-oui-make
		cd ../ && ${MAKE} db-ipv4-assignment-make
		cd ../ && ${MAKE} db-ipv6-assignment-make
		echo "Creates shared library (libipv6calc.so)"
		$(CC) -o libipv6calc.so.@PACKAGE_VERSION@ $(OBJS) $(LDFLAGS) -shared -Wl,$(SO_NAME_FLAGS),libipv6calc.so.@PACKAGE_VERSION@
else
		echo "Nothing to do (shared library mode is not enabled)"
endif

distclean:
		${MAKE} clean

autoclean:
		${MAKE} distclean

clean:
		rm -f *.o *.a *.so *.so.*

install:	all
ifeq ($(SHARED_LIBRARY), yes)
		echo "Install shared library"
		mkdir -p $(DESTDIR)$(libdir)
		install -m 755 libipv6calc.so.@PACKAGE_VERSION@ $(DESTDIR)$(libdir)
		/sbin/ldconfig -n $(DESTDIR)$(libdir)
else
		echo "Nothing to do (shared library mode is not enabled)"
endif

test:
