mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-12-31 01:16:46 +02:00
9c517fdaa2
The patch-specs.sh utility dumps the GCC specs of a given toolchain and modifies them to always include $STAGING_DIR in the link and compiler command lines, this makes most -I and -L flags unnecessary and lets the compiler automatically find libraries and headers in the staging dir, also solves the majority of -rpath issues. git-svn-id: svn://svn.openwrt.org/openwrt/trunk@29767 3c298f89-4303-0410-b956-a3cf2f4a3e73
65 lines
1.2 KiB
Bash
Executable File
65 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
DIR="$1"
|
|
FOUND=0
|
|
|
|
if [ -d "$DIR" ]; then
|
|
DIR="$(cd "$DIR"; pwd)"
|
|
else
|
|
echo "Usage: $0 toolchain-dir"
|
|
exit 1
|
|
fi
|
|
|
|
echo -n "Locating cpp ... "
|
|
for bin in bin usr/bin usr/local/bin; do
|
|
for cmd in "$DIR/$bin/"*-cpp; do
|
|
if [ -x "$cmd" ]; then
|
|
echo "$cmd"
|
|
CPP="$cmd"
|
|
break
|
|
fi
|
|
done
|
|
done
|
|
|
|
if [ ! -x "$CPP" ]; then
|
|
echo "Can't locate a cpp executable in '$DIR' !"
|
|
exit 1
|
|
fi
|
|
|
|
for lib in $(STAGING_DIR="$dir" "$CPP" -x c -v /dev/null 2>&1 | sed -ne 's#:# #g; s#^LIBRARY_PATH=##p'); do
|
|
if [ -d "$lib" ]; then
|
|
grep -qs "STAGING_DIR" "$lib/specs" && rm -f "$lib/specs"
|
|
if [ $FOUND -lt 1 ]; then
|
|
echo -n "Patching specs ... "
|
|
STAGING_DIR="$dir" "$CPP" -dumpspecs | awk '
|
|
mode ~ "link" {
|
|
sub("%{L.}", "%{L*} -L %:getenv(STAGING_DIR /usr/lib) -rpath-link %:getenv(STAGING_DIR /usr/lib)")
|
|
}
|
|
mode ~ "cpp" {
|
|
$0 = $0 " -idirafter %:getenv(STAGING_DIR /usr/include)"
|
|
}
|
|
{
|
|
print $0
|
|
mode = ""
|
|
}
|
|
/^\*cpp:/ {
|
|
mode = "cpp"
|
|
}
|
|
/^\*link.*:/ {
|
|
mode = "link"
|
|
}
|
|
' > "$lib/specs"
|
|
echo "ok"
|
|
FOUND=1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [ $FOUND -lt 1 ]; then
|
|
echo "Failed to locate library directory!"
|
|
exit 1
|
|
else
|
|
echo "Toolchain successfully patched."
|
|
exit 0
|
|
fi
|