]> gcc.gnu.org Git - gcc.git/blob - gcc/genmultilib
* genmultilib: Create temporary files in unique subdirectory.
[gcc.git] / gcc / genmultilib
1 #!/bin/sh
2 # Generates multilib.h.
3 # Copyright (C) 1994, 1995, 1996, 1997, 1999, 2002 Free Software Foundation, Inc.
4
5 #This file is part of GCC.
6
7 #GCC is free software; you can redistribute it and/or modify it under
8 #the terms of the GNU General Public License as published by the Free
9 #Software Foundation; either version 2, or (at your option) any later
10 #version.
11
12 #GCC is distributed in the hope that it will be useful, but WITHOUT
13 #ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 #FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 #for more details.
16
17 #You should have received a copy of the GNU General Public License
18 #along with GCC; see the file COPYING. If not, write to the Free
19 #Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 #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 optional sixth argument is a list of exclusions used internally by
57 # the compiler similar to exceptions. The difference being that exclusions
58 # allow matching default options that genmultilib does not know about and
59 # is done at runtime as opposed to being sorted out at compile time.
60 # Each element in the list is a separate exclusion rule. Each rule is
61 # a list of options (sans preceding '-') separated by a '/'. The options
62 # on the rule are grouped as an AND operation, and all options much match
63 # for the rule to exclude a set. Options can be preceded with a '!' to
64 # match a logical NOT.
65
66 # The optional sevenths argument is a list of OS subdirectory names.
67 # The format is the same as of the second argument.
68 # The difference is that second argument describes multilib directories
69 # in GCC conventions, while this one the OS multilib convention.
70
71 # The last option should be "yes" if multilibs are enabled. If it is not
72 # "yes", all GCC multilib dir names will be ".".
73
74 # The output looks like
75 # #define MULTILIB_MATCHES "\
76 # SUBDIRECTORY OPTIONS;\
77 # ...
78 # "
79 # The SUBDIRECTORY is the subdirectory to use. The OPTIONS are
80 # multiple options separated by spaces. Each option may start with an
81 # exclamation point. gcc will consider each line in turn. If none of
82 # the options beginning with an exclamation point are present, and all
83 # of the other options are present, that subdirectory will be used.
84 # The order of the subdirectories is such that they can be created in
85 # order; that is, a subdirectory is preceded by all its parents.
86
87 # Here is an example (this is from the actual sparc64 case):
88 # genmultilib 'm64/m32 mno-app-regs|mcmodel=medany' '64 32 alt'
89 # 'mcmodel?medany=mcmodel?medmid' 'm32/mno-app-regs* m32/mcmodel=*'
90 # '' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany'
91 # '../lib64 ../lib32 alt' yes
92 # This produces:
93 # ". !m64 !m32 !mno-app-regs !mcmodel=medany;",
94 # "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;",
95 # "32:../lib32 !m64 m32 !mno-app-regs !mcmodel=medany;",
96 # "alt !m64 !m32 mno-app-regs mcmodel=medany;",
97 # "alt !m64 !m32 mno-app-regs !mcmodel=medany;",
98 # "alt !m64 !m32 !mno-app-regs mcmodel=medany;",
99 # "64/alt:../lib64/alt m64 !m32 mno-app-regs mcmodel=medany;",
100 # "64/alt:../lib64/alt m64 !m32 mno-app-regs !mcmodel=medany;",
101 # "64/alt:../lib64/alt m64 !m32 !mno-app-regs mcmodel=medany;",
102 #
103 # The effect is that `gcc -mno-app-regs' (for example) will append "alt"
104 # to the directory name when searching for libraries or startup files and
105 # `gcc -m32 -mcmodel=medany' (for example) will append "32/alt". Also note
106 # that exclusion above is moot, unless the compiler had a default of -m32,
107 # which would mean that all of the "alt" directories (not the 64/alt ones)
108 # would be ignored (not generated, nor used) since the exclusion also
109 # matches the multilib_default args.
110
111 # Copy the positional parameters into variables.
112 options=$1
113 dirnames=$2
114 matches=$3
115 exceptions=$4
116 extra=$5
117 exclusions=$6
118 osdirnames=$7
119 enable_multilib=$8
120
121 echo "static const char *const multilib_raw[] = {"
122
123 mkdir tmpmultilib.$$ || exit 1
124 cd tmpmultilib.$$ || exit 1
125
126 # What we want to do is select all combinations of the sets in
127 # options. Each combination which includes a set of mutually
128 # exclusive options must then be output multiple times, once for each
129 # item in the set. Selecting combinations is a recursive process.
130 # Since not all versions of sh support functions, we achieve recursion
131 # by creating a temporary shell script which invokes itself.
132 rm -f tmpmultilib
133 cat >tmpmultilib <<\EOF
134 #!/bin/sh
135 # This recursive script basically outputs all combinations of its
136 # input arguments, handling mutually exclusive sets of options by
137 # repetition. When the script is called, ${initial} is the list of
138 # options which should appear before all combinations this will
139 # output. The output looks like a list of subdirectory names with
140 # leading and trailing slashes.
141 if [ "$#" != "0" ]; then
142 first=$1
143 shift
144 case "$first" in
145 *\|*)
146 all=${initial}`echo $first | sed -e 's_|_/_'g`
147 first=`echo $first | sed -e 's_|_ _'g`
148 echo ${all}/
149 initial="${initial}${all}/" ./tmpmultilib $@
150 ./tmpmultilib $first $@ | grep -v "^${all}"
151 ;;
152 *)
153 for opt in `echo $first | sed -e 's|/| |'g`; do
154 echo ${initial}${opt}/
155 done
156 ./tmpmultilib $@
157 for opt in `echo $first | sed -e 's|/| |'g`; do
158 initial="${initial}${opt}/" ./tmpmultilib $@
159 done
160 esac
161 fi
162 EOF
163 chmod +x tmpmultilib
164
165 combinations=`initial=/ ./tmpmultilib ${options}`
166
167 # If there exceptions, weed them out now
168 if [ -n "${exceptions}" ]; then
169 cat >tmpmultilib2 <<\EOF
170 #!/bin/sh
171 # This recursive script weeds out any combination of multilib
172 # switches that should not be generated. The output looks like
173 # a list of subdirectory names with leading and trailing slashes.
174
175 for opt in $@; do
176 case "$opt" in
177 EOF
178
179 for except in ${exceptions}; do
180 echo " /${except}/) : ;;" >> tmpmultilib2
181 done
182
183 cat >>tmpmultilib2 <<\EOF
184 *) echo ${opt};;
185 esac
186 done
187 EOF
188 chmod +x tmpmultilib2
189 combinations=`./tmpmultilib2 ${combinations}`
190 fi
191
192 # Construct a sed pattern which will convert option names to directory
193 # names.
194 todirnames=
195 if [ -n "${dirnames}" ]; then
196 set x ${dirnames}
197 shift
198 for set in ${options}; do
199 for opts in `echo ${set} | sed -e 's|/| |'g`; do
200 patt="/"
201 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
202 if [ "$1" != "${opt}" ]; then
203 todirnames="${todirnames} -e s|/${opt}/|/${1}/|g"
204 patt="${patt}${1}/"
205 if [ "${patt}" != "/${1}/" ]; then
206 todirnames="${todirnames} -e s|${patt}|/${1}/|g"
207 fi
208 fi
209 done
210 shift
211 done
212 done
213 fi
214
215 # Construct a sed pattern which will convert option names to OS directory
216 # names.
217 toosdirnames=
218 if [ -n "${osdirnames}" ]; then
219 set x ${osdirnames}
220 shift
221 for set in ${options}; do
222 for opts in `echo ${set} | sed -e 's|/| |'g`; do
223 patt="/"
224 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
225 if [ "$1" != "${opt}" ]; then
226 toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g"
227 patt="${patt}${1}/"
228 if [ "${patt}" != "/${1}/" ]; then
229 toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g"
230 fi
231 fi
232 done
233 shift
234 done
235 done
236 fi
237
238 # We need another recursive shell script to correctly handle positive
239 # matches. If we are invoked as
240 # genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2"
241 # we must output
242 # opt1/opt2 opt1 opt2
243 # opt1/opt2 nopt1 opt2
244 # opt1/opt2 opt1 nopt2
245 # opt1/opt2 nopt1 nopt2
246 # In other words, we must output all combinations of matches.
247 rm -f tmpmultilib2
248 cat >tmpmultilib2 <<\EOF
249 #!/bin/sh
250 # The positional parameters are a list of matches to consider.
251 # ${dirout} is the directory name and ${optout} is the current list of
252 # options.
253 if [ "$#" = "0" ]; then
254 echo "\"${dirout} ${optout};\","
255 else
256 first=$1
257 shift
258 dirout="${dirout}" optout="${optout}" ./tmpmultilib2 $@
259 l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'`
260 r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'`
261 if expr " ${optout} " : ".* ${l} .*" > /dev/null; then
262 newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'`
263 dirout="${dirout}" optout="${newopt}" ./tmpmultilib2 $@
264 fi
265 fi
266 EOF
267 chmod +x tmpmultilib2
268
269 # Start with the current directory, which includes only negations.
270 optout=
271 for set in ${options}; do
272 for opt in `echo ${set} | sed -e 's_[/|]_ _g'`; do
273 optout="${optout} !${opt}"
274 done
275 done
276 optout=`echo ${optout} | sed -e 's/^ //'`
277 echo "\". ${optout};\","
278
279 # Work over the list of combinations. We have to translate each one
280 # to use the directory names rather than the option names, we have to
281 # include the information in matches, and we have to generate the
282 # correct list of options and negations.
283 for combo in ${combinations}; do
284 # Use the directory names rather than the option names.
285 if [ -n "${todirnames}" ]; then
286 dirout=`echo ${combo} | sed ${todirnames}`
287 else
288 dirout=${combo}
289 fi
290 # Remove the leading and trailing slashes.
291 dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/$||g'`
292
293 # Use the OS directory names rather than the option names.
294 if [ -n "${toosdirnames}" ]; then
295 osdirout=`echo ${combo} | sed ${toosdirnames}`
296 # Remove the leading and trailing slashes.
297 osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/$||g'`
298 if [ "x${enable_multilib}" != xyes ]; then
299 dirout=".:${osdirout}"
300 else
301 dirout="${dirout}:${osdirout}"
302 fi
303 else
304 if [ "x${enable_multilib}" != xyes ]; then
305 # genmultilib with --disable-multilib should be
306 # called with '' '' '' '' '' '' '' no
307 # if MULTILIB_OSDIRNAMES is empty.
308 exit 1
309 fi
310 fi
311
312 # Look through the options. We must output each option that is
313 # present, and negate each option that is not present.
314 optout=
315 for set in ${options}; do
316 setopts=`echo ${set} | sed -e 's_[/|]_ _g'`
317 for opt in ${setopts}; do
318 if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then
319 optout="${optout} ${opt}"
320 else
321 optout="${optout} !${opt}"
322 fi
323 done
324 done
325 optout=`echo ${optout} | sed -e 's/^ //'`
326
327 # Output the line with all appropriate matches.
328 dirout="${dirout}" optout="${optout}" ./tmpmultilib2
329 done
330
331 # Terminate the list of string.
332 echo "NULL"
333 echo "};"
334
335 # Output all of the matches now as option and that is the same as that, with
336 # a semicolon trailer. Include all of the normal options as well.
337 # Note, the format of the matches is reversed compared
338 # to what we want, so switch them around.
339 echo ""
340 echo "static const char *const multilib_matches_raw[] = {"
341 for match in ${matches}; do
342 l=`echo ${match} | sed -e 's/=.*$//' -e 's/?/=/g'`
343 r=`echo ${match} | sed -e 's/^.*=//' -e 's/?/=/g'`
344 echo "\"${r} ${l};\","
345 done
346 for set in ${options}; do
347 for opt in `echo ${set} | sed -e 's_[/|]_ _'g`; do
348 echo "\"${opt} ${opt};\","
349 done
350 done
351 echo "NULL"
352 echo "};"
353
354 # Output the default options now
355 echo ""
356 echo "static const char *multilib_extra = \"${extra}\";"
357
358 # Output the exclusion rules now
359 echo ""
360 echo "static const char *const multilib_exclusions_raw[] = {"
361 for rule in ${exclusions}; do
362 s=`echo ${rule} | sed -e 's,/, ,g'`
363 echo "\"${s};\","
364 done
365 echo "NULL"
366 echo "};"
367
368 # Output the options now
369 moptions=`echo ${options} | sed -e 's,[ ][ ]*, ,g'`
370 echo ""
371 echo "static const char *multilib_options = \"${moptions}\";"
372
373 cd ..
374 rm -r tmpmultilib.$$
375
376 exit 0
This page took 0.064057 seconds and 6 git commands to generate.