[hackers] [libgrapheme] Port build system to MinGW-W64/Cygwin || Laslo Hunhold

From: <git_AT_suckless.org>
Date: Fri, 24 Feb 2023 18:24:36 +0100 (CET)

commit bfe647805d3456bf847df9fac576fd93c9f2f6c4
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Thu Feb 23 23:16:46 2023 +0100
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Thu Feb 23 23:16:46 2023 +0100

    Port build system to MinGW-W64/Cygwin
    
    This requires the ability to specify executable-suffixes. We trick a
    bit by not diving into the import library madness for MSVC and instead
    act as if we exported the import library "libgrapheme.lib", which
    however is just the static library.
    
    Signed-off-by: Laslo Hunhold <dev_AT_frign.de>

diff --git a/Makefile b/Makefile
index f0561a1..e403bb2 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -109,7 +109,7 @@ MAN3 =\
 MAN7 =\
         man/libgrapheme\
 
-all: data/LICENSE $(MAN3:=.3) $(MAN7:=.7) libgrapheme.a $(SONAME)
+all: data/LICENSE $(MAN3:=.3) $(MAN7:=.7) $(ANAME) $(SONAME)
 
 data/BidiBrackets.txt:
         wget -O $_AT_ https://www.unicode.org/Public/$(UNICODE_VERSION)/ucd/BidiBrackets.txt
_AT_@ -206,44 +206,44 @@ test/utf8-decode.o: test/utf8-decode.c Makefile config.mk grapheme.h test/util.h
 test/util.o: test/util.c Makefile config.mk test/util.h
 test/word.o: test/word.c Makefile config.mk gen/word-test.h grapheme.h test/util.h
 
-benchmark/bidirectional: benchmark/bidirectional.o benchmark/util.o libgrapheme.a
-benchmark/case: benchmark/case.o benchmark/util.o libgrapheme.a
-benchmark/character: benchmark/character.o benchmark/util.o libgrapheme.a
-benchmark/line: benchmark/line.o benchmark/util.o libgrapheme.a
-benchmark/sentence: benchmark/sentence.o benchmark/util.o libgrapheme.a
-benchmark/utf8-decode: benchmark/utf8-decode.o benchmark/util.o libgrapheme.a
-benchmark/word: benchmark/word.o benchmark/util.o libgrapheme.a
-gen/bidirectional: gen/bidirectional.o gen/util.o
-gen/bidirectional-test: gen/bidirectional-test.o gen/util.o
-gen/case: gen/case.o gen/util.o
-gen/character: gen/character.o gen/util.o
-gen/character-test: gen/character-test.o gen/util.o
-gen/line: gen/line.o gen/util.o
-gen/line-test: gen/line-test.o gen/util.o
-gen/sentence: gen/sentence.o gen/util.o
-gen/sentence-test: gen/sentence-test.o gen/util.o
-gen/word: gen/word.o gen/util.o
-gen/word-test: gen/word-test.o gen/util.o
-test/bidirectional: test/bidirectional.o test/util.o libgrapheme.a
-test/case: test/case.o test/util.o libgrapheme.a
-test/character: test/character.o test/util.o libgrapheme.a
-test/line: test/line.o test/util.o libgrapheme.a
-test/sentence: test/sentence.o test/util.o libgrapheme.a
-test/utf8-encode: test/utf8-encode.o test/util.o libgrapheme.a
-test/utf8-decode: test/utf8-decode.o test/util.o libgrapheme.a
-test/word: test/word.o test/util.o libgrapheme.a
-
-gen/bidirectional.h: data/BidiBrackets.txt data/BidiMirroring.txt data/DerivedBidiClass.txt data/UnicodeData.txt gen/bidirectional
-gen/bidirectional-test.h: data/BidiCharacterTest.txt data/BidiTest.txt gen/bidirectional-test
-gen/case.h: data/DerivedCoreProperties.txt data/UnicodeData.txt data/SpecialCasing.txt gen/case
-gen/character.h: data/emoji-data.txt data/GraphemeBreakProperty.txt gen/character
-gen/character-test.h: data/GraphemeBreakTest.txt gen/character-test
-gen/line.h: data/emoji-data.txt data/EastAsianWidth.txt data/LineBreak.txt gen/line
-gen/line-test.h: data/LineBreakTest.txt gen/line-test
-gen/sentence.h: data/SentenceBreakProperty.txt gen/sentence
-gen/sentence-test.h: data/SentenceBreakTest.txt gen/sentence-test
-gen/word.h: data/WordBreakProperty.txt gen/word
-gen/word-test.h: data/WordBreakTest.txt gen/word-test
+benchmark/bidirectional$(BINSUFFIX): benchmark/bidirectional.o benchmark/util.o $(ANAME)
+benchmark/case$(BINSUFFIX): benchmark/case.o benchmark/util.o $(ANAME)
+benchmark/character$(BINSUFFIX): benchmark/character.o benchmark/util.o $(ANAME)
+benchmark/line$(BINSUFFIX): benchmark/line.o benchmark/util.o $(ANAME)
+benchmark/sentence$(BINSUFFIX): benchmark/sentence.o benchmark/util.o $(ANAME)
+benchmark/utf8-decode$(BINSUFFIX): benchmark/utf8-decode.o benchmark/util.o $(ANAME)
+benchmark/word$(BINSUFFIX): benchmark/word.o benchmark/util.o $(ANAME)
+gen/bidirectional$(BINSUFFIX): gen/bidirectional.o gen/util.o
+gen/bidirectional-test$(BINSUFFIX): gen/bidirectional-test.o gen/util.o
+gen/case$(BINSUFFIX): gen/case.o gen/util.o
+gen/character$(BINSUFFIX): gen/character.o gen/util.o
+gen/character-test$(BINSUFFIX): gen/character-test.o gen/util.o
+gen/line$(BINSUFFIX): gen/line.o gen/util.o
+gen/line-test$(BINSUFFIX): gen/line-test.o gen/util.o
+gen/sentence$(BINSUFFIX): gen/sentence.o gen/util.o
+gen/sentence-test$(BINSUFFIX): gen/sentence-test.o gen/util.o
+gen/word$(BINSUFFIX): gen/word.o gen/util.o
+gen/word-test$(BINSUFFIX): gen/word-test.o gen/util.o
+test/bidirectional$(BINSUFFIX): test/bidirectional.o test/util.o $(ANAME)
+test/case$(BINSUFFIX): test/case.o test/util.o $(ANAME)
+test/character$(BINSUFFIX): test/character.o test/util.o $(ANAME)
+test/line$(BINSUFFIX): test/line.o test/util.o $(ANAME)
+test/sentence$(BINSUFFIX): test/sentence.o test/util.o $(ANAME)
+test/utf8-encode$(BINSUFFIX): test/utf8-encode.o test/util.o $(ANAME)
+test/utf8-decode$(BINSUFFIX): test/utf8-decode.o test/util.o $(ANAME)
+test/word$(BINSUFFIX): test/word.o test/util.o $(ANAME)
+
+gen/bidirectional.h: data/BidiBrackets.txt data/BidiMirroring.txt data/DerivedBidiClass.txt data/UnicodeData.txt gen/bidirectional$(BINSUFFIX)
+gen/bidirectional-test.h: data/BidiCharacterTest.txt data/BidiTest.txt gen/bidirectional-test$(BINSUFFIX)
+gen/case.h: data/DerivedCoreProperties.txt data/UnicodeData.txt data/SpecialCasing.txt gen/case$(BINSUFFIX)
+gen/character.h: data/emoji-data.txt data/GraphemeBreakProperty.txt gen/character$(BINSUFFIX)
+gen/character-test.h: data/GraphemeBreakTest.txt gen/character-test$(BINSUFFIX)
+gen/line.h: data/emoji-data.txt data/EastAsianWidth.txt data/LineBreak.txt gen/line$(BINSUFFIX)
+gen/line-test.h: data/LineBreakTest.txt gen/line-test$(BINSUFFIX)
+gen/sentence.h: data/SentenceBreakProperty.txt gen/sentence$(BINSUFFIX)
+gen/sentence-test.h: data/SentenceBreakTest.txt gen/sentence-test$(BINSUFFIX)
+gen/word.h: data/WordBreakProperty.txt gen/word$(BINSUFFIX)
+gen/word-test.h: data/WordBreakTest.txt gen/word-test$(BINSUFFIX)
 
 man/grapheme_is_character_break.3: man/grapheme_is_character_break.sh Makefile config.mk
 man/grapheme_is_uppercase.3: man/grapheme_is_uppercase.sh man/template/is_case.sh Makefile config.mk
_AT_@ -280,19 +280,19 @@ $(BENCHMARK:=.o) benchmark/util.o $(TEST:=.o) test/util.o:
 $(SRC:=.o):
         $(CC) -c -o $_AT_ $(CPPFLAGS) $(CFLAGS) $(SHFLAGS) $(@:.o=.c)
 
-$(BENCHMARK):
- $(CC) -o $_AT_ $(LDFLAGS) $@.o benchmark/util.o libgrapheme.a -lutf8proc
+$(BENCHMARK:=$(BINSUFFIX)):
+ $(CC) -o $_AT_ $(LDFLAGS) $(@:$(BINSUFFIX)=.o) benchmark/util.o $(ANAME) -lutf8proc
 
-$(GEN):
- $(BUILD_CC) -o $_AT_ $(BUILD_LDFLAGS) $@.o gen/util.o
+$(GEN:=$(BINSUFFIX)):
+ $(BUILD_CC) -o $_AT_ $(BUILD_LDFLAGS) $(@:$(BINSUFFIX)=.o) gen/util.o
 
-$(TEST):
- $(CC) -o $_AT_ $(LDFLAGS) $@.o test/util.o libgrapheme.a
+$(TEST:=$(BINSUFFIX)):
+ $(CC) -o $_AT_ $(LDFLAGS) $(@:$(BINSUFFIX)=.o) test/util.o $(ANAME)
 
 $(GEN:=.h):
- $(_AT_:.h=) > $@
+ $(_AT_:.h=$(BINSUFFIX)) > $@
 
-libgrapheme.a: $(SRC:=.o)
+$(ANAME): $(SRC:=.o)
         $(AR) -rc $_AT_ $?
         $(RANLIB) $_AT_
 
_AT_@ -305,13 +305,13 @@ $(MAN3:=.3):
 $(MAN7:=.7):
         SH="$(SH)" MAN_DATE="$(MAN_DATE)" UNICODE_VERSION="$(UNICODE_VERSION)" $(SH) $(_AT_:.7=.sh) > $@
 
-benchmark: $(BENCHMARK)
- for m in $(BENCHMARK); do ./$$m; done
+benchmark: $(BENCHMARK:=$(BINSUFFIX))
+ for m in $(BENCHMARK:=$(BINSUFFIX)); do ./$$m; done
 
 check: test
 
-test: $(TEST)
- for m in $(TEST); do ./$$m; done
+test: $(TEST:=$(BINSUFFIX))
+ for m in $(TEST:=$(BINSUFFIX)); do ./$$m; done
 
 install: all
         mkdir -p "$(DESTDIR)$(LIBPREFIX)"
_AT_@ -320,7 +320,7 @@ install: all
         mkdir -p "$(DESTDIR)$(MANPREFIX)/man7"
         cp -f $(MAN3:=.3) "$(DESTDIR)$(MANPREFIX)/man3"
         cp -f $(MAN7:=.7) "$(DESTDIR)$(MANPREFIX)/man7"
- cp -f libgrapheme.a "$(DESTDIR)$(LIBPREFIX)"
+ cp -f $(ANAME) "$(DESTDIR)$(LIBPREFIX)"
         cp -f $(SONAME) "$(DESTDIR)$(LIBPREFIX)/$(SONAME)"
         if [ "$(SOSYMLINK)" = "true" ]; then i=0; while [ "$$i" -le $(VERSION_MINOR) ]; do ln -sf "$(SONAME)" "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so.$(VERSION_MAJOR).$$i"; i=$$((i+1)); done; fi
         if [ "$(SOSYMLINK)" = "true" ]; then ln -sf "$(SONAME)" "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so.$(VERSION_MAJOR)"; fi
_AT_@ -332,7 +332,7 @@ install: all
 uninstall:
         for m in $(MAN3:=.3); do rm -f "$(DESTDIR)$(MANPREFIX)/man3/`basename $$m`"; done
         for m in $(MAN7:=.7); do rm -f "$(DESTDIR)$(MANPREFIX)/man7/`basename $$m`"; done
- rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.a"
+ rm -f "$(DESTDIR)$(LIBPREFIX)/$(ANAME)"
         rm -f "$(DESTDIR)$(LIBPREFIX)/$(SONAME)"
         if [ "$(SOSYMLINK)" = "true" ]; then i=0; while [ "$$i" -le $(VERSION_MINOR) ]; do rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so.$(VERSION_MAJOR).$$i"; i=$$((i+1)); done; fi
         if [ "$(SOSYMLINK)" = "true" ]; then rm -f "$(DESTDIR)$(LIBPREFIX)/libgrapheme.so.$(VERSION_MAJOR)"; fi
_AT_@ -342,7 +342,7 @@ uninstall:
         if ! [ -z "$(PCPREFIX)" ]; then rm -f "$(DESTDIR)$(PCPREFIX)/libgrapheme.pc"; fi
 
 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 $(SONAME) $(MAN3:=.3) $(MAN7:=.7)
+ rm -f $(BENCHMARK:=.o) benchmark/util.o $(BENCHMARK:=$(BINSUFFIX)) $(GEN:=.h) $(GEN:=.o) gen/util.o $(GEN:=$(BINSUFFIX)) $(SRC:=.o) src/util.o $(TEST:=.o) test/util.o $(TEST:=$(BINSUFFIX)) $(ANAME) $(SONAME) $(MAN3:=.3) $(MAN7:=.7)
 
 clean-data:
         rm -f $(DATA)
diff --git a/config.mk b/config.mk
index 16916d2..5dcc742 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -8,6 +8,11 @@ LIBPREFIX = $(PREFIX)/lib
 MANPREFIX = $(PREFIX)/share/man
 PCPREFIX = $(LIBPREFIX)/pkgconfig
 
+# names
+ANAME = libgrapheme.a
+SONAME = libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
+BINSUFFIX =
+
 # flags
 CPPFLAGS = -D_DEFAULT_SOURCE
 CFLAGS = -std=c99 -Os -Wall -Wextra -Wpedantic
_AT_@ -18,9 +23,7 @@ BUILD_CFLAGS = $(CFLAGS)
 BUILD_LDFLAGS = $(LDFLAGS)
 
 SHFLAGS = -fPIC -ffreestanding
-
 SOFLAGS = -shared -nostdlib -Wl,--soname=libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR)
-SONAME = libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
 SOSYMLINK = true
 
 # tools (unset $LDCONFIG to not call ldconfig(1) after install/uninstall)
diff --git a/configure b/configure
index 0f5e650..685b529 100755
--- a/configure
+++ b/configure
_AT_@ -13,22 +13,36 @@ replace_line()
 case $(uname) in
         DragonFly|FreeBSD|Linux|MidnightBSD|NetBSD)
                 # the default
- replace_line 'SOFLAGS' ' ' '-shared -nostdlib -Wl,--soname=libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR)'
- replace_line 'SONAME' ' ' 'libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)'
- replace_line 'SOSYMLINK' '' 'true'
- replace_line 'LDCONFIG' '' 'ldconfig'
+ replace_line 'ANAME' ' ' 'libgrapheme.a'
+ replace_line 'SONAME' ' ' 'libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)'
+ replace_line 'BINSUFFIX' '' ''
+ replace_line 'SOFLAGS' ' ' '-shared -nostdlib -Wl,--soname=libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR)'
+ replace_line 'SOSYMLINK' '' 'true'
+ replace_line 'LDCONFIG' '' 'ldconfig'
                 ;;
         OpenBSD)
- replace_line 'SOFLAGS' ' ' '-shared -nostdlib'
- replace_line 'SONAME' ' ' 'libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR)'
- replace_line 'SOSYMLINK' '' 'false'
- replace_line 'LDCONFIG' '' ''
+ replace_line 'ANAME' ' ' 'libgrapheme.a'
+ replace_line 'SONAME' ' ' 'libgrapheme.so.$(VERSION_MAJOR).$(VERSION_MINOR)'
+ replace_line 'BINSUFFIX' '' ''
+ replace_line 'SOFLAGS' ' ' '-shared -nostdlib'
+ replace_line 'SOSYMLINK' '' 'false'
+ replace_line 'LDCONFIG' '' ''
                 ;;
         Darwin)
- replace_line 'SOFLAGS' ' ' '-dynamiclib -install_name libgrapheme.$(VERSION_MAJOR).dylib -current_version $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) -compatibility_version $(VERSION_MAJOR).$(VERSION_MINOR).0'
- replace_line 'SONAME' ' ' 'libgrapheme.$(VERSION_MAJOR).dylib'
- replace_line 'SOSYMLINK' '' 'false'
- replace_line 'LDCONFIG' '' ''
+ replace_line 'ANAME' ' ' 'libgrapheme.a'
+ replace_line 'SONAME' ' ' 'libgrapheme.$(VERSION_MAJOR).dylib'
+ replace_line 'BINSUFFIX' '' ''
+ replace_line 'SOFLAGS' ' ' '-dynamiclib -install_name libgrapheme.$(VERSION_MAJOR).dylib -current_version $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) -compatibility_version $(VERSION_MAJOR).$(VERSION_MINOR).0'
+ replace_line 'SOSYMLINK' '' 'false'
+ replace_line 'LDCONFIG' '' ''
+ ;;
+ CYGWIN*|MSYS*|WINGW*)
+ replace_line 'ANAME' ' ' 'libgrapheme.lib'
+ replace_line 'SONAME' ' ' 'libgrapheme.dll'
+ replace_line 'BINSUFFIX' '' '.exe'
+ replace_line 'SOFLAGS' ' ' '-shared'
+ replace_line 'SOSYMLINK' '' 'false'
+ replace_line 'LDCONFIG' '' ''
                 ;;
         *)
                 echo "Your system does not have a preset. Edit config.mk and send a patch please! :)"
Received on Fri Feb 24 2023 - 18:24:36 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 24 2023 - 18:25:01 CET