Enhance build-system to perfectly support OpenBSD and macOS - libgrapheme - uni… | |
git clone git://git.suckless.org/libgrapheme | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit a6b3a194f0381c5aef9346d39b02eb058111d2a2 | |
parent d42f53b5baafe01caa48477e204b63e065660117 | |
Author: Laslo Hunhold <[email protected]> | |
Date: Sat, 8 Oct 2022 10:40:03 +0200 | |
Enhance build-system to perfectly support OpenBSD and macOS | |
Studying the source material on OpenBSD[0], it is written that | |
Quite a few ports need tweaks to build shared libraries correctly | |
anyways. Remember that building shared libraries should be done with | |
$ cc -shared -fpic|-fPIC -o libfoo.so.4.5 obj1 obj2 | |
Trying to rename the library after the fact to adjust the version | |
number does not work: ELF libraries use some extra magic to set the | |
library internal name, so you must link it with the correct version | |
the first time. | |
Thus, it is necessary to directly compile into $(SONAME), which is | |
changed to in this commit. | |
The magic flags for macOS were taken from [1]. It sets up the linker | |
such that it automatically respects semantic versioning and will load | |
any library with a smaller compatible version (e.g. same minor-version). | |
Additionally, both OpenBSD and macOS have smarter linkers than Linux | |
and don't need symlinks from varying versions to work right. Thus a | |
flag SOSYMLINK was added to enable toggling this from the config.mk. | |
For convenience, the best-practices for each platform are added to | |
the config.mk in a commented-out form, saving everybody some time. | |
[0]:https://www.openbsd.org/faq/ports/specialtopics.html#SharedLibs | |
[1]:https://begriffs.com/posts/2021-07-04-shared-libraries.html#linking | |
Signed-off-by: Laslo Hunhold <[email protected]> | |
Diffstat: | |
M Makefile | 22 +++++++++++----------- | |
M config.mk | 19 +++++++++++++++++-- | |
2 files changed, 28 insertions(+), 13 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
@@ -99,7 +99,7 @@ MAN3 =\ | |
MAN7 =\ | |
man/libgrapheme\ | |
-all: data/LICENSE $(MAN3:=.3) $(MAN7:=.7) libgrapheme.a libgrapheme.so | |
+all: data/LICENSE $(MAN3:=.3) $(MAN7:=.7) libgrapheme.a $(SONAME) | |
data/DerivedCoreProperties.txt: | |
wget -O $@ https://www.unicode.org/Public/$(UNICODE_VERSION)/ucd/Deriv… | |
@@ -260,7 +260,7 @@ libgrapheme.a: $(SRC:=.o) | |
$(AR) -rc $@ $? | |
$(RANLIB) $@ | |
-libgrapheme.so: $(SRC:=.o) | |
+$(SONAME): $(SRC:=.o) | |
$(CC) -o $@ $(SOFLAGS) $(LDFLAGS) $(SRC:=.o) | |
$(MAN3:=.3): | |
@@ -283,10 +283,10 @@ install: all | |
cp -f $(MAN3:=.3) "$(DESTDIR)$(MANPREFIX)/man3" | |
cp -f $(MAN7:=.7) "$(DESTDIR)$(MANPREFIX)/man7" | |
cp -f libgrapheme.a "$(DESTDIR)$(LIBPREFIX)" | |
- cp -f libgrapheme.so "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so.$(VERSION)" | |
- i=0; while [ "$$i" -le $(VERSION_MINOR) ]; do ln -sf "libgrapheme.so.$… | |
- ln -sf "libgrapheme.so.$(VERSION)" "$(DESTDIR)$(LIBPREFIX)/libgrapheme… | |
- ln -sf "libgrapheme.so.$(VERSION)" "$(DESTDIR)$(LIBPREFIX)/libgrapheme… | |
+ cp -f $(SONAME) "$(DESTDIR)$(LIBPREFIX)/$(SONAME)" | |
+ if [ "$(SOSYMLINK)" = "true" ]; then i=0; while [ "$$i" -le $(VERSION_… | |
+ if [ "$(SOSYMLINK)" = "true" ]; then ln -sf "$(SONAME)" "$(DESTDIR)$(L… | |
+ if [ "$(SOSYMLINK)" = "true" ]; then ln -sf "$(SONAME)" "$(DESTDIR)$(L… | |
cp -f grapheme.h "$(DESTDIR)$(INCPREFIX)" | |
$(LDCONFIG) | |
@@ -294,15 +294,15 @@ uninstall: | |
for m in $(MAN3:=.3); do rm -f "$(DESTDIR)$(MANPREFIX)/man3/`basename … | |
for m in $(MAN7:=.7); do rm -f "$(DESTDIR)$(MANPREFIX)/man7/`basename … | |
rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.a" | |
- rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so.$(VERSION)" | |
- i=0; while [ "$$i" -le $(VERSION_MINOR) ]; do rm -f "$(DESTDIR)$(LIBPR… | |
- rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so.$(VERSION_MAJOR)" | |
- rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so" | |
+ rm -f "$(DESTDIR)$(LIBPREFIX)/$(SONAME)" | |
+ if [ "$(SOSYMLINK)" = "true" ]; then i=0; while [ "$$i" -le $(VERSION_… | |
+ if [ "$(SOSYMLINK)" = "true" ]; then rm -f "$(DESTDIR)$(LIBPREFIX)/lib… | |
+ if [ "$(SOSYMLINK)" = "true" ]; then rm -f "$(DESTDIR)$(LIBPREFIX)/lib… | |
rm -f "$(DESTDIR)$(INCPREFIX)/grapheme.h" | |
$(LDCONFIG) | |
clean: | |
- rm -f $(BENCHMARK:=.o) benchmark/util.o $(BENCHMARK) $(GEN:=.h) $(GEN:… | |
+ rm -f $(BENCHMARK:=.o) benchmark/util.o $(BENCHMARK) $(GEN:=.h) $(GEN:… | |
clean-data: | |
rm -f $(DATA) | |
diff --git a/config.mk b/config.mk | |
@@ -15,8 +15,23 @@ BUILD_CPPFLAGS = $(CPPFLAGS) | |
BUILD_CFLAGS = $(CFLAGS) | |
BUILD_LDFLAGS = $(LDFLAGS) | |
-SHFLAGS = -fPIC -ffreestanding | |
-SOFLAGS = -shared -nostdlib -Wl,--soname=libgrapheme.so.$(VERSION_MAJOR).$(VE… | |
+SHFLAGS = -fPIC -ffreestanding | |
+ | |
+SOFLAGS = -shared -nostdlib -Wl,--soname=libgrapheme.so.$(VERSION_MAJOR).$(V… | |
+SONAME = libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) | |
+SOSYMLINK = true | |
+ | |
+# -- OpenBSD -- (also unset LDCONFIG) | |
+# SOFLAGS = -shared -nostdlib | |
+# SONAME = libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR) | |
+# SOSYMLINK = false | |
+ | |
+# -- macOS -- (also unset LDCONFIG) | |
+# SOFLAGS = -dynamiclib -install_name "libgrapheme.$(VERSION_MAJOR).dylib" \ | |
+# -current_version "$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PA… | |
+# -compatibility_version "$(VERSION_MAJOR).$(VERSION_MINOR).0" | |
+# SONAME = libgrapheme.$(VERSION_MAJOR).dylib | |
+# SOSYMLINK = false | |
# tools | |
CC = cc |