2 # Script to generate SYSROOT_SUFFIX_SPEC equivalent to MULTILIB_OSDIRNAMES
3 # Arguments are MULTILIB_OSDIRNAMES, MULTILIB_OPTIONS and MULTILIB_MATCHES.
5 # Copyright (C) 2018 Free Software Foundation, Inc.
6 # Contributed by C-SKY Microsystems and Mentor Graphics.
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 \
33 # > t-sysroot-suffix.h
35 # The three options exactly correspond to the variables of the same
36 # names defined in the tmake_file fragments.
39 # sh ./gcc/config/print-sysroot-suffix.sh "a=A" "a b/c/d" ""
41 # #undef SYSROOT_SUFFIX_SPEC
42 # #define SYSROOT_SUFFIX_SPEC "" \
50 # The script uses temporary subscripts in order to permit a recursive
51 # algorithm without the use of functions.
59 cat > print-sysroot-suffix3.sh
<<\EOF
61 # Print all the multilib matches for this option
65 l
=`echo $x | sed -e 's/=.*$//' -e 's/?/=/g'`
66 r
=`echo $x | sed -e 's/^.*=//' -e 's/?/=/g'`
67 echo "[ \"\$1\" = \"$l\" ] && result=\"\$result|$r\"" >> print-sysroot-suffix3.sh
69 echo 'echo $result' >> print-sysroot-suffix3.sh
70 chmod +x print-sysroot-suffix3.sh
72 cat > print-sysroot-suffix2.sh
<<\EOF
74 # Recursive script to enumerate all multilib combinations, match against
75 # multilib directories and output a spec string of the result.
76 # Will fold identical trees.
87 for x
in $dirnames; do
88 # p=`echo $x | sed -e 's,=!,/$=/,'`
89 p
=`echo $x | sed -e 's/=//g'`
90 # pat="$pat -e 's=^//$p='"
91 pat
="$pat -e 's/$p/g'"
93 echo ' optstring=`echo "/$optstring" | sed '"$pat\`" >> print-sysroot-suffix2.sh
94 cat >> print-sysroot-suffix2.sh
<<\EOF
108 for x
in `echo "$thisopt" | sed -e 's,/, ,g'`; do
111 for x
in `echo "$options" | sed -e 's,/, ,g'`; do
112 match
=`./print-sysroot-suffix3.sh "$x"`
113 echo "$x) optmatch=\"$match\" ;;" >> print-sysroot-suffix2.sh
115 cat >> print-sysroot-suffix2.sh
<<\EOF
117 bit
=`"$0" "$padding " "$optstring$x/" "$@"`
118 if [ -z "$lastopt" ]; then
121 if [ "$lastbit" = "$bit" ]; then
122 lastopt
="$lastopt|$optmatch"
124 result
="$result$lastopt:$lastbit;$n"
130 bit
=`"$0" "$padding " "$optstring" "$@"`
131 if [ "$bit" = "$lastbit" ]; then
132 if [ -z "$result" ]; then
135 echo "$n%{$result:$bit}"
138 echo "$n%{$result$lastopt:$lastbit;$n:$bit}"
142 chmod +x .
/print-sysroot-suffix2.sh
143 result
=`./print-sysroot-suffix2.sh \"\" \"\" $options`
144 echo "#undef SYSROOT_SUFFIX_SPEC"
145 echo "#define SYSROOT_SUFFIX_SPEC \"$result\""
146 rm print-sysroot-suffix2.sh
147 rm print-sysroot-suffix3.sh