commit fc071310eecb27fe2a469a64a3154c8db514a779
Author:     Laslo Hunhold <[email protected]>
AuthorDate: Sat Oct 17 20:57:52 2020 +0200
Commit:     Laslo Hunhold <[email protected]>
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 <[email protected]>

diff --git a/Makefile b/Makefile
index c92c109..af7aa66 100644
--- a/Makefile
+++ b/Makefile
@@ -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 $@ $(LDFLAGS) $< $(REQ:=.o)
+test: $(TEST)
+       for m in $(TEST); do ./$$m; done
+
+$(TEST):
+       $(CC) -o $@ $(LDFLAGS) $< $(LIB:=.o)
 
 .c.o:
        $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
 
-libgrapheme.a: $(REQ:=.o)
+libgrapheme.a: $(LIB:=.o)
        $(AR) rc $@ $?
        $(RANLIB) $@
 
-libgrapheme.so: $(REQ:=.o)
+libgrapheme.so: $(LIB:=.o)
        $(CC) -o $@ -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" > $@
+data/gbp.h: data/gbp.awk data/gbp.txt
+       printf "/* Automatically generated by gbp.awk */\n" > $@
+       printf "#include <stdint.h>\n\n" >> $@
+       awk -f data/gbp.awk data/gbp.txt >> $@
+       printf "\n" >> $@
+
+data/emo.h: data/emo.awk data/emo.txt
+       printf "/* Automatically generated by emo.awk */\n" > $@
        printf "#include <stdint.h>\n\n" >> $@
-       awk -f data/gbp.awk $(GBP) >> $@
-       awk -f data/emo.awk $(EMO) >> $@
+       awk -f data/emo.awk data/emo.txt >> $@
        printf "\n" >> $@
-       cat src/boundary_body.c >> $@
 
-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" > $@
        printf "#include <stddef.h>\n" >> $@
        printf "#include <stdint.h>\n\n" >> $@
        printf "#include \"../grapheme.h\"\n\n" >> $@
-       awk -f data/gbt.awk $(GBT) >> $@
+       awk -f data/gbt.awk data/gbt.txt >> $@
        printf "\n" >> $@
-       cat src/test_body.c >> $@
 
-$(GBP):
-       wget -O $@ $(GBP_URL)
+data/gbp.txt:
+       wget -O $@ 
https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakProperty.txt
 
-$(EMO):
-       wget -O $@ $(EMO_URL)
+data/emo.txt:
+       wget -O $@ 
https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
 
-$(GBT):
-       wget -O $@ $(GBT_URL)
+data/gbt.txt:
+       wget -O $@ 
https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakTest.txt
 
 install: all
        mkdir -p "$(DESTDIR)$(LIBPREFIX)"
@@ -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
@@ -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
@@ -5,6 +5,7 @@
 #include <string.h>
 
 #include "../grapheme.h"
+#include "../data/gbt.h"
 
 #define LEN(x) (sizeof(x) / sizeof(*x))
 

Reply via email to