2 # Script to generate SYSROOT_SUFFIX_SPEC equivalent to MULTILIB_OSDIRNAMES
3 # Arguments are MULTILIB_OSDIRNAMES, MULTILIB_OPTIONS and MULTILIB_MATCHES.
5 # Copyright (C) 2009 Free Software Foundation, Inc.
7 # This file is part of GCC.
9 # GCC is free software; you can redistribute it and/or modify it under
10 # the terms of the GNU General Public License as published by the Free
11 # Software Foundation; either version 3, or (at your option) any later
14 # GCC is distributed in the hope that it will be useful, but WITHOUT
15 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 # You should have received a copy of the GNU General Public License
20 # along with GCC; see the file COPYING3. If not see
21 # <http://www.gnu.org/licenses/>.
23 # This shell script produces a header file fragment that defines
24 # SYSROOT_SUFFIX_SPEC. It assumes that the sysroots will have the same
25 # structure and names used by the multilibs.
28 # print-sysroot-suffix.sh \
29 # MULTILIB_OSDIRNAMES \
32 # > t-sysroot-suffix.h
34 # The three options exactly correspond to the variables of the same
35 # names defined in the tmake_file fragments.
38 # sh ./gcc/config/print-sysroot-suffix.sh "a=A" "a b/c/d" ""
40 # #undef SYSROOT_SUFFIX_SPEC
41 # #define SYSROOT_SUFFIX_SPEC "" \
49 # The script uses temporary subscripts in order to permit a recursive
50 # algorithm without the use of functions.
58 cat > print-sysroot-suffix3.sh
<<\EOF
60 # Print all the multilib matches for this option
64 l
=`echo $x | sed -e 's/=.*$//' -e 's/?/=/g'`
65 r
=`echo $x | sed -e 's/^.*=//' -e 's/?/=/g'`
66 echo "[ \"\$1\" = \"$l\" ] && result=\"\$result|$r\"" >> print-sysroot-suffix3.sh
68 echo 'echo $result' >> print-sysroot-suffix3.sh
69 chmod +x print-sysroot-suffix3.sh
71 cat > print-sysroot-suffix2.sh
<<\EOF
73 # Recursive script to enumerate all multilib combinations, match against
74 # multilib directories and output a spec string of the result.
75 # Will fold identical trees.
86 for x
in $dirnames; do
87 p
=`echo $x | sed -e 's,=!,/$=/,'`
88 pat
="$pat -e 's=^//$p='"
90 echo ' optstring=`echo "/$optstring" | sed '"$pat\`" >> print-sysroot-suffix2.sh
91 cat >> print-sysroot-suffix2.sh
<<\EOF
105 for x
in `echo "$thisopt" | sed -e 's,/, ,g'`; do
108 for x
in `echo "$options" | sed -e 's,/, ,g'`; do
109 match
=`./print-sysroot-suffix3.sh "$x"`
110 echo "$x) optmatch=\"$match\" ;;" >> print-sysroot-suffix2.sh
112 cat >> print-sysroot-suffix2.sh
<<\EOF
114 bit
=`"$0" "$padding " "$optstring$x/" "$@"`
115 if [ -z "$lastopt" ]; then
118 if [ "$lastbit" = "$bit" ]; then
119 lastopt
="$lastopt|$optmatch"
121 result
="$result$lastopt:$lastbit;$n"
127 bit
=`"$0" "$padding " "$optstring" "$@"`
128 if [ "$bit" = "$lastbit" ]; then
129 if [ -z "$result" ]; then
132 echo "$n%{$result:$bit}"
135 echo "$n%{$result$lastopt:$lastbit;$n:$bit}"
140 chmod +x .
/print-sysroot-suffix2.sh
141 result
=`./print-sysroot-suffix2.sh "" "/" $options`
142 echo "#undef SYSROOT_SUFFIX_SPEC"
143 echo "#define SYSROOT_SUFFIX_SPEC \"$result\""
144 rm print-sysroot-suffix2.sh
145 rm print-sysroot-suffix3.sh