Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script is for building gdal and gdal dependencies under mingw64, needed by both PostGIS and ogr_fdw
#my windows 64-bit build chain described here is available at http://www.bostongis.com/postgisstuff/ming64gcc48.7z
#(with most of these libraries already built)
#My 32-bit chain is much the same except uses gcc 4.8.1, I'll be posting that as well after I clean it up a bit
#Paul's instructions for setting up mingw on 32-bit are pretty close in concept - https://github.com/pramsey/postgis-build-windows
#Although these are built with mingw64 chain, they are designed to work with the EDB VC++ distributions of PostgreSQL
export OS_BUILD=64
export GCC_TYPE=gcc48
PROJECTS=/projects
SOURCES=/sources
if [[ "${OS_BUILD}" == "64" ]] ; then
export MINGHOST=x86_64-w64-mingw32
else
export MINGHOST=i686-w64-mingw32
fi
if true; then
cd ${PROJECTS}
LIBICONV_VER=1.15
wget --no-parent -O /sources/libiconv-${LIBICONV_VER}.tar.gz http://ftp.gnu.org/gnu/libiconv/libiconv-${LIBICONV_VER}.tar.gz
rm -rf libiconv-${LIBICONV_VER}
tar xvfz /sources/libiconv-${LIBICONV_VER}.tar.gz
cd libiconv-${LIBICONV_VER}
export LFLAGS="-static-libgcc"
./configure --build=${MINGHOST} --target=${MINGHOST} --prefix=${PROJECTS}/rel-libiconv-${LIBICONV_VER}w${OS_BUILD}${GCC_TYPE}
make && make install
make check
rm -rf ${PROJECTS}/libiconv-${LIBICONV_VER}
fi
#build SQLite needed for SQLite, OSM, PBF formats
if true; then
cd ${PROJECTS}/sqlite
wget http://www.sqlite.org/2017/sqlite-autoconf-3160200.tar.gz
tar xvfz sqlite-autoconf-3160200.tar.gz
cd sqlite-autoconf-3160200
export "CFLAGS=-O3 -DSQLITE_ENABLE_STAT3=1 -DSQLITE_ENABLE_TREE_EXPLAIN=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1 -DSQLITE_ENABLE_COLUMN_METADATA=1"
./configure --target=${MINGHOST} --prefix=${PROJECTS}/sqlite/rel-sqlite3w${OS_BUILD}${GCC_TYPE}
make
make install-strip
make check
fi
#compile freexl needed for XLS support in GDAL
#compile freexl
if true; then
export PATH="/mingw/usr/bin:/mingw/bin:/mingw/include:/mingw/lib:/bin:${PROJECTS}/rel-libiconv-1.15w${OS_BUILD}${GCC_TYPE}/bin"
cd ${PROJECTS}
mkdir freexl
export FREEXL_VER=1.0.4
cd ${SOURCES}
#wget http://www.gaia-gis.it/gaia-sins/freexl-${FREEXL_VER}.tar.gz
rm -rf freexl-${FREEXL_VER}
tar xvfz freexl-${FREEXL_VER}.tar.gz
cd freexl-${FREEXL_VER}
export FREEXL_REL_PATH=${PROJECTS}/freexl/rel-freexl-${FREEXL_VER}w${OS_BUILD}${GCC_TYPE}
./configure --disable-static --enable-shared --prefix=${FREEXL_REL_PATH}
make && make install
make check
fi
## build expat needed for XLSX support (and I think used by OSM format as well)
if true; then
cd ${PROJECTS}
mkdir expat
EXPAT_VER=2.2.0
cd ${SOURCES}
cd ${PROJECTS}/expat
#need to download expat from here
#wget https://github.com/libexpat/libexpat/archive/R_2_2_0.tar.gz -O expat-${EXPAT_VER}.tar.gz
#exit
#tar xvfz expat-${EXPAT_VER}.tar.gz
#mv libexpat-R_2_2_0 expat-${EXPAT_VER}
cd expat-${EXPAT_VER}/expat
sh buildconf.sh
./configure --host=${MINGHOST} --target=${MINGHOST} --prefix=${PROJECTS}/expat/rel-expat-${EXPAT_VER}w${OS_BUILD}${GCC_TYPE}
make && make install
#doc build fails, that's okay
fi
#compile openjpeg needed for jp2 support (not really needed for ogrfdw, but needed for PostGIS raster)
if true; then #note you need to compile with GDAL 2.2.2 or above to use OPENJPEG_VER=2.2.0
cd ${PROJECTS}
mkdir openjpeg
export OPENJPEG_VER=2.2.0
cd ${SOURCES}
export PATH="/cmake/bin:/mingw/bin:/mingw/include:/mingw/lib:/bin"
wget https://github.com/uclouvain/openjpeg/archive/v2.2.0.tar.gz -O openjpeg-${OPENJPEG_VER}.tar.gz
rm -rf openjpeg-${OPENJPEG_VER}
tar xvfz openjpeg-${OPENJPEG_VER}.tar.gz
rm -rf build
mkdir -p build
cd build
/cmake/bin/cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=${PROJECTS}/openjpeg/rel-openjpeg-${OPENJPEG_VER}w${OS_BUILD}${GCC_TYPE} ../openjpeg-${OPENJPEG_VER}
make && make install
make check
fi
##build curl needed WFS, CartoDb, CouchDB and other webservices support
#refer to my https://gist.github.com/robe2/0cc07f3d4f7dbb61025c (makecurl_ssl.sh )
#build gdal with wfs, xls, xlsx, default, and odbc drivers
if false; then
export PATH=$PATHOLD
export LIBICONV_VER=1.15
export PATH="/mingw/bin:/mingw/include:/mingw/lib:/bin:${PROJECTS}/rel-libiconv-${LIBICONV_VER}w${OS_BUILD}${GCC_TYPE}/lib:${PROJECTS}/rel-libiconv-${LIBICONV_VER}w${OS_BUILD}${GCC_TYPE}/bin"
cd ${PROJECTS}
mkdir gdal
cd ${PROJECTS}/gdal
export GDAL_VER=2.2.2
export GDAL_VER_PRE=2.2.2
cd ${SOURCES}
#rm gdal-${GDAL_VER_PRE}.tar.gz
#wget http://download.osgeo.org/gdal/${GDAL_VER}/gdal-${GDAL_VER_PRE}.tar.gz
rm -rf gdal-${GDAL_VER}
tar xvfz gdal-${GDAL_VER_PRE}.tar.gz
export EXPAT_VER=2.2.0
export CURL_VER=7.54.1
export SSL_VER=1.0.2g
export CURL_REL_PATH=${PROJECTS}/curl/rel-curl-${CURL_VER}w${OS_BUILD}${GCC_TYPE}
export FREEXL_VER=1.0.4
export ZLIB_VER=1.28
export OPENJPEG_VER=2.2.0
export FREEXL_REL_PATH=${PROJECTS}/freexl/rel-freexl-${FREEXL_VER}w${OS_BUILD}${GCC_TYPE}
#cd branches/${GDAL_VER}/gdal
cp /projects/gdal/branches/${GDAL_VER}/port/cpl_odbc.cpp gdal-${GDAL_VER}/port
cd gdal-${GDAL_VER}
#if you get a static exes (huge exes) and no dll it's usually libiconv or zlib that is the culprit.
# (I use --with-libz=internal because mingw sometimes comes with static libz that causes build to be static )
# Make sure after install you have a .dll in your install bin folder
export CPPFLAGS="-I${PROJECTS}/rel-libiconv-${LIBICONV_VER}w${OS_BUILD}${GCC_TYPE}/include "
export LDFLAGS="-L${PROJECTS}/ssl/rel-openssl-${SSL_VER}w${OS_BUILD}${GCC_TYPE}/lib -L${PROJECTS}/rel-libiconv-${LIBICONV_VER}w${OS_BUILD}${GCC_TYPE}/lib -L${CURL_REL_PATH}/lib -L/mingw/x86_64-w64-mingw32"
./configure --host=${MINGHOST} --enable-shared --disable-static --with-expat=${PROJECTS}/expat/rel-expat-${EXPAT_VER}w${OS_BUILD}${GCC_TYPE} --with-freexl=${FREEXL_REL_PATH} --with-odbc=/mingw/${MINGHOST} --with-sqlite3=${PROJECTS}/sqlite/rel-sqlite3w${OS_BUILD}${GCC_TYPE} --with-curl=${CURL_REL_PATH}/bin/curl-config \
--with-openjpeg=${PROJECTS}/openjpeg/rel-openjpeg-${OPENJPEG_VER}w${OS_BUILD}${GCC_TYPE} \
--with-libz=internal \
--prefix=${PROJECTS}/gdal/rel-${GDAL_VER}w${OS_BUILD}${GCC_TYPE}
make && make install
cd ${PROJECTS}/gdal/rel-${GDAL_VER}w${OS_BUILD}${GCC_TYPE}/bin
strip *.dll
strip *.exe
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.