[hackers] [libgrapheme] Refactor directory structure and Makefile || Laslo Hunhold

From: <git_AT_suckless.org>
Date: Sat, 17 Oct 2020 20:58:40 +0200 (CEST)

commit fc071310eecb27fe2a469a64a3154c8db514a779
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Sat Oct 17 20:57:52 2020 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Sat Oct 17 20:57:52 2020 +0200

    Refactor directory structure and Makefile
    
    I didn't like it that the test was in the src/-directory and we
    basically did what the C-preprocessor does with an include, which
    is why now, instead of those *_body.c source files, we just include
    the headers of the data we generated, which are now reasonably located
    in data/.
    
    Signed-off-by: Laslo Hunhold <dev_AT_frign.de>

diff --git a/Makefile b/Makefile
index c92c109..af7aa66 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -4,67 +4,66 @@
 
 include config.mk
 
-BIN = src/test
-REQ = src/boundary src/codepoint src/grapheme
-GBP_URL = https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakProperty.txt
-EMO_URL = https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
-GBT_URL = https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakTest.txt
-GBP = data/gbp.txt
-EMO = data/emo.txt
-GBT = data/gbt.txt
+LIB = src/boundary src/codepoint src/grapheme
+TEST = test/test
+DATA = data/gbp data/emo data/gbt
+
 MAN3 = man/grapheme_bytelen.3
 MAN7 = man/libgrapheme.7
 
-all: libgrapheme.a libgrapheme.so $(BIN)
-
-test: src/test
- ./$<
+all: libgrapheme.a libgrapheme.so $(TEST)
 
-src/test: src/test.o $(REQ:=.o)
-
-src/boundary.o: src/boundary.c config.mk grapheme.h
+src/boundary.o: src/boundary.c config.mk data/emo.h data/gbp.h grapheme.h
 src/codepoint.o: src/codepoint.c config.mk grapheme.h
 src/grapheme.o: src/grapheme.c config.mk grapheme.h
-src/test.o: src/test.c config.mk grapheme.h
+test/test.o: test/test.c config.mk data/gbt.h grapheme.h
+
+test/test: test/test.o $(LIB:=.o)
 
-.o:
- $(CC) -o $_AT_ $(LDFLAGS) $< $(REQ:=.o)
+test: $(TEST)
+ for m in $(TEST); do ./$$m; done
+
+$(TEST):
+ $(CC) -o $_AT_ $(LDFLAGS) $< $(LIB:=.o)
 
 .c.o:
         $(CC) -c -o $_AT_ $(CPPFLAGS) $(CFLAGS) $<
 
-libgrapheme.a: $(REQ:=.o)
+libgrapheme.a: $(LIB:=.o)
         $(AR) rc $_AT_ $?
         $(RANLIB) $_AT_
 
-libgrapheme.so: $(REQ:=.o)
+libgrapheme.so: $(LIB:=.o)
         $(CC) -o $_AT_ -shared $?
 
-src/boundary.c: data/gbp.awk $(GBP) data/emo.awk $(EMO) src/boundary_body.c
- printf "/* Automatically generated by gbp.awk and emo.awk */\n" > $_AT_
+data/gbp.h: data/gbp.awk data/gbp.txt
+ printf "/* Automatically generated by gbp.awk */\n" > $_AT_
+ printf "#include <stdint.h>\n\n" >> $_AT_
+ awk -f data/gbp.awk data/gbp.txt >> $_AT_
+ printf "\n" >> $_AT_
+
+data/emo.h: data/emo.awk data/emo.txt
+ printf "/* Automatically generated by emo.awk */\n" > $_AT_
         printf "#include <stdint.h>\n\n" >> $_AT_
- awk -f data/gbp.awk $(GBP) >> $_AT_
- awk -f data/emo.awk $(EMO) >> $_AT_
+ awk -f data/emo.awk data/emo.txt >> $_AT_
         printf "\n" >> $_AT_
- cat src/boundary_body.c >> $_AT_
 
-src/test.c: data/gbt.awk $(GBT) src/test_body.c
+data/gbt.h: data/gbt.awk data/gbt.txt
         printf "/* Automatically generated by gbt.awk */\n" > $_AT_
         printf "#include <stddef.h>\n" >> $_AT_
         printf "#include <stdint.h>\n\n" >> $_AT_
         printf "#include \"../grapheme.h\"\n\n" >> $_AT_
- awk -f data/gbt.awk $(GBT) >> $_AT_
+ awk -f data/gbt.awk data/gbt.txt >> $_AT_
         printf "\n" >> $_AT_
- cat src/test_body.c >> $_AT_
 
-$(GBP):
- wget -O $_AT_ $(GBP_URL)
+data/gbp.txt:
+ wget -O $_AT_ https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakProperty.txt
 
-$(EMO):
- wget -O $_AT_ $(EMO_URL)
+data/emo.txt:
+ wget -O $_AT_ https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
 
-$(GBT):
- wget -O $_AT_ $(GBT_URL)
+data/gbt.txt:
+ wget -O $_AT_ https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakTest.txt
 
 install: all
         mkdir -p "$(DESTDIR)$(LIBPREFIX)"
_AT_@ -85,7 +84,7 @@ uninstall:
         rm -f "$(DESTDIR)$(INCPREFIX)/grapheme.h"
 
 clean:
- rm -f src/boundary.c src/test.c $(REQ:=.o) $(BIN:=.o) $(BIN) libgrapheme.a libgrapheme.so
+ rm -f $(DATA:=.h) $(LIB:=.o) $(TEST:=.o) $(TEST) libgrapheme.a libgrapheme.so
 
 clean-data:
- rm -f $(GBP) $(EMO) $(GBT)
+ rm -f $(DATA:=.txt)
diff --git a/src/boundary_body.c b/src/boundary.c
similarity index 99%
rename from src/boundary_body.c
rename to src/boundary.c
index 3a41215..01724b6 100644
--- a/src/boundary_body.c
+++ b/src/boundary.c
_AT_@ -3,6 +3,9 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#include "../data/emo.h"
+#include "../data/gbp.h"
+
 #define LEN(x) (sizeof(x) / sizeof(*x))
 
 enum {
diff --git a/src/test_body.c b/test/test.c
similarity index 99%
rename from src/test_body.c
rename to test/test.c
index 1d9233d..82613a1 100644
--- a/src/test_body.c
+++ b/test/test.c
_AT_@ -5,6 +5,7 @@
 #include <string.h>
 
 #include "../grapheme.h"
+#include "../data/gbt.h"
 
 #define LEN(x) (sizeof(x) / sizeof(*x))
 
Received on Sat Oct 17 2020 - 20:58:40 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 17 2020 - 21:00:35 CEST