This is a maintenance fork
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
970 B

1 year ago
1 year ago
  1. #!/bin/sh
  2. #-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
  3. #───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
  4. #
  5. # OVERVIEW
  6. #
  7. # Generic Command Runner
  8. #
  9. # DESCRIPTION
  10. #
  11. # This does auto mkdir and ephemeral logging.
  12. #
  13. # EXAMPLE
  14. #
  15. # build/do PROG [ARGS...]
  16. MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
  17. # Ensure directory creation if -o PATH flag is passed.
  18. OUT="$TARGET"
  19. FIRST=1
  20. OUTARG=0
  21. for x; do
  22. if [ $FIRST -eq 1 ]; then
  23. set --
  24. FIRST=0
  25. elif [ $OUTARG -eq 1 ]; then
  26. OUTARG=0
  27. OUT="$x"
  28. fi
  29. case "$x" in
  30. -o)
  31. OUTARG=1
  32. ;;
  33. -o*)
  34. OUT=${x#-o}
  35. ;;
  36. esac
  37. set -- "$@" "$x"
  38. done
  39. if [ "$OUT" ]; then
  40. OUTDIR="${OUT%/*}"
  41. if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
  42. $MKDIR "$OUTDIR" || exit 2
  43. fi
  44. fi
  45. # Log command.
  46. if [ "$SILENT" = "0" ]; then
  47. printf "%s\n" "$*" >&2
  48. else
  49. printf "$LOGFMT" "${ACTION:-BUILD}" "$TARGET" >&2
  50. fi
  51. exec "$@"