-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbpfc
More file actions
executable file
·39 lines (30 loc) · 738 Bytes
/
bpfc
File metadata and controls
executable file
·39 lines (30 loc) · 738 Bytes
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
#!/bin/bash
set -o nounset -o pipefail -o errexit
SCRIPT_DIR=$(readlink -f "$0" | xargs dirname)
PP=${PP-$SCRIPT_DIR/pp}
INCLUDE_INPUT=
OUTPUT=${OUTPUT-/dev/stdout}
while getopts "io:-" OPT; do
case $OPT in
i) INCLUDE_INPUT=1 ;;
o) OUTPUT=$OPTARG ;;
-) break ;;
?) exit 2 ;;
esac
done
shift $((OPTIND-1))
BPF_ASM=${BPF_ASM-bpf_asm}
if ! command -v "$BPF_ASM" > /dev/null; then
BPF_ASM=$SCRIPT_DIR/bpf/bpf_asm
fi
INPUT=$1
TMP=$(mktemp)
trap 'rm -f $TMP' EXIT
if [ -n "$INCLUDE_INPUT" ]; then
echo "/** bpf_asm $INPUT" >> "$TMP"
echo " * " >> "$TMP"
sed 's,^, * ,' < "$INPUT" >> "$TMP"
echo "**/" >> "$TMP"
fi
"$PP" "$INPUT" | "$BPF_ASM" -c >> "$TMP"
cp "$TMP" "$OUTPUT"