[hackers] [libgrapheme] Separate CC into CC and BUILD_CC, add option to disable ldconfig(1)-call || Laslo Hunhold

From: <git_AT_suckless.org>
Date: Tue, 16 Aug 2022 19:05:13 +0200 (CEST)

commit 68391fc580b9a855271be57038d69cd2ce6ca0de
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Tue Aug 16 18:56:21 2022 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Aug 16 18:56:21 2022 +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_AT_frign.de>

diff --git a/Makefile b/Makefile
index d53cf96..f24b65e 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -171,27 +171,30 @@ data/WordBreakProperty.txt:
 data/WordBreakTest.txt:
         wget -O $_AT_ https://www.unicode.org/Public/14.0.0/ucd/auxiliary/WordBreakTest.txt
 
+$(BENCHMARK:=.o) $(GEN:=.o) $(TEST:=.o):
+ $(BUILD_CC) -c -o $_AT_ $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) $(@:.o=.c)
+
+$(SRC:=.o):
+ $(CC) -c -o $_AT_ $(CPPFLAGS) $(CFLAGS) $(@:.o=.c)
+
 $(BENCHMARK):
- $(CC) -o $_AT_ $(LDFLAGS) $@.o benchmark/util.o libgrapheme.a -lutf8proc
+ $(BUILD_CC) -o $_AT_ $(BUILD_LDFLAGS) $@.o benchmark/util.o libgrapheme.a -lutf8proc
 
 $(GEN):
- $(CC) -o $_AT_ $(LDFLAGS) $@.o gen/util.o
-
-$(GEN:=.h):
- $(_AT_:.h=) > $@
+ $(BUILD_CC) -o $_AT_ $(BUILD_LDFLAGS) $@.o gen/util.o
 
 $(TEST):
- $(CC) -o $_AT_ $(LDFLAGS) $@.o test/util.o libgrapheme.a
+ $(BUILD_CC) -o $_AT_ $(BUILD_LDFLAGS) $@.o test/util.o libgrapheme.a
 
-.c.o:
- $(CC) -c -o $_AT_ $(CPPFLAGS) $(CFLAGS) $<
+$(GEN:=.h):
+ $(_AT_:.h=) > $@
 
 libgrapheme.a: $(SRC:=.o)
         $(AR) -rc $_AT_ $?
         $(RANLIB) $_AT_
 
 libgrapheme.so: $(SRC:=.o)
- $(CC) -o $_AT_ -shared $(SRC:=.o)
+ $(CC) -o $_AT_ -shared $(LDFLAGS) $(SRC:=.o)
 
 benchmark: $(BENCHMARK)
         for m in $(BENCHMARK); do ./$$m; done
_AT_@ -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
_AT_@ -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
_AT_@ -225,9 +228,6 @@ clean:
 clean-data:
         rm -f $(DATA)
 
-print:
- _AT_echo $(PREFIX)
-
 dist:
         rm -rf "libgrapheme-$(VERSION)"
         mkdir "libgrapheme-$(VERSION)"
diff --git a/config.mk b/config.mk
index 3408f44..585d0ea 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -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
Received on Tue Aug 16 2022 - 19:05:13 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 16 2022 - 19:12:38 CEST