snowball (0+svn546-2) shared-library.diff

Summary

 GNUmakefile |   38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

    
download this patch

Patch contents

Description: Build libstemmer as a shared library.
Author: Stefano Rivera <stefanor@debian.org>
Forwarded: http://news.gmane.org/find-root.php?message_id=%3c20110821220427.GC1738%40bach.rivera.co.za%3e
Last-Update: 2011-09-25

--- a/GNUmakefile
+++ b/GNUmakefile
@@ -72,12 +72,13 @@
 CFLAGS=-O2
 CPPFLAGS=-W -Wall -Wmissing-prototypes -Wmissing-declarations -Iinclude
 
-all: snowball libstemmer.o stemwords $(C_OTHER_SOURCES) $(C_OTHER_HEADERS) $(C_OTHER_OBJECTS)
+all: snowball libstemmer.so stemwords $(C_OTHER_SOURCES) $(C_OTHER_HEADERS) $(C_OTHER_OBJECTS)
 
 clean:
 	rm -f $(COMPILER_OBJECTS) $(RUNTIME_OBJECTS) \
 	      $(LIBSTEMMER_OBJECTS) $(LIBSTEMMER_UTF8_OBJECTS) $(STEMWORDS_OBJECTS) snowball \
-	      libstemmer.o stemwords \
+	      $(wildcard libstemmer.so*) libstemmer.a \
+	          stemwords \
               libstemmer/modules.h \
               libstemmer/modules_utf8.h \
               snowball.splint \
@@ -86,7 +87,7 @@
 	      $(JAVA_SOURCES) $(JAVA_CLASSES) $(JAVA_RUNTIME_CLASSES) \
               libstemmer/mkinc.mak libstemmer/mkinc_utf8.mak \
               libstemmer/libstemmer.c libstemmer/libstemmer_utf8.c
-	rm -rf dist
+	rm -rf dist .shared
 	rmdir $(c_src_dir) || true
 
 snowball: $(COMPILER_OBJECTS)
@@ -108,11 +109,16 @@
 
 libstemmer/libstemmer.o: libstemmer/modules.h $(C_LIB_HEADERS)
 
-libstemmer.o: libstemmer/libstemmer.o $(RUNTIME_OBJECTS) $(C_LIB_OBJECTS)
-	$(AR) -cru $@ $^
+libstemmer.so: libstemmer/libstemmer.o $(RUNTIME_OBJECTS) $(C_LIB_OBJECTS)
+	$(CC) $(CFLAGS) -shared $(LDFLAGS) \
+	      -Wl,--version-script=debian/libstemmer.ver,-soname,libstemmer.so.0d \
+	      -o $@.0d.0.0 ${^:%=.shared/%}
+	ln -s $@.0d.0.0 $@.0d
+	ln -s $@.0d.0.0 $@
+	$(AR) -crs ${@:.so=.a} $^
 
-stemwords: $(STEMWORDS_OBJECTS) libstemmer.o
-	$(CC) -o $@ $^
+stemwords: $(STEMWORDS_OBJECTS) libstemmer.so
+	$(CC) -g -o $@ $(STEMWORDS_OBJECTS) -L. -lstemmer
 
 algorithms/%/stem_Unicode.sbl: algorithms/%/stem_ISO_8859_1.sbl
 	cp $^ $@
@@ -146,7 +152,6 @@
 	./snowball $< -o $${o} -eprefix $${l}_ISO_8859_2_ -r ../runtime
 
 $(c_src_dir)/stem_%.o: $(c_src_dir)/stem_%.c $(c_src_dir)/stem_%.h
-	$(CC) $(CFLAGS) -O2 -c -o $@ $< -Wall
 
 $(java_src_dir)/%Stemmer.java: algorithms/%/stem_Unicode.sbl snowball
 	@mkdir -p $(java_src_dir)
@@ -261,31 +266,38 @@
 
 check_koi8r: $(KOI8_R_algorithms:%=check_koi8r_%)
 
+STEMWORDS=LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./stemwords
+
 check_utf8_%: ../data/% stemwords
 	@echo "Checking output of `echo $<|sed 's!.*/!!'` stemmer with UTF-8"
-	@./stemwords -c UTF_8 -l `echo $<|sed 's!.*/!!'` -i $</voc.txt -o tmp.txt
+	@$(STEMWORDS) -c UTF_8 -l `echo $<|sed 's!.*/!!'` -i $</voc.txt -o tmp.txt
 	@diff -u $</output.txt tmp.txt
 	@if [ -e $</diffs.txt ] ; \
 	then \
-	  ./stemwords -c UTF_8 -l `echo $<|sed 's!.*/!!'` -i $</voc.txt -o tmp.txt -p2 && \
+	  $(STEMWORDS) -c UTF_8 -l `echo $<|sed 's!.*/!!'` -i $</voc.txt -o tmp.txt -p2 && \
 	  diff -u $</diffs.txt tmp.txt; \
 	fi
 	@rm tmp.txt
 
 check_iso_8859_1_%: ../data/% stemwords
 	@echo "Checking output of `echo $<|sed 's!.*/!!'` stemmer with ISO_8859_1"
-	@iconv -fUTF8 -tISO8859-1 $</voc.txt|./stemwords -c ISO_8859_1 -l `echo $<|sed 's!.*/!!'` -o tmp.txt
+	@iconv -fUTF8 -tISO8859-1 $</voc.txt|$(STEMWORDS) -c ISO_8859_1 -l `echo $<|sed 's!.*/!!'` -o tmp.txt
 	@iconv -fUTF8 -tISO8859-1 $</output.txt|diff -u - tmp.txt
 	@rm tmp.txt
 
 check_iso_8859_2_%: ../data/% stemwords
 	@echo "Checking output of `echo $<|sed 's!.*/!!'` stemmer with ISO_8859_2"
-	@iconv -fUTF8 -tISO8859-2 $</voc.txt|./stemwords -c ISO_8859_2 -l `echo $<|sed 's!.*/!!'` -o tmp.txt
+	@iconv -fUTF8 -tISO8859-2 $</voc.txt|$(STEMWORDS) -c ISO_8859_2 -l `echo $<|sed 's!.*/!!'` -o tmp.txt
 	@iconv -fUTF8 -tISO8859-2 $</output.txt|diff -u - tmp.txt
 	@rm tmp.txt
 
 check_koi8r_%: ../data/% stemwords
 	@echo "Checking output of `echo $<|sed 's!.*/!!'` stemmer with KOI8R"
-	@iconv -fUTF8 -tKOI8R $</voc.txt|./stemwords -c KOI8_R -l `echo $<|sed 's!.*/!!'` -o tmp.txt
+	@iconv -fUTF8 -tKOI8R $</voc.txt|$(STEMWORDS) -c KOI8_R -l `echo $<|sed 's!.*/!!'` -o tmp.txt
 	@iconv -fUTF8 -tKOI8R $</output.txt|diff -u - tmp.txt
 	@rm tmp.txt
+
+%.o: %.c
+	@mkdir -p $(shell dirname ${@:%=.shared/%})
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c -fPIC -o ${@:%=.shared/%} $<
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<