Commit 60a89ccb02
Unsigned
Layout: unified · split
imake +38 −14
| @@ -3,30 +3,54 @@ | |||
| 3 | 3 | ||
| 4 | DIR="$(pwd)" | 4 | DIR="$(pwd)" |
| 5 | IMAKEFILE="$DIR/IMakefile" | 5 | IMAKEFILE="$DIR/IMakefile" |
| 6 | TARGET="${1:-compile}" | ||
| 6 | 7 | ||
| 7 | if [[ ! -f "$IMAKEFILE" ]]; then | 8 | if [[ ! -f "$IMAKEFILE" ]]; then |
| 8 | echo "imake: IMakefile not found in $DIR" >&2 | 9 | echo "imake: IMakefile not found in $DIR" >&2 |
| 9 | exit 1 | 10 | exit 1 |
| 10 | fi | 11 | fi |
| 11 | 12 | ||
| 12 | while IFS= read -r line || [[ -n "$line" ]]; do | 13 | if ! grep -qE "^${TARGET}:" "$IMAKEFILE"; then |
| 13 | [[ -z "$line" ]] && continue | 14 | echo "imake: *** no rule to make target '$TARGET'. stop." >&2 |
| 15 | exit 1 | ||
| 16 | fi | ||
| 14 | 17 | ||
| 15 | printf '%s:\n' "$line" | 18 | in_target=0 |
| 16 | 19 | ||
| 17 | output=$(bash -c "$line" 2>&1) | 20 | while IFS= read -r line || [[ -n "$line" ]]; do |
| 18 | status=$? | 21 | [[ "$line" =~ ^[[:space:]]*$ ]] && continue |
| 22 | [[ "$line" =~ ^[[:space:]]*# ]] && continue | ||
| 19 | 23 | ||
| 20 | if [[ -n "$output" ]]; then | 24 | if [[ "$line" =~ ^([a-zA-Z0-9_-]+):[[:space:]]*$ ]]; then |
| 21 | while IFS= read -r output_line || [[ -n "$output_line" ]]; do | 25 | current_target="${BASH_REMATCH[1]}" |
| 22 | printf ' %s\n' "$output_line" | 26 | if [[ "$current_target" == "$TARGET" ]]; then |
| 23 | done <<< "$output" | 27 | in_target=1 |
| 24 | else | 28 | else |
| 25 | printf ' \n' | 29 | in_target=0 |
| 30 | fi | ||
| 31 | continue | ||
| 26 | fi | 32 | fi |
| 27 | 33 | ||
| 28 | if [[ $status -ne 0 ]]; then | 34 | if [[ $in_target -eq 1 ]]; then |
| 29 | printf ' Command failed with exit code %d\n' "$status" | 35 | [[ "$line" =~ ^[[:space:]]*(.*)$ ]] |
| 30 | exit "$status" | 36 | cmd_print="${BASH_REMATCH[1]}" |
| 37 | |||
| 38 | printf '%s:\n' "$cmd_print" | ||
| 39 | |||
| 40 | output=$(bash -c "$line" 2>&1) | ||
| 41 | status=$? | ||
| 42 | |||
| 43 | if [[ -n "$output" ]]; then | ||
| 44 | while IFS= read -r output_line || [[ -n "$output_line" ]]; do | ||
| 45 | printf ' %s\n' "$output_line" | ||
| 46 | done <<< "$output" | ||
| 47 | else | ||
| 48 | printf ' \n' | ||
| 49 | fi | ||
| 50 | |||
| 51 | if [[ $status -ne 0 ]]; then | ||
| 52 | printf ' command failed with exit code %d\n' "$status" | ||
| 53 | exit "$status" | ||
| 54 | fi | ||
| 31 | fi | 55 | fi |
| 32 | done < "$IMAKEFILE" | 56 | done < "$IMAKEFILE" |