diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2012-01-18 03:11:45 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2012-01-18 03:11:45 +0000 |
commit | 6df3af8a3695a3b204d87e2ba032953bce693c56 (patch) | |
tree | 7de1e30d2d0440cf83c4977dfe33732c4ad08c49 /scripts | |
parent | 5b7668ca44e6d6e2bcf175e7f64093bd1b71db19 (diff) | |
download | mtk-20170518-6df3af8a3695a3b204d87e2ba032953bce693c56.zip mtk-20170518-6df3af8a3695a3b204d87e2ba032953bce693c56.tar.gz mtk-20170518-6df3af8a3695a3b204d87e2ba032953bce693c56.tar.bz2 |
add patch-specs.sh, a utility for modifying GCC specs 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.
SVN-Revision: 29767
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/patch-specs.sh | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/patch-specs.sh b/scripts/patch-specs.sh new file mode 100755 index 0000000..4d02a00 --- /dev/null +++ b/scripts/patch-specs.sh @@ -0,0 +1,64 @@ +#!/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 |