-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccc-override.sh
More file actions
executable file
·54 lines (39 loc) · 1.67 KB
/
ccc-override.sh
File metadata and controls
executable file
·54 lines (39 loc) · 1.67 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
#!/bin/sh
# Convenience script for clang's CCC_OVERRIDE_OPTIONS
die() { echo "ccc-override: error: $@" >&2; exit 1; }
help() {
cat <<HERE
usage: $0 [-q] [edit ...] [cmd ...]
Runs a command with edits specified in the CCC_OVERRIDE_OPTIONS
environment variable, which is recognized by clang.
Edits may be one or more of the following:
'^': Add FOO as a new argument at the beginning of the command line.
'+': Add FOO as a new argument at the end of the command line.
's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
line.
'xOPTION': Removes all instances of the literal argument OPTION.
'XOPTION': Removes all instances of the literal argument OPTION,
and the following argument.
'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
at the end of the command line.
If no edits are provided, the default is 'O0 +-g'
HERE
}
[ -z "$CCC_OVERRIDE_OPTIONS" ] || die "CCC_OVERRIDE_OPTIONS already set?"
export CCC_OVERRIDE_OPTIONS
while :; do
case $1 in
^*) CCC_OVERRIDE_OPTIONS="$CCC_OVERRIDE_OPTIONS $1"; shift;;
+*) CCC_OVERRIDE_OPTIONS="$CCC_OVERRIDE_OPTIONS $1"; shift;;
s/*) CCC_OVERRIDE_OPTIONS="$CCC_OVERRIDE_OPTIONS $1"; shift;;
x*) CCC_OVERRIDE_OPTIONS="$CCC_OVERRIDE_OPTIONS $1"; shift;;
O[sz0-9]) CCC_OVERRIDE_OPTIONS="$CCC_OVERRIDE_OPTIONS $1"; shift;;
X*) CCC_OVERRIDE_OPTIONS="$CCC_OVERRIDE_OPTIONS $1 $2"; shift 2;;
-q) CCC_OVERRIDE_OPTIONS="#$CCC_OVERRIDE_OPTIONS"; shift;;
-h|--help) help; exit 0;;
*) break;
esac
done
[ -n "$CCC_OVERRIDE_OPTIONS" ] || CCC_OVERRIDE_OPTIONS="O0 +-g"
[ $# -gt 0 ] || die "No command provided\n\n$(help)"
exec "$@"