# Project    : ipv6calc
# File       : databases/lib/Makefile
# Version    : $Id: 17833f74feab546ea2cb3d1d1f87b0626f8100b3 $
# Copyright  : 2013-2020 by Peter Bieringer <pb (at) bieringer.de>
#
# Information:
#  Makefile for ipv6calc database libraries
#

libdir	= @libdir@

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

LDFLAGS += @LDFLAGS@

INCLUDES= -I../../lib -I../.. @MMDB_INCLUDE_L2@ @IP2LOCATION_INCLUDE_L2@

SHARED_LIBRARY=@SHARED_LIBRARY@

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

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

OBJS	=	libipv6calc_db_wrapper.o \
		libipv6calc_db_wrapper_MMDB.o \
		libipv6calc_db_wrapper_GeoIP2.o \
		libipv6calc_db_wrapper_IP2Location.o \
		libipv6calc_db_wrapper_DBIP2.o \
		libipv6calc_db_wrapper_External.o \
		libipv6calc_db_wrapper_BuiltIn.o

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

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

$(OBJS):	libipv6calc_db_wrapper.h \
		libipv6calc_db_wrapper_MMDB.h \
		libipv6calc_db_wrapper_GeoIP2.h \
		libipv6calc_db_wrapper_IP2Location.h \
		libipv6calc_db_wrapper_DBIP2.h \
		libipv6calc_db_wrapper_External.h \
		libipv6calc_db_wrapper_BuiltIn.h \
		../../lib/libipv6calcdebug.h \
		../ieee-oui/dbieee_oui.h \
		../ieee-oui36/dbieee_oui36.h \
		../ieee-iab/dbieee_iab.h \
		../ipv4-assignment/dbipv4addr_assignment.h \
		../ipv6-assignment/dbipv6addr_assignment.h \
		../as-assignment/dbasn_assignment.h \
		../cc-assignment/db_cc_reg_assignment.h \
		../../config.h

libipv6calc_db_wrapper.a:	$(OBJS)
		echo "Create library"
		$(AR) r libipv6calc_db_wrapper.a $(OBJS)
		$(RANLIB) libipv6calc_db_wrapper.a

libipv6calc_db_wrapper.so.@PACKAGE_VERSION@:	$(OBJS)
ifeq ($(SHARED_LIBRARY), yes)
		echo "Create shared library (libipv6calc_db_wrapper.so)"
		$(CC) -o libipv6calc_db_wrapper.so.@PACKAGE_VERSION@ $(OBJS) $(LDFLAGS) -shared -Wl,$(SO_NAME_FLAGS),libipv6calc_db_wrapper.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_db_wrapper.so.@PACKAGE_VERSION@ $(DESTDIR)$(libdir)
		/sbin/ldconfig -n $(DESTDIR)$(libdir)
else
		echo "Nothing to do (shared library mode is not enabled)"
endif

test:
