libgrapheme

unicode string library
git clone git://git.suckless.org/libgrapheme
Log | Files | Refs | README | LICENSE

commit 68391fc580b9a855271be57038d69cd2ce6ca0de
parent 3697387a0a5fcb53df0094d988496f7a681ae54c
Author: Laslo Hunhold <dev@frign.de>
Date:   Tue, 16 Aug 2022 18:56:21 +0200

Separate CC into CC and BUILD_CC, add option to disable ldconfig(1)-call

The libgrapheme-Gentoo-ebuild[0] has to resort to modify the Makefile
itself given we unconditionally call $(CC) both for the tools we
compile at build-time and the final library objects.

It might however be the case that we're cross-compiling to another
architecture, where we have to make a distinction between local and
target compilers. Using BUILD_CC is an established approach, while also
having separate BUILD_*-flags for those compiler/linker-calls
respectively.

Additionally, use an LDCONFIG-variable that can be unset to not call
ldconfig after installing and uninstalling. This is necessary for
porting given e.g. Gentoo prefers to call ldconfig itself when it
deems it appropriate.

This commit also removes the useless print-target that got left over
from a long-forgotten debugging-session.

As a minor thing, we add the soname-flag to the default linker-options
to properly set SONAME for libgrapheme.so. We naturally don't do symbol
versioning, given even though there are some name-changes from version
1 the names should be stable now and new ones only added, not removed
or changed.

This should, in general, greatly simplify packaging of libgrapheme
as soon as the next version 2 is released.

[0]:https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-libs/libgrapheme/libgrapheme-1.ebuild

Signed-off-by: Laslo Hunhold <dev@frign.de>

Diffstat:
MMakefile | 28++++++++++++++--------------
Mconfig.mk | 14++++++++++----
2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile @@ -171,27 +171,30 @@ data/WordBreakProperty.txt: data/WordBreakTest.txt: wget -O $@ https://www.unicode.org/Public/14.0.0/ucd/auxiliary/WordBreakTest.txt +$(BENCHMARK:=.o) $(GEN:=.o) $(TEST:=.o): + $(BUILD_CC) -c -o $@ $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) $(@:.o=.c) + +$(SRC:=.o): + $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(@:.o=.c) + $(BENCHMARK): - $(CC) -o $@ $(LDFLAGS) $@.o benchmark/util.o libgrapheme.a -lutf8proc + $(BUILD_CC) -o $@ $(BUILD_LDFLAGS) $@.o benchmark/util.o libgrapheme.a -lutf8proc $(GEN): - $(CC) -o $@ $(LDFLAGS) $@.o gen/util.o - -$(GEN:=.h): - $(@:.h=) > $@ + $(BUILD_CC) -o $@ $(BUILD_LDFLAGS) $@.o gen/util.o $(TEST): - $(CC) -o $@ $(LDFLAGS) $@.o test/util.o libgrapheme.a + $(BUILD_CC) -o $@ $(BUILD_LDFLAGS) $@.o test/util.o libgrapheme.a -.c.o: - $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $< +$(GEN:=.h): + $(@:.h=) > $@ libgrapheme.a: $(SRC:=.o) $(AR) -rc $@ $? $(RANLIB) $@ libgrapheme.so: $(SRC:=.o) - $(CC) -o $@ -shared $(SRC:=.o) + $(CC) -o $@ -shared $(LDFLAGS) $(SRC:=.o) benchmark: $(BENCHMARK) for m in $(BENCHMARK); do ./$$m; done @@ -209,7 +212,7 @@ install: all cp -f libgrapheme.a "$(DESTDIR)$(LIBPREFIX)" cp -f libgrapheme.so "$(DESTDIR)$(LIBPREFIX)" cp -f grapheme.h "$(DESTDIR)$(INCPREFIX)" - ldconfig || true + $(LDCONFIG) uninstall: for m in $(MAN3); do rm -f "$(DESTDIR)$(MANPREFIX)/man3/`basename $$m`"; done @@ -217,7 +220,7 @@ uninstall: rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.a" rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so" rm -f "$(DESTDIR)$(INCPREFIX)/grapheme.h" - ldconfig || true + $(LDCONFIG) clean: rm -f $(BENCHMARK:=.o) benchmark/util.o $(BENCHMARK) $(GEN:=.h) $(GEN:=.o) gen/util.o $(GEN) $(SRC:=.o) src/util.o $(TEST:=.o) test/util.o $(TEST) libgrapheme.a libgrapheme.so @@ -225,9 +228,6 @@ clean: clean-data: rm -f $(DATA) -print: - @echo $(PREFIX) - dist: rm -rf "libgrapheme-$(VERSION)" mkdir "libgrapheme-$(VERSION)" diff --git a/config.mk b/config.mk @@ -12,9 +12,15 @@ MANPREFIX = $(PREFIX)/share/man # flags CPPFLAGS = -D_DEFAULT_SOURCE CFLAGS = -std=c99 -Os -fPIC -Wall -Wextra -Wpedantic -LDFLAGS = -s +LDFLAGS = -Wl,--soname=libgrapheme.so + +BUILD_CPPFLAGS = $(CPPFLAGS) +BUILD_CFLAGS = $(CFLAGS) +BUILD_LDFLAGS = -s # tools -CC = cc -AR = ar -RANLIB = ranlib +CC = cc +BUILD_CC = $(CC) +AR = ar +RANLIB = ranlib +LDCONFIG = ldconfig # unset to not call ldconfig(1) after install/uninstall