]>
zdv2.bktei.com Git - BK-2023-05.git/blob - src/kr_exercises/ch1/s1.9/compile.sh
2 # Desc: Check sytnax and compiles file using gcc
3 # Usage: compile.sh mysource.c
5 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
6 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
7 try
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
10 if [[ $# -ne 1 ]]; then die
"FATAL:Incorrect argument count:$#"; fi;
11 if [[ ! -f $1 ]]; then die
"FATAL:Not a file:$1"; else f
="$1"; fi;
14 f
="$(readlink -f $f)"; fe
="${f%.c}";
19 if ! try gcc
-fsyntax-only "$f"; then die
"FATAL:Syntax Error."; fi;
22 time { try gcc
-o "$fe" "$f"; };