3 export BTR_DATE
=$
(date +%Y
%m
%d
%H
%M
%S
)
4 export BTR_CPUS
=${CPUS:-$(nproc)}
5 export BTR_PROG
=$
(basename "$0")
7 export BTR_VERBOSE
=false
8 export BTR_FORCEYES
=false
17 echo "$BTR_PROG v0.4.0, (c) Michael Wallner <mike@php.net>"
25 function btr-confirm
{
44 function btr-setup-rundir
{
45 local default_rundir
="${1:-/tmp/btr}"
47 if test -z "$BTR_RUNDIR"
49 export BTR_RUNDIR
="$default_rundir"
51 export BTR_RUNDIR
=$
(realpath
"$BTR_RUNDIR")
54 mkdir
-p "$BTR_RUNDIR" || error
"Could not create directory '$BTR_RUNDIR'"
56 export -f btr-setup-rundir
58 function btr-setup-verbosity
{
59 local for_make
=${1:-false}
61 if ${BTR_VERBOSE:-false}
85 export BTR_QUIET BTR_VERBOSE BTR_FORCEYES BTR_QUIET_FLAG BTR_SILENT_FLAG BTR_VERBOSE_FLAG SAY
87 export -f btr-setup-verbosity
89 function btr-shortoptions
{
94 for f
in common
$BTR_PROG
98 test -e "$BTR_LIBDIR/$f.$e" && cut
-sf1 <"$BTR_LIBDIR/$f.$e"
101 ) |
xargs |
tr -d " "
103 export -f btr-shortoptions
105 function btr-longoptions
{
110 for f
in common
$BTR_PROG
114 test -e "$BTR_LIBDIR/$f.$e" && cut
-sf2 <"$BTR_LIBDIR/$f.$e"
117 ) |
sed -r -e 's/(:+).*/\1/' |
xargs |
tr " " ","
119 export -f btr-longoptions
126 for f
in common
$BTR_PROG
128 test -e "$BTR_LIBDIR/$f.flags" && cut
-sf1 <"$BTR_LIBDIR/$f.flags"
130 ) |
xargs |
tr -d " "
134 function btr-help-options
{
136 for f
in common
$BTR_PROG
138 test -e "$BTR_LIBDIR/$f.$1" && "$BTR_LIBDIR/opt.awk" <"$BTR_LIBDIR/$f.$1"
155 export -f btr-help-options
157 function btr-help-args
{
160 if test -e "$BTR_LIBDIR/$BTR_PROG.args"
166 printf "%b\n" "$d" |
fold -sw46 |
while read l
168 printf " %-16s %s\n" "$a" "$l"
172 done <"$BTR_LIBDIR/$BTR_PROG.args"
175 export -f btr-help-args
178 if test -e "$BTR_LIBDIR/$BTR_PROG.args"
180 cut
-sf1 <"$BTR_LIBDIR/$BTR_PROG.args" |
xargs
187 echo "Usage: $BTR_PROG [-$(btr-flags)] [<options>]" $
(btr-args
)
188 btr-help-options flags
189 btr-help-options opts
191 if test $BTR_PROG != "btrc"
194 echo " Rules format:"
195 echo " type=arg e.g: notify-send=\"-u low\""
196 echo " mail=\"-c copy@to rcpt@to\""
197 echo " irc=\"tcp://btr@chat.freenode.org/#btr\""
198 echo " git=\$HOME/src/btr.git"
200 echo " Note though, that some rules do not use any argument."
203 for ruleset
in source build report
205 printf " %10s: %s\n" $ruleset \
206 "$(find "$BTR_LIBDIR/$ruleset" -name '*.mk' -exec basename {} .mk \; | sort | xargs)"
214 function btr-parseopts
{
215 local shortoptions
="$(btr-shortoptions common btr-flags btr-options)"
216 local longoptions
="$(btr-longoptions common btr-flags btr-options)"
221 --options "$shortoptions" \
222 --longoptions "$longoptions" \
230 eval set -- "$options"
254 BTR_SOURCE_CLEAN
=true
282 test -z "$BTR_BRANCH" && BTR_BRANCH
=master
285 test -z "$BTR_BRANCH" && BTR_BRANCH
=trunk
288 test -z "$BTR_BRANCH" && BTR_BRANCH
=HEAD
291 BTR_SOURCE_RULES
="$(cut -d= -f1 <<<$2)"
292 BTR_SOURCE_ARGS
="$(cut -s -d= -f2- <<<$2)"
296 BTR_BUILD_RULES
="$(cut -d= -f1 <<<$2)"
297 BTR_BUILD_ARGS
="$(cut -s -d= -f2- <<<$2)"
301 BTR_REPORT_RULES
="$(cut -d= -f1 <<<$2)"
302 BTR_REPORT_ARGS
="$(cut -s -d= -f2- <<<$2)"
315 export -f btr-parseopts
317 function btr-conf-dump
{
318 echo "BTR_QUIET='$BTR_QUIET'"
319 echo "BTR_VERBOSE='$BTR_VEROSE'"
320 echo "BTR_FORCEYES='$BTR_FORCEYES'"
321 echo "BTR_BRANCH='$BTR_BRANCH'"
322 echo "BTR_SUFFIX='$BTR_SUFFIX'"
323 echo "BTR_RUNDIR='$BTR_RUNDIR'"
324 echo "BTR_SOURCE_RULES='$BTR_SOURCE_RULES'"
325 test ${BTR_SOURCE_ARGS+defined} && echo "BTR_SOURCE_ARGS='$BTR_SOURCE_ARGS'"
326 test ${BTR_SOURC_CLEAN+defined} && echo "BTR_SOURCE_CLEAN='$BTR_SOURCE_CLEAN'"
327 echo "BTR_BUILD_RULES='$BTR_BUILD_RULES'"
328 test ${BTR_BUILD_ARGS+defined} && echo "BTR_BUILD_ARGS='$BTR_BUILD_ARGS'"
329 test ${BTR_BUILD_CLEAN+defined} && echo "BTR_BUILD_CLEAN='$BTR_BUILD_CLEAN'"
330 test ${BTR_TEST_ARGS+defined} && echo "BTR_TEST_ARGS='$BTR_TEST_ARGS'"
331 echo "BTR_REPORT_RULES='$BTR_REPORT_RULES'"
332 test ${BTR_REPORT_ARGS+defined} && echo "BTR_REPORT_ARGS='$BTR_REPORT_ARGS'"
334 export -f btr-conf-dump