#  Gargoyle Client Software. Tools to read, analyze and manage Argus data.
#  Copyright (c) 2018-2024 QoSient, LLC
#  All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3, or (at your option)
#  any later version.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# 

prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
perlextlib = @PERL_EXT_LIB@
PERL = @V_PERL@
PERL_CFLAGS = $(shell $(PERL) -MConfig -e \
	'print join(" ", @Config{qw(ccflags optimize cccdlflags)}, \
	"-I$$Config{archlib}/CORE")' )
perlvendorarch = $(shell $(PERL) -MConfig -e \ 'print $$Config{sitelib}' )
perlvendorarch_qosient = $(perlvendorarch)/qosient/XS
perlvendorarch_auto = $(perlvendorarch)/auto/qosient/XS/util

# Pathname of directory to install the system binaries
SBINDIR = @sbindir@
# # Pathname of directory to install the system binaries
BINDIR = @bindir@
# Pathname of directory to install the include files
INCLDEST = @includedir@
# Pathname of directory to install the library
LIBDEST =  @libdir@
# Pathname of directory to install the man page
MANDEST = @mandir@
srcdir = @srcdir@
VPATH = @srcdir@


CC = @CC@
CCOPT = @V_CCOPT@
INCLS = -I. -I../include -I../common @V_INCLS_EXAMPLES@ @MYSQL_INCLS@
DEFS = @DEFS@

CLIENTLIB = ../lib/argus_common.a ../lib/argus_client.a
COMPATLIB = @V_PCRE@ @COMPATLIB@ @LIB_SASL@ @LIB_XDR@ @LIBS@ @V_THREADS@ @V_GEOIPDEP@ @V_FTDEP@ @ZLIB@ @DNSLIB@ @LIBMAXMINDDB_LIBS@

MYSQLLIB = @MYSQL_LDFLAGS@ 

# Standard CFLAGS
 CFLAGS = -fPIC $(CCOPT) $(INCLS) $(DEFS) $(EXTRA_CFLAGS)
INSTALL = @INSTALL@

ifeq ($(shell uname),Darwin)
 SOEXT = .dylib
else
 SOEXT = .so
endif

SRC = ../common/argus_parse_time.c swig_ArgusParseTime.c swig_ArgusParseTime_wrap.c

.PHONY: install install-perl uninstall uninstall-perl TOP all depend

all: TOP

install: TOP install-perl

TOP: util$(SOEXT) qosient/XS/util.pm

install-perl: util$(SOEXT) qosient/XS/util.pm
	@set -e ; \
	mkdir -p $(DESTDIR)$(perlvendorarch_qosient) ; \
	$(INSTALL) -m 0644 qosient/XS/util.pm \
	  $(DESTDIR)$(perlvendorarch_qosient)/util.pm ; \
	mkdir -p $(DESTDIR)$(perlvendorarch_auto) ; \
	$(INSTALL) -m 0755 util$(SOEXT) $(DESTDIR)$(perlvendorarch_auto)/util$(SOEXT)

uninstall: uninstall-perl

uninstall-perl:
	rm -f $(DESTDIR)$(perlvendorarch_qosient)/util.pm ; \
	rm -f $(DESTDIR)$(perlvendorarch)/auto/qosient/XS/util.pm
	rm -f $(DESTDIR)$(perlvendorarch_auto)/util$(SOEXT)

util$(SOEXT): swig_ArgusParseTime.o swig_ArgusParseTime_wrap.o argus_parse_time.o
	$(CC) $(CFLAGS) `$(PERL) -MConfig -e 'print $$Config{lddlflags}'` $^ $(CLIENTLIB) $(COMPATLIB) -o $@
argus_parse_time.o: ../common/argus_parse_time.c
	$(CC) $(CFLAGS) -I../include -I../common $(PERL_CFLAGS) -c $(filter %.c, $^)
swig_ArgusParseTime.o: swig_ArgusParseTime.c
	$(CC) $(CFLAGS) -I../include $(PERL_CFLAGS) -c $(filter %.c, $^)
swig_ArgusParseTime_wrap.o: swig_ArgusParseTime_wrap.c
	$(CC) $(CFLAGS) -Wno-unused-variable -Wno-missing-prototypes -Wno-misleading-indentation \
	  -Wno-compound-token-split-by-macro -I../include $(PERL_CFLAGS) -c $(filter %.c, $^)

# multiple targets (left side of the colon) seems to confuse parallel make.
# create intermediate file swig.stamp instead.
swig_ArgusParseTime_wrap.c: swig.stamp
qosient/XS/util.pm: swig.stamp
swig.stamp: swig_ArgusParseTime.i
	mkdir -p qosient/XS
	swig -perl5 $^
	mv util.pm qosient/XS
	touch swig.stamp

.PHONY: clean distclean

distclean: clean
	rm -f Makefile
clean:
	rm -f *.o swig_ArgusParseTime_wrap.c qosient/XS/util.pm util$(SOEXT) swig.stamp

depend: $(SRC)
	../bin/mkdep -c $(CC) $(CFLAGS) $(PERL_CFLAGS) $(SRC)

