Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pkgconfig file #190

Open
rossburton opened this issue Dec 22, 2023 · 10 comments
Open

Add pkgconfig file #190

rossburton opened this issue Dec 22, 2023 · 10 comments

Comments

@rossburton
Copy link

Now that snowball builds a shared library a pkgconfig file to find the library would be much appreciated.

@ojwb
Copy link
Member

ojwb commented Jan 9, 2024

Snowball doesn't yet build a shared library (there are patches floating around for it, but nothing in a suitable state for merging yet).

@eli-schwartz
Copy link

Snowball also still doesn't install anything... people who are distributing a shared library have to manually cp the library into /usr/lib64 or wherever.

@ojwb
Copy link
Member

ojwb commented Jan 11, 2024

Snowball also still doesn't install anything

Yes, but that's literally a separate issue (#189) - please don't mix discussions.

@eli-schwartz
Copy link

It really is not a separate thing, though. It's a prerequisite. A pkg-config file has to include the path that the library and header file is installed to, it cannot do that unless it is in fact installed.

@sidrat
Copy link

sidrat commented Jan 25, 2025

Hi all first time contributor

Here is a pkgconfig file i created for libstemmer

cat > libstemmer.pc << "EOF"

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
sharedlibdir=${libdir}
includedir=${prefix}/include

Name: libstemmer
Description: Snowball compiler and stemming algorithms 
Version: 2.2.0

Requires:
Libs: -L${libdir} -L${sharedlibdir} -lstemmer
Cflags: -I${includedir} 

EOF

To conferm libstemmer.so is picked up from pkgconfig I use libxmlb-0.3.21 build from Beyond Linux From Scratch (BLFS) book


wget -c https://github.com/hughsie/libxmlb/releases/download/0.3.21/libxmlb-0.3.21.tar.xz
tar -xf libxmlb-0.3.21.tar.xz
cd libxmlb-0.3.21

mkdir build &&
cd    build &&

meson setup --prefix=/usr --buildtype=release -D gtkdoc=false -D stemmer=true .. &&
ninja
ninja test

ninja install

I use ldd to check that libstemmer is included in libxmlb.so
ldd /usr/lib/libxmlb.so

result:
	linux-vdso.so.1 (0x00007c29bcf88000)
	libgio-2.0.so.0 => /usr/lib/libgio-2.0.so.0 (0x00007c29bcc00000)
	libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007c29bcedf000)
	libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007c29bcaa1000)
	liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007c29bceaf000)
	libzstd.so.1 => /usr/lib/libzstd.so.1 (0x00007c29bc9a8000)  
libstemmer.so.0d => /usr/lib/libstemmer.so.0d (0x00007c29bc8df000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007c29bc6f9000)
	libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x00007c29bcea6000)
	libz.so.1 => /usr/lib/libz.so.1 (0x00007c29bce87000)
	libmount.so.1 => /usr/lib/libmount.so.1 (0x00007c29bce18000)
	libffi.so.8 => /usr/lib/libffi.so.8 (0x00007c29bce07000)
	libpcre2-8.so.0 => /usr/lib/libpcre2-8.so.0 (0x00007c29bc658000)
	/lib64/ld-linux-x86-64.so.2 (0x00007c29bcf8a000)
	libblkid.so.1 => /usr/lib/libblkid.so.1 (0x00007c29bc5fa000)


I do not know how to test the functions of libstemmer but i hope this points people in the right direction or gives someone an idea.

This is a install script I used after build libstemmer.

cat > install.sh << "EOF"
cp libstemmer.pc /usr/lib/pkgconfig
cp stemwords  /usr/bin
cp snowball  /usr/bin
cp include/*  /usr/include
cp libstemmer.a /usr/lib
cp libstemmer.so.0d.0.0 /usr/lib
ln -s /usr/lib/libstemmer.so.0d /usr/lib/libstemmer.so
ln -s /usr/lib/libstemmer.so.0d.0.0 /usr/lib/libstemmer.so.0d
ldconfig

EOF

This file is need is for the modified GNUmakefile
create a debian dir
mkdir debian

cat > debian/libstemmer.ver<< "EOF"
{
        global:
                sb_*;
        local:
                *;
};
EOF

I created a GNUmakefile.patch file from an early version of 2.2.0 diff file , to manually modify the GNUmakefile from the git folder . This was the closest matching diff to patch the GNUmakefile i could find.

The result is :

        libstemmer.so 
        libstemmer.so.0d 
        libstemmer.so.0d.0.0
        libstemmer.a
cat > GNUmakefile.patch<< "EOF"
--- GNUmakefile	2025-01-25 22:35:08.351722964 +1300
+++ GNUmakefile.new	2025-01-25 22:32:49.754808290 +1300
@@ -61,6 +61,7 @@
 # a sibling to this one.
 STEMMING_DATA ?= ../snowball-data
 STEMMING_DATA_ABS := $(abspath $(STEMMING_DATA))
+STEMWORDS=LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./stemwords$(EXEEXT)
 
 # Keep one in $(THIN_FACTOR) entries from gzipped vocabularies.
 THIN_FACTOR ?= 3
@@ -187,12 +188,12 @@
 JAVA_CLASSES = $(JAVA_SOURCES:.java=.class)
 JAVA_RUNTIME_CLASSES=$(JAVARUNTIME_SOURCES:.java=.class)
 
-CFLAGS=-g -O2 -W -Wall -Wmissing-prototypes -Wmissing-declarations
-CPPFLAGS=
+override CFLAGS += -O2 -W -Wall -Wmissing-prototypes -Wmissing-declarations
+CPPFLAGS?=
 
 INCLUDES=-Iinclude
 
-all: snowball$(EXEEXT) libstemmer.a stemwords$(EXEEXT) $(C_OTHER_SOURCES) $(C_OTHER_HEADERS) $(C_OTHER_OBJECTS)
+all: snowball$(EXEEXT) libstemmer.a libstemmer.so stemwords$(EXEEXT) $(C_OTHER_SOURCES) $(C_OTHER_HEADERS) $(C_OTHER_OBJECTS)
 
 algorithms.mk: libstemmer/mkalgorithms.pl libstemmer/modules.txt
 	libstemmer/mkalgorithms.pl algorithms.mk libstemmer/modules.txt
@@ -200,8 +201,8 @@
 clean:
 	rm -f $(COMPILER_OBJECTS) $(RUNTIME_OBJECTS) \
 	      $(LIBSTEMMER_OBJECTS) $(LIBSTEMMER_UTF8_OBJECTS) $(STEMWORDS_OBJECTS) snowball$(EXEEXT) \
-	      libstemmer.a stemwords$(EXEEXT) \
-              libstemmer/modules.h \
+	      libstemmer.a libstemmer.so stemwords$(EXEEXT) \
+	      libstemmer/modules.h \
               libstemmer/modules_utf8.h \
 	      $(C_LIB_SOURCES) $(C_LIB_HEADERS) $(C_LIB_OBJECTS) \
 	      $(C_OTHER_SOURCES) $(C_OTHER_HEADERS) $(C_OTHER_OBJECTS) \
@@ -215,12 +216,11 @@
 	      stemtest$(EXEEXT) $(STEMTEST_OBJECTS) \
               libstemmer/mkinc.mak libstemmer/mkinc_utf8.mak \
               libstemmer/libstemmer.c libstemmer/libstemmer_utf8.c \
-	      algorithms.mk
+	      algorithms.mk \
+	      stemtest$(EXEEXT) $(STEMTEST_OBJECTS)
 	rm -rf ada/obj dist
-	-rmdir $(c_src_dir)
-	-rmdir $(python_output_dir)
-	-rmdir $(js_output_dir)
-
+	rm -rf dist .shared
+	
 update_version:
 	perl -pi -e 's/(SNOWBALL_VERSION.*?)\d+\.\d+\.\d+/$${1}$(SNOWBALL_VERSION)/' \
 		compiler/header.h \
@@ -254,17 +254,25 @@
 libstemmer.a: 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 [email protected] ${^:%=shared/%}
+	ln -s [email protected] [email protected]
+	ln -s [email protected] $@
+	$(AR) -crs ${@:.so=.a} $^
+
 examples/%.o: examples/%.c
 	$(CC) $(CFLAGS) $(INCLUDES) $(CPPFLAGS) -c -o $@ $<
 
-stemwords$(EXEEXT): $(STEMWORDS_OBJECTS) libstemmer.a
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+stemwords$(EXEEXT): $(STEMWORDS_OBJECTS) libstemmer.so
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(STEMWORDS_OBJECTS) -L. -lstemmer
 
 tests/%.o: tests/%.c
 	$(CC) $(CFLAGS) $(INCLUDES) $(CPPFLAGS) -c -o $@ $<
 
-stemtest$(EXEEXT): $(STEMTEST_OBJECTS) libstemmer.a
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+stemtest$(EXEEXT): $(STEMTEST_OBJECTS) libstemmer.so
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(STEMTEST_OBJECTS) -L. -lstemmer
 
 csharp_stemwords$(EXEEXT): $(CSHARP_STEMWORDS_SOURCES) $(CSHARP_RUNTIME_SOURCES) $(CSHARP_SOURCES)
 	$(MCS) -unsafe -target:exe -out:$@ $(CSHARP_STEMWORDS_SOURCES) $(CSHARP_RUNTIME_SOURCES) $(CSHARP_SOURCES)
@@ -478,7 +486,7 @@
 	cp -a $(PYTHON_RUNTIME_SOURCES) $${dest}/src/$(python_runtime_dir) && \
 	cp -a $(COMMON_FILES) $(PYTHON_PACKAGE_FILES) $${dest} && \
 	(cd $${dest} && $(python) setup.py sdist bdist_wheel && cp dist/*.tar.gz dist/*.whl ..) && \
-	rm -rf $${dest}
+	cp -a $(COMMON_FILES) $(PYTHON_PACKAGE_FILES) $${dest}
 
 dist_libstemmer_js: $(JS_SOURCES) $(COMMON_FILES)
 	destname=jsstemmer-$(SNOWBALL_VERSION); \
@@ -507,7 +515,7 @@
 check: check_stemtest check_utf8 check_iso_8859_1 check_iso_8859_2 check_koi8r
 
 check_stemtest: stemtest$(EXEEXT)
-	./stemtest
+	LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./stemtest
 
 check_utf8: $(libstemmer_algorithms:%=check_utf8_%)
 
@@ -520,9 +528,9 @@
 check_utf8_%: $(STEMMING_DATA)/% stemwords$(EXEEXT)
 	@echo "Checking output of $* stemmer with UTF-8"
 	@if test -f '$</voc.txt.gz' ; then \
-	  gzip -dc '$</voc.txt.gz'|./stemwords$(EXEEXT) -c UTF_8 -l $* -o tmp.txt; \
+	  gzip -dc '$</voc.txt.gz'|$(STEMWORDS) -c UTF_8 -l `echo $<|sed 's!.*/!!'` -o tmp.txt; \
 	else \
-	  ./stemwords$(EXEEXT) -c UTF_8 -l $* -i $</voc.txt -o tmp.txt; \
+	  $(STEMWORDS) -c UTF_8 -l `echo $<|sed 's!.*/!!'` -i $</voc.txt -o tmp.txt; \
 	fi
 	@if test -f '$</output.txt.gz' ; then \
 	  gzip -dc '$</output.txt.gz'|$(DIFF) -u - tmp.txt; \
@@ -534,7 +542,7 @@
 check_iso_8859_1_%: $(STEMMING_DATA)/% stemwords$(EXEEXT)
 	@echo "Checking output of $* stemmer with ISO_8859_1"
 	@$(ICONV) -f UTF-8 -t ISO-8859-1 '$</voc.txt' |\
-	    ./stemwords -c ISO_8859_1 -l $* -o tmp.txt
+	    $(STEMWORDS) -c ISO_8859_1 -l `echo $<|sed 's!.*/!!'` -o tmp.txt
 	@$(ICONV) -f UTF-8 -t ISO-8859-1 '$</output.txt' |\
 	    $(DIFF) -u - tmp.txt
 	@rm tmp.txt
@@ -542,7 +550,7 @@
 check_iso_8859_2_%: $(STEMMING_DATA)/% stemwords$(EXEEXT)
 	@echo "Checking output of $* stemmer with ISO_8859_2"
 	@$(ICONV) -f UTF-8 -t ISO-8859-2 '$</voc.txt' |\
-	    ./stemwords -c ISO_8859_2 -l $* -o tmp.txt
+	    $(STEMWORDS) -c ISO_8859_2 -l `echo $<|sed 's!.*/!!'` -o tmp.txt
 	@$(ICONV) -f UTF-8 -t ISO-8859-2 '$</output.txt' |\
 	    $(DIFF) -u - tmp.txt
 	@rm tmp.txt
@@ -550,7 +558,7 @@
 check_koi8r_%: $(STEMMING_DATA)/% stemwords$(EXEEXT)
 	@echo "Checking output of $* stemmer with KOI8R"
 	@$(ICONV) -f UTF-8 -t KOI8-R '$</voc.txt' |\
-	    ./stemwords -c KOI8_R -l $* -o tmp.txt
+	    $(STEMWORDS) -c KOI8_R -l `echo $<|sed 's!.*/!!'` -o tmp.txt
 	@$(ICONV) -f UTF-8 -t KOI8-R '$</output.txt' |\
 	    $(DIFF) -u - tmp.txt
 	@rm tmp.txt
@@ -795,4 +803,10 @@
 ada/bin/stemwords: $(ADA_SOURCES)
 	cd ada && $(gprbuild) -Pstemwords -p
 
+%.o: %.c
+	@mkdir -p $(shell dirname ${@:%=shared/%})
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c -fPIC -o ${@:%=shared/%} $<
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+
+
 .SUFFIXES: .class .java

EOF

@sidrat
Copy link

sidrat commented Jan 25, 2025

Sorry the GNUmakefile.patch i posted earlier did not format well so i have placed it in my old git project file with a link for those who want the patch

https://github.com/sidrat/mylfsos/blob/master/patches/GNUmakefile.patch

@eli-schwartz
Copy link

The text box for GitHub comments says "use markdown to format your comment" as a hint that you should use markdown. Don't paste raw text, paste triple-backticks enclosed code blocks.

You can edit your previous comment to fix that mistake (or delete it entirely).

@sidrat
Copy link

sidrat commented Jan 26, 2025

thanks for the hint , i don't use markdown much.

@ojwb
Copy link
Member

ojwb commented Jan 27, 2025

In general, if you want to submit a patch then open a PR instead of pasting patch text into comments or putting a patch file in some random other git repo.

However for this patch that wouldn't actually help as I can't merge a patch which adds shared library support but with a hardcoded assumptions that are wrong for some platforms (not all platforms name shared libraries with a.so extension and LD_LIBRARY_PATH isn't universal either). This is why none of the previous PRs for shared library support have been merged.

@eli-schwartz
Copy link

What constraints are there on how to add shared library support? Does it have to use a GNUmakefile or is using another build system (automake, meson) on the table?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants