2 # Script to generate SYSROOT_SUFFIX_SPEC equivalent to MULTILIB_OSDIRNAMES
3 # Arguments are MULTILIB_OSDIRNAMES, MULTILIB_OPTIONS, MULTILIB_MATCHES,
6 # Copyright (C) 2009-2019 Free Software Foundation, Inc.
8 # This file is part of GCC.
10 # GCC is free software; you can redistribute it and/or modify it under
11 # the terms of the GNU General Public License as published by the Free
12 # Software Foundation; either version 3, or (at your option) any later
15 # GCC is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # You should have received a copy of the GNU General Public License
21 # along with GCC; see the file COPYING3. If not see
22 # <http://www.gnu.org/licenses/>.
24 # This shell script produces a header file fragment that defines
25 # SYSROOT_SUFFIX_SPEC. It assumes that the sysroots will have the same
26 # structure and names used by the multilibs.
29 # print-sysroot-suffix.sh \
30 # MULTILIB_OSDIRNAMES \
34 # > t-sysroot-suffix.h
36 # The four options exactly correspond to the variables of the same
37 # names defined in the t-sysroot-suffix tmake_file fragment.
40 # sh ./gcc/config/print-sysroot-suffix.sh "a=A" "a b/c/d" ""
42 # #undef SYSROOT_SUFFIX_SPEC
43 # #define SYSROOT_SUFFIX_SPEC "" \
51 # The script uses temporary subscripts in order to permit a recursive
52 # algorithm without the use of functions.
61 cat > print-sysroot-suffix3.sh
<<\EOF
63 # Print all the multilib matches for this option
67 l
=`echo $x | sed -e 's/=.*$//' -e 's/?/=/g'`
68 r
=`echo $x | sed -e 's/^.*=//' -e 's/?/=/g'`
69 echo "[ \"\$1\" = \"$l\" ] && result=\"\$result|$r\"" >> print-sysroot-suffix3.sh
71 echo 'echo $result' >> print-sysroot-suffix3.sh
72 chmod +x print-sysroot-suffix3.sh
74 cat > print-sysroot-suffix2.sh
<<\EOF
76 # Recursive script to enumerate all multilib combinations, match against
77 # multilib directories and output a spec string of the result.
78 # Will fold identical trees.
89 l
=`echo $x | sed -e 's/=.*$//' -e 's/\./=/g'`
90 r
=`echo $x | sed -e 's/^.*=//' -e 's/\./=/g'`
91 echo "/$r/) optstring=\"/$l/\" ;;" >> print-sysroot-suffix2.sh
93 echo " esac" >> print-sysroot-suffix2.sh
96 for x
in $dirnames; do
97 p
=`echo $x | sed -e 's,=!,/$=/,'`
98 pat
="$pat -e 's=^//$p='"
100 echo ' optstring=`echo "/$optstring" | sed '"$pat\`" >> print-sysroot-suffix2.sh
101 cat >> print-sysroot-suffix2.sh
<<\EOF
115 for x
in `echo "$thisopt" | sed -e 's,/, ,g'`; do
118 for x
in `echo "$options" | sed -e 's,/, ,g'`; do
119 match
=`./print-sysroot-suffix3.sh "$x"`
120 echo "$x) optmatch=\"$match\" ;;" >> print-sysroot-suffix2.sh
122 cat >> print-sysroot-suffix2.sh
<<\EOF
124 bit
=`"$0" "$padding " "$optstring$x/" "$@"`
125 if [ -z "$lastopt" ]; then
128 if [ "$lastbit" = "$bit" ]; then
129 lastopt
="$lastopt|$optmatch"
131 result
="$result$lastopt:$lastbit;$n"
137 bit
=`"$0" "$padding " "$optstring" "$@"`
138 if [ "$bit" = "$lastbit" ]; then
139 if [ -z "$result" ]; then
142 echo "$n%{$result:$bit}"
145 echo "$n%{$result$lastopt:$lastbit;$n:$bit}"
150 chmod +x .
/print-sysroot-suffix2.sh
151 result
=`./print-sysroot-suffix2.sh "" "/" $options`
152 echo "#undef SYSROOT_SUFFIX_SPEC"
153 echo "#define SYSROOT_SUFFIX_SPEC \"$result\""
154 rm print-sysroot-suffix2.sh
155 rm print-sysroot-suffix3.sh