| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | die () { |
| 6 | echo >&2 "$1" |
| 7 | exit 1 |
| 8 | } |
| 9 | |
| 10 | usage () { |
| 11 | die "usage: $name [--exclude <path> ...]" |
| 12 | } |
| 13 | |
| 14 | |
| 15 | name=$(basename "$0") |
| 16 | dir=$(dirname "$0") |
| 17 | root=$(cd "$dir/.." && pwd) |
| 18 | bin="$root/bin" |
| 19 | |
| 20 | declare -a exclude |
| 21 | while [ "$#" -gt 0 ]; do |
| 22 | case "$1" in |
| 23 | "--exclude") |
| 24 | shift |
| 25 | if [ "$#" -gt 0 ]; then |
| 26 | exclude+=("$1"); |
| 27 | shift |
| 28 | fi |
| 29 | ;; |
| 30 | *) usage |
| 31 | ;; |
| 32 | esac |
| 33 | done |
| 34 | |
| 35 | doit () { |
| 36 | # rm -rf '.#'* .*~ *~ *.a *.o .cm core mlmon.out svn-commit.* |
| 37 | "$bin/ls-ignore" | xargs rm -rf |
| 38 | for f in *; do |
| 39 | if [ -d "$f" ]; then |
| 40 | for ((i=0; i < ${#exclude[*]}; i++)); do |
| 41 | if [ "$f" == "${exclude[$i]}" ]; then |
| 42 | continue 2 |
| 43 | fi |
| 44 | done |
| 45 | cd "$f" |
| 46 | if [ -r Makefile ]; then |
| 47 | "$bin/mmake" clean || doit |
| 48 | else |
| 49 | doit |
| 50 | fi |
| 51 | cd .. |
| 52 | fi |
| 53 | done |
| 54 | } |
| 55 | |
| 56 | doit |