@@ -174,3 +174,62 @@ docker_to_linux_arch() {
174174
175175 eval " ${oldstate} "
176176}
177+
178+ find_argument () {
179+ # Extracts the value from an argument of the form VARIABLE=VALUE
180+ local needle=" $1 "
181+ local return_var=" $2 "
182+ shift 2
183+ local prefix=" ${needle} ="
184+ for var in " ${@ } " ; do
185+ case " $var " in
186+ " $prefix " * )
187+ eval " $return_var =${var# " ${prefix} " } "
188+ return 0 ;;
189+ * ) ;;
190+ esac
191+ done
192+ echo " Missing argument ${needle} "
193+ exit 1
194+ }
195+
196+ symlinkify_if_same () {
197+ local file1=" $1 "
198+ local file2=" $2 "
199+ # Only make a symlink if the files are identical, and the destination file isn't already a symlink
200+ if [ ! -L " ${file2} " ] && cmp " $file1 " " $file2 " ; then
201+ ln -sf " $file1 " " $file2 "
202+ fi
203+ }
204+
205+ symlinkify_and_strip_toolchain () {
206+ local target=" $1 "
207+ local gcc_ver=" $2 "
208+
209+ local target_bin=" /usr/local/${target} /bin"
210+ local local_bin=" /usr/local/bin"
211+
212+ # The first set of tools appear as /usr/local/bin/<target>-<tool> and /usr/local/<target>/bin/<tool>
213+
214+ # Special case: ld is itself usually hardlinked to ld.bfd
215+ symlinkify_if_same " ${local_bin} /ld" " ${local_bin} /ld.bfd"
216+
217+ # Turn hard links or otherwise identical files into symlinks
218+ for tool in ar as ld ld.bfd nm objcopy objdump ranlib readelf strip; do
219+ local src=" ${local_bin} /${target} -${tool} "
220+ local dest=" ${target_bin} /${tool} "
221+ symlinkify_if_same " ${src} " " ${dest} "
222+ strip " ${src} "
223+ done
224+
225+ # The second set of tools only appear as /usr/local/bin/<target>-<tool>
226+
227+ # Special case: c++ and g++ are usually the same file
228+ symlinkify_if_same " ${local_bin} /${target} -c++" " ${local_bin} /${target} -g++"
229+ # Special case: gcc and gcc-<version>
230+ symlinkify_if_same " ${local_bin} /${target} -gcc" " ${local_bin} /${target} -gcc-${gcc_ver} "
231+
232+ for tool in addr2line c++ c++filt cpp elfedit g++ gcc gcc-${gcc_ver} gcc-ar gcc-nm gcc-ranlib gcov gcov-dump gcov-tool gfortran gprof size strings; do
233+ strip " ${local_bin} /${target} -${tool} "
234+ done
235+ }
0 commit comments