From 3ed5b1178bdc7081a0112a59785218a4dcbb6870 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 1 Nov 2021 12:45:12 +0300 Subject: [PATCH] Refactor C-code building, use pkgconf --- all.do | 2 +- cmd/.gitignore | 1 - cmd/enzstd/.gitignore | 1 - cmd/enzstd/README | 4 ---- cmd/enzstd/compile_flags.txt.do | 1 - cmd/enzstd/enzstd.do | 3 --- cmd/unzstd/.gitignore | 1 - cmd/unzstd/compile_flags.txt.do | 1 - cmd/unzstd/unzstd.do | 3 --- cmd/zstd/.gitignore | 3 +++ cmd/zstd/README | 11 +++++++++++ cmd/zstd/all.do | 1 + cmd/zstd/compile_flags.txt.do | 5 +++++ cmd/zstd/conf/.gitignore | 1 + cmd/zstd/conf/pkgconf.rc.do | 1 + cmd/zstd/conf/zstd.cflags.rc.do | 3 +++ cmd/zstd/conf/zstd.libs.rc.do | 3 +++ cmd/zstd/default.do | 5 +++++ cmd/{enzstd => zstd}/enzstd.c | 0 cmd/{unzstd => zstd}/unzstd.c | 0 default.cmd.do | 6 ++++-- doc/warcs.texi | 6 ++---- warc/open.go | 2 +- 23 files changed, 41 insertions(+), 23 deletions(-) delete mode 100644 cmd/.gitignore delete mode 100644 cmd/enzstd/.gitignore delete mode 100644 cmd/enzstd/README delete mode 120000 cmd/enzstd/compile_flags.txt.do delete mode 100644 cmd/enzstd/enzstd.do delete mode 100644 cmd/unzstd/.gitignore delete mode 100644 cmd/unzstd/compile_flags.txt.do delete mode 100644 cmd/unzstd/unzstd.do create mode 100644 cmd/zstd/.gitignore create mode 100644 cmd/zstd/README create mode 100644 cmd/zstd/all.do create mode 100644 cmd/zstd/compile_flags.txt.do create mode 100644 cmd/zstd/conf/.gitignore create mode 100644 cmd/zstd/conf/pkgconf.rc.do create mode 100644 cmd/zstd/conf/zstd.cflags.rc.do create mode 100644 cmd/zstd/conf/zstd.libs.rc.do create mode 100644 cmd/zstd/default.do rename cmd/{enzstd => zstd}/enzstd.c (100%) rename cmd/{unzstd => zstd}/unzstd.c (100%) diff --git a/all.do b/all.do index c4a5702..4f7b66f 100644 --- a/all.do +++ b/all.do @@ -1,2 +1,2 @@ -redo-ifchange cert.pem tofuproxy.cmd fifos/ensure cmd/unzstd/unzstd +redo-ifchange cert.pem tofuproxy.cmd fifos/ensure cmd/zstd/unzstd mkdir -p certs ccerts diff --git a/cmd/.gitignore b/cmd/.gitignore deleted file mode 100644 index 895dab3..0000000 --- a/cmd/.gitignore +++ /dev/null @@ -1 +0,0 @@ -compile_flags.txt diff --git a/cmd/enzstd/.gitignore b/cmd/enzstd/.gitignore deleted file mode 100644 index 6fcec77..0000000 --- a/cmd/enzstd/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/enzstd diff --git a/cmd/enzstd/README b/cmd/enzstd/README deleted file mode 100644 index ca20ab6..0000000 --- a/cmd/enzstd/README +++ /dev/null @@ -1,4 +0,0 @@ -enzstd creates Zstandard compressed stream of frames, where each frame -holds exactly single WARC record. It also explicitly adds checksum. -Utility takes records from stdin, where each record has 64-bit -big-endian length prefix. diff --git a/cmd/enzstd/compile_flags.txt.do b/cmd/enzstd/compile_flags.txt.do deleted file mode 120000 index 0f4f6ff..0000000 --- a/cmd/enzstd/compile_flags.txt.do +++ /dev/null @@ -1 +0,0 @@ -../unzstd/compile_flags.txt.do \ No newline at end of file diff --git a/cmd/enzstd/enzstd.do b/cmd/enzstd/enzstd.do deleted file mode 100644 index c381e4e..0000000 --- a/cmd/enzstd/enzstd.do +++ /dev/null @@ -1,3 +0,0 @@ -src=enzstd.c -redo-ifchange $src -${CC:-cc} ${CFLAGS} -o $3 $src $LDFLAGS -lzstd diff --git a/cmd/unzstd/.gitignore b/cmd/unzstd/.gitignore deleted file mode 100644 index f2358dc..0000000 --- a/cmd/unzstd/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/unzstd diff --git a/cmd/unzstd/compile_flags.txt.do b/cmd/unzstd/compile_flags.txt.do deleted file mode 100644 index 13b13f1..0000000 --- a/cmd/unzstd/compile_flags.txt.do +++ /dev/null @@ -1 +0,0 @@ -printf "%s" "$CFLAGS $LDFLAGS" | tr " " "\n" | grep -v "^$" | sort | uniq diff --git a/cmd/unzstd/unzstd.do b/cmd/unzstd/unzstd.do deleted file mode 100644 index 8b50f9f..0000000 --- a/cmd/unzstd/unzstd.do +++ /dev/null @@ -1,3 +0,0 @@ -src=unzstd.c -redo-ifchange $src -${CC:-cc} ${CFLAGS} -o $3 $src $LDFLAGS -lzstd diff --git a/cmd/zstd/.gitignore b/cmd/zstd/.gitignore new file mode 100644 index 0000000..06ed646 --- /dev/null +++ b/cmd/zstd/.gitignore @@ -0,0 +1,3 @@ +/compile_flags.txt +/enzstd +/unzstd diff --git a/cmd/zstd/README b/cmd/zstd/README new file mode 100644 index 0000000..7a1612c --- /dev/null +++ b/cmd/zstd/README @@ -0,0 +1,11 @@ +enzstd creates Zstandard compressed stream of frames, where each frame +holds exactly single WARC record. It also explicitly adds checksum. +Utility takes records from stdin, where each record has 64-bit +big-endian length prefix. + +unzstd decompressed Zstandard frames stream from stdin to stdout. If +stream starts with the dictionary (either compressed, or uncompressed) +it is loaded first. If 3rd file descriptor is opened, then each frame's +offset (its size) with decompressed data size is printed in +tab-separated format. If the stream contains dictionary, then first +frame's data size equals to zero. diff --git a/cmd/zstd/all.do b/cmd/zstd/all.do new file mode 100644 index 0000000..aac1e34 --- /dev/null +++ b/cmd/zstd/all.do @@ -0,0 +1 @@ +redo-ifchange enzstd unzstd diff --git a/cmd/zstd/compile_flags.txt.do b/cmd/zstd/compile_flags.txt.do new file mode 100644 index 0000000..d07460a --- /dev/null +++ b/cmd/zstd/compile_flags.txt.do @@ -0,0 +1,5 @@ +redo-ifchange $src conf/zstd.cflags.rc conf/zstd.libs.rc +read ZSTD_CFLAGS < conf/zstd.cflags.rc +read ZSTD_LIBS < conf/zstd.libs.rc +printf "%s" "$CFLAGS $ZSTD_CFLAGS $LDFLAGS $ZSTD_LIBS" | + tr " " "\n" | grep -v "^$" | sort | uniq diff --git a/cmd/zstd/conf/.gitignore b/cmd/zstd/conf/.gitignore new file mode 100644 index 0000000..27f2869 --- /dev/null +++ b/cmd/zstd/conf/.gitignore @@ -0,0 +1 @@ +/*.rc diff --git a/cmd/zstd/conf/pkgconf.rc.do b/cmd/zstd/conf/pkgconf.rc.do new file mode 100644 index 0000000..5b57e6e --- /dev/null +++ b/cmd/zstd/conf/pkgconf.rc.do @@ -0,0 +1 @@ +echo ${PKGCONF:-`command -v pkgconf || command -v pkg-config`} diff --git a/cmd/zstd/conf/zstd.cflags.rc.do b/cmd/zstd/conf/zstd.cflags.rc.do new file mode 100644 index 0000000..2dcf2b2 --- /dev/null +++ b/cmd/zstd/conf/zstd.cflags.rc.do @@ -0,0 +1,3 @@ +redo-ifchange pkgconf.rc +read PKGCONF < pkgconf.rc +$PKGCONF --cflags libzstd diff --git a/cmd/zstd/conf/zstd.libs.rc.do b/cmd/zstd/conf/zstd.libs.rc.do new file mode 100644 index 0000000..d9b1fb7 --- /dev/null +++ b/cmd/zstd/conf/zstd.libs.rc.do @@ -0,0 +1,3 @@ +redo-ifchange pkgconf.rc +read PKGCONF < pkgconf.rc +$PKGCONF --libs libzstd diff --git a/cmd/zstd/default.do b/cmd/zstd/default.do new file mode 100644 index 0000000..387fbb5 --- /dev/null +++ b/cmd/zstd/default.do @@ -0,0 +1,5 @@ +src=$1.c +redo-ifchange $src conf/zstd.cflags.rc conf/zstd.libs.rc +read ZSTD_CFLAGS < conf/zstd.cflags.rc +read ZSTD_LIBS < conf/zstd.libs.rc +${CC:-cc} $CFLAGS $ZSTD_CFLAGS -o $3 $src $ZSTD_LIBS diff --git a/cmd/enzstd/enzstd.c b/cmd/zstd/enzstd.c similarity index 100% rename from cmd/enzstd/enzstd.c rename to cmd/zstd/enzstd.c diff --git a/cmd/unzstd/unzstd.c b/cmd/zstd/unzstd.c similarity index 100% rename from cmd/unzstd/unzstd.c rename to cmd/zstd/unzstd.c diff --git a/default.cmd.do b/default.cmd.do index c2ee005..97e1502 100644 --- a/default.cmd.do +++ b/default.cmd.do @@ -6,5 +6,7 @@ redo-ifchange \ rounds/*.go \ tls/*.go \ warc/*.go -GO_LDFLAGS="${GO_LDFLAGS:--ldflags=-s}" -${GO:-go} build -o $3 $GO_LDFLAGS ./cmd/${1%.cmd} +UNZSTD_PATH="`pwd`/cmd/zstd/unzstd" +GO_LDFLAGS="${GO_LDFLAGS:--s}" +GO_LDFLAGS="$GO_LDFLAGS -X go.stargrave.org/tofuproxy/warc.UnZSTDPath=$UNZSTD_PATH" +${GO:-go} build -o $3 -ldflags="$GO_LDFLAGS" ./cmd/${1%.cmd} diff --git a/doc/warcs.texi b/doc/warcs.texi index b20b120..a88cde4 100644 --- a/doc/warcs.texi +++ b/doc/warcs.texi @@ -24,13 +24,11 @@ Zstandard compressed WARC, as in Multi-frame format is properly indexed. Dictionary at the beginning is also supported. -It is processed with with @command{unzstd} (@file{cmd/unzstd/unzstd}) +It is processed with with @command{unzstd} (@file{cmd/zstd/unzstd}) utility. It eats compressed stream from @code{stdin}, outputs decompressed data to @code{stdout}, and prints each frame size with corresponding decompressed data size to 3rd file descriptor (if it is -opened). You can adjust path to it with -@code{-X go.stargrave.org/tofuproxy/warc.UnZSTDPath} command line option -during building. +opened). @end table diff --git a/warc/open.go b/warc/open.go index e742f9e..ade3079 100644 --- a/warc/open.go +++ b/warc/open.go @@ -24,7 +24,7 @@ import ( "path" ) -var UnZSTDPath = "/home/stargrave/work/tofuproxy/cmd/unzstd/unzstd" +var UnZSTDPath = "/home/stargrave/work/tofuproxy/cmd/zstd/unzstd" type Offset struct { Z int64 // Compressed frame size -- 2.44.0