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