liblinear (1.6+dfsg-1) 0001-Properly-build-shared-and-static-libraries-programs.patch

Summary

 Makefile |   50 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)

    
download this patch

Patch contents

From: Christian Kastner <debian@kvr.at>
Date: Fri, 9 Jul 2010 18:09:09 +0200
Subject: [PATCH] Properly build shared and static libraries, programs

Modify upstream's Makefile to properly build shared and static libraries,
link upstream's programs to the shared libraries.

Forwarded: no
Last-Update: 2010-07-09
---
 Makefile |   50 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile
index 5004ff9..4d77d2f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,27 +1,41 @@
-CXX ?= g++
+XX ?= g++
 CC ?= gcc
-CFLAGS = -Wall -Wconversion -O3 -fPIC
-LIBS =
-SHVER = 1
-#LIBS = -lblas
+CFLAGS +=
+LDFLAGS += -L.
+LIBS +=
 
-all: train predict
+LIB_CFLAGS += $(CFLAGS) -fPIC
+LIB_LDFLAGS += $(LDFLAGS)
+LIB_LIBS += $(LIBS) -lblas
 
-lib: linear.o tron.o
-	$(CXX) -shared -dynamiclib linear.o tron.o -o liblinear.so.$(SHVER)
+PROG_CFLAGS += $(CFLAGS)
+PROG_LDFLAGS += $(LDFLAGS)
+PROG_LIBS += $(LIBS) -llinear
 
-train: tron.o linear.o train.c
-	$(CXX) $(CFLAGS) -o train train.c tron.o linear.o $(LIBS)
+LVER ?= 0
+LSUBVER ?= 0
+LIBFILE = liblinear.so.$(LVER).$(LSUBVER)
 
-predict: tron.o linear.o predict.c
-	$(CXX) $(CFLAGS) -o predict predict.c tron.o linear.o $(LIBS)
 
-tron.o: tron.cpp tron.h
-	$(CXX) $(CFLAGS) -c -o tron.o tron.cpp
+all: liblinear-train liblinear-predict liblinear.a
 
-linear.o: linear.cpp linear.h
-	$(CXX) $(CFLAGS) -c -o linear.o linear.cpp
+liblinear-train: train.c $(LIBFILE)
+	$(CXX) $(PROG_CFLAGS) $(PROG_LDFLAGS) -o $@ train.c $(PROG_LIBS)
+
+liblinear-predict: predict.c $(LIBFILE)
+	$(CXX) $(PROG_CFLAGS) $(PROG_LDFLAGS) -o $@ predict.c $(PROG_LIBS)
+
+$(LIBFILE): linear.cpp linear.h tron.cpp tron.h
+	$(CXX) $(LIB_CFLAGS) $(LIB_LDFLAGS) -shared \
+		-Wl,-soname,liblinear.so.$(LVER) \
+		-o $@ linear.cpp tron.cpp $(LIB_LIBS)
+	ln -s $@ liblinear.so.$(LVER)
+	ln -s liblinear.so.$(LVER) liblinear.so
+
+liblinear.a:
+	$(CXX) $(CFLAGS) $(LDFLAGS) -c -o linear-static.o linear.cpp
+	$(CXX) $(CFLAGS) $(LDFLAGS) -c -o tron-static.o tron.cpp
+	ar cru liblinear.a linear-static.o tron-static.o
 
 clean:
-	cd matlab;	make clean
-	rm -f *~ tron.o linear.o train predict liblinear.so.$(SHVER)
+	rm -f *~ *.o *.a *.so* liblinear-train liblinear-predict
--