the original directory so that # - the next file is processed in correct conditions # - the temporary file can be removed cd "$orig_pwd" || exit 1 rel= } # func_dirname FILE - Return the directory part of FILE. func_dirname () { dirname "$1" 2>/dev/null \ || { echo "$1" | $SED 's!/[^/]*$!!;s!^$!.!'; } } # noext FILE - Return FILE with one extension removed: # foo.bar.baz -> foo.bar noext () { echo "$1" | $SED -e 's/\.[^/.][^/.]*$//' } # absolute NAME - Return an absolute path to NAME. absolute () { case $1 in [\\/]* | ?:[\\/]*) # Absolute paths don't need to be expanded. echo "$1" ;; *) absolute_slashes=`echo "$1" | $SED -n 's,.*[^/]\(/*\)$,\1,p'` absolute_rel=$orig_pwd/`func_dirname "$1"` if test -d "$absolute_rel"; then (cd "$absolute_rel" 2>/dev/null \ && absolute_name=`pwd`/`basename "$1"`"$absolute_slashes" echo "$absolute_name") else error 1 "not a directory: $absolute_rel" fi ;; esac } # ensure_dir DIR1 DIR2... - Make sure given directories exist. ensure_dir () { for dir do # Beware that in parallel builds we may have several concurrent # attempts to create the directory. So fail only if "mkdir" # failed *and* the directory still does not exist. test -d "$dir" \ || mkdir "$dir" \ || test -d "$dir" \ || error 1 "cannot create directory: $dir" done } # error EXIT_STATUS LINE1 LINE2... - Report an error and exit with # failure if EXIT_STATUS is non-null. error () { error_status="$1" shift report "$@" if test "$error_status" != 0; then exit $error_status fi } # findprog PROG - Return true if PROG is somewhere in PATH, else false. findprog () { saveIFS="$IFS" IFS=$path_sep # break path components at the path separator for dir in $PATH; do IFS=$saveIFS # The basic test for an executable is `test -f $f && test -x $f'. # (`test -x' is not enough, because it can also be true for directories.) # We have to try this both for $1 and $1.exe. # # Note: On Cygwin and DJGPP, `test -x' also looks for .exe. On Cygwin, # also `test -f' has this enhancement, but not on DJGPP. (Both are # design decisions, so there is little chance to make them consistent.) # Thusly, it seems to be difficult to make use of these enhancements. # if { test -f "$dir/$1" && test -x "$dir/$1"; } \ || { test -f "$dir/$1.exe" && test -x "$dir/$1.exe"; }; then return 0 fi done return 1 } # report LINE1 LINE2... - Echo each argument to stderr. report () { for i in "$@" do echo >&2 "$0: $i" done } # run COMMAND-LINE - Run COMMAND-LINE verbosely, catching errors as failures. run () { verbose "Running $@" "$@" 2>&5 1>&2 \ || error 1 "$1 failed" } # verbose WORD1 WORD2... - Echo concatenated WORDs to stderr, if $verb. verbose () { if $verb; then echo >&2 "$0: $@" fi } #