target-libpath.exp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. # Copyright (C) 2004-2015 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_library_path_32_saved 0
  21. set orig_ld_library_path_64_saved 0
  22. set orig_dyld_library_path_saved 0
  23. set orig_gcc_exec_prefix_saved 0
  24. set orig_gcc_exec_prefix_checked 0
  25. #######################################
  26. # proc set_gcc_exec_prefix_env_var { }
  27. #######################################
  28. proc set_gcc_exec_prefix_env_var { } {
  29. global TEST_GCC_EXEC_PREFIX
  30. global env
  31. # Set GCC_EXEC_PREFIX for the compiler under test to pick up files not in
  32. # the build tree from a specified location (normally the install tree).
  33. if [info exists TEST_GCC_EXEC_PREFIX] {
  34. setenv GCC_EXEC_PREFIX "$TEST_GCC_EXEC_PREFIX"
  35. }
  36. }
  37. #######################################
  38. # proc set_ld_library_path_env_vars { }
  39. #######################################
  40. proc set_ld_library_path_env_vars { } {
  41. global ld_library_path
  42. global orig_environment_saved
  43. global orig_ld_library_path_saved
  44. global orig_ld_run_path_saved
  45. global orig_shlib_path_saved
  46. global orig_ld_library_path_32_saved
  47. global orig_ld_library_path_64_saved
  48. global orig_dyld_library_path_saved
  49. global orig_gcc_exec_prefix_saved
  50. global orig_gcc_exec_prefix_checked
  51. global orig_ld_library_path
  52. global orig_ld_run_path
  53. global orig_shlib_path
  54. global orig_ld_library_path_32
  55. global orig_ld_library_path_64
  56. global orig_dyld_library_path
  57. global orig_gcc_exec_prefix
  58. global env
  59. # Save the original GCC_EXEC_PREFIX.
  60. if { $orig_gcc_exec_prefix_checked == 0 } {
  61. if [info exists env(GCC_EXEC_PREFIX)] {
  62. set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
  63. set orig_gcc_exec_prefix_saved 1
  64. }
  65. set orig_gcc_exec_prefix_checked 1
  66. }
  67. set_gcc_exec_prefix_env_var
  68. # Setting the ld library path causes trouble when testing cross-compilers.
  69. if { [is_remote target] } {
  70. return
  71. }
  72. if { $orig_environment_saved == 0 } {
  73. set orig_environment_saved 1
  74. # Save the original environment.
  75. if [info exists env(LD_LIBRARY_PATH)] {
  76. set orig_ld_library_path "$env(LD_LIBRARY_PATH)"
  77. set orig_ld_library_path_saved 1
  78. }
  79. if [info exists env(LD_RUN_PATH)] {
  80. set orig_ld_run_path "$env(LD_RUN_PATH)"
  81. set orig_ld_run_path_saved 1
  82. }
  83. if [info exists env(SHLIB_PATH)] {
  84. set orig_shlib_path "$env(SHLIB_PATH)"
  85. set orig_shlib_path_saved 1
  86. }
  87. if [info exists env(LD_LIBRARY_PATH_32)] {
  88. set orig_ld_library_path_32 "$env(LD_LIBRARY_PATH_32)"
  89. set orig_ld_library_path_32_saved 1
  90. }
  91. if [info exists env(LD_LIBRARY_PATH_64)] {
  92. set orig_ld_library_path_64 "$env(LD_LIBRARY_PATH_64)"
  93. set orig_ld_library_path_64_saved 1
  94. }
  95. if [info exists env(DYLD_LIBRARY_PATH)] {
  96. set orig_dyld_library_path "$env(DYLD_LIBRARY_PATH)"
  97. set orig_dyld_library_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 Darwin, we have to set variables akin to LD_LIBRARY_PATH, but called
  106. # DYLD_LIBRARY_PATH. The same applies to Solaris 32 bit
  107. # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
  108. # (SHLIB_PATH). In some cases, the variables are independent of
  109. # LD_LIBRARY_PATH, and in other cases LD_LIBRARY_PATH is used if the
  110. # variable is not defined.
  111. #
  112. # Doing this is somewhat of a hack as ld_library_path gets repeated in
  113. # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables.
  114. if { $orig_ld_library_path_saved } {
  115. setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
  116. } else {
  117. setenv LD_LIBRARY_PATH "$ld_library_path"
  118. }
  119. if { $orig_ld_run_path_saved } {
  120. setenv LD_RUN_PATH "$ld_library_path:$orig_ld_run_path"
  121. } else {
  122. setenv LD_RUN_PATH "$ld_library_path"
  123. }
  124. # The default shared library dynamic path search for 64-bit
  125. # HP-UX executables searches LD_LIBRARY_PATH before SHLIB_PATH.
  126. # LD_LIBRARY_PATH isn't used for 32-bit executables. Thus, we
  127. # set LD_LIBRARY_PATH and SHLIB_PATH as if they were independent.
  128. if { $orig_shlib_path_saved } {
  129. setenv SHLIB_PATH "$ld_library_path:$orig_shlib_path"
  130. } else {
  131. setenv SHLIB_PATH "$ld_library_path"
  132. }
  133. if { $orig_ld_library_path_32_saved } {
  134. setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path_32"
  135. } elseif { $orig_ld_library_path_saved } {
  136. setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path"
  137. } else {
  138. setenv LD_LIBRARY_PATH_32 "$ld_library_path"
  139. }
  140. if { $orig_ld_library_path_64_saved } {
  141. setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path_64"
  142. } elseif { $orig_ld_library_path_saved } {
  143. setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path"
  144. } else {
  145. setenv LD_LIBRARY_PATH_64 "$ld_library_path"
  146. }
  147. if { $orig_dyld_library_path_saved } {
  148. setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path"
  149. } else {
  150. setenv DYLD_LIBRARY_PATH "$ld_library_path"
  151. }
  152. verbose -log "LD_LIBRARY_PATH=[getenv LD_LIBRARY_PATH]"
  153. verbose -log "LD_RUN_PATH=[getenv LD_RUN_PATH]"
  154. verbose -log "SHLIB_PATH=[getenv SHLIB_PATH]"
  155. verbose -log "LD_LIBRARY_PATH_32=[getenv LD_LIBRARY_PATH_32]"
  156. verbose -log "LD_LIBRARY_PATH_64=[getenv LD_LIBRARY_PATH_64]"
  157. verbose -log "DYLD_LIBRARY_PATH=[getenv DYLD_LIBRARY_PATH]"
  158. }
  159. #######################################
  160. # proc restore_gcc_exec_prefix_env_var { }
  161. #######################################
  162. proc restore_gcc_exec_prefix_env_var { } {
  163. global orig_gcc_exec_prefix_saved
  164. global orig_gcc_exec_prefix
  165. global env
  166. if { $orig_gcc_exec_prefix_saved } {
  167. setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
  168. } elseif [info exists env(GCC_EXEC_PREFIX)] {
  169. unsetenv GCC_EXEC_PREFIX
  170. }
  171. }
  172. #######################################
  173. # proc restore_ld_library_path_env_vars { }
  174. #######################################
  175. proc restore_ld_library_path_env_vars { } {
  176. global orig_environment_saved
  177. global orig_ld_library_path_saved
  178. global orig_ld_run_path_saved
  179. global orig_shlib_path_saved
  180. global orig_ld_library_path_32_saved
  181. global orig_ld_library_path_64_saved
  182. global orig_dyld_library_path_saved
  183. global orig_ld_library_path
  184. global orig_ld_run_path
  185. global orig_shlib_path
  186. global orig_ld_library_path_32
  187. global orig_ld_library_path_64
  188. global orig_dyld_library_path
  189. global env
  190. restore_gcc_exec_prefix_env_var
  191. if { $orig_environment_saved == 0 } {
  192. return
  193. }
  194. if { $orig_ld_library_path_saved } {
  195. setenv LD_LIBRARY_PATH "$orig_ld_library_path"
  196. } elseif [info exists env(LD_LIBRARY_PATH)] {
  197. unsetenv LD_LIBRARY_PATH
  198. }
  199. if { $orig_ld_run_path_saved } {
  200. setenv LD_RUN_PATH "$orig_ld_run_path"
  201. } elseif [info exists env(LD_RUN_PATH)] {
  202. unsetenv LD_RUN_PATH
  203. }
  204. if { $orig_shlib_path_saved } {
  205. setenv SHLIB_PATH "$orig_shlib_path"
  206. } elseif [info exists env(SHLIB_PATH)] {
  207. unsetenv SHLIB_PATH
  208. }
  209. if { $orig_ld_library_path_32_saved } {
  210. setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32"
  211. } elseif [info exists env(LD_LIBRARY_PATH_32)] {
  212. unsetenv LD_LIBRARY_PATH_32
  213. }
  214. if { $orig_ld_library_path_64_saved } {
  215. setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64"
  216. } elseif [info exists env(LD_LIBRARY_PATH_64)] {
  217. unsetenv LD_LIBRARY_PATH_64
  218. }
  219. if { $orig_dyld_library_path_saved } {
  220. setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path"
  221. } elseif [info exists env(DYLD_LIBRARY_PATH)] {
  222. unsetenv DYLD_LIBRARY_PATH
  223. }
  224. }
  225. #######################################
  226. # proc get_shlib_extension { }
  227. #######################################
  228. proc get_shlib_extension { } {
  229. global shlib_ext
  230. if { [istarget *-*-darwin*] } {
  231. set shlib_ext "dylib"
  232. } elseif { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
  233. set shlib_ext "dll"
  234. } elseif { [istarget hppa*-*-hpux*] } {
  235. set shlib_ext "sl"
  236. } else {
  237. set shlib_ext "so"
  238. }
  239. return $shlib_ext
  240. }