Commit 60a89ccb02
Unsigned
Layout: unified · split
imake +38 −14
| @@ -3,30 +3,54 @@ | ||
| 3 | 3 | |
| 4 | 4 | DIR="$(pwd)" |
| 5 | 5 | IMAKEFILE="$DIR/IMakefile" |
| 6 | TARGET="${1:-compile}" | |
| 6 | 7 | |
| 7 | 8 | if [[ ! -f "$IMAKEFILE" ]]; then |
| 8 | 9 | echo "imake: IMakefile not found in $DIR" >&2 |
| 9 | 10 | exit 1 |
| 10 | 11 | fi |
| 11 | 12 | |
| 12 | while IFS= read -r line || [[ -n "$line" ]]; do | |
| 13 | [[ -z "$line" ]] && continue | |
| 13 | if ! grep -qE "^${TARGET}:" "$IMAKEFILE"; then | |
| 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) | |
| 18 | status=$? | |
| 20 | while IFS= read -r line || [[ -n "$line" ]]; do | |
| 21 | [[ "$line" =~ ^[[:space:]]*$ ]] && continue | |
| 22 | [[ "$line" =~ ^[[:space:]]*# ]] && continue | |
| 19 | 23 | |
| 20 | if [[ -n "$output" ]]; then | |
| 21 | while IFS= read -r output_line || [[ -n "$output_line" ]]; do | |
| 22 | printf ' %s\n' "$output_line" | |
| 23 | done <<< "$output" | |
| 24 | else | |
| 25 | printf ' \n' | |
| 24 | if [[ "$line" =~ ^([a-zA-Z0-9_-]+):[[:space:]]*$ ]]; then | |
| 25 | current_target="${BASH_REMATCH[1]}" | |
| 26 | if [[ "$current_target" == "$TARGET" ]]; then | |
| 27 | in_target=1 | |
| 28 | else | |
| 29 | in_target=0 | |
| 30 | fi | |
| 31 | continue | |
| 26 | 32 | fi |
| 27 | 33 | |
| 28 | if [[ $status -ne 0 ]]; then | |
| 29 | printf ' Command failed with exit code %d\n' "$status" | |
| 30 | exit "$status" | |
| 34 | if [[ $in_target -eq 1 ]]; then | |
| 35 | [[ "$line" =~ ^[[:space:]]*(.*)$ ]] | |
| 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 | 55 | fi |
| 32 | 56 | done < "$IMAKEFILE" |