libgo: update to Go1.10beta1
[official-gcc.git] / gcc / config / print-sysroot-suffix.sh
blob2cfc390f650708bc896fbf2f91a5b64ec27bcbf6
1 #! /bin/sh
2 # Script to generate SYSROOT_SUFFIX_SPEC equivalent to MULTILIB_OSDIRNAMES
3 # Arguments are MULTILIB_OSDIRNAMES, MULTILIB_OPTIONS, MULTILIB_MATCHES,
4 # and MULTILIB_REUSE.
6 # Copyright (C) 2009-2018 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
13 # version.
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
18 # for more details.
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.
28 # Invocation:
29 # print-sysroot-suffix.sh \
30 # MULTILIB_OSDIRNAMES \
31 # MULTILIB_OPTIONS \
32 # MULTILIB_MATCHES \
33 # MULTILIB_REUSE
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.
39 # Example:
40 # sh ./gcc/config/print-sysroot-suffix.sh "a=A" "a b/c/d" ""
41 # =>
42 # #undef SYSROOT_SUFFIX_SPEC
43 # #define SYSROOT_SUFFIX_SPEC "" \
44 # "%{a:" \
45 # "%{b:A/b/;" \
46 # "c:A/c/;" \
47 # "d:A/d/;" \
48 # ":A/};" \
49 # ":}"
51 # The script uses temporary subscripts in order to permit a recursive
52 # algorithm without the use of functions.
54 set -e
56 dirnames="$1"
57 options="$2"
58 matches="$3"
59 reuse="$4"
61 cat > print-sysroot-suffix3.sh <<\EOF
62 #! /bin/sh
63 # Print all the multilib matches for this option
64 result="$1"
65 EOF
66 for x in $matches; do
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
70 done
71 echo 'echo $result' >> print-sysroot-suffix3.sh
72 chmod +x print-sysroot-suffix3.sh
74 cat > print-sysroot-suffix2.sh <<\EOF
75 #! /bin/sh
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.
80 padding="$1"
81 optstring="$2"
82 shift 2
83 n="\" \\
84 $padding\""
85 if [ $# = 0 ]; then
86 case $optstring in
87 EOF
88 for x in $reuse; do
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
92 done
93 echo " esac" >> print-sysroot-suffix2.sh
95 pat=
96 for x in $dirnames; do
97 p=`echo $x | sed -e 's,=!,/$=/,'`
98 pat="$pat -e 's=^//$p='"
99 done
100 echo ' optstring=`echo "/$optstring" | sed '"$pat\`" >> print-sysroot-suffix2.sh
101 cat >> print-sysroot-suffix2.sh <<\EOF
102 case $optstring in
103 //*)
106 echo "$optstring"
108 esac
109 else
110 thisopt="$1"
111 shift
112 bit=
113 lastcond=
114 result=
115 for x in `echo "$thisopt" | sed -e 's,/, ,g'`; do
116 case $x in
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
121 done
122 cat >> print-sysroot-suffix2.sh <<\EOF
123 esac
124 bit=`"$0" "$padding " "$optstring$x/" "$@"`
125 if [ -z "$lastopt" ]; then
126 lastopt="$optmatch"
127 else
128 if [ "$lastbit" = "$bit" ]; then
129 lastopt="$lastopt|$optmatch"
130 else
131 result="$result$lastopt:$lastbit;$n"
132 lastopt="$optmatch"
135 lastbit="$bit"
136 done
137 bit=`"$0" "$padding " "$optstring" "$@"`
138 if [ "$bit" = "$lastbit" ]; then
139 if [ -z "$result" ]; then
140 echo "$bit"
141 else
142 echo "$n%{$result:$bit}"
144 else
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