aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-12-20 08:13:57 +0000
committermerakor <cem@ckyln.com>2020-12-20 08:13:57 +0000
commitc72c2cc00b2a9e2c7ce7ba0ff22908c209f24822 (patch)
tree8123704477175ed413e61bf79816605557c5f5a1
parent707b6cd4aaa6990349c6693fe2dff140b74370d5 (diff)
downloadcpt-c72c2cc00b2a9e2c7ce7ba0ff22908c209f24822.tar.gz
try out the redo build system
FossilOrigin-Name: 6ca0330a7e548be4e516ad6c275b2878a1521d2de5263fd75defc16f8f52c93b
-rw-r--r--.gitignore11
-rw-r--r--all.do2
-rw-r--r--bin/all.do2
-rw-r--r--bin/clean.do2
-rw-r--r--clean.do5
-rw-r--r--config.rc66
-rw-r--r--default.do42
-rw-r--r--dist.do3
8 files changed, 132 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 6a09127..a4f8bc0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,13 @@ getopt
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
-[._]sw[a-p] \ No newline at end of file
+[._]sw[a-p]
+
+### Redo files
+/.redo
+/.do_built
+/.do_built.dir
+*.tmp
+*.did
+.dep*
+.target*
diff --git a/all.do b/all.do
new file mode 100644
index 0000000..60dfc91
--- /dev/null
+++ b/all.do
@@ -0,0 +1,2 @@
+. ./config.rc
+redo-ifchange bin/all doc/cpt.info
diff --git a/bin/all.do b/bin/all.do
new file mode 100644
index 0000000..aceda74
--- /dev/null
+++ b/bin/all.do
@@ -0,0 +1,2 @@
+. ../config.rc
+redo-ifchange cpt-readlink cpt-stat
diff --git a/bin/clean.do b/bin/clean.do
new file mode 100644
index 0000000..6234248
--- /dev/null
+++ b/bin/clean.do
@@ -0,0 +1,2 @@
+. ../config.rc
+rm -f -- ./*.o cpt-readlink cpt-stat .dep.*
diff --git a/clean.do b/clean.do
new file mode 100644
index 0000000..389daf3
--- /dev/null
+++ b/clean.do
@@ -0,0 +1,5 @@
+. ./config.rc
+redo bin/clean
+redo_clean
+rm -f "cpt-$VERSION.tar.xz"
+find doc -name '*.info' -exec rm -f -- {} +
diff --git a/config.rc b/config.rc
new file mode 100644
index 0000000..d1b2281
--- /dev/null
+++ b/config.rc
@@ -0,0 +1,66 @@
+# -*- mode: redo -*-
+# See LICENSE for copyright information
+
+setv() {
+ # Set variables if unset. Works similar to the Makefile syntax.
+ [ "$3" ] || {
+ printf '%s\n' "Faulty variable syntax" >&2
+ exit 1
+ }
+ var=$1; sym=$2; shift 2
+ case "$sym" in
+ \?=|=) eval "[ \"\$$var\" ]" || export "$var=$*" ;;
+ +=) eval "export \"$var=\$$var $*\""
+ esac
+}
+
+redo_clean() {
+ # Clean function for various redo implementations
+ [ -r .do_built ] && {
+ while read -r file; do
+ [ -d "$file" ] || rm -f "$file"
+ done < .do_built
+ }
+ find . -type f \( -name '*.tmp' -o -name '*.did' -o -name '.dep*' -o -name '.target*' \) \
+ -exec rm -f -- {} +
+ [ "$DO_BUILT" ] || find . -name '.do_built*' -exec rm -rf -- {} +
+ [ "$REDO_BASE" ] || rm -rf -- .redo
+}
+
+PHONY() {
+ # Function that resembles the .PHONY: target on the classic 'make' build
+ # system.
+ [ "$1" ] || {
+ trap 'rm -f $3' EXIT INT
+ return 0
+ }
+ setv PHONY += "$@"
+ trap 'case " $PHONY " in *" $1 "*) rm -f $3; esac' EXIT INT
+}
+
+setv VERSION = 5.1.0
+
+# Paths
+setv PREFIX = /usr/local
+setv BINDIR = "${PREFIX}/bin"
+setv SHAREDIR = "${PREFIX}/share"
+setv DOCDIR = "${SHAREDIR}/doc"
+setv CPTDOC = "${DOCDIR}/cpt"
+setv MANPREFIX = "${SHAREDIR}/man"
+setv MAN1 = "${MANPREFIX}/man1"
+
+# Flags
+setv CFLAGS = -std=c99 -Wpedantic -Wall -Os
+setv CFLAGS += -D_XOPEN_SOURCE=700
+setv LDFLAGS = -s -static
+setv LIBS = -lc
+
+setv CC = cc
+setv LD = "${CC}"
+
+# Documentation tools
+setv EMACS = emacs
+setv MAKEINFO = makeinfo
+
+# Phony targets
+PHONY all dist clean install uninstall test
diff --git a/default.do b/default.do
new file mode 100644
index 0000000..2d091c6
--- /dev/null
+++ b/default.do
@@ -0,0 +1,42 @@
+. ./config.rc
+
+# Extensionless name of file
+fn="${1%.*}"
+
+case "$1" in
+ bin/cpt-readlink|bin/cpt-stat)
+ redo-ifchange "$1.o"
+ "$CC" -o "$3" $LDFLAGS "$1.o" $LIBS
+ ;;
+ *.o)
+ [ -f "${1%.o}.c" ] || exit 99
+ redo-ifchange "$fn.c"
+ "$CC" -c -o "$3" $CFLAGS "$fn.c"
+ ;;
+ *.info)
+ redo-ifchange "$fn.texi"
+ $MAKEINFO "$fn.texi" -o "$3"
+ ;;
+ *.texi)
+ [ -f "$fn.org" ] || exit 99
+ redo-ifchange "$fn.org"
+ $EMACS "$fn.org" --batch -f org-texinfo-export-to-texinfo
+ mv "$1" "$3"
+ ;;
+ "cpt-$VERSION.tar.xz")
+ redo doc/cpt.info
+ rm -rf -- "cpt-$VERSION"
+ find . -type f ! -name '.*' ! -path './.*' |
+ while read -r file; do
+ mkdir -p "cpt-$VERSION/${file%/*}"
+ cp "$file" "cpt-$VERSION/$file"
+ done
+ tar cf "cpt-$VERSION.tar" "cpt-$VERSION"
+ xz -z "cpt-$VERSION.tar"
+ rm -rf -- "cpt-$VERSION"
+ mv "$1" "$3"
+ ;;
+ *)
+ echo "Unknown target $1"
+ exit 99
+esac
diff --git a/dist.do b/dist.do
new file mode 100644
index 0000000..c7f21f1
--- /dev/null
+++ b/dist.do
@@ -0,0 +1,3 @@
+. ./config.rc
+redo clean
+redo "cpt-$VERSION.tar.xz"