rpcd: iwinfo plugin fixes
[openwrt.git] / scripts / patch-specs.sh
blob3307b6b0904501a83a5f8bc8824d91c9304c6fd1
1 #!/usr/bin/env bash
3 DIR="$1"
5 if [ -d "$DIR" ]; then
6 DIR="$(cd "$DIR"; pwd)"
7 else
8 echo "Usage: $0 toolchain-dir"
9 exit 1
12 echo -n "Locating cpp ... "
13 for bin in bin usr/bin usr/local/bin; do
14 for cmd in "$DIR/$bin/"*-cpp; do
15 if [ -x "$cmd" ]; then
16 echo "$cmd"
17 CPP="$cmd"
18 break
20 done
21 done
23 if [ ! -x "$CPP" ]; then
24 echo "Can't locate a cpp executable in '$DIR' !"
25 exit 1
28 patch_specs() {
29 local found=0
31 for lib in $(STAGING_DIR="$DIR" "$CPP" -x c -v /dev/null 2>&1 | sed -ne 's#:# #g; s#^LIBRARY_PATH=##p'); do
32 if [ -d "$lib" ]; then
33 grep -qs "STAGING_DIR" "$lib/specs" && rm -f "$lib/specs"
34 if [ $found -lt 1 ]; then
35 echo -n "Patching specs ... "
36 STAGING_DIR="$DIR" "$CPP" -dumpspecs | awk '
37 mode ~ "link" {
38 sub("%{L.}", "%{L*} -L %:getenv(STAGING_DIR /usr/lib) -rpath-link %:getenv(STAGING_DIR /usr/lib)")
40 mode ~ "cpp" {
41 $0 = $0 " -idirafter %:getenv(STAGING_DIR /usr/include)"
44 print $0
45 mode = ""
47 /^\*cpp:/ {
48 mode = "cpp"
50 /^\*link.*:/ {
51 mode = "link"
53 ' > "$lib/specs"
54 echo "ok"
55 found=1
58 done
60 [ $found -gt 0 ]
61 return $?
65 VERSION="$(STAGING_DIR="$DIR" "$CPP" --version | sed -ne 's/^.* (.*) //; s/ .*$//; 1p')"
66 VERSION="${VERSION:-unknown}"
68 case "${VERSION##* }" in
69 2.*|3.*|4.0.*|4.1.*|4.2.*)
70 echo "The compiler version does not support getenv() in spec files."
71 echo -n "Wrapping binaries instead ... "
73 if "${0%/*}/ext-toolchain.sh" --toolchain "$DIR" --wrap "${CPP%/*}"; then
74 echo "ok"
75 exit 0
76 else
77 echo "failed"
78 exit $?
82 if patch_specs; then
83 echo "Toolchain successfully patched."
84 exit 0
85 else
86 echo "Failed to locate library directory!"
87 exit 1
90 esac