]> gcc.gnu.org Git - gcc.git/blame - gcc/genmultilib
2003-10-13 Michael Koch <konqueror@gmx.de>
[gcc.git] / gcc / genmultilib
CommitLineData
08b28cd3
DE
1#!/bin/sh
2# Generates multilib.h.
c79d892f 3# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2002 Free Software Foundation, Inc.
08b28cd3 4
1322177d 5#This file is part of GCC.
08b28cd3 6
1322177d
LB
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.
08b28cd3 11
1322177d
LB
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.
08b28cd3
DE
16
17#You should have received a copy of the GNU General Public License
1322177d
LB
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.
08b28cd3
DE
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
699a42a6
JJ
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
08b28cd3 32# in the set.
699a42a6
JJ
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.
08b28cd3
DE
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
75814ad4 48# it. Question marks are replaced with equal signs in both options.
08b28cd3 49
e09150c7
MM
50# The optional fourth argument is a list of multilib directory
51# combinations that should not be built.
52
961b7009
MM
53# The optional fifth argument is a list of options that should be
54# used whenever building multilib libraries.
55
0a8d6618
BC
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.
cc712abf
JM
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
0a8d6618
BC
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
5bbcd587
JJ
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
c49d2df6
JJ
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
08b28cd3
DE
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
0a8d6618
BC
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=*'
5bbcd587 90# '' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany'
c49d2df6 91# '../lib64 ../lib32 alt' yes
08b28cd3 92# This produces:
0a8d6618 93# ". !m64 !m32 !mno-app-regs !mcmodel=medany;",
5bbcd587
JJ
94# "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;",
95# "32:../lib32 !m64 m32 !mno-app-regs !mcmodel=medany;",
0a8d6618
BC
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;",
5bbcd587
JJ
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;",
87e24276 102#
0a8d6618
BC
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.
08b28cd3
DE
110
111# Copy the positional parameters into variables.
112options=$1
113dirnames=$2
114matches=$3
e09150c7 115exceptions=$4
961b7009 116extra=$5
0a8d6618 117exclusions=$6
5bbcd587 118osdirnames=$7
c49d2df6 119enable_multilib=$8
961b7009 120
3b304f5b 121echo "static const char *const multilib_raw[] = {"
08b28cd3 122
c79d892f 123mkdir tmpmultilib.$$ || exit 1
e489a31f
JM
124# Use cd ./foo to avoid CDPATH output.
125cd ./tmpmultilib.$$ || exit 1
c79d892f 126
08b28cd3
DE
127# What we want to do is select all combinations of the sets in
128# options. Each combination which includes a set of mutually
129# exclusive options must then be output multiple times, once for each
130# item in the set. Selecting combinations is a recursive process.
131# Since not all versions of sh support functions, we achieve recursion
132# by creating a temporary shell script which invokes itself.
133rm -f tmpmultilib
134cat >tmpmultilib <<\EOF
135#!/bin/sh
136# This recursive script basically outputs all combinations of its
137# input arguments, handling mutually exclusive sets of options by
138# repetition. When the script is called, ${initial} is the list of
139# options which should appear before all combinations this will
140# output. The output looks like a list of subdirectory names with
141# leading and trailing slashes.
142if [ "$#" != "0" ]; then
143 first=$1
144 shift
699a42a6
JJ
145 case "$first" in
146 *\|*)
147 all=${initial}`echo $first | sed -e 's_|_/_'g`
148 first=`echo $first | sed -e 's_|_ _'g`
149 echo ${all}/
150 initial="${initial}${all}/" ./tmpmultilib $@
151 ./tmpmultilib $first $@ | grep -v "^${all}"
152 ;;
153 *)
154 for opt in `echo $first | sed -e 's|/| |'g`; do
155 echo ${initial}${opt}/
156 done
157 ./tmpmultilib $@
158 for opt in `echo $first | sed -e 's|/| |'g`; do
159 initial="${initial}${opt}/" ./tmpmultilib $@
160 done
161 esac
08b28cd3
DE
162fi
163EOF
164chmod +x tmpmultilib
165
166combinations=`initial=/ ./tmpmultilib ${options}`
167
e09150c7
MM
168# If there exceptions, weed them out now
169if [ -n "${exceptions}" ]; then
e09150c7
MM
170 cat >tmpmultilib2 <<\EOF
171#!/bin/sh
172# This recursive script weeds out any combination of multilib
173# switches that should not be generated. The output looks like
174# a list of subdirectory names with leading and trailing slashes.
175
176 for opt in $@; do
177 case "$opt" in
178EOF
179
180 for except in ${exceptions}; do
181 echo " /${except}/) : ;;" >> tmpmultilib2
182 done
183
184cat >>tmpmultilib2 <<\EOF
185 *) echo ${opt};;
186 esac
187 done
188EOF
189 chmod +x tmpmultilib2
190 combinations=`./tmpmultilib2 ${combinations}`
e09150c7
MM
191fi
192
08b28cd3
DE
193# Construct a sed pattern which will convert option names to directory
194# names.
195todirnames=
196if [ -n "${dirnames}" ]; then
197 set x ${dirnames}
198 shift
199 for set in ${options}; do
699a42a6
JJ
200 for opts in `echo ${set} | sed -e 's|/| |'g`; do
201 patt="/"
202 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
203 if [ "$1" != "${opt}" ]; then
204 todirnames="${todirnames} -e s|/${opt}/|/${1}/|g"
205 patt="${patt}${1}/"
206 if [ "${patt}" != "/${1}/" ]; then
207 todirnames="${todirnames} -e s|${patt}|/${1}/|g"
208 fi
209 fi
210 done
08b28cd3
DE
211 shift
212 done
213 done
214fi
215
5bbcd587
JJ
216# Construct a sed pattern which will convert option names to OS directory
217# names.
218toosdirnames=
219if [ -n "${osdirnames}" ]; then
220 set x ${osdirnames}
221 shift
222 for set in ${options}; do
223 for opts in `echo ${set} | sed -e 's|/| |'g`; do
224 patt="/"
225 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
226 if [ "$1" != "${opt}" ]; then
227 toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g"
228 patt="${patt}${1}/"
229 if [ "${patt}" != "/${1}/" ]; then
230 toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g"
231 fi
232 fi
233 done
234 shift
235 done
236 done
237fi
238
08b28cd3
DE
239# We need another recursive shell script to correctly handle positive
240# matches. If we are invoked as
241# genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2"
242# we must output
243# opt1/opt2 opt1 opt2
244# opt1/opt2 nopt1 opt2
245# opt1/opt2 opt1 nopt2
246# opt1/opt2 nopt1 nopt2
247# In other words, we must output all combinations of matches.
248rm -f tmpmultilib2
249cat >tmpmultilib2 <<\EOF
250#!/bin/sh
251# The positional parameters are a list of matches to consider.
252# ${dirout} is the directory name and ${optout} is the current list of
253# options.
254if [ "$#" = "0" ]; then
87e24276 255 echo "\"${dirout} ${optout};\","
08b28cd3
DE
256else
257 first=$1
258 shift
259 dirout="${dirout}" optout="${optout}" ./tmpmultilib2 $@
75814ad4
MM
260 l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'`
261 r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'`
eedea0f2 262 if expr " ${optout} " : ".* ${l} .*" > /dev/null; then
08b28cd3
DE
263 newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'`
264 dirout="${dirout}" optout="${newopt}" ./tmpmultilib2 $@
eedea0f2 265 fi
08b28cd3
DE
266fi
267EOF
268chmod +x tmpmultilib2
269
08b28cd3
DE
270# Start with the current directory, which includes only negations.
271optout=
272for set in ${options}; do
699a42a6 273 for opt in `echo ${set} | sed -e 's_[/|]_ _g'`; do
08b28cd3
DE
274 optout="${optout} !${opt}"
275 done
276done
277optout=`echo ${optout} | sed -e 's/^ //'`
87e24276 278echo "\". ${optout};\","
08b28cd3
DE
279
280# Work over the list of combinations. We have to translate each one
281# to use the directory names rather than the option names, we have to
282# include the information in matches, and we have to generate the
283# correct list of options and negations.
284for combo in ${combinations}; do
285 # Use the directory names rather than the option names.
286 if [ -n "${todirnames}" ]; then
287 dirout=`echo ${combo} | sed ${todirnames}`
288 else
289 dirout=${combo}
290 fi
291 # Remove the leading and trailing slashes.
292 dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/$||g'`
293
5bbcd587
JJ
294 # Use the OS directory names rather than the option names.
295 if [ -n "${toosdirnames}" ]; then
296 osdirout=`echo ${combo} | sed ${toosdirnames}`
297 # Remove the leading and trailing slashes.
298 osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/$||g'`
c49d2df6
JJ
299 if [ "x${enable_multilib}" != xyes ]; then
300 dirout=".:${osdirout}"
301 else
5bbcd587
JJ
302 dirout="${dirout}:${osdirout}"
303 fi
c49d2df6
JJ
304 else
305 if [ "x${enable_multilib}" != xyes ]; then
306 # genmultilib with --disable-multilib should be
307 # called with '' '' '' '' '' '' '' no
308 # if MULTILIB_OSDIRNAMES is empty.
309 exit 1
310 fi
5bbcd587
JJ
311 fi
312
08b28cd3 313 # Look through the options. We must output each option that is
fb685388 314 # present, and negate each option that is not present.
08b28cd3
DE
315 optout=
316 for set in ${options}; do
699a42a6 317 setopts=`echo ${set} | sed -e 's_[/|]_ _g'`
08b28cd3 318 for opt in ${setopts}; do
eedea0f2 319 if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then
08b28cd3 320 optout="${optout} ${opt}"
fb685388
RK
321 else
322 optout="${optout} !${opt}"
eedea0f2 323 fi
08b28cd3 324 done
08b28cd3
DE
325 done
326 optout=`echo ${optout} | sed -e 's/^ //'`
327
08b28cd3 328 # Output the line with all appropriate matches.
961b7009 329 dirout="${dirout}" optout="${optout}" ./tmpmultilib2
08b28cd3
DE
330done
331
87e24276
JW
332# Terminate the list of string.
333echo "NULL"
961b7009
MM
334echo "};"
335
336# Output all of the matches now as option and that is the same as that, with
31031edd 337# a semicolon trailer. Include all of the normal options as well.
961b7009
MM
338# Note, the format of the matches is reversed compared
339# to what we want, so switch them around.
340echo ""
3b304f5b 341echo "static const char *const multilib_matches_raw[] = {"
961b7009
MM
342for match in ${matches}; do
343 l=`echo ${match} | sed -e 's/=.*$//' -e 's/?/=/g'`
344 r=`echo ${match} | sed -e 's/^.*=//' -e 's/?/=/g'`
345 echo "\"${r} ${l};\","
346done
347for set in ${options}; do
699a42a6 348 for opt in `echo ${set} | sed -e 's_[/|]_ _'g`; do
961b7009
MM
349 echo "\"${opt} ${opt};\","
350 done
351done
352echo "NULL"
353echo "};"
08b28cd3 354
961b7009
MM
355# Output the default options now
356echo ""
3b304f5b 357echo "static const char *multilib_extra = \"${extra}\";"
0a8d6618
BC
358
359# Output the exclusion rules now
360echo ""
3b304f5b 361echo "static const char *const multilib_exclusions_raw[] = {"
0a8d6618
BC
362for rule in ${exclusions}; do
363 s=`echo ${rule} | sed -e 's,/, ,g'`
364 echo "\"${s};\","
365done
366echo "NULL"
367echo "};"
368
5bbcd587
JJ
369# Output the options now
370moptions=`echo ${options} | sed -e 's,[ ][ ]*, ,g'`
371echo ""
372echo "static const char *multilib_options = \"${moptions}\";"
373
c79d892f
GK
374cd ..
375rm -r tmpmultilib.$$
08b28cd3
DE
376
377exit 0
This page took 1.517946 seconds and 5 git commands to generate.