File: cpp-interpreter.sh

package info (click to toggle)
saunafs 5.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,820 kB
  • sloc: cpp: 109,287; sh: 18,755; python: 4,737; ansic: 4,023; makefile: 60; awk: 17
file content (16 lines) | stat: -rw-r--r-- 628 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env bash
set -e
# Source file is the first argument. Read it but cut off the #!/... line
source="$(cat "$1" | grep -v '^#!')"
shift
[[ -n "$source" ]] || exit 1

# Compute hash of the source and use it in the name of the executable, so that the name will be
# the same when running the same script many times. This will make it possible to cache the binary
# cached in TEMP_DIR (in tests) or in /tmp (when running by hand)
hash=$(md5sum <<< "$source" | awk '{print $1}')
executable="${TEMP_DIR:-/tmp}/cached_c_$hash"
if ! [[ -x "$executable" ]]; then
	c++ -xc++ -o "$executable" - <<< "$source"
fi
"$executable" "$@"