commit 74c77bfd9932535d4b7a0a7d7cc7447164ead0d5
parent 497b500df21812b49729ff9514dd81dac29ec940
Author: Laslo Hunhold <dev@frign.de>
Date: Wed, 15 Dec 2021 12:53:48 +0100
Refactor Makefile, add dist-target and add test-util
All targets were checked and amended, if necessary. A new dist-target
was added to quickly create a tarball.
For the test-programs, given code-duplication, util.h and util.c
were added.
Signed-off-by: Laslo Hunhold <dev@frign.de>
Diffstat:
7 files changed, 72 insertions(+), 33 deletions(-)
diff --git a/Makefile b/Makefile
@@ -8,11 +8,21 @@ DATA =\
data/emoji-data.txt\
data/GraphemeBreakProperty.txt\
data/GraphemeBreakTest.txt
-GEN = gen/grapheme gen/grapheme-test
-LIB = src/grapheme src/utf8 src/util
-TEST = test/grapheme test/grapheme-performance test/utf8-decode test/utf8-encode
-
-MAN3 = man/lg_grapheme_isbreak.3 man/lg_grapheme_nextbreak.3
+GEN =\
+ gen/grapheme\
+ gen/grapheme-test
+SRC =\
+ src/grapheme\
+ src/utf8\
+ src/util
+TEST =\
+ test/grapheme\
+ test/grapheme-performance\
+ test/utf8-decode\
+ test/utf8-encode
+MAN3 =\
+ man/lg_grapheme_isbreak.3\
+ man/lg_grapheme_nextbreak.3
MAN7 = man/libgrapheme.7
all: libgrapheme.a libgrapheme.so
@@ -20,20 +30,21 @@ all: libgrapheme.a libgrapheme.so
gen/grapheme.o: gen/grapheme.c config.mk gen/util.h
gen/grapheme-test.o: gen/grapheme-test.c config.mk gen/util.h
gen/util.o: gen/util.c config.mk gen/util.h
-src/utf8.o: src/utf8.c config.mk grapheme.h
src/grapheme.o: src/grapheme.c config.mk gen/grapheme.h grapheme.h src/util.h
-src/util.o: src/util.c config.mk src/util.h
-test/grapheme.o: test/grapheme.c config.mk gen/grapheme-test.h grapheme.h
-test/grapheme-performance.o: test/grapheme-performance.c config.mk gen/grapheme-test.h grapheme.h
-test/utf8-encode.o: test/utf8-encode.c config.mk grapheme.h
-test/utf8-decode.o: test/utf8-decode.c config.mk grapheme.h
+src/utf8.o: src/utf8.c config.mk grapheme.h
+src/util.o: src/util.c config.mk grapheme.h src/util.h
+test/grapheme.o: test/grapheme.c config.mk gen/grapheme-test.h grapheme.h test/util.h
+test/grapheme-performance.o: test/grapheme-performance.c config.mk gen/grapheme-test.h grapheme.h test/util.h
+test/utf8-encode.o: test/utf8-encode.c config.mk grapheme.h test/util.h
+test/utf8-decode.o: test/utf8-decode.c config.mk grapheme.h test/util.h
+test/util.o: test/util.c config.mk test/util.h
gen/grapheme: gen/grapheme.o gen/util.o
gen/grapheme-test: gen/grapheme-test.o gen/util.o
-test/grapheme: test/grapheme.o libgrapheme.a
-test/grapheme-performance: test/grapheme-performance.o libgrapheme.a
-test/utf8-encode: test/utf8-encode.o libgrapheme.a
-test/utf8-decode: test/utf8-decode.o libgrapheme.a
+test/grapheme: test/grapheme.o test/util.o libgrapheme.a
+test/grapheme-performance: test/grapheme-performance.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
gen/grapheme.h: data/emoji-data.txt data/GraphemeBreakProperty.txt gen/grapheme
gen/grapheme-test.h: data/GraphemeBreakTest.txt gen/grapheme-test
@@ -54,16 +65,16 @@ $(GEN:=.h):
$(@:.h=) > $@
$(TEST):
- $(CC) -o $@ $(LDFLAGS) $@.o libgrapheme.a
+ $(CC) -o $@ $(LDFLAGS) $@.o test/util.o libgrapheme.a
.c.o:
$(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
-libgrapheme.a: $(LIB:=.o)
+libgrapheme.a: $(SRC:=.o)
$(AR) rc $@ $?
$(RANLIB) $@
-libgrapheme.so: $(LIB:=.o)
+libgrapheme.so: $(SRC:=.o)
$(CC) -o $@ -shared $?
test: $(TEST)
@@ -88,7 +99,23 @@ uninstall:
rm -f "$(DESTDIR)$(INCPREFIX)/grapheme.h"
clean:
- rm -f $(GEN:=.h) $(GEN:=.o) $(GEN) gen/util.o $(LIB:=.o) $(TEST:=.o) $(TEST) libgrapheme.a libgrapheme.so
+ rm -f $(GEN:=.h) $(GEN:=.o) $(GEN) gen/util.o $(SRC:=.o) src/util.o \
+ $(TEST:=.o) test/util.o $(TEST) libgrapheme.a libgrapheme.so
clean-data:
rm -f $(DATA)
+
+dist:
+ mkdir libgrapheme-$(VERSION) libgrapheme-$(VERSION)/data\
+ libgrapheme-$(VERSION)/gen libgrapheme-$(VERSION)/man\
+ libgrapheme-$(VERSION)/src libgrapheme-$(VERSION)/test
+ cp config.mk grapheme.h LICENSE Makefile libgrapheme-$(VERSION)
+ cp $(DATA) libgrapheme-$(VERSION)/data
+ cp $(GEN:=.c) gen/util.c gen/util.h libgrapheme-$(VERSION)/gen
+ cp $(MAN3) $(MAN7) libgrapheme-$(VERSION)/man
+ cp $(SRC:=.c) src/util.h libgrapheme-$(VERSION)/src
+ cp $(TEST:=.c) test/util.c test/util.h libgrapheme-$(VERSION)/test
+ tar -cf libgrapheme-$(VERSION).tar libgrapheme-$(VERSION)
+ rm -rf libgrapheme-$(VERSION)
+
+.PHONY: all test install uninstall clean dist
diff --git a/test/grapheme-performance.c b/test/grapheme-performance.c
@@ -7,17 +7,10 @@
#include "../grapheme.h"
#include "../gen/grapheme-test.h"
+#include "util.h"
-#define LEN(x) (sizeof(x) / sizeof(*(x)))
#define NUM_ITERATIONS 1000
-static double
-time_diff(struct timespec *a, struct timespec *b)
-{
- return (double)(b->tv_sec - a->tv_sec) +
- (double)(b->tv_nsec - a->tv_nsec) * 1E-9;
-}
-
int
main(int argc, char *argv[])
{
diff --git a/test/grapheme.c b/test/grapheme.c
@@ -6,8 +6,7 @@
#include "../grapheme.h"
#include "../gen/grapheme-test.h"
-
-#define LEN(x) (sizeof(x) / sizeof(*(x)))
+#include "util.h"
int
main(int argc, char *argv[])
diff --git a/test/utf8-decode.c b/test/utf8-decode.c
@@ -5,8 +5,7 @@
#include <string.h>
#include "../grapheme.h"
-
-#define LEN(x) (sizeof(x) / sizeof(*(x)))
+#include "util.h"
static const struct {
uint8_t *arr; /* UTF-8 byte sequence */
diff --git a/test/utf8-encode.c b/test/utf8-encode.c
@@ -5,8 +5,7 @@
#include <string.h>
#include "../grapheme.h"
-
-#define LEN(x) (sizeof(x) / sizeof(*(x)))
+#include "util.h"
static const struct {
uint_least32_t cp; /* input code point */
diff --git a/test/util.c b/test/util.c
@@ -0,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+#include <time.h>
+
+#include "util.h"
+
+double
+time_diff(struct timespec *a, struct timespec *b)
+{
+ return (double)(b->tv_sec - a->tv_sec) +
+ (double)(b->tv_nsec - a->tv_nsec) * 1E-9;
+}
diff --git a/test/util.h b/test/util.h
@@ -0,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <time.h>
+
+#define LEN(x) (sizeof(x) / sizeof(*(x)))
+
+double time_diff(struct timespec *, struct timespec *);
+
+#endif /* UTIL_H */