1 1.1 mrg #! /bin/sh 2 1.1 mrg # Script to generate SYSROOT_SUFFIX_SPEC equivalent to MULTILIB_OSDIRNAMES 3 1.6 mrg # Arguments are MULTILIB_OSDIRNAMES, MULTILIB_OPTIONS, MULTILIB_MATCHES, 4 1.6 mrg # and MULTILIB_REUSE. 5 1.1 mrg 6 1.12 mrg # Copyright (C) 2009-2022 Free Software Foundation, Inc. 7 1.1 mrg 8 1.1 mrg # This file is part of GCC. 9 1.1 mrg 10 1.1 mrg # GCC is free software; you can redistribute it and/or modify it under 11 1.1 mrg # the terms of the GNU General Public License as published by the Free 12 1.1 mrg # Software Foundation; either version 3, or (at your option) any later 13 1.1 mrg # version. 14 1.1 mrg 15 1.1 mrg # GCC is distributed in the hope that it will be useful, but WITHOUT 16 1.1 mrg # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 1.1 mrg # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18 1.1 mrg # for more details. 19 1.1 mrg 20 1.1 mrg # You should have received a copy of the GNU General Public License 21 1.1 mrg # along with GCC; see the file COPYING3. If not see 22 1.1 mrg # <http://www.gnu.org/licenses/>. 23 1.1 mrg 24 1.1 mrg # This shell script produces a header file fragment that defines 25 1.1 mrg # SYSROOT_SUFFIX_SPEC. It assumes that the sysroots will have the same 26 1.1 mrg # structure and names used by the multilibs. 27 1.1 mrg 28 1.1 mrg # Invocation: 29 1.1 mrg # print-sysroot-suffix.sh \ 30 1.1 mrg # MULTILIB_OSDIRNAMES \ 31 1.1 mrg # MULTILIB_OPTIONS \ 32 1.1 mrg # MULTILIB_MATCHES \ 33 1.6 mrg # MULTILIB_REUSE 34 1.1 mrg # > t-sysroot-suffix.h 35 1.1 mrg 36 1.6 mrg # The four options exactly correspond to the variables of the same 37 1.6 mrg # names defined in the t-sysroot-suffix tmake_file fragment. 38 1.1 mrg 39 1.1 mrg # Example: 40 1.1 mrg # sh ./gcc/config/print-sysroot-suffix.sh "a=A" "a b/c/d" "" 41 1.1 mrg # => 42 1.1 mrg # #undef SYSROOT_SUFFIX_SPEC 43 1.1 mrg # #define SYSROOT_SUFFIX_SPEC "" \ 44 1.1 mrg # "%{a:" \ 45 1.1 mrg # "%{b:A/b/;" \ 46 1.1 mrg # "c:A/c/;" \ 47 1.1 mrg # "d:A/d/;" \ 48 1.1 mrg # ":A/};" \ 49 1.1 mrg # ":}" 50 1.1 mrg 51 1.1 mrg # The script uses temporary subscripts in order to permit a recursive 52 1.1 mrg # algorithm without the use of functions. 53 1.1 mrg 54 1.1 mrg set -e 55 1.1 mrg 56 1.1 mrg dirnames="$1" 57 1.1 mrg options="$2" 58 1.1 mrg matches="$3" 59 1.6 mrg reuse="$4" 60 1.1 mrg 61 1.1 mrg cat > print-sysroot-suffix3.sh <<\EOF 62 1.1 mrg #! /bin/sh 63 1.1 mrg # Print all the multilib matches for this option 64 1.1 mrg result="$1" 65 1.1 mrg EOF 66 1.1 mrg for x in $matches; do 67 1.1 mrg l=`echo $x | sed -e 's/=.*$//' -e 's/?/=/g'` 68 1.1 mrg r=`echo $x | sed -e 's/^.*=//' -e 's/?/=/g'` 69 1.1 mrg echo "[ \"\$1\" = \"$l\" ] && result=\"\$result|$r\"" >> print-sysroot-suffix3.sh 70 1.1 mrg done 71 1.1 mrg echo 'echo $result' >> print-sysroot-suffix3.sh 72 1.1 mrg chmod +x print-sysroot-suffix3.sh 73 1.1 mrg 74 1.1 mrg cat > print-sysroot-suffix2.sh <<\EOF 75 1.1 mrg #! /bin/sh 76 1.1 mrg # Recursive script to enumerate all multilib combinations, match against 77 1.1 mrg # multilib directories and output a spec string of the result. 78 1.1 mrg # Will fold identical trees. 79 1.1 mrg 80 1.1 mrg padding="$1" 81 1.1 mrg optstring="$2" 82 1.1 mrg shift 2 83 1.1 mrg n="\" \\ 84 1.1 mrg $padding\"" 85 1.1 mrg if [ $# = 0 ]; then 86 1.6 mrg case $optstring in 87 1.1 mrg EOF 88 1.6 mrg for x in $reuse; do 89 1.6 mrg l=`echo $x | sed -e 's/=.*$//' -e 's/\./=/g'` 90 1.6 mrg r=`echo $x | sed -e 's/^.*=//' -e 's/\./=/g'` 91 1.6 mrg echo "/$r/) optstring=\"/$l/\" ;;" >> print-sysroot-suffix2.sh 92 1.6 mrg done 93 1.6 mrg echo " esac" >> print-sysroot-suffix2.sh 94 1.1 mrg 95 1.1 mrg pat= 96 1.1 mrg for x in $dirnames; do 97 1.1 mrg p=`echo $x | sed -e 's,=!,/$=/,'` 98 1.1 mrg pat="$pat -e 's=^//$p='" 99 1.1 mrg done 100 1.1 mrg echo ' optstring=`echo "/$optstring" | sed '"$pat\`" >> print-sysroot-suffix2.sh 101 1.1 mrg cat >> print-sysroot-suffix2.sh <<\EOF 102 1.1 mrg case $optstring in 103 1.1 mrg //*) 104 1.1 mrg ;; 105 1.1 mrg *) 106 1.1 mrg echo "$optstring" 107 1.1 mrg ;; 108 1.1 mrg esac 109 1.1 mrg else 110 1.1 mrg thisopt="$1" 111 1.1 mrg shift 112 1.1 mrg bit= 113 1.1 mrg lastcond= 114 1.1 mrg result= 115 1.1 mrg for x in `echo "$thisopt" | sed -e 's,/, ,g'`; do 116 1.1 mrg case $x in 117 1.1 mrg EOF 118 1.1 mrg for x in `echo "$options" | sed -e 's,/, ,g'`; do 119 1.1 mrg match=`./print-sysroot-suffix3.sh "$x"` 120 1.1 mrg echo "$x) optmatch=\"$match\" ;;" >> print-sysroot-suffix2.sh 121 1.1 mrg done 122 1.1 mrg cat >> print-sysroot-suffix2.sh <<\EOF 123 1.1 mrg esac 124 1.1 mrg bit=`"$0" "$padding " "$optstring$x/" "$@"` 125 1.1 mrg if [ -z "$lastopt" ]; then 126 1.1 mrg lastopt="$optmatch" 127 1.1 mrg else 128 1.1 mrg if [ "$lastbit" = "$bit" ]; then 129 1.1 mrg lastopt="$lastopt|$optmatch" 130 1.1 mrg else 131 1.1 mrg result="$result$lastopt:$lastbit;$n" 132 1.1 mrg lastopt="$optmatch" 133 1.1 mrg fi 134 1.1 mrg fi 135 1.1 mrg lastbit="$bit" 136 1.1 mrg done 137 1.1 mrg bit=`"$0" "$padding " "$optstring" "$@"` 138 1.1 mrg if [ "$bit" = "$lastbit" ]; then 139 1.1 mrg if [ -z "$result" ]; then 140 1.1 mrg echo "$bit" 141 1.1 mrg else 142 1.1 mrg echo "$n%{$result:$bit}" 143 1.1 mrg fi 144 1.1 mrg else 145 1.1 mrg echo "$n%{$result$lastopt:$lastbit;$n:$bit}" 146 1.1 mrg fi 147 1.1 mrg fi 148 1.1 mrg EOF 149 1.1 mrg 150 1.1 mrg chmod +x ./print-sysroot-suffix2.sh 151 1.1 mrg result=`./print-sysroot-suffix2.sh "" "/" $options` 152 1.1 mrg echo "#undef SYSROOT_SUFFIX_SPEC" 153 1.1 mrg echo "#define SYSROOT_SUFFIX_SPEC \"$result\"" 154 1.1 mrg rm print-sysroot-suffix2.sh 155 1.1 mrg rm print-sysroot-suffix3.sh 156