/
gdal.rb
421 lines (371 loc) 路 14 KB
/
gdal.rb
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
require 'formula'
class Gdal < Formula
homepage 'http://www.gdal.org/'
url 'http://download.osgeo.org/gdal/1.10.1/gdal-1.10.1.tar.gz'
sha1 'b4df76e2c0854625d2bedce70cc1eaf4205594ae'
head do
url 'https://svn.osgeo.org/gdal/trunk/gdal'
depends_on 'doxygen' => :build
end
option 'complete', 'Use additional Homebrew libraries to provide more drivers.'
option 'enable-opencl', 'Build with OpenCL acceleration.'
option 'enable-armadillo', 'Build with Armadillo accelerated TPS transforms.'
option 'enable-unsupported', "Allow configure to drag in any library it can find. Invoke this at your own risk."
option 'enable-mdb', 'Build with Access MDB driver (requires Java 1.6+ JDK/JRE, from Apple or Oracle).'
depends_on :python => :recommended
depends_on :libpng
depends_on 'jpeg'
depends_on 'giflib'
depends_on 'libtiff'
depends_on 'libgeotiff'
depends_on 'proj'
depends_on 'geos'
depends_on 'sqlite' # To ensure compatibility with SpatiaLite.
depends_on 'freexl'
depends_on 'libspatialite'
depends_on "postgresql" => :optional
depends_on "mysql" => :optional
# Without Numpy, the Python bindings can't deal with raster data.
depends_on 'numpy' => :python if build.with? 'python'
depends_on 'homebrew/science/armadillo' if build.include? 'enable-armadillo'
if build.include? 'complete'
# Raster libraries
depends_on "homebrew/science/netcdf" # Also brings in HDF5
depends_on "jasper"
depends_on "webp"
depends_on "cfitsio"
depends_on "epsilon"
depends_on "libdap"
# Vector libraries
depends_on "unixodbc" # OS X version is not complete enough
depends_on "xerces-c"
# Other libraries
depends_on "xz" # get liblzma compression algorithm library from XZutils
depends_on "poppler"
end
def get_configure_args
args = [
# Base configuration.
"--prefix=#{prefix}",
"--mandir=#{man}",
"--disable-debug",
"--with-local=#{prefix}",
"--with-threads",
"--with-libtool",
# GDAL native backends.
"--with-pcraster=internal",
"--with-pcidsk=internal",
"--with-bsb",
"--with-grib",
"--with-pam",
# Backends supported by OS X.
"--with-libiconv-prefix=/usr",
"--with-libz=/usr",
"--with-png=#{Formula["libpng"].opt_prefix}",
"--with-expat=/usr",
"--with-curl=/usr/bin/curl-config",
# Default Homebrew backends.
"--with-jpeg=#{HOMEBREW_PREFIX}",
"--without-jpeg12", # Needs specially configured JPEG and TIFF libraries.
"--with-gif=#{HOMEBREW_PREFIX}",
"--with-libtiff=#{HOMEBREW_PREFIX}",
"--with-geotiff=#{HOMEBREW_PREFIX}",
"--with-sqlite3=#{Formula["sqlite"].opt_prefix}",
"--with-freexl=#{HOMEBREW_PREFIX}",
"--with-spatialite=#{HOMEBREW_PREFIX}",
"--with-geos=#{HOMEBREW_PREFIX}/bin/geos-config",
"--with-static-proj4=#{HOMEBREW_PREFIX}",
# GRASS backend explicitly disabled. Creates a chicken-and-egg problem.
# Should be installed separately after GRASS installation using the
# official GDAL GRASS plugin.
"--without-grass",
"--without-libgrass"
]
# Optional Homebrew packages supporting additional formats.
supported_backends = %w[
liblzma
cfitsio
hdf5
netcdf
jasper
xerces
odbc
dods-root
epsilon
webp
poppler
]
if build.include? 'complete'
supported_backends.delete 'liblzma'
args << '--with-liblzma=yes'
args.concat supported_backends.map {|b| '--with-' + b + '=' + HOMEBREW_PREFIX}
else
args.concat supported_backends.map {|b| '--without-' + b} unless build.include? 'enable-unsupported'
end
# The following libraries are either proprietary, not available for public
# download or have no stable version in the Homebrew core that is
# compatible with GDAL. Interested users will have to install such software
# manually and most likely have to tweak the install routine.
#
# Podofo is disabled because Poppler provides the same functionality and
# then some.
unsupported_backends = %w[
gta
ogdi
fme
hdf4
openjpeg
fgdb
ecw
kakadu
mrsid
jp2mrsid
mrsid_lidar
msg
oci
ingres
libkml
dwgdirect
idb
sde
podofo
rasdaman
]
args.concat unsupported_backends.map {|b| '--without-' + b} unless build.include? 'enable-unsupported'
# Database support.
args << (build.with?("postgresql") ? "--with-pg=#{HOMEBREW_PREFIX}/bin/pg_config" : "--without-pg")
args << (build.with?("mysql") ? "--with-mysql=#{HOMEBREW_PREFIX}/bin/mysql_config" : "--without-mysql")
if build.include? 'enable-mdb'
args << "--with-java=yes"
# The rpath is only embedded for Oracle (non-framework) installs
args << "--with-jvm-lib-add-rpath=yes"
args << "--with-mdb=yes"
end
# Python is installed manually to ensure everything is properly sandboxed.
args << '--without-python'
# Scripting APIs that have not been re-worked to respect Homebrew prefixes.
#
# Currently disabled as they install willy-nilly into locations outside of
# the Homebrew prefix. Enable if you feel like it, but uninstallation may be
# a manual affair.
#
# TODO: Fix installation of script bindings so they install into the
# Homebrew prefix.
args << "--without-perl"
args << "--without-php"
args << "--without-ruby"
args << (build.include?("enable-opencl") ? "--with-opencl" : "--without-opencl")
args << (build.include?("enable-armadillo") ? "--with-armadillo=yes" : "--with-armadillo=no")
return args
end
def patches
p = []
if build.stable?
# Patch of configure that finds Mac Java for MDB driver (uses Oracle or Mac default JDK)
# TODO: Remove when future GDAL release includes a fix
# http://trac.osgeo.org/gdal/ticket/5267 (patch applied to trunk, 2.0 release milestone)
# Must come before DATA
p << "https://gist.github.com/dakcarto/6877854/raw" if build.include? 'enable-mdb'
# Prevent build failure on 10.6 / 10.7: http://trac.osgeo.org/gdal/ticket/5197
# Fix build against MySQL 5.6.x: http://trac.osgeo.org/gdal/ticket/5284
p << DATA
end
return p
end
def install
# Linking flags for SQLite are not added at a critical moment when the GDAL
# library is being assembled. This causes the build to fail due to missing
# symbols. Also, ensure Homebrew SQLite is used so that Spatialite is
# functional.
#
# Fortunately, this can be remedied using LDFLAGS.
sqlite = Formula["sqlite"]
ENV.append 'LDFLAGS', "-L#{sqlite.opt_lib} -lsqlite3"
ENV.append 'CFLAGS', "-I#{sqlite.opt_include}"
# Needed by libdap
ENV.libxml2 if build.include? 'complete'
# Reset ARCHFLAGS to match how we build.
ENV['ARCHFLAGS'] = "-arch #{MacOS.preferred_arch}"
# Fix hardcoded mandir: http://trac.osgeo.org/gdal/ticket/5092
inreplace 'configure', %r[^mandir='\$\{prefix\}/man'$], ''
system "./configure", *get_configure_args
system "make"
system "make install"
# `python-config` may try to talk us into building bindings for more
# architectures than we really should.
if MacOS.prefer_64_bit?
ENV.append_to_cflags "-arch #{Hardware::CPU.arch_64_bit}"
else
ENV.append_to_cflags "-arch #{Hardware::CPU.arch_32_bit}"
end
cd 'swig/python' do
system "python", "setup.py", "install", "--prefix=#{prefix}", "--record=installed.txt", "--single-version-externally-managed"
bin.install Dir['scripts/*']
end
system 'make', 'man' if build.head?
system 'make', 'install-man'
# Clean up any stray doxygen files.
Dir[bin + '*.dox'].each { |p| rm p }
end
def caveats
if build.include? 'enable-mdb'
<<-EOS.undent
To have a functional MDB driver, install supporting .jar files in:
`/Library/Java/Extensions/`
See: `http://www.gdal.org/ogr/drv_mdb.html`
EOS
end
end
end
__END__
diff --git a/GDALmake.opt.in b/GDALmake.opt.in
index d7273aa..2fcbd53 100644
--- a/GDALmake.opt.in
+++ b/GDALmake.opt.in
@@ -123,6 +123,7 @@ INGRES_INC = @INGRES_INC@
HAVE_MYSQL = @HAVE_MYSQL@
MYSQL_LIB = @MYSQL_LIB@
MYSQL_INC = @MYSQL_INC@
+MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION = @MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION@
LIBS += $(MYSQL_LIB)
#
diff --git a/configure b/configure
index 1c4f8fb..120b17f 100755
--- a/configure
+++ b/configure
@@ -700,6 +700,7 @@ INGRES_INC
INGRES_LIB
II_SYSTEM
HAVE_INGRES
+MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION
MYSQL_LIB
MYSQL_INC
HAVE_MYSQL
@@ -23045,6 +23046,34 @@ $as_echo "no, mysql is pre-4.x" >&6; }
MYSQL_INC="`$MYSQL_CONFIG --include`"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
+
+ # Check if mysql headers declare load_defaults
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking load_defaults() in MySQL" >&5
+$as_echo_n "checking load_defaults() in MySQL... " >&6; }
+ rm -f testmysql.*
+ echo '#include "my_global.h"' > testmysql.cpp
+ echo '#include "my_sys.h"' >> testmysql.cpp
+ echo 'int main(int argc, char** argv) { load_defaults(0, 0, 0, 0); return 0; } ' >> testmysql.cpp
+ if test -z "`${CXX} ${CXXFLAGS} ${MYSQL_INC} -o testmysql testmysql.cpp ${MYSQL_LIB} 2>&1`" ; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, found in my_sys.h" >&5
+$as_echo "yes, found in my_sys.h" >&6; }
+ else
+ echo 'extern "C" void load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv);' > testmysql.cpp
+ echo 'int main(int argc, char** argv) { load_defaults(0, 0, 0, 0); return 0; } ' >> testmysql.cpp
+ if test -z "`${CXX} ${CXXFLAGS} ${MYSQL_INC} -o testmysql testmysql.cpp ${MYSQL_LIB} 2>&1`" ; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, found in library but not in header" >&5
+$as_echo "yes, found in library but not in header" >&6; }
+ MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION=yes
+ else
+ HAVE_MYSQL=no
+ MYSQL_LIB=
+ MYSQL_INC=
+ as_fn_error $? "Cannot find load_defaults()" "$LINENO" 5
+ fi
+ fi
+ rm -f testmysql.*
+ rm -f testmysql
+
;;
esac
fi
@@ -23055,6 +23084,8 @@ MYSQL_INC=$MYSQL_INC
MYSQL_LIB=$MYSQL_LIB
+MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION=$MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION
+
diff --git a/configure.in b/configure.in
index 481e8ea..d83797f 100644
--- a/configure.in
+++ b/configure.in
@@ -2294,6 +2294,31 @@ else
MYSQL_LIB="`$MYSQL_CONFIG --libs`"
MYSQL_INC="`$MYSQL_CONFIG --include`"
AC_MSG_RESULT([yes])
+
+ # Check if mysql headers declare load_defaults
+ AC_MSG_CHECKING([load_defaults() in MySQL])
+ rm -f testmysql.*
+ echo '#include "my_global.h"' > testmysql.cpp
+ echo '#include "my_sys.h"' >> testmysql.cpp
+ echo 'int main(int argc, char** argv) { load_defaults(0, 0, 0, 0); return 0; } ' >> testmysql.cpp
+ if test -z "`${CXX} ${CXXFLAGS} ${MYSQL_INC} -o testmysql testmysql.cpp ${MYSQL_LIB} 2>&1`" ; then
+ AC_MSG_RESULT([yes, found in my_sys.h])
+ else
+ echo 'extern "C" void load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv);' > testmysql.cpp
+ echo 'int main(int argc, char** argv) { load_defaults(0, 0, 0, 0); return 0; } ' >> testmysql.cpp
+ if test -z "`${CXX} ${CXXFLAGS} ${MYSQL_INC} -o testmysql testmysql.cpp ${MYSQL_LIB} 2>&1`" ; then
+ AC_MSG_RESULT([yes, found in library but not in header])
+ MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION=yes
+ else
+ HAVE_MYSQL=no
+ MYSQL_LIB=
+ MYSQL_INC=
+ AC_MSG_ERROR([Cannot find load_defaults()])
+ fi
+ fi
+ rm -f testmysql.*
+ rm -f testmysql
+
;;
esac
fi
@@ -2301,6 +2326,7 @@ fi
AC_SUBST(HAVE_MYSQL,$HAVE_MYSQL)
AC_SUBST(MYSQL_INC,$MYSQL_INC)
AC_SUBST(MYSQL_LIB,$MYSQL_LIB)
+AC_SUBST(MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION,$MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION)
dnl ---------------------------------------------------------------------------
dnl INGRES support.
diff --git a/ogr/ogrsf_frmts/mysql/GNUmakefile b/ogr/ogrsf_frmts/mysql/GNUmakefile
index 292ae45..e78398d 100644
--- a/ogr/ogrsf_frmts/mysql/GNUmakefile
+++ b/ogr/ogrsf_frmts/mysql/GNUmakefile
@@ -7,6 +7,11 @@ OBJ = ogrmysqldriver.o ogrmysqldatasource.o \
CPPFLAGS := -I.. -I../.. $(GDAL_INCLUDE) $(MYSQL_INC) $(CPPFLAGS)
+ifeq ($(MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION),yes)
+CPPFLAGS += -DMYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION
+endif
+
+
default: $(O_OBJ:.o=.$(OBJ_EXT))
clean:
diff --git a/ogr/ogrsf_frmts/mysql/ogrmysqldatasource.cpp b/ogr/ogrsf_frmts/mysql/ogrmysqldatasource.cpp
index 65c275b..447e374 100644
--- a/ogr/ogrsf_frmts/mysql/ogrmysqldatasource.cpp
+++ b/ogr/ogrsf_frmts/mysql/ogrmysqldatasource.cpp
@@ -36,6 +36,16 @@
#include "cpl_conv.h"
#include "cpl_string.h"
+/* Recent versions of mysql no longer declare load_defaults() in my_sys.h */
+/* but they still have it in the lib. Very fragile... */
+#ifdef MYSQL_NEEDS_LOAD_DEFAULTS_DECLARATION
+extern "C" {
+int load_defaults(const char *conf_file, const char **groups,
+ int *argc, char ***argv);
+void free_defaults(char **argv);
+}
+#endif
+
CPL_CVSID("$Id: ogrmysqldatasource.cpp 24947 2012-09-22 09:54:23Z rouault $");
/************************************************************************/
/* OGRMySQLDataSource() */
diff --git a/port/cpl_spawn.cpp b/port/cpl_spawn.cpp
index d702594..69ea3c2 100644
--- a/port/cpl_spawn.cpp
+++ b/port/cpl_spawn.cpp
@@ -464,7 +464,7 @@ void CPLSpawnAsyncCloseErrorFileHandle(CPLSpawnedProcess* p)
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
- #if defined(__APPLE__) && !defined(TARGET_OS_IPHONE)
+ #if defined(__APPLE__) && (!defined(TARGET_OS_IPHONE) || TARGET_OS_IPHONE==0)
#include <crt_externs.h>
#define environ (*_NSGetEnviron())
#else