Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gmt_prepmex.sh 5.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 1991-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
  4. # See LICENSE.TXT file for copying and redistribution conditions.
  5. #
  6. # Until/if we are able to get MATLAB to not override every
  7. # single request for a shared library with its own out-of-date
  8. # version which results in version conflicts, we have to use
  9. # this trick under OS X:
  10. #
  11. # 1. Duplicate the lib, bin, include files from the bundle into
  12. # an separate directory, here /opt/gmt.
  13. # 2. Rebaptize all libs with unique names by inserting an "X"
  14. # 3. Link the gmt.mex executable with these libraries.
  15. #
  16. # To prepare your system to run the gmt.mex application, run
  17. # /Application/GMT-6.x.x[_r#####.app]/Contents/Resources/share/tools/gmt_prepmex.sh
  18. # This will require sudo privileges.
  19. #
  20. #-------------------------------------------------------------------------
  21. Rel=$(gmt --version | awk '{print substr($1,1,3)}')
  22. printf "\ngmt_prepmex.sh will convert a GMT %s.x bundle so libraries are suitable for building the MATLAB interface.\n" $Rel >&2
  23. printf "You must have sudo privileges on this computer.\n\nContinue? (y/n) [y]:" >&2
  24. read answer
  25. if [ "X$answer" = "Xn" ]; then
  26. exit 0
  27. fi
  28. here=$(pwd)
  29. # First get a reliable absolute path to the bundle's top directory
  30. pushd $(dirname $0) > /dev/null
  31. BUNDLEDIR=$(pwd | sed -e sB/Contents/Resources/share/toolsBBg)
  32. popd > /dev/null
  33. # Set path to the new gmt installation
  34. MEXGMT5DIR=/tmp/$$/gmt
  35. # Set path to additional subdirectories
  36. MEXLIBDIR=$MEXGMT5DIR/lib
  37. MEXINCDIR=$MEXGMT5DIR/include
  38. MEXSHADIR=$MEXGMT5DIR/share
  39. MEXBINDIR=$MEXGMT5DIR/bin
  40. MEXSUPDIR=$MEXLIBDIR/gmt/plugins
  41. # Create install directory [remove first if exist]
  42. rm -rf $MEXGMT5DIR
  43. printf "gmt_prepmex.sh: Create $MEXGMT5DIR and copy files\n" >&2
  44. mkdir -p $MEXBINDIR $MEXSUPDIR $MEXINCDIR
  45. # Copy the share files
  46. cd $BUNDLEDIR/Contents/Resources
  47. cp -r share $MEXSHADIR
  48. # Copy the include files
  49. cd $BUNDLEDIR/Contents/Resources/include
  50. cp -r gmt $MEXINCDIR
  51. # Copy the bin files
  52. cd $BUNDLEDIR/Contents/Resources/bin
  53. cp -r * $MEXBINDIR
  54. # Now copy the lib files
  55. printf "gmt_prepmex.sh: Copy and rename libraries\n" >&2
  56. cd $BUNDLEDIR/Contents/Resources/lib
  57. # Find a list of all libs shipped with the OSX bundle, except our own:
  58. ls *.dylib | egrep -v 'libgmt.dylib|libpostscriptlight.dylib' > /tmp/l.lis
  59. # For each, duplicate into /opt/gmt but add a leading X to each name
  60. while read lib; do
  61. new=$(echo $lib | awk '{printf "libX%s\n", substr($1,4)}')
  62. cp $lib $MEXLIBDIR/$new
  63. done < /tmp/l.lis
  64. # Copy the supplement shared plugin
  65. cp gmt/plugins/supplements.so $MEXLIBDIR/gmt/plugins
  66. cd $MEXLIBDIR
  67. ls *.dylib > /tmp/l.lis
  68. printf "gmt_prepmex.sh: Rebaptize libraries\n" >&2
  69. # For all libs in $MEXLIBDIR, change internal references to contain the leading "X"
  70. while read lib; do
  71. otool -L $lib | grep executable_path | awk '{print $1}' > /tmp/t.lis
  72. let k=1
  73. while read old; do
  74. new=$(echo $old | awk -F/ '{printf "libX%s\n", substr($NF,4)}')
  75. if [ $k -eq 1 ]; then # Do the id change
  76. was=$(echo $lib | awk -F/ '{print substr($1,4)}')
  77. install_name_tool -id /opt/gmt/lib/$new $lib
  78. else
  79. install_name_tool -change $old /opt/gmt/lib/$new $lib
  80. fi
  81. let k=k+1
  82. done < /tmp/t.lis
  83. done < /tmp/l.lis
  84. # Set links to the new libs
  85. ln -s libXgmt.dylib libgmt.dylib
  86. ln -s libXpostscriptlight.dylib libpostscriptlight.dylib
  87. ln -s libXgmt.6.dylib libXgmt.dylib
  88. ln -s libXpostscriptlight.6.dylib libXpostscriptlight.dylib
  89. # If argument gs is given then we also do the same to the GS library.
  90. if [ "$1" == "gs" ]; then
  91. # Same stuff for gs which is called by psconvert as a system call.
  92. # Here we must determine from where to copy...
  93. GSV=$(gs --version)
  94. if [ -d /sw/lib ]; then # Fink has no shared lib yet...
  95. FROM=/sw/lib
  96. echo "Sorry, no libgs.dylib under fink yet"
  97. elif [ -d /opt/local/lib ]; then # Macports
  98. FROM=/opt/local/lib
  99. cp $FROM/libgs.${GSV}.dylib libXgs.${GSV}.dylib
  100. cp $FROM/libfreetype.6.dylib libXfreetype.6.dylib
  101. install_name_tool -id /opt/gmt/lib/libXgs.${GSV}.dylib libXgs.${GSV}.dylib
  102. install_name_tool -id /opt/gmt/lib/libXfreetype.6.dylib libXfreetype.6.dylib
  103. install_name_tool -change $FROM/libtiff.5.dylib /opt/gmt/lib/libXtiff.5.dylib libXgs.${GSV}.dylib
  104. install_name_tool -change $FROM/libfreetype.6.dylib /opt/gmt/lib/libXfreetype.6.dylib libXgs.${GSV}.dylib
  105. elif [ -d /usr/local/lib ]; then # Brew
  106. FROM=/usr/local/lib
  107. echo "Sorry, no libgs.dylib under HomeBrew yet"
  108. fi
  109. fi
  110. # Do plugin supplement separately since not called lib*
  111. cd gmt/plugins
  112. otool -L supplements.so | grep executable_path | awk '{print $1}' > /tmp/t.lis
  113. let k=1
  114. while read old; do
  115. new=$(echo $old | awk -F/ '{printf "libX%s\n", substr($NF,4)}')
  116. install_name_tool -change $old /opt/gmt/lib/$new supplements.so
  117. let k=k+1
  118. done < /tmp/t.lis
  119. # Do bin dir
  120. cd $MEXBINDIR
  121. otool -L gmt | grep executable_path | awk '{print $1}' > /tmp/t.lis
  122. let k=1
  123. while read old; do
  124. new=$(echo $old | awk -F/ '{printf "libX%s\n", substr($NF,4)}')
  125. install_name_tool -change $old /opt/gmt/lib/$new gmt
  126. let k=k+1
  127. done < /tmp/t.lis
  128. chmod -R ugo+r $MEXGMT5DIR
  129. printf "gmt_prepmex.sh: Install /opt/gmt\n" >&2
  130. sudo cp -fpR $MEXGMT5DIR /opt
  131. rm -rf /tmp/$$
  132. cd $here
  133. version=$(/opt/gmt/bin/gmt-config --version)
  134. # Report
  135. cat << EOF >&2
  136. gmt_prepmex.sh: Made updated GMT $version installation in /opt/gmt
  137. gmt_prepmex.sh: Add /opt/gmt to your .gmtversions and run gmtswitch to select this version
  138. gmt_prepmex.sh: MATLAB may need a gmt.conf file with GMT_CUSTOM_LIBS=/opt/gmt/lib/gmt/plugins/supplements.so in the startup directory
  139. EOF
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...