1 1.1 mrg #!/bin/sh 2 1.1 mrg # Generates multilib.h. 3 1.12 mrg # Copyright (C) 1994-2022 Free Software Foundation, Inc. 4 1.1 mrg 5 1.1 mrg #This file is part of GCC. 6 1.1 mrg 7 1.1 mrg #GCC is free software; you can redistribute it and/or modify it under 8 1.1 mrg #the terms of the GNU General Public License as published by the Free 9 1.1 mrg #Software Foundation; either version 3, or (at your option) any later 10 1.1 mrg #version. 11 1.1 mrg 12 1.1 mrg #GCC is distributed in the hope that it will be useful, but WITHOUT 13 1.1 mrg #ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 1.1 mrg #FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 1.1 mrg #for more details. 16 1.1 mrg 17 1.1 mrg #You should have received a copy of the GNU General Public License 18 1.1 mrg #along with GCC; see the file COPYING3. If not see 19 1.1 mrg #<http://www.gnu.org/licenses/>. 20 1.1 mrg 21 1.1 mrg # This shell script produces a header file which the gcc driver 22 1.1 mrg # program uses to pick which library to use based on the machine 23 1.1 mrg # specific options that it is given. 24 1.1 mrg 25 1.1 mrg # The first argument is a list of sets of options. The elements in 26 1.1 mrg # the list are separated by spaces. Within an element, the options 27 1.1 mrg # are separated by slashes or pipes. No leading dash is used on the 28 1.1 mrg # options. 29 1.1 mrg # Each option in a set separated by slashes is mutually incompatible 30 1.1 mrg # with all other options 31 1.1 mrg # in the set. 32 1.1 mrg # Each option in a set separated by pipes will be used for the library 33 1.1 mrg # compilation and any of the options in the set will be sufficient 34 1.1 mrg # for it to be triggered. 35 1.1 mrg 36 1.1 mrg # The optional second argument is a list of subdirectory names. If 37 1.1 mrg # the second argument is non-empty, there must be as many elements in 38 1.1 mrg # the second argument as there are options in the first argument. The 39 1.1 mrg # elements in the second list are separated by spaces. If the second 40 1.1 mrg # argument is empty, the option names will be used as the directory 41 1.1 mrg # names. 42 1.1 mrg 43 1.1 mrg # The optional third argument is a list of options which are 44 1.1 mrg # identical. The elements in the list are separated by spaces. Each 45 1.1 mrg # element must be of the form OPTION=OPTION. The first OPTION should 46 1.1 mrg # appear in the first argument, and the second should be a synonym for 47 1.1 mrg # it. Question marks are replaced with equal signs in both options. 48 1.1 mrg 49 1.1 mrg # The optional fourth argument is a list of multilib directory 50 1.1 mrg # combinations that should not be built. 51 1.1 mrg 52 1.1 mrg # The optional fifth argument is a list of options that should be 53 1.1 mrg # used whenever building multilib libraries. 54 1.1 mrg 55 1.1 mrg # The optional sixth argument is a list of exclusions used internally by 56 1.1 mrg # the compiler similar to exceptions. The difference being that exclusions 57 1.1 mrg # allow matching default options that genmultilib does not know about and 58 1.1 mrg # is done at runtime as opposed to being sorted out at compile time. 59 1.1 mrg # Each element in the list is a separate exclusion rule. Each rule is 60 1.1 mrg # a list of options (sans preceding '-') separated by a '/'. The options 61 1.1 mrg # on the rule are grouped as an AND operation, and all options much match 62 1.1 mrg # for the rule to exclude a set. Options can be preceded with a '!' to 63 1.1 mrg # match a logical NOT. 64 1.1 mrg 65 1.1 mrg # The optional seventh argument is a list of OS subdirectory names. 66 1.1 mrg # The format is either the same as of the second argument, or a set of 67 1.1 mrg # mappings. When it is the same as the second argument, it describes 68 1.1 mrg # the multilib directories using OS conventions, rather than GCC 69 1.1 mrg # conventions. When it is a set of mappings of the form gccdir=osdir, 70 1.1 mrg # the left side gives the GCC convention and the right gives the 71 1.1 mrg # equivalent OS defined location. If the osdir part begins with a !, 72 1.1 mrg # the os directory names are used exclusively. Use the mapping when 73 1.1 mrg # there is no one-to-one equivalence between GCC levels and the OS. 74 1.1 mrg 75 1.3 mrg # The optional eighth argument which intends to reduce the effort to write 76 1.3 mrg # so many MULTILIB_EXCEPTIONS rules. This option defines a series of option 77 1.3 mrg # combinations that we actually required. 78 1.3 mrg # For some cases, the generated option combinations are far more than what 79 1.3 mrg # we need, we have to write a lot of rules to screen out combinations we 80 1.3 mrg # don't need. If we missed some rules, the unexpected libraries will be built. 81 1.3 mrg # Now with this argument, one can simply give what combinations are needed. 82 1.3 mrg # It is pretty straigtforward. 83 1.3 mrg # This argument can be used together with MULTILIB_EXCEPTIONS and will take 84 1.3 mrg # effect after the MULTILIB_EXCEPTIONS. 85 1.3 mrg 86 1.3 mrg # The optional ninth argument is the multiarch name. 87 1.3 mrg 88 1.3 mrg # The optional tenth argument specifies how to reuse multilib for different 89 1.3 mrg # option sets. 90 1.3 mrg 91 1.1 mrg # The last option should be "yes" if multilibs are enabled. If it is not 92 1.1 mrg # "yes", all GCC multilib dir names will be ".". 93 1.1 mrg 94 1.1 mrg # The output looks like 95 1.1 mrg # #define MULTILIB_MATCHES "\ 96 1.1 mrg # SUBDIRECTORY OPTIONS;\ 97 1.1 mrg # ... 98 1.1 mrg # " 99 1.1 mrg # The SUBDIRECTORY is the subdirectory to use. The OPTIONS are 100 1.1 mrg # multiple options separated by spaces. Each option may start with an 101 1.1 mrg # exclamation point. gcc will consider each line in turn. If none of 102 1.1 mrg # the options beginning with an exclamation point are present, and all 103 1.1 mrg # of the other options are present, that subdirectory will be used. 104 1.1 mrg # The order of the subdirectories is such that they can be created in 105 1.1 mrg # order; that is, a subdirectory is preceded by all its parents. 106 1.1 mrg 107 1.1 mrg # Here is an example (this is from the actual sparc64 case): 108 1.1 mrg # genmultilib 'm64/m32 mno-app-regs|mcmodel=medany' '64 32 alt' 109 1.1 mrg # 'mcmodel?medany=mcmodel?medmid' 'm32/mno-app-regs* m32/mcmodel=*' 110 1.1 mrg # '' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany' 111 1.3 mrg # '../lib64 ../lib32 alt' '' '' '' yes 112 1.1 mrg # This produces: 113 1.1 mrg # ". !m64 !m32 !mno-app-regs !mcmodel=medany;", 114 1.1 mrg # "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;", 115 1.1 mrg # "32:../lib32 !m64 m32 !mno-app-regs !mcmodel=medany;", 116 1.1 mrg # "alt !m64 !m32 mno-app-regs mcmodel=medany;", 117 1.1 mrg # "alt !m64 !m32 mno-app-regs !mcmodel=medany;", 118 1.1 mrg # "alt !m64 !m32 !mno-app-regs mcmodel=medany;", 119 1.1 mrg # "64/alt:../lib64/alt m64 !m32 mno-app-regs mcmodel=medany;", 120 1.1 mrg # "64/alt:../lib64/alt m64 !m32 mno-app-regs !mcmodel=medany;", 121 1.1 mrg # "64/alt:../lib64/alt m64 !m32 !mno-app-regs mcmodel=medany;", 122 1.1 mrg # 123 1.1 mrg # The effect is that `gcc -mno-app-regs' (for example) will append "alt" 124 1.1 mrg # to the directory name when searching for libraries or startup files and 125 1.1 mrg # `gcc -m32 -mcmodel=medany' (for example) will append "32/alt". Also note 126 1.1 mrg # that exclusion above is moot, unless the compiler had a default of -m32, 127 1.1 mrg # which would mean that all of the "alt" directories (not the 64/alt ones) 128 1.1 mrg # would be ignored (not generated, nor used) since the exclusion also 129 1.1 mrg # matches the multilib_default args. 130 1.1 mrg 131 1.1 mrg # Copy the positional parameters into variables. 132 1.1 mrg options=$1 133 1.1 mrg dirnames=$2 134 1.1 mrg matches=$3 135 1.1 mrg exceptions=$4 136 1.1 mrg extra=$5 137 1.1 mrg exclusions=$6 138 1.1 mrg osdirnames=$7 139 1.3 mrg multilib_required=$8 140 1.3 mrg multiarch=$9 141 1.3 mrg multilib_reuse=${10} 142 1.3 mrg enable_multilib=${11} 143 1.1 mrg 144 1.1 mrg echo "static const char *const multilib_raw[] = {" 145 1.1 mrg 146 1.1 mrg mkdir tmpmultilib.$$ || exit 1 147 1.1 mrg # Use cd ./foo to avoid CDPATH output. 148 1.1 mrg cd ./tmpmultilib.$$ || exit 1 149 1.1 mrg 150 1.1 mrg # What we want to do is select all combinations of the sets in 151 1.1 mrg # options. Each combination which includes a set of mutually 152 1.1 mrg # exclusive options must then be output multiple times, once for each 153 1.1 mrg # item in the set. Selecting combinations is a recursive process. 154 1.1 mrg # Since not all versions of sh support functions, we achieve recursion 155 1.1 mrg # by creating a temporary shell script which invokes itself. 156 1.1 mrg rm -f tmpmultilib 157 1.1 mrg cat >tmpmultilib <<EOF 158 1.1 mrg #!${CONFIG_SHELL:-/bin/sh} 159 1.1 mrg EOF 160 1.1 mrg cat >>tmpmultilib <<\EOF 161 1.1 mrg # This recursive script basically outputs all combinations of its 162 1.1 mrg # input arguments, handling mutually exclusive sets of options by 163 1.1 mrg # repetition. When the script is called, ${initial} is the list of 164 1.1 mrg # options which should appear before all combinations this will 165 1.1 mrg # output. The output looks like a list of subdirectory names with 166 1.1 mrg # leading and trailing slashes. 167 1.1 mrg if [ "$#" != "0" ]; then 168 1.1 mrg first=$1 169 1.1 mrg shift 170 1.1 mrg case "$first" in 171 1.1 mrg *\|*) 172 1.1 mrg all=${initial}`echo $first | sed -e 's_|_/_'g` 173 1.1 mrg first=`echo $first | sed -e 's_|_ _'g` 174 1.1 mrg echo ${all}/ 175 1.1 mrg initial="${initial}${all}/" ./tmpmultilib $@ 176 1.1 mrg ./tmpmultilib $first $@ | grep -v "^${all}" 177 1.1 mrg ;; 178 1.1 mrg *) 179 1.1 mrg for opt in `echo $first | sed -e 's|/| |'g`; do 180 1.1 mrg echo ${initial}${opt}/ 181 1.1 mrg done 182 1.1 mrg ./tmpmultilib $@ 183 1.1 mrg for opt in `echo $first | sed -e 's|/| |'g`; do 184 1.1 mrg initial="${initial}${opt}/" ./tmpmultilib $@ 185 1.1 mrg done 186 1.1 mrg esac 187 1.1 mrg fi 188 1.1 mrg EOF 189 1.1 mrg chmod +x tmpmultilib 190 1.1 mrg 191 1.9 mrg combinations=`initial=/ ./tmpmultilib ${options}` 192 1.1 mrg 193 1.1 mrg # If there exceptions, weed them out now 194 1.1 mrg if [ -n "${exceptions}" ]; then 195 1.1 mrg cat >tmpmultilib2 <<EOF 196 1.1 mrg #!${CONFIG_SHELL:-/bin/sh} 197 1.1 mrg EOF 198 1.1 mrg cat >>tmpmultilib2 <<\EOF 199 1.1 mrg # This recursive script weeds out any combination of multilib 200 1.1 mrg # switches that should not be generated. The output looks like 201 1.1 mrg # a list of subdirectory names with leading and trailing slashes. 202 1.1 mrg 203 1.1 mrg for opt in $@; do 204 1.1 mrg case "$opt" in 205 1.1 mrg EOF 206 1.1 mrg 207 1.1 mrg for except in ${exceptions}; do 208 1.1 mrg echo " /${except}/) : ;;" >> tmpmultilib2 209 1.1 mrg done 210 1.1 mrg 211 1.1 mrg cat >>tmpmultilib2 <<\EOF 212 1.1 mrg *) echo ${opt};; 213 1.1 mrg esac 214 1.1 mrg done 215 1.1 mrg EOF 216 1.1 mrg chmod +x tmpmultilib2 217 1.1 mrg combinations=`./tmpmultilib2 ${combinations}` 218 1.1 mrg fi 219 1.1 mrg 220 1.3 mrg # If the MULTILIB_REQUIRED list are provided, 221 1.3 mrg # filter out combinations not in this list. 222 1.3 mrg if [ -n "${multilib_required}" ]; then 223 1.3 mrg cat >tmpmultilib2 <<\EOF 224 1.3 mrg #!/bin/sh 225 1.3 mrg # This recursive script weeds out any combination of multilib 226 1.3 mrg # switches that not in the expected list. 227 1.3 mrg 228 1.3 mrg for opt in $@; do 229 1.3 mrg case "$opt" in 230 1.3 mrg EOF 231 1.3 mrg 232 1.3 mrg for expect in ${multilib_required}; do 233 1.3 mrg echo " /${expect}/) echo \${opt};;" >> tmpmultilib2 234 1.3 mrg done 235 1.3 mrg 236 1.3 mrg cat >>tmpmultilib2 <<\EOF 237 1.3 mrg *) ;; 238 1.3 mrg esac 239 1.3 mrg done 240 1.3 mrg EOF 241 1.3 mrg 242 1.3 mrg chmod +x tmpmultilib2 243 1.3 mrg combinations=`./tmpmultilib2 ${combinations}` 244 1.3 mrg 245 1.3 mrg fi 246 1.3 mrg 247 1.1 mrg # Construct a sed pattern which will convert option names to directory 248 1.1 mrg # names. 249 1.1 mrg todirnames= 250 1.1 mrg if [ -n "${dirnames}" ]; then 251 1.1 mrg set x ${dirnames} 252 1.1 mrg shift 253 1.1 mrg for set in ${options}; do 254 1.1 mrg for opts in `echo ${set} | sed -e 's|/| |'g`; do 255 1.1 mrg patt="/" 256 1.1 mrg for opt in `echo ${opts} | sed -e 's_|_ _'g`; do 257 1.1 mrg if [ "$1" != "${opt}" ]; then 258 1.1 mrg todirnames="${todirnames} -e s|/${opt}/|/${1}/|g" 259 1.1 mrg patt="${patt}${1}/" 260 1.1 mrg if [ "${patt}" != "/${1}/" ]; then 261 1.1 mrg todirnames="${todirnames} -e s|${patt}|/${1}/|g" 262 1.1 mrg fi 263 1.1 mrg fi 264 1.1 mrg done 265 1.1 mrg shift 266 1.1 mrg done 267 1.1 mrg done 268 1.1 mrg fi 269 1.1 mrg 270 1.1 mrg # Construct a sed pattern which will convert option names to OS directory 271 1.1 mrg # names. 272 1.1 mrg toosdirnames= 273 1.1 mrg defaultosdirname= 274 1.3 mrg defaultosdirname2= 275 1.3 mrg if [ -n "${multiarch}" ]; then 276 1.3 mrg defaultosdirname=::${multiarch} 277 1.3 mrg fi 278 1.1 mrg if [ -n "${osdirnames}" ]; then 279 1.1 mrg set x ${osdirnames} 280 1.1 mrg shift 281 1.1 mrg while [ $# != 0 ] ; do 282 1.1 mrg case "$1" in 283 1.1 mrg .=*) 284 1.1 mrg defaultosdirname=`echo $1 | sed 's|^.=|:|'` 285 1.3 mrg if [ -n "${multiarch}" ]; then 286 1.3 mrg defaultosdirname=${defaultosdirname}:${multiarch} 287 1.3 mrg fi 288 1.3 mrg case "$defaultosdirname" in 289 1.3 mrg ::*) ;; 290 1.3 mrg *) 291 1.3 mrg defaultosdirname2=${defaultosdirname} 292 1.3 mrg defaultosdirname= 293 1.3 mrg ;; 294 1.3 mrg esac 295 1.1 mrg shift 296 1.1 mrg ;; 297 1.1 mrg *=*) 298 1.1 mrg patt=`echo $1 | sed -e 's|=|/$=/|'` 299 1.1 mrg toosdirnames="${toosdirnames} -e s=^/${patt}/=" 300 1.1 mrg shift 301 1.1 mrg ;; 302 1.1 mrg *) 303 1.1 mrg break 304 1.1 mrg ;; 305 1.1 mrg esac 306 1.1 mrg done 307 1.1 mrg 308 1.1 mrg if [ $# != 0 ]; then 309 1.1 mrg for set in ${options}; do 310 1.1 mrg for opts in `echo ${set} | sed -e 's|/| |'g`; do 311 1.1 mrg patt="/" 312 1.1 mrg for opt in `echo ${opts} | sed -e 's_|_ _'g`; do 313 1.1 mrg if [ "$1" != "${opt}" ]; then 314 1.1 mrg toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g" 315 1.1 mrg patt="${patt}${1}/" 316 1.1 mrg if [ "${patt}" != "/${1}/" ]; then 317 1.1 mrg toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g" 318 1.1 mrg fi 319 1.1 mrg fi 320 1.1 mrg done 321 1.1 mrg shift 322 1.1 mrg done 323 1.1 mrg done 324 1.1 mrg fi 325 1.1 mrg fi 326 1.1 mrg 327 1.1 mrg # We need another recursive shell script to correctly handle positive 328 1.1 mrg # matches. If we are invoked as 329 1.1 mrg # genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2" 330 1.1 mrg # we must output 331 1.1 mrg # opt1/opt2 opt1 opt2 332 1.1 mrg # opt1/opt2 nopt1 opt2 333 1.1 mrg # opt1/opt2 opt1 nopt2 334 1.1 mrg # opt1/opt2 nopt1 nopt2 335 1.1 mrg # In other words, we must output all combinations of matches. 336 1.1 mrg rm -f tmpmultilib2 337 1.1 mrg cat >tmpmultilib2 <<EOF 338 1.1 mrg #!${CONFIG_SHELL:-/bin/sh} 339 1.1 mrg EOF 340 1.1 mrg cat >>tmpmultilib2 <<\EOF 341 1.1 mrg # The positional parameters are a list of matches to consider. 342 1.1 mrg # ${dirout} is the directory name and ${optout} is the current list of 343 1.1 mrg # options. 344 1.1 mrg if [ "$#" = "0" ]; then 345 1.1 mrg echo "\"${dirout} ${optout};\"," 346 1.1 mrg else 347 1.1 mrg first=$1 348 1.1 mrg shift 349 1.1 mrg dirout="${dirout}" optout="${optout}" ./tmpmultilib2 $@ 350 1.1 mrg l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'` 351 1.1 mrg r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'` 352 1.1 mrg if expr " ${optout} " : ".* ${l} .*" > /dev/null; then 353 1.1 mrg newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'` 354 1.1 mrg dirout="${dirout}" optout="${newopt}" ./tmpmultilib2 $@ 355 1.1 mrg fi 356 1.1 mrg fi 357 1.1 mrg EOF 358 1.1 mrg chmod +x tmpmultilib2 359 1.1 mrg 360 1.1 mrg # Start with the current directory, which includes only negations. 361 1.1 mrg optout= 362 1.1 mrg for set in ${options}; do 363 1.1 mrg for opt in `echo ${set} | sed -e 's_[/|]_ _g'`; do 364 1.1 mrg optout="${optout} !${opt}" 365 1.1 mrg done 366 1.1 mrg done 367 1.1 mrg optout=`echo ${optout} | sed -e 's/^ //'` 368 1.1 mrg echo "\".${defaultosdirname} ${optout};\"," 369 1.3 mrg [ -n "${defaultosdirname2}" ] && echo "\".${defaultosdirname2} ${optout};\"," 370 1.3 mrg 371 1.3 mrg # This part of code convert an option combination to 372 1.3 mrg # its corresponding directory names. 373 1.3 mrg # The directory names will be deduced from MULTILIB_DIRNAMES, 374 1.3 mrg # MULTILIB_OSDIRNAMES or the option combination itself. 375 1.3 mrg rm -rf tmpmultilib3 376 1.3 mrg cat >tmpmultilib3 <<\EOF 377 1.3 mrg #!/bin/sh 378 1.3 mrg 379 1.3 mrg dirout= 380 1.3 mrg combo=$1 381 1.3 mrg todirnames=$2 382 1.3 mrg toosdirnames=$3 383 1.3 mrg enable_multilib=$4 384 1.3 mrg 385 1.3 mrg if [ -n "${todirnames}" ]; then 386 1.3 mrg dirout=`echo ${combo} | sed ${todirnames}` 387 1.3 mrg else 388 1.3 mrg dirout=`echo ${combo} | sed -e 's/=/-/g'` 389 1.3 mrg fi 390 1.3 mrg # Remove the leading and trailing slashes. 391 1.3 mrg dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'` 392 1.3 mrg 393 1.3 mrg # Use the OS directory names rather than the option names. 394 1.3 mrg if [ -n "${toosdirnames}" ]; then 395 1.3 mrg osdirout=`echo ${combo} | sed ${toosdirnames}` 396 1.3 mrg # Remove the leading and trailing slashes. 397 1.3 mrg osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'` 398 1.3 mrg if [ "x${enable_multilib}" != xyes ]; then 399 1.3 mrg dirout=".:${osdirout}" 400 1.3 mrg disable_multilib=yes 401 1.3 mrg else 402 1.3 mrg case "${osdirout}" in 403 1.3 mrg !*) 404 1.3 mrg dirout=`echo ${osdirout} | sed 's/^!//'` 405 1.3 mrg ;; 406 1.3 mrg *) 407 1.3 mrg dirout="${dirout}:${osdirout}" 408 1.3 mrg ;; 409 1.3 mrg esac 410 1.3 mrg fi 411 1.3 mrg else 412 1.3 mrg if [ "x${enable_multilib}" != xyes ]; then 413 1.3 mrg # genmultilib with --disable-multilib should be 414 1.3 mrg # called with '' '' '' '' '' '' '' no 415 1.3 mrg # if MULTILIB_OSDIRNAMES is empty. 416 1.3 mrg exit 1 417 1.3 mrg fi 418 1.3 mrg fi 419 1.3 mrg echo "${dirout}" 420 1.3 mrg EOF 421 1.3 mrg chmod +x tmpmultilib3 422 1.3 mrg 423 1.3 mrg # Script to look through the options and output each option that is present, 424 1.3 mrg # and negate each option that is not present. 425 1.3 mrg rm -rf tmpmultilib4 426 1.3 mrg cat > tmpmultilib4 <<\EOF 427 1.3 mrg #!/bin/sh 428 1.3 mrg 429 1.3 mrg optout= 430 1.3 mrg combo=$1 431 1.3 mrg options=$2 432 1.3 mrg 433 1.3 mrg for set in ${options}; do 434 1.3 mrg setopts=`echo ${set} | sed -e 's_[/|]_ _g'` 435 1.3 mrg for opt in ${setopts}; do 436 1.3 mrg if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then 437 1.3 mrg optout="${optout} ${opt}" 438 1.3 mrg else 439 1.3 mrg optout="${optout} !${opt}" 440 1.3 mrg fi 441 1.3 mrg done 442 1.3 mrg done 443 1.3 mrg optout=`echo ${optout} | sed -e 's/^ //'` 444 1.3 mrg echo "${optout}" 445 1.3 mrg EOF 446 1.3 mrg chmod +x tmpmultilib4 447 1.1 mrg 448 1.1 mrg # Work over the list of combinations. We have to translate each one 449 1.1 mrg # to use the directory names rather than the option names, we have to 450 1.1 mrg # include the information in matches, and we have to generate the 451 1.1 mrg # correct list of options and negations. 452 1.1 mrg for combo in ${combinations}; do 453 1.1 mrg # Use the directory names rather than the option names. 454 1.3 mrg dirout=`./tmpmultilib3 "${combo}" "${todirnames}" "${toosdirnames}" "${enable_multilib}"` 455 1.1 mrg 456 1.1 mrg # Look through the options. We must output each option that is 457 1.1 mrg # present, and negate each option that is not present. 458 1.3 mrg optout=`./tmpmultilib4 "${combo}" "${options}"` 459 1.1 mrg 460 1.1 mrg # Output the line with all appropriate matches. 461 1.1 mrg dirout="${dirout}" optout="${optout}" ./tmpmultilib2 462 1.1 mrg done 463 1.1 mrg 464 1.1 mrg # Terminate the list of string. 465 1.1 mrg echo "NULL" 466 1.1 mrg echo "};" 467 1.1 mrg 468 1.9 mrg # Generate a regular expression to validate option combinations. 469 1.9 mrg options_re= 470 1.9 mrg for set in ${options}; do 471 1.9 mrg for opt in `echo ${set} | sed -e 's_[/|]_ _g' -e 's/+/./g' `; do 472 1.9 mrg options_re="${options_re}${options_re:+|}${opt}" 473 1.9 mrg done 474 1.9 mrg done 475 1.9 mrg options_re="^/((${options_re})/)*\$" 476 1.9 mrg 477 1.3 mrg # Output rules used for multilib reuse. 478 1.3 mrg echo "" 479 1.3 mrg echo "static const char *const multilib_reuse_raw[] = {" 480 1.3 mrg for rrule in ${multilib_reuse}; do 481 1.3 mrg # The left part of the rule are the options we used to build multilib. 482 1.3 mrg # The right part of the rule are the options that can reuse this multilib. 483 1.9 mrg combo=`echo ${rrule} | sed -e 's/=.*$//' -e 's/\([^\\]\)\./\1=/g' -e 's/\\\././g'` 484 1.9 mrg copts=`echo ${rrule} | sed -e 's/^.*=//' -e 's/\([^\\]\)\./\1=/g' -e 's/\\\././g'` 485 1.3 mrg # The variable ${combinations} are the option combinations we will build 486 1.3 mrg # multilib from. If the combination in the left part of reuse rule isn't 487 1.3 mrg # in this variable, it means no multilib will be built for current reuse 488 1.3 mrg # rule. Thus the reuse purpose specified by current rule is meaningless. 489 1.3 mrg if expr "${combinations} " : ".*/${combo}/.*" > /dev/null; then 490 1.9 mrg if echo "/${copts}/" | grep -E "${options_re}" > /dev/null; then 491 1.8 mrg combo="/${combo}/" 492 1.8 mrg dirout=`./tmpmultilib3 "${combo}" "${todirnames}" "${toosdirnames}" "${enable_multilib}"` 493 1.8 mrg copts="/${copts}/" 494 1.8 mrg optout=`./tmpmultilib4 "${copts}" "${options}"` 495 1.8 mrg # Output the line with all appropriate matches. 496 1.8 mrg dirout="${dirout}" optout="${optout}" ./tmpmultilib2 497 1.8 mrg else 498 1.8 mrg echo "The rule ${rrule} contains an option absent from MULTILIB_OPTIONS." >&2 499 1.8 mrg exit 1 500 1.8 mrg fi 501 1.3 mrg else 502 1.8 mrg echo "The rule ${rrule} is trying to reuse nonexistent multilib." >&2 503 1.3 mrg exit 1 504 1.3 mrg fi 505 1.3 mrg done 506 1.3 mrg 507 1.3 mrg # Terminate the list of string. 508 1.3 mrg echo "NULL" 509 1.3 mrg echo "};" 510 1.3 mrg 511 1.1 mrg # Output all of the matches now as option and that is the same as that, with 512 1.1 mrg # a semicolon trailer. Include all of the normal options as well. 513 1.1 mrg # Note, the format of the matches is reversed compared 514 1.1 mrg # to what we want, so switch them around. 515 1.1 mrg echo "" 516 1.1 mrg echo "static const char *const multilib_matches_raw[] = {" 517 1.1 mrg for match in ${matches}; do 518 1.1 mrg l=`echo ${match} | sed -e 's/=.*$//' -e 's/?/=/g'` 519 1.1 mrg r=`echo ${match} | sed -e 's/^.*=//' -e 's/?/=/g'` 520 1.1 mrg echo "\"${r} ${l};\"," 521 1.1 mrg done 522 1.1 mrg for set in ${options}; do 523 1.1 mrg for opt in `echo ${set} | sed -e 's_[/|]_ _'g`; do 524 1.1 mrg echo "\"${opt} ${opt};\"," 525 1.1 mrg done 526 1.1 mrg done 527 1.1 mrg echo "NULL" 528 1.1 mrg echo "};" 529 1.1 mrg 530 1.1 mrg # Output the default options now 531 1.1 mrg echo "" 532 1.1 mrg echo "static const char *multilib_extra = \"${extra}\";" 533 1.1 mrg 534 1.1 mrg # Output the exclusion rules now 535 1.1 mrg echo "" 536 1.1 mrg echo "static const char *const multilib_exclusions_raw[] = {" 537 1.1 mrg for rule in ${exclusions}; do 538 1.1 mrg s=`echo ${rule} | sed -e 's,/, ,g'` 539 1.1 mrg echo "\"${s};\"," 540 1.1 mrg done 541 1.1 mrg echo "NULL" 542 1.1 mrg echo "};" 543 1.1 mrg 544 1.1 mrg # Output the options now 545 1.1 mrg moptions=`echo ${options} | sed -e 's,[ ][ ]*, ,g'` 546 1.1 mrg echo "" 547 1.1 mrg echo "static const char *multilib_options = \"${moptions}\";" 548 1.1 mrg 549 1.1 mrg # Finally output the disable flag if specified 550 1.1 mrg if [ "x${disable_multilib}" = xyes ]; then 551 1.1 mrg echo "" 552 1.1 mrg echo "#define DISABLE_MULTILIB 1" 553 1.1 mrg fi 554 1.1 mrg 555 1.1 mrg cd .. 556 1.1 mrg rm -r tmpmultilib.$$ 557 1.1 mrg 558 1.1 mrg exit 0 559