-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgen-cdefdb
More file actions
executable file
·61 lines (48 loc) · 1.57 KB
/
Copy pathgen-cdefdb
File metadata and controls
executable file
·61 lines (48 loc) · 1.57 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
# Copyright (C) 2014-2015 Brian Downing. MIT License.
set -e
lj_cdefdb_dir=${LJ_CDEFDB_DIR:-$(luajit -e "print(require('cdefdb.config').dir)")}
usage() {
echo "Usage: $0 [options] (file.c|-) -- <cc args...>" >&2
echo " -o DIR, --output-dir=DIR set output directory" >&2
echo " (default 'lj-cdefdb-out')" >&2
echo " -p PRIO, --priority=PRIO set priority for generated database" >&2
echo " (default 0)" >&2
exit $1
}
OPTS=$(getopt -o ho:p: -l help,output-dir:,priority: -n "$0" -- "$@")
eval set -- "$OPTS"
out=lj-cdefdb-out
prio=0
while true; do
case "$1" in
-h|--help) usage 0; shift;;
-o|--output-dir) out=$2; shift 2;;
-p|--priority) prio=$2; shift 2;;
--) shift; break;;
*) echo "Option parse error!"; exit 1;;
esac
done
if [ -z "$1" ]; then
echo "$0: No input file specified" >&2
echo "Try '$0 --help' for more information." >&2
exit 1
fi
file="$1"; shift
. "$lj_cdefdb_dir"/functions.sh
out=$(readlink -f "$out")
pp_tmpdir="/tmp/lj-cdefdb-$$"
mkdir -p "$pp_tmpdir"
trap "rm -rf $pp_tmpdir" 0
pp_output="$pp_tmpdir/preprocessed$$.c"
${CC:-cc} -E -dD "$@" "$file" > "$pp_output"
hash=$(sha1sum "$pp_output" | cut -b1-8)
mkdir -p "$out"
run_in_ljclang ../gen-cdefdb.lua "$pp_output" "$out" "$hash" "$prio"
mkdir -p "$out"/cdefdb.d
mv "$out"/"$hash".db "$out"/cdefdb.d
if [ -e "$out"/"$hash".c ]; then
mkdir -p "$out"/stubs
${CC:-cc} -fPIC -shared -O2 -o "$out"/stubs/"$hash".so "$out"/"$hash".c
rm "$out"/"$hash".c
fi