cpphash.c (special_symbol): Remove spurious argument to cpp_lookup.
[gcc.git] / gcc / genmultilib
1 #!/bin/sh
2 # Generates multilib.h.
3 # Copyright (C) 1994, 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
4
5 #This file is part of GNU CC.
6
7 #GNU CC is free software; you can redistribute it and/or modify
8 #it under the terms of the GNU General Public License as published by
9 #the Free Software Foundation; either version 2, or (at your option)
10 #any later version.
11
12 #GNU CC is distributed in the hope that it will be useful,
13 #but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 #GNU General Public License for more details.
16
17 #You should have received a copy of the GNU General Public License
18 #along with GNU CC; see the file COPYING. If not, write to
19 #the Free Software Foundation, 59 Temple Place - Suite 330,
20 #Boston, MA 02111-1307, USA.
21
22 # This shell script produces a header file which the gcc driver
23 # program uses to pick which library to use based on the machine
24 # specific options that it is given.
25
26 # The first argument is a list of sets of options. The elements in
27 # the list are separated by spaces. Within an element, the options
28 # are separated by slashes or pipes. No leading dash is used on the
29 # options.
30 # Each option in a set separated by slashes is mutually incompatible
31 # with all other options
32 # in the set.
33 # Each option in a set separated by pipes will be used for the library
34 # compilation and any of the options in the set will be sufficient
35 # for it to be triggered.
36
37 # The optional second argument is a list of subdirectory names. If
38 # the second argument is non-empty, there must be as many elements in
39 # the second argument as there are options in the first argument. The
40 # elements in the second list are separated by spaces. If the second
41 # argument is empty, the option names will be used as the directory
42 # names.
43
44 # The optional third argument is a list of options which are
45 # identical. The elements in the list are separated by spaces. Each
46 # element must be of the form OPTION=OPTION. The first OPTION should
47 # appear in the first argument, and the second should be a synonym for
48 # it. Question marks are replaced with equal signs in both options.
49
50 # The optional fourth argument is a list of multilib directory
51 # combinations that should not be built.
52
53 # The optional fifth argument is a list of options that should be
54 # used whenever building multilib libraries.
55
56 # The output looks like
57 # #define MULTILIB_MATCHES "\
58 # SUBDIRECTORY OPTIONS;\
59 # ...
60 # "
61 # The SUBDIRECTORY is the subdirectory to use. The OPTIONS are
62 # multiple options separated by spaces. Each option may start with an
63 # exclamation point. gcc will consider each line in turn. If none of
64 # the options beginning with an exclamation point are present, and all
65 # of the other options are present, that subdirectory will be used.
66 # The order of the subdirectories is such that they can be created in
67 # order; that is, a subdirectory is preceded by all its parents.
68
69 # Here is a example (this is simplified from the actual 680x0 case):
70 # genmultilib "m68000/m68020 msoft-float" "m68000 m68020 msoft-float"
71 # "m68000=mc68000"
72 # This produces:
73 # ". !m68000 !mc68000 !m68020 !msoft-float;",
74 # "m68000 m68000 !m68020 !msoft-float;",
75 # "m68000 mc60000 !m68020 !msoft-float;",
76 # "m68020 !m68000 !mc68000 m68020 !msoft-float;",
77 # "msoft-float !m68000 !mc68000 !m68020 msoft-float;",
78 # "m68000/msoft-float m68000 !m68020 msoft-float;",
79 # "m68000/msoft-float mc68000 !m68020 msoft-float;",
80 # "m68020/msoft-float !m68000 !mc68000 m68020 msoft-float;",
81 #
82 # The effect is that `gcc -msoft-float' (for example) will append
83 # msoft-float to the directory name when searching for libraries or
84 # startup files, and `gcc -m68000 -msoft-float' (for example) will
85 # append m68000/msoft-float.
86
87 # Copy the positional parameters into variables.
88 options=$1
89 dirnames=$2
90 matches=$3
91 exceptions=$4
92 extra=$5
93
94 echo "static char *multilib_raw[] = {"
95
96 # What we want to do is select all combinations of the sets in
97 # options. Each combination which includes a set of mutually
98 # exclusive options must then be output multiple times, once for each
99 # item in the set. Selecting combinations is a recursive process.
100 # Since not all versions of sh support functions, we achieve recursion
101 # by creating a temporary shell script which invokes itself.
102 rm -f tmpmultilib
103 cat >tmpmultilib <<\EOF
104 #!/bin/sh
105 # This recursive script basically outputs all combinations of its
106 # input arguments, handling mutually exclusive sets of options by
107 # repetition. When the script is called, ${initial} is the list of
108 # options which should appear before all combinations this will
109 # output. The output looks like a list of subdirectory names with
110 # leading and trailing slashes.
111 if [ "$#" != "0" ]; then
112 first=$1
113 shift
114 case "$first" in
115 *\|*)
116 all=${initial}`echo $first | sed -e 's_|_/_'g`
117 first=`echo $first | sed -e 's_|_ _'g`
118 echo ${all}/
119 initial="${initial}${all}/" ./tmpmultilib $@
120 ./tmpmultilib $first $@ | grep -v "^${all}"
121 ;;
122 *)
123 for opt in `echo $first | sed -e 's|/| |'g`; do
124 echo ${initial}${opt}/
125 done
126 ./tmpmultilib $@
127 for opt in `echo $first | sed -e 's|/| |'g`; do
128 initial="${initial}${opt}/" ./tmpmultilib $@
129 done
130 esac
131 fi
132 EOF
133 chmod +x tmpmultilib
134
135 combinations=`initial=/ ./tmpmultilib ${options}`
136
137 rm -f tmpmultilib
138
139 # If there exceptions, weed them out now
140 if [ -n "${exceptions}" ]; then
141 rm -f tmpmultilib2
142 cat >tmpmultilib2 <<\EOF
143 #!/bin/sh
144 # This recursive script weeds out any combination of multilib
145 # switches that should not be generated. The output looks like
146 # a list of subdirectory names with leading and trailing slashes.
147
148 for opt in $@; do
149 case "$opt" in
150 EOF
151
152 for except in ${exceptions}; do
153 echo " /${except}/) : ;;" >> tmpmultilib2
154 done
155
156 cat >>tmpmultilib2 <<\EOF
157 *) echo ${opt};;
158 esac
159 done
160 EOF
161 chmod +x tmpmultilib2
162 combinations=`./tmpmultilib2 ${combinations}`
163 rm -f ./tmpmultilib2
164 fi
165
166 # Construct a sed pattern which will convert option names to directory
167 # names.
168 todirnames=
169 if [ -n "${dirnames}" ]; then
170 set x ${dirnames}
171 shift
172 for set in ${options}; do
173 for opts in `echo ${set} | sed -e 's|/| |'g`; do
174 patt="/"
175 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
176 if [ "$1" != "${opt}" ]; then
177 todirnames="${todirnames} -e s|/${opt}/|/${1}/|g"
178 patt="${patt}${1}/"
179 if [ "${patt}" != "/${1}/" ]; then
180 todirnames="${todirnames} -e s|${patt}|/${1}/|g"
181 fi
182 fi
183 done
184 shift
185 done
186 done
187 fi
188
189 # We need another recursive shell script to correctly handle positive
190 # matches. If we are invoked as
191 # genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2"
192 # we must output
193 # opt1/opt2 opt1 opt2
194 # opt1/opt2 nopt1 opt2
195 # opt1/opt2 opt1 nopt2
196 # opt1/opt2 nopt1 nopt2
197 # In other words, we must output all combinations of matches.
198 rm -f tmpmultilib2
199 cat >tmpmultilib2 <<\EOF
200 #!/bin/sh
201 # The positional parameters are a list of matches to consider.
202 # ${dirout} is the directory name and ${optout} is the current list of
203 # options.
204 if [ "$#" = "0" ]; then
205 echo "\"${dirout} ${optout};\","
206 else
207 first=$1
208 shift
209 dirout="${dirout}" optout="${optout}" ./tmpmultilib2 $@
210 l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'`
211 r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'`
212 if expr " ${optout} " : ".* ${l} .*" > /dev/null; then
213 newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'`
214 dirout="${dirout}" optout="${newopt}" ./tmpmultilib2 $@
215 fi
216 fi
217 EOF
218 chmod +x tmpmultilib2
219
220 # Start with the current directory, which includes only negations.
221 optout=
222 for set in ${options}; do
223 for opt in `echo ${set} | sed -e 's_[/|]_ _g'`; do
224 optout="${optout} !${opt}"
225 done
226 done
227 optout=`echo ${optout} | sed -e 's/^ //'`
228 echo "\". ${optout};\","
229
230 # Work over the list of combinations. We have to translate each one
231 # to use the directory names rather than the option names, we have to
232 # include the information in matches, and we have to generate the
233 # correct list of options and negations.
234 for combo in ${combinations}; do
235 # Use the directory names rather than the option names.
236 if [ -n "${todirnames}" ]; then
237 dirout=`echo ${combo} | sed ${todirnames}`
238 else
239 dirout=${combo}
240 fi
241 # Remove the leading and trailing slashes.
242 dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/$||g'`
243
244 # Look through the options. We must output each option that is
245 # present, and negate each option that is not present.
246 optout=
247 for set in ${options}; do
248 setopts=`echo ${set} | sed -e 's_[/|]_ _g'`
249 for opt in ${setopts}; do
250 if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then
251 optout="${optout} ${opt}"
252 else
253 optout="${optout} !${opt}"
254 fi
255 done
256 done
257 optout=`echo ${optout} | sed -e 's/^ //'`
258
259 # Output the line with all appropriate matches.
260 dirout="${dirout}" optout="${optout}" ./tmpmultilib2
261 done
262
263 # Terminate the list of string.
264 echo "NULL"
265 echo "};"
266
267 # Output all of the matches now as option and that is the same as that, with
268 # a semicolon trailer. Include all of the normal options as well.
269 # Note, the format of the matches is reversed compared
270 # to what we want, so switch them around.
271 echo ""
272 echo "static char *multilib_matches_raw[] = {"
273 for match in ${matches}; do
274 l=`echo ${match} | sed -e 's/=.*$//' -e 's/?/=/g'`
275 r=`echo ${match} | sed -e 's/^.*=//' -e 's/?/=/g'`
276 echo "\"${r} ${l};\","
277 done
278 for set in ${options}; do
279 for opt in `echo ${set} | sed -e 's_[/|]_ _'g`; do
280 echo "\"${opt} ${opt};\","
281 done
282 done
283 echo "NULL"
284 echo "};"
285
286 # Output the default options now
287 echo ""
288 echo "static char *multilib_extra = \"${extra}\";"
289 rm -f tmpmultilib2
290
291 exit 0