gcc/
[official-gcc.git] / gcc / config / print-sysroot-suffix.sh
blob55579ad864bc66975858fbc0668ea0572bb04997
1 #! /bin/sh
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
12 # version.
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
17 # for more details.
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.
27 # Invocation:
28 # print-sysroot-suffix.sh \
29 # MULTILIB_OSDIRNAMES \
30 # MULTILIB_OPTIONS \
31 # MULTILIB_MATCHES \
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.
37 # Example:
38 # sh ./gcc/config/print-sysroot-suffix.sh "a=A" "a b/c/d" ""
39 # =>
40 # #undef SYSROOT_SUFFIX_SPEC
41 # #define SYSROOT_SUFFIX_SPEC "" \
42 # "%{a:" \
43 # "%{b:A/b/;" \
44 # "c:A/c/;" \
45 # "d:A/d/;" \
46 # ":A/};" \
47 # ":}"
49 # The script uses temporary subscripts in order to permit a recursive
50 # algorithm without the use of functions.
52 set -e
54 dirnames="$1"
55 options="$2"
56 matches="$3"
58 cat > print-sysroot-suffix3.sh <<\EOF
59 #! /bin/sh
60 # Print all the multilib matches for this option
61 result="$1"
62 EOF
63 for x in $matches; do
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
67 done
68 echo 'echo $result' >> print-sysroot-suffix3.sh
69 chmod +x print-sysroot-suffix3.sh
71 cat > print-sysroot-suffix2.sh <<\EOF
72 #! /bin/sh
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.
77 padding="$1"
78 optstring="$2"
79 shift 2
80 n="\" \\
81 $padding\""
82 if [ $# = 0 ]; then
83 EOF
85 pat=
86 for x in $dirnames; do
87 p=`echo $x | sed -e 's,=!,/$=/,'`
88 pat="$pat -e 's=^//$p='"
89 done
90 echo ' optstring=`echo "/$optstring" | sed '"$pat\`" >> print-sysroot-suffix2.sh
91 cat >> print-sysroot-suffix2.sh <<\EOF
92 case $optstring in
93 //*)
96 echo "$optstring"
98 esac
99 else
100 thisopt="$1"
101 shift
102 bit=
103 lastcond=
104 result=
105 for x in `echo "$thisopt" | sed -e 's,/, ,g'`; do
106 case $x in
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
111 done
112 cat >> print-sysroot-suffix2.sh <<\EOF
113 esac
114 bit=`"$0" "$padding " "$optstring$x/" "$@"`
115 if [ -z "$lastopt" ]; then
116 lastopt="$optmatch"
117 else
118 if [ "$lastbit" = "$bit" ]; then
119 lastopt="$lastopt|$optmatch"
120 else
121 result="$result$lastopt:$lastbit;$n"
122 lastopt="$optmatch"
125 lastbit="$bit"
126 done
127 bit=`"$0" "$padding " "$optstring" "$@"`
128 if [ "$bit" = "$lastbit" ]; then
129 if [ -z "$result" ]; then
130 echo "$bit"
131 else
132 echo "$n%{$result:$bit}"
134 else
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