target-libpath.exp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # This file was contributed by John David Anglin (dave.anglin@nrc-cnrc.gc.ca)
  16. set orig_environment_saved 0
  17. set orig_ld_library_path_saved 0
  18. set orig_ld_run_path_saved 0
  19. set orig_shlib_path_saved 0
  20. set orig_ld_libraryn32_path_saved 0
  21. set orig_ld_library64_path_saved 0
  22. set orig_ld_library_path_32_saved 0
  23. set orig_ld_library_path_64_saved 0
  24. set orig_dyld_library_path_saved 0
  25. set orig_path_saved 0
  26. #######################################
  27. # proc set_ld_library_path_env_vars { }
  28. #######################################
  29. proc set_ld_library_path_env_vars { } {
  30. global ld_library_path
  31. global orig_environment_saved
  32. global orig_ld_library_path_saved
  33. global orig_ld_run_path_saved
  34. global orig_shlib_path_saved
  35. global orig_ld_libraryn32_path_saved
  36. global orig_ld_library64_path_saved
  37. global orig_ld_library_path_32_saved
  38. global orig_ld_library_path_64_saved
  39. global orig_dyld_library_path_saved
  40. global orig_path_saved
  41. global orig_ld_library_path
  42. global orig_ld_run_path
  43. global orig_shlib_path
  44. global orig_ld_libraryn32_path
  45. global orig_ld_library64_path
  46. global orig_ld_library_path_32
  47. global orig_ld_library_path_64
  48. global orig_dyld_library_path
  49. global orig_path
  50. global GCC_EXEC_PREFIX
  51. # Set the relocated compiler prefix, but only if the user hasn't specified one.
  52. if { [info exists GCC_EXEC_PREFIX] && ![info exists env(GCC_EXEC_PREFIX)] } {
  53. setenv GCC_EXEC_PREFIX "$GCC_EXEC_PREFIX"
  54. }
  55. # Setting the ld library path causes trouble when testing cross-compilers.
  56. if { [is_remote target] } {
  57. return
  58. }
  59. if { $orig_environment_saved == 0 } {
  60. global env
  61. set orig_environment_saved 1
  62. # Save the original environment.
  63. if [info exists env(LD_LIBRARY_PATH)] {
  64. set orig_ld_library_path "$env(LD_LIBRARY_PATH)"
  65. set orig_ld_library_path_saved 1
  66. }
  67. if [info exists env(LD_RUN_PATH)] {
  68. set orig_ld_run_path "$env(LD_RUN_PATH)"
  69. set orig_ld_run_path_saved 1
  70. }
  71. if [info exists env(SHLIB_PATH)] {
  72. set orig_shlib_path "$env(SHLIB_PATH)"
  73. set orig_shlib_path_saved 1
  74. }
  75. if [info exists env(LD_LIBRARYN32_PATH)] {
  76. set orig_ld_libraryn32_path "$env(LD_LIBRARYN32_PATH)"
  77. set orig_ld_libraryn32_path_saved 1
  78. }
  79. if [info exists env(LD_LIBRARY64_PATH)] {
  80. set orig_ld_library64_path "$env(LD_LIBRARY64_PATH)"
  81. set orig_ld_library64_path_saved 1
  82. }
  83. if [info exists env(LD_LIBRARY_PATH_32)] {
  84. set orig_ld_library_path_32 "$env(LD_LIBRARY_PATH_32)"
  85. set orig_ld_library_path_32_saved 1
  86. }
  87. if [info exists env(LD_LIBRARY_PATH_64)] {
  88. set orig_ld_library_path_64 "$env(LD_LIBRARY_PATH_64)"
  89. set orig_ld_library_path_64_saved 1
  90. }
  91. if [info exists env(DYLD_LIBRARY_PATH)] {
  92. set orig_dyld_library_path "$env(DYLD_LIBRARY_PATH)"
  93. set orig_dyld_library_path_saved 1
  94. }
  95. if [info exists env(PATH)] {
  96. set orig_path "$env(PATH)"
  97. set orig_path_saved 1
  98. }
  99. }
  100. # We need to set ld library path in the environment. Currently,
  101. # unix.exp doesn't set the environment correctly for all systems.
  102. # It only sets SHLIB_PATH and LD_LIBRARY_PATH when it executes a
  103. # program. We also need the environment set for compilations, etc.
  104. #
  105. # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
  106. # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
  107. # (for the 64-bit ABI). The same applies to Darwin (DYLD_LIBRARY_PATH),
  108. # Solaris 32 bit (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64),
  109. # and HP-UX (SHLIB_PATH). In some cases, the variables are independent
  110. # of LD_LIBRARY_PATH, and in other cases LD_LIBRARY_PATH is used if the
  111. # variable is not defined.
  112. #
  113. # Doing this is somewhat of a hack as ld_library_path gets repeated in
  114. # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables.
  115. if { $orig_ld_library_path_saved } {
  116. setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
  117. } else {
  118. setenv LD_LIBRARY_PATH "$ld_library_path"
  119. }
  120. if { $orig_ld_run_path_saved } {
  121. setenv LD_RUN_PATH "$ld_library_path:$orig_ld_run_path"
  122. } else {
  123. setenv LD_RUN_PATH "$ld_library_path"
  124. }
  125. # The default shared library dynamic path search for 64-bit
  126. # HP-UX executables searches LD_LIBRARY_PATH before SHLIB_PATH.
  127. # LD_LIBRARY_PATH isn't used for 32-bit executables. Thus, we
  128. # set LD_LIBRARY_PATH and SHLIB_PATH as if they were independent.
  129. if { $orig_shlib_path_saved } {
  130. setenv SHLIB_PATH "$ld_library_path:$orig_shlib_path"
  131. } else {
  132. setenv SHLIB_PATH "$ld_library_path"
  133. }
  134. if { $orig_ld_libraryn32_path_saved } {
  135. setenv LD_LIBRARYN32_PATH "$ld_library_path:$orig_ld_libraryn32_path"
  136. } elseif { $orig_ld_library_path_saved } {
  137. setenv LD_LIBRARYN32_PATH "$ld_library_path:$orig_ld_library_path"
  138. } else {
  139. setenv LD_LIBRARYN32_PATH "$ld_library_path"
  140. }
  141. if { $orig_ld_library64_path_saved } {
  142. setenv LD_LIBRARY64_PATH "$ld_library_path:$orig_ld_library64_path"
  143. } elseif { $orig_ld_library_path_saved } {
  144. setenv LD_LIBRARY64_PATH "$ld_library_path:$orig_ld_library_path"
  145. } else {
  146. setenv LD_LIBRARY64_PATH "$ld_library_path"
  147. }
  148. if { $orig_ld_library_path_32_saved } {
  149. setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path_32"
  150. } elseif { $orig_ld_library_path_saved } {
  151. setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path"
  152. } else {
  153. setenv LD_LIBRARY_PATH_32 "$ld_library_path"
  154. }
  155. if { $orig_ld_library_path_64_saved } {
  156. setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path_64"
  157. } elseif { $orig_ld_library_path_saved } {
  158. setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path"
  159. } else {
  160. setenv LD_LIBRARY_PATH_64 "$ld_library_path"
  161. }
  162. if { $orig_dyld_library_path_saved } {
  163. setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path"
  164. } else {
  165. setenv DYLD_LIBRARY_PATH "$ld_library_path"
  166. }
  167. if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
  168. if { $orig_path_saved } {
  169. setenv PATH "$ld_library_path:$orig_path"
  170. } else {
  171. setenv PATH "$ld_library_path"
  172. }
  173. }
  174. verbose -log "set_ld_library_path_env_vars: ld_library_path=$ld_library_path"
  175. }
  176. #######################################
  177. # proc restore_ld_library_path_env_vars { }
  178. #######################################
  179. proc restore_ld_library_path_env_vars { } {
  180. global orig_environment_saved
  181. global orig_ld_library_path_saved
  182. global orig_ld_run_path_saved
  183. global orig_shlib_path_saved
  184. global orig_ld_libraryn32_path_saved
  185. global orig_ld_library64_path_saved
  186. global orig_ld_library_path_32_saved
  187. global orig_ld_library_path_64_saved
  188. global orig_dyld_library_path_saved
  189. global orig_path_saved
  190. global orig_ld_library_path
  191. global orig_ld_run_path
  192. global orig_shlib_path
  193. global orig_ld_libraryn32_path
  194. global orig_ld_library64_path
  195. global orig_ld_library_path_32
  196. global orig_ld_library_path_64
  197. global orig_dyld_library_path
  198. global orig_path
  199. if { $orig_environment_saved == 0 } {
  200. return
  201. }
  202. if { $orig_ld_library_path_saved } {
  203. setenv LD_LIBRARY_PATH "$orig_ld_library_path"
  204. } elseif [info exists env(LD_LIBRARY_PATH)] {
  205. unsetenv LD_LIBRARY_PATH
  206. }
  207. if { $orig_ld_run_path_saved } {
  208. setenv LD_RUN_PATH "$orig_ld_run_path"
  209. } elseif [info exists env(LD_RUN_PATH)] {
  210. unsetenv LD_RUN_PATH
  211. }
  212. if { $orig_shlib_path_saved } {
  213. setenv SHLIB_PATH "$orig_shlib_path"
  214. } elseif [info exists env(SHLIB_PATH)] {
  215. unsetenv SHLIB_PATH
  216. }
  217. if { $orig_ld_libraryn32_path_saved } {
  218. setenv LD_LIBRARYN32_PATH "$orig_ld_libraryn32_path"
  219. } elseif [info exists env(LD_LIBRARYN32_PATH)] {
  220. unsetenv LD_LIBRARYN32_PATH
  221. }
  222. if { $orig_ld_library64_path_saved } {
  223. setenv LD_LIBRARY64_PATH "$orig_ld_library64_path"
  224. } elseif [info exists env(LD_LIBRARY64_PATH)] {
  225. unsetenv LD_LIBRARY64_PATH
  226. }
  227. if { $orig_ld_library_path_32_saved } {
  228. setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32"
  229. } elseif [info exists env(LD_LIBRARY_PATH_32)] {
  230. unsetenv LD_LIBRARY_PATH_32
  231. }
  232. if { $orig_ld_library_path_64_saved } {
  233. setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64"
  234. } elseif [info exists env(LD_LIBRARY_PATH_64)] {
  235. unsetenv LD_LIBRARY_PATH_64
  236. }
  237. if { $orig_dyld_library_path_saved } {
  238. setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path"
  239. } elseif [info exists env(DYLD_LIBRARY_PATH)] {
  240. unsetenv DYLD_LIBRARY_PATH
  241. }
  242. if { $orig_path_saved } {
  243. setenv PATH "$orig_path"
  244. } elseif [info exists env(PATH)] {
  245. unsetenv PATH
  246. }
  247. }
  248. #######################################
  249. # proc get_shlib_extension { }
  250. #######################################
  251. proc get_shlib_extension { } {
  252. global shlib_ext
  253. if { [ istarget *-*-darwin* ] } {
  254. set shlib_ext "dylib"
  255. } elseif { [ istarget *-*-cygwin* ] || [ istarget *-*-mingw* ] } {
  256. set shlib_ext "dll"
  257. } elseif { [ istarget hppa*-*-hpux* ] } {
  258. set shlib_ext "sl"
  259. } else {
  260. set shlib_ext "so"
  261. }
  262. return $shlib_ext
  263. }