print-sysroot-suffix.sh 3.7 KB

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