File: cpp-interpreter.sh

package info (click to toggle)
lizardfs 3.12.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,064 kB
  • sloc: cpp: 91,899; sh: 9,341; python: 3,878; ansic: 3,109; pascal: 128; makefile: 57
file content (16 lines) | stat: -rw-r--r-- 628 bytes parent folder | download | duplicates (3)
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" "$@"