blob: 87745e7aad7b7454b2190eba42765a223fa936ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/bin/bash
#Code to find directory of this file from https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
FOUND="no"
for FILE in "$@"
do
if [ "${FILE: -2}" == ".c" ]
then
if ! cc -c $FILE -o $DIR/a.out ; then
echo "$0: error: Could not compile file with cc"
exit 1
fi
rm $DIR/a.out
if [ $1 == "-rr" ]
then
rr record $DIR/yielding_c_fun.bin "${@:2}" > $DIR/TMP_OUT_WITH_RR
# rr does not print when stdout is redirected
cat $DIR/TMP_OUT_WITH_RR
rm $DIR/TMP_OUT_WITH_RR
else
$DIR/yielding_c_fun.bin $@
fi
fi
FOUND="yes"
done
if [ $FOUND == "no" ]
then
echo "$0: error: Expected a file name with .c ending"
exit 1
fi
|