From 86794866532f1f1d41c6650d7d4669281dbf8f9a Mon Sep 17 00:00:00 2001
From: Nikoli <nikoli@gmx.us>
Date: Sun, 2 Feb 2014 13:44:25 +0400
Subject: [PATCH] Fix build with LDFLAGS="-Wl,-O1 -Wl,--as-needed", fix 'make
 install' for libs

---
 Makefile.in               |  4 ++--
 databases/lib/Makefile.in | 12 ++++++++----
 ipv6calc/Makefile.in      |  8 ++++----
 ipv6loganon/Makefile.in   |  8 ++++----
 ipv6logconv/Makefile.in   |  8 ++++----
 ipv6logstats/Makefile.in  |  8 ++++----
 lib/Makefile.in           | 16 +++++++++-------
 tools/Makefile.in         |  4 ++--
 8 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index f2cd03e..e5c5507 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -20,7 +20,7 @@ CC	= @CC@
 all:		md5-make $(GETOPT_MAKE) ipv6calc ipv6logconv ipv6logstats ipv6loganon
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 
 ipv6logconv:	$(GETOPT_MAKE) lib-make ipv6logconv-make
@@ -74,7 +74,7 @@ clean:
 		done
 
 install:
-		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc man lib $(GETOPT_MAKE); do \
+		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc man lib databases/lib $(GETOPT_MAKE); do \
 			ocwd=`pwd`; \
 			cd $$dir || exit 1; \
 			${MAKE} install; \
diff --git a/databases/lib/Makefile.in b/databases/lib/Makefile.in
index ca0dff5..96400e3 100644
--- a/databases/lib/Makefile.in
+++ b/databases/lib/Makefile.in
@@ -7,6 +7,8 @@
 #  Makefile for ipv6calc database libraries
 #
 
+libdir	= @libdir@
+
 # Compiler and Linker Options
 #  -D__EXTENSIONS__ is for Solaris & strtok_r
 DEFAULT_CFLAGS ?= -O2 -Wall
@@ -14,6 +16,8 @@ CFLAGS += -D__EXTENSIONS__ -fPIC
 
 INCLUDES= -I../../lib -I../.. $(GETOPT_INCLUDE)
 
+SHARED_LIBRARY=@SHARED_LIBRARY@
+
 CC	= @CC@
 AR	= ar
 RANLIB	= @RANLIB@
@@ -25,10 +29,10 @@ OBJS	=	libipv6calc_db_wrapper.o \
 
 all:		
 		${MAKE} libipv6calc_db_wrapper.a
-		${MAKE} libipv6calc_db_wrapper.so
+		${MAKE} libipv6calc_db_wrapper.so.@PACKAGE_VERSION@
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 $(OBJS):	libipv6calc_db_wrapper.h \
 		libipv6calc_db_wrapper_GeoIP.h \
@@ -41,9 +45,9 @@ libipv6calc_db_wrapper.a:	$(OBJS)
 		$(AR) r libipv6calc_db_wrapper.a $(OBJS)
 		$(RANLIB) libipv6calc_db_wrapper.a
 
-libipv6calc_db_wrapper.so:	$(OBJS)
+libipv6calc_db_wrapper.so.@PACKAGE_VERSION@:	$(OBJS)
 		echo "Create shared library (.so)"
-		$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,libipv6calc_db_wrapper.so.@PACKAGE_VERSION@ -o libipv6calc_db_wrapper.so.@PACKAGE_VERSION@ $(OBJS)
+		$(CC) -o libipv6calc_db_wrapper.so.@PACKAGE_VERSION@ $(OBJS) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,libipv6calc_db_wrapper.so.@PACKAGE_VERSION@
 
 distclean:
 		${MAKE} clean
diff --git a/ipv6calc/Makefile.in b/ipv6calc/Makefile.in
index bcc9753..8ec7afa 100644
--- a/ipv6calc/Makefile.in
+++ b/ipv6calc/Makefile.in
@@ -35,7 +35,7 @@ SPLINT_TODO_LATER = -unrecog  -retvalint
 all:		ipv6calc
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 $(OBJS):	ipv6calc.h ipv6calchelp_local.h showinfo.h ipv6calcoptions_local.h ../config.h
 
@@ -46,10 +46,10 @@ libipv6calc_db_wrapper:
 		cd ../ && ${MAKE} lib-make
 
 ipv6calc:	$(OBJS) libipv6calc libipv6calc_db_wrapper
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6calc $(OBJS) $(GETOBJS) $(LIBS) -lm
+		$(CC) -o ipv6calc $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) $(LIBS) -lm
 
 static:		ipv6calc
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6calc-static $(OBJS) $(GETOBJS) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
+		$(CC) -o ipv6calc-static $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
 
 distclean:
 		${MAKE} clean
@@ -76,6 +76,6 @@ codecheck:
 splint:		
 		splint *.c ../lib/*.c -I.. -I../lib $(SPLINT_OPT_OUTSIDE) $(SPLINT_TODO_LATER)
 
-install:	ipv6calc
+install:	all
 		mkdir -p $(DESTDIR)$(bindir)
 		install -m 755 ipv6calc $(DESTDIR)$(bindir)
diff --git a/ipv6loganon/Makefile.in b/ipv6loganon/Makefile.in
index c2026fb..65dc5f1 100644
--- a/ipv6loganon/Makefile.in
+++ b/ipv6loganon/Makefile.in
@@ -35,7 +35,7 @@ SPLINT_TODO_LATER = -unrecog -retvalint
 all:		ipv6loganon
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 $(OBJS):	ipv6loganonoptions.h ipv6loganonhelp.h ipv6loganon.h ../config.h ../lib/ipv6calccommands.h
 
@@ -46,10 +46,10 @@ libipv6calc_db_wrapper:
 		cd ../ && ${MAKE} lib-make
 
 ipv6loganon:	$(OBJS) libipv6calc libipv6calc_db_wrapper
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6loganon $(OBJS) $(GETOBJS) $(LIBS) ../md5/md5.o -lm
+		$(CC) -o ipv6loganon $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) $(LIBS) ../md5/md5.o -lm
 
 static:		ipv6loganon
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6loganon-static $(OBJS) $(GETOBJS) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
+		$(CC) -o ipv6loganon-static $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
 
 distclean:
 		${MAKE} clean
@@ -73,7 +73,7 @@ codecheck:
 splint:
 		splint *.c ../lib/*.c -I.. -I../lib $(SPLINT_OPT_OUTSIDE) $(SPLINT_TODO_LATER)
 
-install:	ipv6loganon
+install:	all
 		mkdir -p $(DESTDIR)$(bindir)
 		install -m 755 ipv6loganon $(DESTDIR)$(bindir)
 	
diff --git a/ipv6logconv/Makefile.in b/ipv6logconv/Makefile.in
index 3c5ab4d..1687ac8 100644
--- a/ipv6logconv/Makefile.in
+++ b/ipv6logconv/Makefile.in
@@ -35,7 +35,7 @@ SPLINT_TODO_LATER = -unrecog -retvalint
 all:		ipv6logconv
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 $(OBJS):	ipv6logconvoptions.h ipv6logconvhelp.h ipv6logconv.h
 
@@ -46,10 +46,10 @@ libipv6calc_db_wrapper:
 		cd ../ && ${MAKE} lib-make
 
 ipv6logconv:	$(OBJS) libipv6calc libipv6calc_db_wrapper
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6logconv $(OBJS) $(GETOBJS) $(LIBS) ../md5/md5.o -lm
+		$(CC) -o ipv6logconv $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) $(LIBS) ../md5/md5.o -lm
 
 static:		ipv6logconv
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6logconv-static $(OBJS) $(GETOBJS) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
+		$(CC) -o ipv6logconv-static $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
 
 distclean:
 		${MAKE} clean
@@ -72,7 +72,7 @@ codecheck:
 splint:
 		splint *.c ../lib/*.c -I.. -I../lib $(SPLINT_OPT_OUTSIDE) $(SPLINT_TODO_LATER)
 
-install:	ipv6logconv
+install:	all
 		mkdir -p $(DESTDIR)$(bindir)
 		install -m 755 ipv6logconv $(DESTDIR)$(bindir)
 	
diff --git a/ipv6logstats/Makefile.in b/ipv6logstats/Makefile.in
index 4945f6e..e0d0121 100644
--- a/ipv6logstats/Makefile.in
+++ b/ipv6logstats/Makefile.in
@@ -35,7 +35,7 @@ SPLINT_TODO_LATER = -unrecog
 all:		ipv6logstats
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -D__EXTENSIONS__ -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 libipv6calc.a:
 		cd ../ && ${MAKE} lib-make
@@ -46,10 +46,10 @@ libipv6calc_db_wrapper.a:
 $(OBJS):	ipv6logstatsoptions.h ipv6logstatshelp.h ipv6logstats.h
 
 ipv6logstats:	$(OBJS) libipv6calc.a libipv6calc_db_wrapper.a
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6logstats $(OBJS) $(GETOBJS) $(LIBS) ../md5/md5.o -lm
+		$(CC) -o ipv6logstats $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) $(LIBS) ../md5/md5.o -lm
 
 static:		ipv6logstats
-		$(CC) $(LDFLAGS) $(LDFLAGS_EXTRA) -o ipv6logstats-static $(OBJS) $(GETOBJS) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
+		$(CC) -o ipv6logstats-static $(OBJS) $(GETOBJS) $(LDFLAGS) $(LDFLAGS_EXTRA) -lipv6calc -lipv6calc_db_wrapper -L../lib/ -L../databases/lib/ -static $(LIBS) -lm
 
 distclean:
 		${MAKE} clean
@@ -72,7 +72,7 @@ codecheck:
 splint:
 		splint *.c ../lib/*.c -I.. -I../lib $(SPLINT_OPT_OUTSIDE) $(SPLINT_TODO_LATER)
 
-install:        ipv6logstats
+install:        all
 		mkdir -p $(DESTDIR)$(bindir)
 		install -m 755 ipv6logstats $(DESTDIR)$(bindir)
 
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 382131a..5f0bf4e 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -7,6 +7,8 @@
 #  Makefile for ipv6calc libraries
 #
 
+libdir	= @libdir@
+
 # Compiler and Linker Options
 #  -D__EXTENSIONS__ is for Solaris & strtok_r
 DEFAULT_CFLAGS ?= -O2 -Wall
@@ -40,22 +42,22 @@ OBJS	=	libipv6calc.o  \
 
 all:		
 		${MAKE} libipv6calc.a
-		${MAKE} libipv6calc.so
+		${MAKE} libipv6calc.so.@PACKAGE_VERSION@
 
 libieee.o:	../databases/ieee-oui/dbieee_oui.h libieee.c libieee.h
 		cd ../ && ${MAKE} db-ieee-oui-make
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c libieee.c
+		$(CC) -c libieee.c $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 libipv4addr.o:	../databases/ipv4-assignment/dbipv4addr_assignment.h libipv4addr.c libipv4addr.h
 		cd ../ && ${MAKE} db-ipv4-assignment-make
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c libipv4addr.c
+		$(CC) -c libipv4addr.c $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 libipv6addr.o:	../databases/ipv6-assignment/dbipv6addr_assignment.h libipv6addr.c libipv6addr.h
 		cd ../ && ${MAKE} db-ipv6-assignment-make
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c libipv6addr.c
+		$(CC) -c libipv6addr.c $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 $(OBJS):	libipv6calcdebug.h  \
 		libipv6calc.h       \
@@ -86,12 +88,12 @@ libipv6calc.a:	$(OBJS)
 		$(AR) r libipv6calc.a $(OBJS)
 		$(RANLIB) libipv6calc.a
 
-libipv6calc.so: $(OBJS)
+libipv6calc.so.@PACKAGE_VERSION@: $(OBJS)
 		cd ../ && ${MAKE} db-ieee-oui-make
 		cd ../ && ${MAKE} db-ipv4-assignment-make
 		cd ../ && ${MAKE} db-ipv6-assignment-make
 		echo "Creates shared library (.so)"
-		$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,libipv6calc.so.@PACKAGE_VERSION@ -o libipv6calc.so.@PACKAGE_VERSION@ $(OBJS)
+		$(CC) -o libipv6calc.so.@PACKAGE_VERSION@ $(OBJS) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,libipv6calc.so.@PACKAGE_VERSION@
 
 distclean:
 		${MAKE} clean
diff --git a/tools/Makefile.in b/tools/Makefile.in
index fc6521d..3dc6ed0 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -30,7 +30,7 @@ SPLINT_TODO_LATER = -unrecog  -retvalint
 all:		registry-assignment-to-list
 
 .c.o:
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES) -c $<
+		$(CC) -c $< $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDES)
 
 $(OBJS):	../config.h
 
@@ -38,7 +38,7 @@ libipv6calc.a:
 		cd ../ && ${MAKE} lib-make
 
 registry-assignment-to-list:	$(OBJS) libipv6calc.a
-		$(CC) $(DEFAULT_CFLAGS) $(CFLAGS) -o registry-assignment-to-list $(OBJS) $(GETOBJS) -lipv6calc -L../lib/ $(LDFLAGS)
+		$(CC) -o registry-assignment-to-list $(OBJS) $(GETOBJS) $(DEFAULT_CFLAGS) $(CFLAGS) -lipv6calc -L../lib/ $(LDFLAGS)
 
 distclean:
 		${MAKE} clean
-- 
1.8.3.2

