diff --git a/Makefile b/Makefile index ead62ba..4dc9dc7 100644 --- a/Makefile +++ b/Makefile @@ -114,7 +114,7 @@ install: all install --verbose --compare --mode 644 share/sake.d/*.* $(datadir)/$(PROJECT)/sake.d install --verbose --compare --mode 644 share/milligram/*.* $(datadir)/$(PROJECT)/milligram sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/jqt - sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/sake + sed -i -e "s#JQTLIB='.*'#JQTLIB='$(datadir)/jqt'#" $(bindir)/sake uninstall: rm --verbose --force -- $(addprefix $(prefix)/,$(wildcard bin/*)) diff --git a/bin/jqt b/bin/jqt index 156b0f7..0a98165 100755 --- a/bin/jqt +++ b/bin/jqt @@ -529,7 +529,6 @@ function usage function help { cat <<'EOF' -jqt - jq based web template engine [version 0.5.1] Usage: jqt [-h | --help | -p | -V | --version] jqt [options] < infile > result jqt [options] infile > result diff --git a/bin/sake b/bin/sake index 8845863..5dd64bc 100755 --- a/bin/sake +++ b/bin/sake @@ -1,83 +1,101 @@ #!/bin/bash # -# Wraps make +# Wraps GNU Make # -# Environment -declare -ri NCORES=${NCORES:-2} +######################################################################## +# Bash options +######################################################################## -# Options set -o errexit -o noglob -o nounset -o pipefail + shopt -s expand_aliases -# Script name -declare -r SELF=${0##*/} +######################################################################## +# Environment +######################################################################## + +# Imported from environment if defined; otherwise use default value +declare -ri NCORES=${NCORES:-2} # Exported to use in makefiles and Sakefile declare -xr JQTLIB='/usr/local/share/jqt' -# GMake call -declare -ra makeflags=( - --jobs=$(( NCORES * 150 / 100 )) # NCORES * 1.5 - --makefile=Sakefile - --output-sync=target -) -alias _sake='exec make "${makeflags[@]}"' - +######################################################################## # Check project on current directory +######################################################################## + +# Sakefile must exist if test ! -e Sakefile; then - echo 1>&2 "${SELF}: no \`Sakefile\` found." + echo 1>&2 "sake: no \`Sakefile\` found." exit 1 fi + +# Configuration file must exist if test ! -e config.yaml && test ! -e config.json; then - echo 1>&2 "${SELF}: no \`config.yaml\` or \`config.json\` file found." + echo 1>&2 "sake: no \`config.yaml\` or \`config.json\` file found." exit 1 fi -# Check arguments +######################################################################## +# Run +######################################################################## + +# Options to gmake +declare -ra makeflags=( + --jobs=$(( NCORES * 150 / 100 )) # NCORES * 1.5 + --makefile=Sakefile + --output-sync=target +) + +# Exec gmake +alias _sake='exec make "${makeflags[@]}"' + +# Default command: `build` [[ $# == 0 ]] && set -- build # Run _sake case $1 in + help) + echo 'Usage: sake [command] [[options] [variable=definition] ...]' + echo -e '\nCommands, builtin and user defined:\n' + ;& # fall through + list) + make -f Sakefile -np 2>&1 | + grep -v '^[SmM]akefile' | + awk '/^[^ \t.%][-A-Za-z0-9_.]*:/ { print $1 }' | + sort --unique | + sed 's/:\+$//' | + pr --omit-pagination --width=50 --columns=4 --across + [[ $1 == help ]] && { + echo -e '\nSee the manpage for full documentation.' + } + ;; + clober) + shift + _sake clobber "$@" + ;; + config) + shift + _sake configure "$@" + ;; dag) - make -f Sakefile -Bdn \ + make -f Sakefile -Bdn build \ | sed -n \ -e "s/'//g" \ -e 's/\.$//' \ -e 's/Considering target file //p' ;; - help) - echo 1>&2 "${SELF}: Target \`help\` not implemented." - exit 1 - ;; new) - echo 1>&2 "${SELF}: Target \`new\` not implemented." + echo 1>&2 "sake: Target \`new\` not implemented." exit 1 ;; - list) - echo 'Usage: sake [goal] [[options] [variable=string] ...]' - echo 'Goals:' - make -f Sakefile -dpq 2>&1 \ - | grep -v '^[SmM]akefile' \ - | awk '/^[^ \t.%][-A-Za-z0-9_.]*:/ { print $1 }' \ - | sort --unique \ - | sed 's/:\+$//' \ - | pr --omit-pagination --width=80 --columns=6 - ;; touch) if test -e config.yaml; then touch config.yaml; else touch config.json; fi shift _sake build "$@" ;; - config) - shift - _sake configure "$@" - ;; - clober) - shift - _sake clobber "$@" - ;; *) _sake "$@" ;; diff --git a/bump-version.sh b/bump-version.sh index f6d0ec7..f8f3c4b 100755 --- a/bump-version.sh +++ b/bump-version.sh @@ -39,9 +39,8 @@ if [[ -f VERSION ]]; then cp /tmp/$$-changes CHANGES rm /tmp/$$-changes git add CHANGES VERSION - sed -i "s/^declare -r VERSION=$/declare -r VERSION=${NEXT_VERSION}'/" bin/jqt - sed -i "s/\[version .*\]/[version ${NEXT_VERSION}]/" bin/jqt - sed -i "s/^version: *.*/version: ${NEXT_VERSION}/" docs/config.yaml + sed -i "s/^declare -r VERSION=.*$/declare -r VERSION='${NEXT_VERSION}'/" bin/jqt + sed -i "s/^version: *.*/version: ${NEXT_VERSION}/" docs/config.yaml git commit -am "Version bump to ${NEXT_VERSION}" git tag -a -m "Tagging version ${NEXT_VERSION}" "v${NEXT_VERSION}" [[ $PUSH == yes ]] && git push origin --tags diff --git a/docs/README.md b/docs/README.md index d9d74ec..d338c9c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -96,13 +96,11 @@ makefile must contain the following include: ## Current _Sake_ commands -Targets not defined now: `help`, `new`. - ``` -Targets: - build configure help new - clean h5.lint list touch - clobber h5.valid +Usage: sake [command] [[options] [variable=definition] ...] +Commands: +build clobber dag h5.lint help new +clean configure depend h5.valid list nuke ``` ## Autocompletion diff --git a/docs/Sakefile b/docs/Sakefile index 2c2a099..2bc228e 100644 --- a/docs/Sakefile +++ b/docs/Sakefile @@ -42,14 +42,12 @@ JQTFLAGS += -5 --toc-depth=4 # experimental ######################################################################## -print-%: ; @echo $* = $($*) - depend: $(Meta)/phase3d.make cat $< | egrep -v '^#|^$$' | cut -c -72 - | sed 's/$$/.../' -# TODO: new, help, man page, SITE section on web, taxonomies (flags, series...) +# TODO: new, man page, SITE section on web, taxonomies (flags, series...) # TODO: enhance `dag` command -# TODO: -t -W -B +# TODO: -t -W -B ??? # TODO: show content pending to render? #newer: $(Meta)/lastbuild diff --git a/share/sake.d/main.make b/share/sake.d/main.make index 08d180f..727d366 100644 --- a/share/sake.d/main.make +++ b/share/sake.d/main.make @@ -128,7 +128,7 @@ __build := 1 # Standard targets. ######################################################################## -sake_builtin := new help touch list dag +sake_builtin := new help list dag touch .PHONY: build clean clobber nuke configure $(sake_builtin) # Filter builtin tools defined in `sake`script. diff --git a/share/sake.d/tools.make b/share/sake.d/tools.make index 73f0cf9..86f5daf 100644 --- a/share/sake.d/tools.make +++ b/share/sake.d/tools.make @@ -7,9 +7,17 @@ # VNU # Root # Defined targets: +# print-% # h5.lint # h5.valid +######################################################################## +# Debug utilities. +######################################################################## + +# Print any variable value +print-%: ; @echo $* = $($*) + ######################################################################## # HTML 5 validation. ########################################################################