commit 7230c626e0e193ec0b8ee45404e84e530c796e78
Author:     Laslo Hunhold <d...@frign.de>
AuthorDate: Wed Aug 17 09:55:10 2022 +0200
Commit:     Laslo Hunhold <d...@frign.de>
CommitDate: Wed Aug 17 09:55:10 2022 +0200

    Build tests and benchmarks locally and add separate shared build-flags
    
    Naturally, given tests and benchmark link against the built libgrapheme,
    it makes no sense to compile them in the local build architecture.
    
    Additionally, we add the establisheed SHFLAGS- and SOFLAGS-variables to
    config.mk to give finer control over build-flags specific for the
    shared object files and linking of the final so. This saves us from
    indiscriminately compiling all object files as PIC and setting soname
    for the test- and benchmark-binaries, which makes zero sense.
    
    Signed-off-by: Laslo Hunhold <d...@frign.de>

diff --git a/Makefile b/Makefile
index f24b65e..209ce36 100644
--- a/Makefile
+++ b/Makefile
@@ -171,20 +171,23 @@ 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):
+$(GEN:=.o):
        $(BUILD_CC) -c -o $@ $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) $(@:.o=.c)
 
-$(SRC:=.o):
+$(BENCHMARK:=.o) $(TEST:=.o):
        $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(@:.o=.c)
 
+$(SRC:=.o):
+       $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(SHFLAGS) $(@:.o=.c)
+
 $(BENCHMARK):
-       $(BUILD_CC) -o $@ $(BUILD_LDFLAGS) $@.o benchmark/util.o libgrapheme.a 
-lutf8proc
+       $(CC) -o $@ $(LDFLAGS) $@.o benchmark/util.o libgrapheme.a -lutf8proc
 
 $(GEN):
        $(BUILD_CC) -o $@ $(BUILD_LDFLAGS) $@.o gen/util.o
 
 $(TEST):
-       $(BUILD_CC) -o $@ $(BUILD_LDFLAGS) $@.o test/util.o libgrapheme.a
+       $(CC) -o $@ $(LDFLAGS) $@.o test/util.o libgrapheme.a
 
 $(GEN:=.h):
        $(@:.h=) > $@
@@ -194,7 +197,7 @@ libgrapheme.a: $(SRC:=.o)
        $(RANLIB) $@
 
 libgrapheme.so: $(SRC:=.o)
-       $(CC) -o $@ -shared $(LDFLAGS) $(SRC:=.o)
+       $(CC) -o $@ $(SOFLAGS) $(LDFLAGS) $(SRC:=.o)
 
 benchmark: $(BENCHMARK)
        for m in $(BENCHMARK); do ./$$m; done
diff --git a/config.mk b/config.mk
index 585d0ea..9e66400 100644
--- a/config.mk
+++ b/config.mk
@@ -11,12 +11,15 @@ MANPREFIX = $(PREFIX)/share/man
 
 # flags
 CPPFLAGS = -D_DEFAULT_SOURCE
-CFLAGS   = -std=c99 -Os -fPIC -Wall -Wextra -Wpedantic
-LDFLAGS  = -Wl,--soname=libgrapheme.so
+CFLAGS   = -std=c99 -Os -Wall -Wextra -Wpedantic
+LDFLAGS  = -s
 
 BUILD_CPPFLAGS = $(CPPFLAGS)
 BUILD_CFLAGS   = $(CFLAGS)
-BUILD_LDFLAGS  = -s
+BUILD_LDFLAGS  = $(LDFLAGS)
+
+SHFLAGS  = -fPIC
+SOFLAGS  = -shared -Wl,--soname=libgrapheme.so
 
 # tools
 CC       = cc

Reply via email to