[ipv6calc] 0.61.0 configure.in tweaks

Niko Tyni ntyni at iki.fi
Wed Oct 18 21:09:49 CEST 2006


Hi Peter and other ipv6calc list members,

here's a patch for 0.61.0 that adds the following 'configure' features:

  --enable-system-geoip   Use the system GeoIP library instead of the bundled
                          one (default: bundled)
  --enable-default-geoip-file=file
                          Use a default GeoIP database file when ipv6calc is
                          invoked with '-G'

Additionally, it tries to detect the presence of the getopt library
and uses the system one if possible. There are also tiny fixes for
'ipv6calc --help'.

These are tweaks that would make the Debian packaging simpler.
I'm currently patching the various Makefile.in files to get the system
getopt and GeoIP in, and it would be nice if that could be configurable.
I hope they would benefit other distributions as well.

I added the new '-G' option for enabling GeoIP with a default database,
so the users don't have to type the path every time when they want to
use the only database provided by the system.

Please consider applying this (and running autogen afterwards, of
course). I can split it off into separate patches if you like, but the
system-geoip and the default-geoip-file stuff overlap somewhat.

I haven't been able to test the getopt stuff with a real system
that doesn't have getopt in its libc, but I think it should work.


Ultimately, I would like to have something like

--with-geoip=/path/to/geoip-build-dir
--with-ip2location=/path/to/ip2location-build-dir

so there wouldn't be any need to bundle them inside the ipv6calc tarball,
as users could "easily" include them into the build. Do you think this 
would be a good idea? I could prepare the patch if you like it...


BTW, the bundled GeoIP code doesn't currently build due to files
missing from <...>/GeoIP-1.3.17/apps :

make[3]: *** No rule to make target `geoiplookup.o', needed by `geoiplookup'.  Stop.

Cheers,
-- 
Niko Tyni		ntyni at iki.fi
-------------- next part --------------
--- ipv6calc-0.61.0.orig/lib/Makefile
+++ ipv6calc-0.61.0/lib/Makefile
@@ -11,7 +11,7 @@
 #  -D__EXTENSIONS__ is for Solaris & strtok_r
 COPTS = -O2 -Wall -D__EXTENSIONS__
 
-CFLAGS	= $(COPTS) -I../ -I../getopt/ -I../md5/
+CFLAGS	= $(COPTS) -I../ $(GETOPT_INCLUDE) -I../md5/
 
 CC	= gcc
 AR	= ar
--- ipv6calc-0.61.0.orig/lib/ipv6calcoptions.h
+++ ipv6calc-0.61.0/lib/ipv6calcoptions.h
@@ -35,8 +35,9 @@
  *  q = be more quiet
  *  p <path to IP2Location file> = path to IP2Location database file
  *  g <path to GeoIP file> = path to GeoIP database file
+ *  G = enable GeoIP with a default database file
  */
-/*@unused@*/ static char *ipv6calc_shortopts = "vh?p:g:rmabd:iulqUFCI:O:A:";
+/*@unused@*/ static char *ipv6calc_shortopts = "vh?p:g:Grmabd:iulqUFCI:O:A:";
 
 /* define long options */
 /*@unused@*/ static struct option ipv6calc_longopts[] = {
@@ -44,6 +45,7 @@
 	{"debug", 1, 0, (int) 'd'},
 	{"path", 1, 0, (int) 'p'},
 	{"path-geoip", 1, 0, (int) 'g'},
+	{"default-geoip", 0, 0, (int) 'G'},
 
 	/* help options */
 	{"help", 0, 0, (int) 'h'},
--- ipv6calc-0.61.0.orig/lib/ipv6calchelp.c
+++ ipv6calc-0.61.0/lib/ipv6calchelp.c
@@ -239,7 +239,13 @@
 	fprintf(stderr, "\n");
 	fprintf(stderr, "  --showinfo|-i [--machine_readable|-m] : show information about input data\n");
 #ifdef SUPPORT_IP2LOCATION
-	fprintf(stderr, "  [-p <file>]                           : IP2Location datafile (optional\n");
+	fprintf(stderr, "  [-p <file>]                           : IP2Location datafile (optional)\n");
+#endif
+#ifdef SUPPORT_GEOIP
+	fprintf(stderr, "  [-g <file>]                           : GeoIP datafile (optional)\n");
+#ifdef GEOIP_DEFAULT_FILE
+	fprintf(stderr, "  [-G]                                  : enable GeoIP (optional)\n");
+#endif
 #endif
 	fprintf(stderr, "  --showinfo|-i --show_types            : show available types on '-m'\n");
 	fprintf(stderr, "\n");
--- ipv6calc-0.61.0.orig/ipv6calc/ipv6calc.c
+++ ipv6calc-0.61.0/ipv6calc/ipv6calc.c
@@ -45,8 +45,12 @@
 
 #ifdef SUPPORT_GEOIP
 int  use_geoip = 0; /* if set to 1, GeoIP is enabled by option(s) */
+#ifdef GEOIP_DEFAULT_FILE
+char file_geoip[NI_MAXHOST] = GEOIP_DEFAULT_FILE;
+#else
 char file_geoip[NI_MAXHOST] = "";
 #endif
+#endif
 
 void printversion(void) {
 	fprintf(stderr, "%s: version %s\n", PROGRAM_NAME, PACKAGE_VERSION);
@@ -143,6 +147,11 @@
 #endif
 			
 				break;
+			case 'G':
+#ifdef GEOIP_DEFAULT_FILE
+				use_geoip = 1;
+#endif
+				break;
 
 			case CMD_printexamples:
 				command = CMD_printexamples;
--- ipv6calc-0.61.0.orig/ipv6calc/Makefile.in
+++ ipv6calc-0.61.0/ipv6calc/Makefile.in
@@ -13,9 +13,9 @@
 # Compiler and Linker Options
 COPTS = -O2 -Wall -g
 
-CFLAGS	= $(COPTS) -I../getopt/ -I../ -I../lib/
+CFLAGS	= $(COPTS) @GETOPT_INCLUDE@ -I../ -I../lib/
 
-GETOBJS = ../getopt/getopt.o ../getopt/getopt1.o ../md5/md5.o
+GETOBJS = @LIBOBJS@ ../md5/md5.o
 
 ifeq (@ENABLE_SUPPORT_IP2LOCATION@, 1)
   COPTS := $(COPTS) -DSUPPORT_IP2LOCATION
@@ -25,8 +25,12 @@
 
 ifeq (@ENABLE_SUPPORT_GEOIP@, 1)
   COPTS := $(COPTS) -DSUPPORT_GEOIP
-  CFLAGS := $(CFLAGS) -I../databases/GeoIP/GeoIP-1.3.17/libGeoIP/
-  GETOBJS := $(GETOBJS) ../databases/GeoIP/GeoIP-1.3.17/libGeoIP/GeoIP.o ../databases/GeoIP/GeoIP-1.3.17/libGeoIP/GeoIPCity.o
+  ifeq (@ENABLE_SYSTEM_GEOIP@, 1)
+    GETOBJS := $(GETOBJS) -lGeoIP
+  else
+    CFLAGS := $(CFLAGS) -I../databases/GeoIP/GeoIP-1.3.17/libGeoIP/
+    GETOBJS := $(GETOBJS) ../databases/GeoIP/GeoIP-1.3.17/libGeoIP/GeoIP.o ../databases/GeoIP/GeoIP-1.3.17/libGeoIP/GeoIPCity.o
+  endif
 endif
 
 CC	= gcc
--- ipv6calc-0.61.0.orig/configure.in
+++ ipv6calc-0.61.0/configure.in
@@ -27,6 +27,17 @@
 AC_FUNC_MEMCMP
 AC_CHECK_FUNCS(strspn strstr)
 
+dnl Check for getopt
+AC_CHECK_FUNC(getopt_long, [],
+  [
+    AC_LIBOBJ(../getopt/getopt)
+    AC_LIBOBJ(../getopt/getopt1)
+    GETOPT_INCLUDE=-I../getopt
+    ENABLE_BUNDLED_GETOPT=1
+  ])
+AC_SUBST(GETOPT_INCLUDE)
+AC_SUBST(ENABLE_BUNDLED_GETOPT)
+
 AC_ARG_ENABLE([ip2location], 
 	AS_HELP_STRING([--enable-ip2location],
 	               [Enable IP2Location support (default: disabled)]),
@@ -43,6 +54,27 @@
 		ENABLE_SUPPORT_GEOIP=1
 		AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want GeoIP support.)
 	fi])
+
+AC_ARG_ENABLE([system-geoip],
+	AS_HELP_STRING([--enable-system-geoip],
+		[Use the system GeoIP library instead of the bundled one (default: bundled)]),
+	[if test "x$enable_system_geoip" = "xyes"; then
+		AC_CHECK_HEADER([GeoIP.h], [], AC_MSG_ERROR([System GeoIP library not found]))
+		ENABLE_SYSTEM_GEOIP=1
+		ENABLE_SUPPORT_GEOIP=1
+		AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want to use GeoIP support.)
+	fi])
+
+AC_ARG_ENABLE([default-geoip-file],
+	AS_HELP_STRING([--enable-default-geoip-file=file],
+		[Use a default GeoIP database file when ipv6calc is invoked with '-G']),
+	[if test "x$enable_default_geoip_file" != xno; then
+		AC_DEFINE_UNQUOTED(GEOIP_DEFAULT_FILE, "$enable_default_geoip_file", Define for a default GeoIP database file.)
+		ENABLE_SUPPORT_GEOIP=1
+		AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want to use GeoIP support.)
+	fi])
+
 AC_SUBST(ENABLE_SUPPORT_GEOIP)
+AC_SUBST(ENABLE_SYSTEM_GEOIP)
 
 AC_OUTPUT([Makefile ipv6calc/Makefile man/Makefile ipv6logconv/Makefile ipv6logstats/Makefile contrib/ipv6calc.spec ipv6calcweb/ipv6calcweb.cgi ])
--- ipv6calc-0.61.0.orig/Makefile.in
+++ ipv6calc-0.61.0/Makefile.in
@@ -10,36 +10,42 @@
 # Compiler and Linker Options
 COPTS = -O2 -Wall -g
 
-CFLAGS	= $(COPTS) -Igetopt/
+ifeq (@ENABLE_BUNDLED_GETOPT@, 1)
+  GETOPT_MAKE = getopt-make
+  GETOPT_DIR  = getopt
+endif
 
-CC	= gcc
+CFLAGS	= $(COPTS) -I$(GETOPT_DIR)
 
-GETOBJS	= getopt/getopt.o getopt/getopt1.o md5/md5.o
+CC	= gcc
 
 ifeq (@ENABLE_SUPPORT_IP2LOCATION@, 1)
   IP2LOCATION_MAKE = ip2location-make
 endif
 ifeq (@ENABLE_SUPPORT_GEOIP@, 1)
-  GEOIP_MAKE = geoip-make
+  ifeq (, @ENABLE_SYSTEM_GEOIP@)
+    GEOIP_MAKE = geoip-make
+  endif
 endif
 
-all:		md5-make getopt-make ipv6calc ipv6logconv ipv6logstats
+all:		md5-make $(GETOPT_MAKE) ipv6calc ipv6logconv ipv6logstats
 
 .c.o:
 		$(CC) $(CFLAGS) -c $<
 
 
-ipv6logconv:	getopt-make lib-make ipv6logconv-make
+ipv6logconv:	$(GETOPT_MAKE) lib-make ipv6logconv-make
 
-ipv6logstats:	getopt-make lib-make ipv6logstats-make
+ipv6logstats:	$(GETOPT_MAKE) lib-make ipv6logstats-make
 
-ipv6calc:	getopt-make lib-make ipv6calc-make ipv6calcweb-make
+ipv6calc:	$(GETOPT_MAKE) lib-make ipv6calc-make ipv6calcweb-make
 
 distclean:
 		${MAKE} clean
 		rm -f config.cache config.status config.log
 		rm -rf autom4te.cache
-		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 getopt databases/ieee-oui databases/ieee-iab databases/ipv4-assignment databases/ipv6-assignment databases/IP2Location/C-IP2Location-1.1.0 databases/GeoIP/GeoIP-1.3.17; do \
+
+		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_DIR) databases/ieee-oui databases/ieee-iab databases/ipv4-assignment databases/ipv6-assignment databases/IP2Location/C-IP2Location-1.1.0 databases/GeoIP/GeoIP-1.3.17; do \
 			ocwd=`pwd`; \
 			cd $$dir; \
 			${MAKE} $@ ; \
@@ -52,7 +58,7 @@
 		rm -f Makefile
 		rm -f contrib/ipv6calc.spec
 		rm config.h
-		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 getopt; do \
+		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_DIR); do \
 			ocwd=`pwd`; \
 			cd $$dir; \
 			${MAKE} $@ ; \
@@ -60,7 +66,7 @@
 		done
 
 clean:
-		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 getopt databases/IP2Location/C-IP2Location-1.1.0 databases/GeoIP/GeoIP-1.3.17; do \
+		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_DIR) databases/IP2Location/C-IP2Location-1.1.0 databases/GeoIP/GeoIP-1.3.17; do \
 			ocwd=`pwd`; \
 			cd $$dir; \
 			${MAKE} $@ ; \
@@ -72,7 +78,7 @@
 		${MAKE} installonly
 
 installonly:
-		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 getopt; do \
+		for dir in ipv6logconv ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_DIR); do \
 			ocwd=`pwd`; \
 			cd $$dir; \
 			${MAKE} install; \
@@ -86,7 +92,7 @@
 		cd md5 && ${MAKE}
 
 lib-make:	md5-make db-ieee-oui-make db-ieee-iab-make db-ipv4-assignment-make db-ipv6-assignment-make
-		cd lib && ${MAKE}
+		cd lib && ${MAKE} GETOPT_INCLUDE=@GETOPT_INCLUDE@
 
 ipv6logconv-make: lib-make
 		cd ipv6logconv && ${MAKE}
--- ipv6calc-0.61.0.orig/ipv6logconv/Makefile.in
+++ ipv6calc-0.61.0/ipv6logconv/Makefile.in
@@ -13,9 +13,9 @@
 # Compiler and Linker Options
 COPTS = -O2 -Wall -g -D__EXTENSIONS__
 
-CFLAGS	= $(COPTS) -I../getopt/ -I../ -I../lib/
+CFLAGS	= $(COPTS) @GETOPT_INCLUDE@ -I../ -I../lib/
 
-GETOBJS = ../getopt/getopt.o ../getopt/getopt1.o
+GETOBJS = @LIBOBJS@
 
 CC	= gcc
 
--- ipv6calc-0.61.0.orig/ipv6logstats/Makefile.in
+++ ipv6calc-0.61.0/ipv6logstats/Makefile.in
@@ -13,9 +13,9 @@
 # Compiler and Linker Options
 COPTS = -O2 -Wall -g -D__EXTENSIONS__
 
-CFLAGS	= $(COPTS) -I../getopt/ -I../ -I../lib/
+CFLAGS	= $(COPTS) @GETOPT_INCLUDE@ -I../ -I../lib/
 
-GETOBJS = ../getopt/getopt.o ../getopt/getopt1.o
+GETOBJS = @LIBOBJS@
 
 CC	= gcc
 


More information about the ipv6calc mailing list