Skip to content

Instantly share code, notes, and snippets.

@rnix
Last active December 13, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnix/4958168 to your computer and use it in GitHub Desktop.
Save rnix/4958168 to your computer and use it in GitHub Desktop.
GDAL Java ./configure and swig/java/java.opt patches for building gdal.jar on Mac OS X.
curl -ks https://gist.github.com/rnix/4958168/raw/build.sh | bash

Then remember to add the following to the JVM's environment that'll be importing gdal:

export LD_LIBRARY_PATH=${PWD}/.libs:${LD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:${LD_LIBRARY_PATH}

where ${PWD} is the gdal/swig/java directory (unless you install the libraries).

DISCLAIMER

This has only been tested on:

$ sw_vers -productVersion
10.8.2

$ uname -a
Darwin 12.2.1 Darwin Kernel Version 12.2.1: Thu Oct 18 16:32:48 PDT 2012; root:xnu-2050.20.9~2/RELEASE_X86_64 x86_64
#!/bin/bash
[ -f GDALmake.opt ] || {
[ -d gdal ] || svn co https://svn.osgeo.org/gdal/trunk/gdal
cd gdal
}
export JAVA_HOME=${JAVA_HOME:-$(/usr/libexec/java_home)}
[ "${JAVA_HOME}" ] || {
echo set JAVA_HOME >&2
exit ${LINENO}
}
# Build GDAL
grep include/darwin || curl -ks https://gist.github.com/rnix/4958168/raw/configure.patch | patch configure
./configure --with-java=${JAVA_HOME} --with-static-proj4=/usr/local/lib/libproj.a
make
# Build swig wrapper and JAR
cd swig/java
[ -f gdal.jar ] || {
grep darwin java.op || curl -ks https://gist.github.com/rnix/4958168/raw/java.opt.patch | patch java.opt
perl -pi -e 's|JAVA_HOME\s*=[^\n]+|JAVA_HOME='${JAVA_HOME}'|' java.opt
make
}
# Verify that the library can be loaded
export LD_LIBRARY_PATH=${PWD}/.libs:${LD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:${LD_LIBRARY_PATH}
curl -ksO https://gist.github.com/rnix/4958168/raw/Verify.java && {
javac -cp gdal.jar Verify.java \
&& java -cp gdal.jar:. Verify \
&& echo ok
}
--- configure 2013-02-14 21:28:33.000000000 -0500
+++ configure.darwin.fix 2013-02-14 21:26:32.000000000 -0500
@@ -28023,6 +28023,11 @@
JAVA_INC="-I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
+ elif test -d "$with_java/include/darwin"; then
+ JAVA_HOME="$with_java"
+ JAVA_INC="-I$JAVA_HOME/include -I$JAVA_HOME/include/darwin"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
elif test -d "$with_java/include/solaris"; then
JAVA_HOME="$with_java"
JAVA_INC="-I$JAVA_HOME/include -I$JAVA_HOME/include/solaris"
--- java.opt 2013-02-14 22:02:37.000000000 -0500
+++ java.opt.darwin.fix 2013-02-14 22:02:28.000000000 -0500
@@ -1,8 +1,9 @@
#
# Java Stuff
-JAVA_HOME = "C:\Program Files\Java\jdk1.6.0_16"
+JAVA_HOME="/Library/Java/1.7.0"
JAVADOC=$(JAVA_HOME)/bin/javadoc
JAVAC=$(JAVA_HOME)/bin/javac
JAVA=$(JAVA_HOME)/bin/java
JAR=$(JAVA_HOME)/bin/jar
-JAVA_INCLUDE=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
+JAVA_INCLUDE=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
+
public class Verify { public static void main(String... args) { org.gdal.gdal.gdal.AllRegister(); } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment