aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-12-24 14:38:21 +0000
committermerakor <cem@ckyln.com>2020-12-24 14:38:21 +0000
commitf9c2b3033aad39704e52a7b6fccad0548ba74771 (patch)
treeca647c793727a65d16afdf1189abb2c2db7f2593
parent70a32fc9b0969fc9ee8c5e2ea6077d08ae304dbe (diff)
downloadcpt-f9c2b3033aad39704e52a7b6fccad0548ba74771.tar.gz
lib.rc: move helper functions to a seperate file
In order to avoid confusion, I have moved helper functions to lib.rc from the config.rc file. FossilOrigin-Name: a51d7fa1235547b1f948eae9cd55ddf3ae365d56364eaa2644b16113ea8dd979
-rw-r--r--config.rc60
-rw-r--r--docs/default.do1
-rw-r--r--lib.rc60
-rw-r--r--src/test.do4
4 files changed, 67 insertions, 58 deletions
diff --git a/config.rc b/config.rc
index cd0c8d8..1bcb708 100644
--- a/config.rc
+++ b/config.rc
@@ -1,18 +1,9 @@
# -*- 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
-}
+# This loads some functions that are shared between redo files.
+# shellcheck source=./lib.rc
+. "${SRC_ROOT:=.}/lib.rc"
setv VERSION = 5.1.1
@@ -38,48 +29,3 @@ setv LD = "${CC}"
# Documentation tools
setv EMACS = emacs
setv MAKEINFO = makeinfo
-
-# Helper functions
-target=$1 basename=$2 dest=$3
-
-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
-}
-
-targcheck() {
- # Usage: targcheck [target...]
- #
- # Check if current target is one of the given arguments of this function.
- # Returns 0 if target is one of the arguments, returns 1 if not.
- case " $* " in *" $target "*) return 0; esac; return 1
-}
-
-PHONY() {
- # Usage: PHONY [[target...]]
- #
- # Function that resembles the .PHONY: target on the classic 'make' system.
- # You can either use it without an argument on a single target, or specify
- # multiple targets.
- if [ -z "$1" ] || targcheck "$@"; then
- # shellcheck disable=2064
- trap "rm -f $dest" EXIT INT
- fi
-}
-
-getbin() {
- # Function to get all executables
- find src contrib -name 'cpt-*' ! -name '*.in'
-}
-
-
-# Phony targets
-PHONY all dist clean install uninstall test
diff --git a/docs/default.do b/docs/default.do
index 3519aec..1ce12e2 100644
--- a/docs/default.do
+++ b/docs/default.do
@@ -1,3 +1,4 @@
+SRC_ROOT=..
. ../config.rc
# Extensionless name of file
diff --git a/lib.rc b/lib.rc
new file mode 100644
index 0000000..193baf0
--- /dev/null
+++ b/lib.rc
@@ -0,0 +1,60 @@
+# -*- mode: redo -*-
+# Helper functions
+target=$1 basename=$2 dest=$3
+
+# Make all targets dependent on the library and the config file
+redo-ifchange "$SRC_ROOT/lib.rc" "$SRC_ROOT/config.rc"
+
+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
+}
+
+targcheck() {
+ # Usage: targcheck [target...]
+ #
+ # Check if current target is one of the given arguments of this function.
+ # Returns 0 if target is one of the arguments, returns 1 if not.
+ case " $* " in *" $target "*) return 0; esac; return 1
+}
+
+PHONY() {
+ # Usage: PHONY [[target...]]
+ #
+ # Function that resembles the .PHONY: target on the classic 'make' system.
+ # You can either use it without an argument on a single target, or specify
+ # multiple targets.
+ if [ -z "$1" ] || targcheck "$@"; then
+ # shellcheck disable=2064
+ trap "rm -f $dest" EXIT INT
+ fi
+}
+
+getbin() {
+ # Function to get all executables
+ find src contrib -name 'cpt-*' ! -name '*.in'
+}
+
+# Phony targets
+PHONY all dist clean install uninstall test
diff --git a/src/test.do b/src/test.do
index 9791cea..159cece 100644
--- a/src/test.do
+++ b/src/test.do
@@ -1,4 +1,6 @@
-. ../config.rc
+SRC_ROOT=..
+. ${SRC_ROOT}/config.rc
+
redo-ifchange cpt-lib
exec >&2
find . ../contrib -name 'cpt-*' ! -name '*.*' -exec shellcheck -e 2119 -x -f gcc {} +