Skip to content

Instantly share code, notes, and snippets.

@robe2
Last active September 29, 2017 05:42
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 robe2/5942642 to your computer and use it in GitHub Desktop.
Save robe2/5942642 to your computer and use it in GitHub Desktop.
PostGIS 2.2 - 2.5 dep mingw64 gcc 4.8
#PostGIS 2.1, 2.2 dep mingw64 gcc 4.8 (4.8.0 or 4.8.1)
# If you are building 32-bit PostgreSQL 9.4 and expect it to work with EDB Win32 builds
# You must use gcc 4.8.1+ and will also need to edit the
# change the postgresql src/templates/win32 to LDFLAGS="-Wl,--allow-multiple-definition"
# this change is not needed for building 64-bit
# (used to build dependeinces included in http://www.bostongis.com/postgisstuff/ming64gcc48.7z, ming32gcc48.7z )
export OS_BUILD=64 #set to 32 if you are using 32-bit chain
export GCC_TYPE=gcc48 #change this to gcc481 if building with 4.8.1
PROJECTS=/projects
if [[ "${OS_BUILD}" == "" && "$1" == "" ]] ; then
echo "Usage: makedependencies OS_BUILD"
echo " OS_BUILD = 32|64"
echo " or export OS_BUILD=xx"
exit 1
fi
if [[ "${OS_BUILD}" == "64" ]] ; then
export MINGHOST=x86_64-w64-mingw32
export PG_BITS=
else
export MINGHOST=i686-w64-mingw32
export PG_BITS=w32
fi
CMAKE_PATH=/cmake
cd ${PROJECTS}
export PATH="/mingw/bin:/mingw/include:/mingw/lib:/bin"
cd ${PROJECTS}
if false; 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
if false; then
#this is needed for CUnit tests in postgis,
# I tried newer CUnit but couldn't get it to work
cd ${PROJECTS}
rm -rf CUnit-2.1-2
#wget --no-parent -O /sources/CUnit-2.1-2-src.tar.bz2 http://iweb.dl.sourceforge.net/project/cunit/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2
tar xvf /sources/CUnit-2.1-2-src.tar.bz2
cd CUnit-2.1-2
./configure --target=${MINGHOST} --prefix=/mingw/${MINGHOST}
make clean
make && make install
make check
rm -rf ${PROJECTS}/CUnit-2.1-2
fi
if false; then
#this is needed for ST_GeomFromKML And ST_GeomFromGML
export LIBXML_VER=2.7.8
mkdir ${PROJECTS}/libxml
cd ${PROJECTS}/libxml
#wget -O /sources/libxml2-2.7.8.tar.gz ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
rm -rf libxml2-${LIBXML_VER}
tar xvfz /sources/libxml2-${LIBXML_VER}.tar.gz
cd libxml2-${LIBXML_VER}
./configure --prefix=${PROJECTS}/libxml/rel-libxml2-${LIBXML_VER}w${OS_BUILD}${GCC_TYPE} --target=${MINGHOST} --with-threads=no --enable-shared CFLAGS=-O2
make clean
make
make install
make check
rm -rf ${PROJECTS}/libxml/libxml2-${LIBXML_VER}
fi
if false; then
#This is needed for ST_GeomFromGeoJSON and family
mkdir ${PROJECTS}/json-c
cd ${PROJECTS}/json-c
export JSON_VER=0.12
#rm json-c-${JSON_VER}.zip
cd ${SOURCES}
wget --no-check-certificate --output-document=${SOURCES}/json-c-${JSON_VER}.zip https://github.com/json-c/json-c/archive/json-c-${JSON_VER}.zip
rm -rf json-c-${JSON_VER}
unzip ${SOURCES}/json-c-${JSON_VER}.zip
mv json-c-json-c-${JSON_VER} json-c-${JSON_VER}
cd json-c-${JSON_VER}
## had to compile with -w (disable warnings otherwise it gave errors)
# note we use --enable-static -disable-shared so we don't have a small itsy bitsy json..dll we need to distribute
# this will force json support to be embedded directly in postgis-.dll
export VERBOSE=1
./configure --target=${MINGHOST} \
--prefix=${PROJECTS}/json-c/rel-${JSON_VER}w${OS_BUILD}${GCC_TYPE} --enable-static --disable-shared CFLAGS=-w
make
make install
make check #fails for some reason
#after install change lib/libjson-c.la file from library_names='' to library_names='libjson-c.a'
fi
#from tar build PostgreSQL
if false; then
export LIBXML_VER=2.7.8
cd ${PROJECTS}/postgresql
export PG_VER=9.6w${OS_BUILD}${GCC_TYPE}
export PG_VER_FULL=9.6.2
export PG_DIR=${PROJECTS}/postgresql/postgresql-${PG_VER_FULL}
rm postgresql-${PG_VER_FULL}.tar.bz2
rm -rf postgresql-${PG_VER_FULL}
wget http://ftp.postgresql.org/pub/source/v${PG_VER_FULL}/postgresql-${PG_VER_FULL}.tar.bz2
#wget http://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2
#tar -xvjf postgresql-snapshot.tar.bz2
tar -xvjf postgresql-${PG_VER_FULL}.tar.bz2
cd postgresql-${PG_VER_FULL}
export PATH="${PROJECTS}/rel/pg${PG_VER}/bin:${PROJECTS}/rel/pg${PG_VER}/lib:$PATH"
export PATH="${PROJECTS}/libxml/rel-libxml2-${LIBXML_VER}w${OS_BUILD}${GCC_TYPE}/bin:$PATH"
make distclean
#if you are building for 64-bit then use x86_64-w64-mingw32 for the build,host,target
#32 bit uses i686-w64-mingw32 for build, host, target
#9.4 LDFLAGS=-Wl,--allow-multiple-definition -Wl,--disable-auto-import -Wl,--as-needed
#9.3 LDFLAGS=-Wl,--allow-multiple-definition -Wl,--as-needed
#export LDFLAGS=-Wl,--allow-multiple-definition -Wl,--enable-auto-import -Wl,--as-needed
./configure --prefix=${PROJECTS}/postgresql/rel/pg${PG_VER}\
--build=${MINGHOST} \
--with-pgport=8443 --enable-cassert --enable-debug \
--without-zlib --with-libxml
#9.4 and below EDB version add to configure
## --disable-float8-byval
make clean
make
rm -rf ${PROJECTS}/postgresql/rel/pg${PG_VER}
make install
make check
#gmake install-world
cd ${PG_DIR}/contrib/postgres_fdw
make install
cd ${PG_DIR}/contrib/hstore
make
make install
cd ${PG_DIR}/contrib/fuzzystrmatch
make
make install
cd ${PG_DIR}/contrib/pg_trgm
make
make install
fi
#build Geos with cmake
if false; then
export PATH="/mingw/bin:/mingw/include:/mingw/lib:/bin"
mkdir ${PROJECTS}/geos
mkdir ${PROJECTS}/geos/branches
cd ${PROJECTS}/geos/branches
#note you can use githttps://git.osgeo.org/gogs/geos/geos.git (svn-trunk,svn-3.6 )
#or tar ball - http://download.osgeo.org/geos/?C=M;O=D
#svn checkout https://svn.osgeo.org/geos/branches/3.6 3.6
cd ${PROJECTS}/geos/branches/3.6
svn update
export PATH="${PATH}:${CMAKE_PATH}/bin"
export GEOS_VER=3.6.2
#make distclean
sh autogen.sh
#if building from svn
tools/svn_repo_revision.sh
cd ../
rm -rf buildw${OS_BUILD}
mkdir -p buildw${OS_BUILD}
cd buildw${OS_BUILD}
if [[ "${OS_BUILD}" == "64" ]] ; then
cmake -G "MSYS Makefiles" DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=${PROJECTS}/geos/rel-${GEOS_VER}w${OS_BUILD}${GCC_TYPE} -DHAVE_STD_ISNAN=1 -DHAVE_LONG_LONG_INT_64=1 -DGEOS_ENABLE_INLINE=NO -DGEOS_ENABLE_TESTS=ON - ../3.6
else
cmake -G "MSYS Makefiles" DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=${PROJECTS}/geos/rel-${GEOS_VER}w${OS_BUILD}${GCC_TYPE} -DHAVE_STD_ISNAN=1 -DGEOS_ENABLE_INLINE=NO -DGEOS_ENABLE_TESTS=ON - ../3.6
fi
make
make install
make test
make check
strip ${PROJECTS}/geos/rel-${GEOS_VER}w${OS_BUILD}${GCC_TYPE}/bin/*.dll
fi
if false; then
export PROJ_VER=4.9.3
cd ${SOURCES}
rm -rf proj-${PROJ_VER}
wget http://download.osgeo.org/proj/proj-${PROJ_VER}.tar.gz
wget http://download.osgeo.org/proj/proj-datumgrid-1.6.zip
tar xvfz proj-${PROJ_VER}.tar.gz
cd proj-${PROJ_VER}
cd nad
unzip ../../proj-datumgrid-1.6.zip
cd ..
./configure --prefix=${PROJECTS}/proj/rel-${PROJ_VER}w${OS_BUILD}${GCC_TYPE} --build=${MINGHOST}
make clean
make && make install
cd ${PROJECTS}/proj/rel-${PROJ_VER}w${OS_BUILD}${GCC_TYPE}
strip bin/*.dll
fi
#build GDAL - refer to GDAL build script
# https://gist.github.com/robe2/83be1da8b85dd83b7f950d55f5154d81
#-- SFCGAL and pgRouting dependencies start here --
cd ${PROJECTS}
mkdir CGAL
GMP_VER=5.1.2
MPFR_VER=3.1.2
#caveat for pgRouting had trouble building against 4.6.1, but works against 4.6.1,
# so I build both but test with 4.6.1
CGAL_VER=4.6.1
BOOST_VER=1.59.0
#BOOST_VER=1.53.0
BOOST_VER_WU=1_59_0
#BOOST_VER_WU=1_53_0
export export PATH="/mingw/bin:/mingw/include:/c/Windows/system32" PATH="${PATH}:${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/include:${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/lib:${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/bin"
PATH="${PATH}:${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}/include:${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}/lib:${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}/bin"
PATH="${PATH}:${PROJECTS}/CGAL/rel-cgal-${CGAL_VER}w${OS_BUILD}${GCC_TYPE}/include:${PROJECTS}/CGAL/rel-cgal-${CGAL_VER}w${OS_BUILD}${GCC_TYPE}/lib"
#PATH="${PATH}:${PROJECTS}/CGAL/gmp-${GMP_VER}"
PATH="${PATH}:.:/bin:/include"
#build boost (new pgRouting around 2.5-2.6, will require --with-graph, ealier do not)
if false; then
cd ${PROJECTS}
mkdir boost
cd ${PROJECTS}/boost
wget http://sourceforge.net/projects/boost/files/boost/${BOOST_VER}/boost_${BOOST_VER_WU}.tar.bz2
rm -rf boost_${BOOST_VER_WU}
tar -xvjf boost_${BOOST_VER_WU}.tar.bz2
cd ${PROJECTS}/boost/boost_${BOOST_VER_WU}/tools/build/v2
cmd //c bootstrap.bat gcc
cd tools/build
cd ../..
b2 --clean
b2 toolset=gcc address-model=${OS_BUILD} define=BOOST_USE_WINDOWS_H threading=multi variant=release link=static,shared --with-thread --with-system --with-date_time --with-serialization --with-graph --with-program_options --prefix=${PROJECTS}/boost/rel-${BOOST_VER_WU}w${OS_BUILD}${GCC_TYPE} install
fi
if false; then
cd ${PROJECTS}/CGAL
wget ftp://ftp.gmplib.org/pub/gmp/gmp-${GMP_VER}.tar.bz2
rm -rf gmp-${GMP_VER}
tar xvjf gmp-${GMP_VER}.tar.bz2
cd gmp-${GMP_VER}
#make clean
./configure --build=${MINGHOST} --enable-static --disable-shared --prefix=${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}
make && make install
make check
fi
if false; then
cd ${PROJECTS}/CGAL
wget http://www.mpfr.org/mpfr-current/mpfr-${MPFR_VER}.tar.bz2
rm -rf mpfr-${MPFR_VER}
tar xvjf mpfr-${MPFR_VER}.tar.bz2
cd mpfr-${MPFR_VER}
#make clean
export CPPFLAGS="-I${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/include"
export LDFLAGS="-L${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/lib"
./configure --build=${MINGHOST} --enable-static --disable-shared --prefix=${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}
make && make install
make check
fi
if false; then
#for building older CGAL
cd ${PROJECTS}/CGAL
export CGAL_VER=4.2
# # this site requires a login so you have to fetch the file interactively
# #wget -N --no-check-certificate https://gforge.inria.fr/frs/download.php/2912
rm -rf CGAL-${CGAL_VER}
tar xvjf /c/projects/sources/CGAL-${CGAL_VER}.tar.bz2 CGAL-${CGAL_VER}
export PATH="${PATH}:/cmake/bin"
rm -rf build
mkdir -p build
cd build
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=${PROJECTS}/CGAL/rel-cgal-${CGAL_VER}w${OS_BUILD}${GCC_TYPE} -DBoost_USE_STATIC_LIBS=ON -DCMAKE_CXX_FLAGS:STRING="-DBOOST_THREAD_USE_LIB -DBoost_USE_STATIC_LIBS -DBOOST_USE_WINDOWS_H" -DBOOST_ROOT:PATH=${PROJECTS}/boost/rel-${BOOST_VER_WU}w${OS_BUILD}${GCC_TYPE} ../CGAL-${CGAL_VER}
## Fixup generated files - this doesn't seem to be needed for CGAL 4.2
if false; then
mv src/CGAL/all_files.cpp aatmp
echo "#include <windows.h>" > src/CGAL/all_files.cpp
cat aatmp >> src/CGAL/all_files.cpp
rm aatmp
mv src/ImageIO/all_files.cpp aatmp
echo "#include <windows.h>" > src/ImageIO/all_files.cpp
cat aatmp >> src/ImageIO/all_files.cpp
rm aatmp
fi
make && make install
fi
#build SFCGAL needed for postgis_sfcgal extension (PostGIS 2.1+ for advanced 3D support like ST_3DIntersection)
# http://postgis.net/docs/reference.html#reference_sfcgal
if true; then
export SFCGAL_VER=1.3.0
#export PATH="/mingw/bin:/mingw/include:/c/Windows/system32"
PATH="${PATH}:${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/include:${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/lib:${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/bin"
PATH="${PATH}:${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}/include:${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}/lib:${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}/bin"
PATH="${PATH}:${PROJECTS}/CGAL/rel-cgal-${CGAL_VER}w${OS_BUILD}${GCC_TYPE}/include:${PROJECTS}/CGAL/rel-cgal-${CGAL_VER}w${OS_BUILD}${GCC_TYPE}/lib"
#PATH="${PATH}:${PROJECTS}/CGAL/gmp-${GMP_VER}"
#PATH="${PATH}:.:/bin:/include"
export PATH="${PATH}:/cmake/bin"
#cd ${PROJECTS}/CGAL
cd ${SOURCES}
rm -rf SFCGAL-${SFCGAL_VER}
wget --no-check-certificate -O SFCGAL-${SFCGAL_VER}.tar.gz https://github.com/Oslandia/SFCGAL/archive/v${SFCGAL_VER}.tar.gz
export MPFR_DIR=${PROJECTS}/CGAL/rel-mpfr-${MPFR_VER}w${OS_BUILD}${GCC_TYPE}
export GMP_DIR=${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}
export CPPFLAGS="-I${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/include"
export LDFLAGS="-L${PROJECTS}/CGAL/rel-gmp-${GMP_VER}w${OS_BUILD}${GCC_TYPE}/lib"
tar xvfz SFCGAL-${SFCGAL_VER}.tar.gz
#make sure to change file src/CMakeList.txt move MPFR check before GMP
rm -rf build
mkdir -p build
cd build
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=${PROJECTS}/CGAL/rel-sfcgal-${SFCGAL_VER}w${OS_BUILD}${GCC_TYPE} -DBoost_USE_STATIC_LIBS=ON -DCMAKE_CXX_FLAGS:STRING="-DBOOST_THREAD_USE_LIB -DBoost_USE_STATIC_LIBS -DBOOST_USE_WINDOWS_H" -DBOOST_ROOT:PATH=${PROJECTS}/boost/rel-${BOOST_VER_WU}w${OS_BUILD}${GCC_TYPE} ../SFCGAL-${SFCGAL_VER}
make
make install
cd ${PROJECTS}/CGAL/rel-sfcgal-${SFCGAL_VER}w${OS_BUILD}${GCC_TYPE}/bin
strip *.dll
#config file looks for dll in the lib folder instead of bin
cp ${PROJECTS}/CGAL/rel-sfcgal-${SFCGAL_VER}w${OS_BUILD}${GCC_TYPE}/bin/*.dll ${PROJECTS}/CGAL/rel-sfcgal-${SFCGAL_VER}w${OS_BUILD}${GCC_TYPE}/lib
fi
#--SFCGAL and pgRouting dependencies end here --
#Protobuf needed for building PostGIS 2.4 with Protobuf support (needed by ST_AsMVT, ST_ASGeoBuf and family)
if true; then
export PATH="/mingw/bin:/mingw/include:/bin"
cd ${PROJECTS}
mkdir protobuf
cd ${PROJECTS}/protobuf
cd ${SOURCES}
export PROTOBUF_VER=3.2.0
rm protobuf-${PROTOBUF_VER}.tar.gz
wget https://github.com/google/protobuf/archive/v${PROTOBUF_VER}.tar.gz -O protobuf-${PROTOBUF_VER}.tar.gz
rm -rf protobuf-${PROTOBUF_VER}
tar xvfz protobuf-${PROTOBUF_VER}.tar.gz
cd protobuf-${PROTOBUF_VER}
sh autogen.sh
./configure --build=${MINGHOST} --prefix=${PROJECTS}/protobuf/rel-${PROTOBUF_VER}w${OS_BUILD}${GCC_TYPE}
make && make install
cd ${PROJECTS}/protobuf/rel-${PROTOBUF_VER}w${OS_BUILD}${GCC_TYPE}
strip *.dll
fi
if true; then
export PATH="/mingw/bin:/mingw/include:/bin"
cd ${PROJECTS}
cd ${SOURCES}
export PROTOBUFC_VER=1.2.1
export PROTOBUF_VER=3.2.0
export PKG_CONFIG_PATH=${PROJECTS}/protobuf/rel-${PROTOBUF_VER}w${OS_BUILD}${GCC_TYPE}/lib/pkgconfig;
rm protobuf-c-${PROTOBUFC_VER}.tar.gz
wget https://github.com/protobuf-c/protobuf-c/releases/download/v${PROTOBUFC_VER}/protobuf-c-${PROTOBUFC_VER}.tar.gz
rm -rf protobuf-c-${PROTOBUFC_VER}
tar xvfz protobuf-c-${PROTOBUFC_VER}.tar.gz
cd protobuf-c-${PROTOBUFC_VER}
./configure --build=${MINGHOST} --prefix=${PROJECTS}/protobuf/rel-${PROTOBUF_VER}w${OS_BUILD}${GCC_TYPE}
make && make install
cd ${PROJECTS}/protobuf/rel-${PROTOBUF_VER}w${OS_BUILD}${GCC_TYPE}
strip *.dll
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment