Annotation of pkgsrc/lang/rust/files/gcc-wrap, Revision 1.4
1.1 he 1: #! /bin/sh
2:
3: # Root of targets tools + dest directories
4: # or unset to default to a native build.
5:
6: # This script assumes target tools in $root/tools
7: # and target's destdir in $root/dest, the result of a NetBSD build.sh.
8: # ...or the native root, when we don't cross-compile
9: root=${CROSS_ROOT:-/}
10:
11: native=false
12: if [ $root = "/" ]; then
13: native=true
14: else
15: # What's the tools/bin prefix (if we're cross-building)?
16: gnuarch=${GNU_CROSS_TARGET:?}
17: fi
18:
19: # Who are we a wrapper for? (Typically either gcc or c++)
20: who=$(basename $0 | sed -e 's/-wrap$//')
21:
22: args=""
1.2 he 23:
24: # May need to add $linkadd before first -l or fist -L
25: linkadd="-Wl,--sysroot=${root}/dest"
26: # (perhaps this is overly cautious, other adjustments we do
27: # below may be sufficient...)
28: # Lib directories to ensure we search and have in run-path
29: libs="/lib /usr/lib /usr/pkg/lib"
30:
31: for d in $libs; do
32: if ! $native; then
33: linkadd="$linkadd -L=$d"
34: linkadd="$linkadd -Wl,-rpath-link=${root}/dest/$d"
35: fi
36: # Run-path is for when we execute on the target,
37: # so no $root prefix
38: linkadd="$linkadd -Wl,-rpath,$d"
39: done
40:
41: # ...and add a placeholder so we can tweak RPATH with chrpath,
42: # since chrpath can't extend the length of the run path
43: # (This may also not be needed, we use LD_LIBRARY_PATH instead)
44: placeholder="placeholder-$(date | openssl dgst -sha1 | \
45: awk '{ print $2 }')"
46: linkadd="$linkadd -Wl,-rpath,/$placeholder"
47: # the / is a sneaky attempt to let it past cwrapper...
48:
49: # More debugging
50: linkadd="$linkadd -Wl,--verbose"
51:
52: linktweaked=false
1.1 he 53:
54: # Step through args, tweak where required
55: set -- "$@"
56: while [ $# -gt 0 ]; do
57: case "$1" in
58: # Insert = at the front of -isystem args.
59: # This is to get --sysroot prepended, so that
60: # we pick up the correct set of header files.
61: # (I thought this wasn't reqired, but apparently it is...)
62: -isystem)
63: shift
64: args="$args -isystem =$1"
65: ;;
66: # Also doctor -I directives of known paths and
67: # redirect them to the --sysroot.
68: -I/usr/include)
69: args="$args -I=/usr/include"
70: ;;
71: -I/usr/include/krb5)
72: args="$args -I=/usr/include/krb5"
73: ;;
1.3 he 74: -I/usr/pkg/include)
75: args="$args -I=/usr/pkg/include"
76: ;;
77: -I)
78: if [ $2 = "/usr/include" ]; then
79: args="$args -I=/usr/include"
80: shift
81: elif [ $2 = "/usr/include/krb5" ]; then
82: args="$args -I=/usr/include/krb5"
83: shift
84: elif [ $2 = "/usr/pkg/include" ]; then
85: args="$args -I=/usr/pkg/include"
86: shift
87: else
88: args="$args -I"
89: fi
90: ;;
1.1 he 91: -l*)
1.2 he 92: if ! $linktweaked; then
93: args="$args $linkadd"
94: linktweaked=true
95: fi
1.1 he 96: args="$args $1"
1.2 he 97: ;;
98: -L)
99: if ! $linktweaked; then
100: args="$args $linkadd"
101: linktweaked=true
102: fi
103: shift
104: tweaked=false
105: # redirect these to -Wl,--sysroot
106: for d in /lib /usr/lib /usr/pkg/lib; do
107: if [ $1 = $d ]; then
108: args="$args -L =$d"
109: tweaked=true
110: fi
111: done
112: # Not redirected? If so we need to add
113: if ! $tweaked; then
114: args="$args -L $1"
115: fi
116: ;;
117:
118: -L/lib)
119: if ! $linktweaked; then
120: args="$args $linkadd"
121: linktweaked=true
122: fi
123: args="$args -L=/lib"
124: ;;
125: -L/usr/lib)
126: if ! $linktweaked; then
127: args="$args $linkadd"
128: linktweaked=true
129: fi
130: args="$args -L=/usr/lib"
131: ;;
132: -L/usr/pkg/lib)
133: if ! $linktweaked; then
134: args="$args $linkadd"
135: linktweaked=true
136: fi
137: args="$args -L=/usr/pkg/lib"
1.1 he 138: ;;
1.4 ! he 139: -Wl,--enable-new-dtags)
! 140: # ignore
! 141: ;;
1.1 he 142: *)
143: args="$args $1"
144: ;;
145: esac
146: shift
147: done
148:
149: if $native; then
150: # Try to avoid cwrappers, which does "undocumented magic"
1.2 he 151: # by invoking the compiler "directly".
1.1 he 152: cmd="/usr/bin/${who} $args"
153: else
154: cmd="${root}/tools/bin/${gnuarch}-${who} \
155: --sysroot=${root}/dest \
156: $args"
157: fi
158:
159: # Cannot echo to stdout, messes up e.g. "gcc -print-prog-name=ld" output...
160: #echo $cmd >&2
161: exec $cmd
CVSweb <webmaster@jp.NetBSD.org>