| 1 | = PostGIS 2.0 Build Using MinGW/MSYS/VisualC++ = |
| 2 | |
| 3 | These directions are based on building a PostGIS 2.0 installation using a mixture of MinGW and Visual C++ (MSVC). Some of the libraries that PostGIS 2.0 depends on, such as GEOS and GDAL, are more frequently built and tested under MSVC than under MinGW. |
| 4 | |
| 5 | == Operating System == |
| 6 | |
| 7 | This build recipe has been put together and tested on Windows XP, with all current patches from Microsoft. |
| 8 | |
| 9 | == MinGW/MSYS == |
| 10 | |
| 11 | MinGW/MSYS have been recently revived using a lightweight package manager called '"mingw-get". Like apt-get and yum, mingw-get makes it very easy to pull down pieces of software and all the necessary dependencies in one step. First get the base installer for mingw-get. |
| 12 | |
| 13 | http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/mingw-get-inst-20111118.exe |
| 14 | |
| 15 | Run the installer, and opt for support of C, C++ and MSYS. Once the install is finished, open up the "MinGW Shell" and run the following commands: |
| 16 | |
| 17 | {{{ |
| 18 | mingw-get install msys-bison msys-flex |
| 19 | mingw-get install msys-unzip msys-zip |
| 20 | mingw-get install msys-autoconf |
| 21 | mingw-get install msys-automake |
| 22 | mingw-get install msys-libtool |
| 23 | mingw-get install msys-wget |
| 24 | mingw-get install mingw32-gettext |
| 25 | mingw-get install mingw32-libiconv |
| 26 | mingw-get install mingw32-zlib mingw32-libz |
| 27 | mingw-get install mingw-utils |
| 28 | }}} |
| 29 | |
| 30 | Then set up the build and target directories: |
| 31 | |
| 32 | {{{ |
| 33 | # target directory |
| 34 | mkdir /c/pgsql |
| 35 | |
| 36 | # build directory |
| 37 | mkdir /c/build/ |
| 38 | mkdir /c/build/sources |
| 39 | mkdir /c/build/binaries |
| 40 | }}} |
| 41 | |
| 42 | == SVN == |
| 43 | |
| 44 | In order to build the latest versions of PostGIS 2.0 you will need an SVN client, so download a command line SVN client: |
| 45 | |
| 46 | {{{ |
| 47 | cd /c/build/binaries |
| 48 | wget http://www.sliksvn.com/pub/Slik-Subversion-1.7.2-win32.msi |
| 49 | }}} |
| 50 | |
| 51 | Once you've downloaded, install with the default options. |
| 52 | |
| 53 | == Visual C++ Express == |
| 54 | |
| 55 | To build the MSVC libraries, you will need the free version of Visual C++, which microsoft makes available. |
| 56 | |
| 57 | http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express |
| 58 | |
| 59 | Download Visual C++ Express and install it. |
| 60 | |
| 61 | == CMake == |
| 62 | |
| 63 | CMake is a multi-platform build tool, used by GEOS to control compilation on non-UNIX platforms. Download CMake from: |
| 64 | |
| 65 | http://www.cmake.org/cmake/resources/software.html |
| 66 | |
| 67 | Install, and opt to add to system path for all users when prompted. |
| 68 | |
| 69 | == GEOS == |
| 70 | |
| 71 | GEOS is the geometry library underlying most of the PostGIS geometry functions. |
| 72 | |
| 73 | {{{ |
| 74 | cd /c/build/sources |
| 75 | wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2 |
| 76 | tar xvfj geos-3.3.3.tar.bz2 |
| 77 | mkdir geos-3.3.3-build |
| 78 | cd geos-3.3.3 |
| 79 | ./configure --prefix=/c/pgsql |
| 80 | }}} |
| 81 | |
| 82 | Edit the CMakeLists.txt file and the following line to stop floating point precision issues (which will lead to regression failures in PostGIS later on if you don't make the change) |
| 83 | {{{ |
| 84 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /fp:strict /fp:except-") |
| 85 | }}} |
| 86 | right before this line |
| 87 | {{{ |
| 88 | add_definitions(-D_SCL_SECURE_NO_WARNINGS) |
| 89 | }}} |
| 90 | |
| 91 | Open up the "Visual Studio 2008 Command Prompt", and run the build commands below. |
| 92 | |
| 93 | {{{ |
| 94 | cd \ |
| 95 | cd build |
| 96 | cd sources |
| 97 | cd geos-3.2.2-build |
| 98 | cmake -G "NMake MakeFiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=C:\pgsql ..\geos-3.3.2 |
| 99 | nmake |
| 100 | nmake install |
| 101 | }}} |
| 102 | |
| 103 | Open up the "MinGW Shell" and clean out the static libraries and copy the dynamic libraries over to the lib dir: |
| 104 | |
| 105 | {{{ |
| 106 | cd /c/pgsql/bin |
| 107 | cp geos*dll ../lib |
| 108 | cd ../lib |
| 109 | rm geos*.lib |
| 110 | }}} |
| 111 | |
| 112 | Now you have GEOS, but PostGIS is going to need a geos-config file to build, so... |
| 113 | |
| 114 | {{{ |
| 115 | cd /c/build/sources/geos-3.3.3 |
| 116 | cp tools/geos-config /c/pgsql/bin |
| 117 | chmod 755 /c/pgsql/bin/geos-config |
| 118 | }}} |
| 119 | |
| 120 | == PostgreSQL == |
| 121 | |
| 122 | {{{ |
| 123 | cd /c/build/sources |
| 124 | wget http://ftp.postgresql.org/pub/source/v9.1.2/postgresql-9.1.2.tar.bz2 |
| 125 | tar xvfj postgresql-9.1.2.tar.bz2 |
| 126 | cd postgresql-9.1.2 |
| 127 | ./configure --prefix=/c/pgsql |
| 128 | make |
| 129 | make install |
| 130 | }}} |
| 131 | |
| 132 | == CUnit == |
| 133 | |
| 134 | {{{ |
| 135 | cd /c/build/sources |
| 136 | wget http://downloads.sourceforge.net/project/cunit/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2 |
| 137 | tar xvfj CUnit-2.1-2-src.tar.bz2 |
| 138 | cd CUnit-2.1-2 |
| 139 | ./configure --prefix=/c/pgsql |
| 140 | make |
| 141 | make install |
| 142 | }}} |
| 143 | |
| 144 | == Proj == |
| 145 | |
| 146 | {{{ |
| 147 | cd /c/build/sources |
| 148 | wget http://download.osgeo.org/proj/proj-4.6.1.tar.gz |
| 149 | wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip |
| 150 | tar xvfz proj-4.6.1.tar.gz |
| 151 | cd proj-4.6.1/nad |
| 152 | unzip ../../proj-datumgrid-1.5.zip |
| 153 | }}} |
| 154 | |
| 155 | Edit the nmake.opt file and set the INSTDIR variable to "c:\pgsql". |
| 156 | |
| 157 | Open up the "Visual Studio 2008 Command Prompt" |
| 158 | |
| 159 | {{{ |
| 160 | cd \ |
| 161 | cd build\sources\proj-4.6.1 |
| 162 | nmake -f makefile.vc |
| 163 | nmake -f makefile.vc install-all |
| 164 | }}} |
| 165 | |
| 166 | Open up the "MinGW Shell" and clean out the static libraries and copy the dynamic libraries over to the lib dir: |
| 167 | |
| 168 | {{{ |
| 169 | cd /c/pgsql/bin |
| 170 | cp proj*dll ../lib |
| 171 | cd ../lib |
| 172 | rm proj*.lib |
| 173 | }}} |
| 174 | |
| 175 | == GTK+ Bundle == |
| 176 | |
| 177 | {{{ |
| 178 | cd /c/build/binaries |
| 179 | wget http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip |
| 180 | unzip gtk+-bundle_2.24.10-20120208_win32.zip -d /c/pgsql |
| 181 | }}} |
| 182 | |
| 183 | == EnterpriseDB PostgreSQL == |
| 184 | |
| 185 | If you're planning on eventually copying the binaries into an EnterpriseDB build for distribution here's where to get the binaries: |
| 186 | |
| 187 | {{{ |
| 188 | cd /c/build/binaries |
| 189 | wget http://get.enterprisedb.com/postgresql/postgresql-9.1.2-1-windows-binaries.zip |
| 190 | mkdir /c/pgsql-edb |
| 191 | unzip postgresql-9.1.2-1-windows-binaries.zip -d /c/pgsql-edb |
| 192 | }}} |
| 193 | |
| 194 | == LibXML2 == |
| 195 | |
| 196 | You have to get libxml2 and its dependencies, iconv and zlib. |
| 197 | |
| 198 | {{{ |
| 199 | cd /c/build/binaries |
| 200 | wget ftp://ftp.zlatkovic.com/libxml/libxml2-2.7.8.win32.zip |
| 201 | wget ftp://ftp.zlatkovic.com/libxml/iconv-1.9.2.win32.zip |
| 202 | wget ftp://ftp.zlatkovic.com/libxml/zlib-1.2.5.win32.zip |
| 203 | |
| 204 | unzip libxml2-2.7.8.win32.zip |
| 205 | cd libxml2-2.7.8.win32 |
| 206 | cp -r bin/* /c/pgsql/bin |
| 207 | cp -r bin/* /c/pgsql/lib |
| 208 | cp -r include /c/pgsql/ |
| 209 | cd .. |
| 210 | |
| 211 | unzip iconv-1.9.2.win32.zip |
| 212 | cd iconv-1.9.2.win32 |
| 213 | cp -r bin/* /c/pgsql/bin |
| 214 | cp -r bin/* /c/pgsql/lib |
| 215 | cp -r include /c/pgsql/ |
| 216 | cd .. |
| 217 | |
| 218 | unzip zlib-1.2.5.win32.zip |
| 219 | cd zlib-1.2.5.win32 |
| 220 | cp -r bin/* /c/pgsql/bin |
| 221 | cp -r bin/* /c/pgsql/lib |
| 222 | cp -r include /c/pgsql/ |
| 223 | cd .. |
| 224 | }}} |
| 225 | |
| 226 | Now you have libxml2, but you don't have an xml2-config file. So... |
| 227 | |
| 228 | {{{ |
| 229 | cp /c/pgsql/bin/geos-config /c/pgsql/bin/xml2-config |
| 230 | }}} |
| 231 | |
| 232 | Now edit /c/pgsql/bin/xml2-config so it returns the right answers! |
| 233 | |
| 234 | * Change the --libes option so that "-lgeos" becomes "-lxml2 -lz -lpthread -liconv -lm" |
| 235 | * Change the --cflags option to return "-I/c/pgsql/include/libxml" |
| 236 | |
| 237 | == JSON-C == |
| 238 | |
| 239 | {{{ |
| 240 | cd /c/build/sources |
| 241 | wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz |
| 242 | tar xvfz json-c-0.9.tar.gz |
| 243 | cd json-c-0.9 |
| 244 | CFLAGS=-w ./configure --prefix=/c/pgsql --enable-shared --disable-static |
| 245 | make |
| 246 | make install |
| 247 | cd /c/pgsql/lib |
| 248 | a2dll libjson.a -o libjson.dll |
| 249 | cp libjson.dll ../bin |
| 250 | rm libjson.a |
| 251 | }}} |
| 252 | |
| 253 | == GDAL == |
| 254 | |
| 255 | Getting a working GDAL is an involved process... |
| 256 | |
| 257 | {{{ |
| 258 | cd /c/build/sources |
| 259 | http://download.osgeo.org/gdal/gdal-1.9.0.tar.gz |
| 260 | tar xvfz gdal-1.9.0.tar.gz |
| 261 | cd gdal-1.9.0 |
| 262 | ./configure --prefix=/c/pgsql |
| 263 | cd apps |
| 264 | make gdal-config |
| 265 | }}} |
| 266 | |
| 267 | In order get get all the symbols linking you need to edit nmake.opt appropriately. Find the following line in the file and disable STDCALL by following the directions (commenting out the line and adding the CPL_DISABLE_STDCALL flag to the OPTFLAGS later in the file. |
| 268 | {{{ |
| 269 | # If you don't want some entry points to have STDCALL conventions, |
| 270 | # comment out the following and add -DCPL_DISABLE_STDCALL in OPTFLAGS. |
| 271 | # This option has no effect on 64-bit windows. |
| 272 | #STDCALL=YES |
| 273 | }}} |
| 274 | While you're at it, also carry out the following edits: |
| 275 | {{{ |
| 276 | GDAL_HOME = "C:\pgsql" |
| 277 | }}} |
| 278 | Set the version string to blank |
| 279 | {{{ |
| 280 | VERSION = |
| 281 | }}} |
| 282 | Note on the above: Blanking out the version string is necessarily to line up the DLL name with the expectation of the PostGIS configure script that gdal will be named "gdal" and not "gdal19". This is fine for a one-time compile, but in the long run, to avoid DLL conflicts, we would be better off with a properly named GDAL and having the PostGIS configure process pick up the right name from the gdal-config script and apply it to all tests. |
| 283 | |
| 284 | Open up the "Visual Studio 2008 Command Prompt" |
| 285 | |
| 286 | {{{ |
| 287 | nmake -f makefile.vc MSVC_VER=1500 |
| 288 | nmake -f makefile.vc MSVC_VER=1500 install |
| 289 | }}} |
| 290 | |
| 291 | Copy the dynamic gdal-config script into place. |
| 292 | {{{ |
| 293 | cp apps/gdal-config /c/pgsql/bin |
| 294 | chmod 755 /c/pgsql/bin/gdal-config |
| 295 | }}} |
| 296 | Copy the static libraries across |
| 297 | {{{ |
| 298 | cp /c/pgsql/bin/gdal19.dll /c/pgdal/lib/gdal.dll |
| 299 | }}} |
| 300 | |
| 301 | Ensure gdal-config returns the right answers! |
| 302 | |
| 303 | Copy the header files over, since the install process seems to not move them. |
| 304 | {{{ |
| 305 | cd /c/build/sources/gdal-1.9.0 |
| 306 | cp gcore/*.h /c/pgsql/include |
| 307 | cp port/*.h /c/pgsql/include |
| 308 | cp ogr/*.h /c/pgsql/include |
| 309 | cp alg/*.h /c/pgsql/include |
| 310 | cp frmts/vrt/*.h /c/pgsql/include |
| 311 | }}} |
| 312 | |
| 313 | == PostGIS == |
| 314 | |
| 315 | Now we are ready to try and build PostGIS. Using the "MinGW Shell", |
| 316 | |
| 317 | {{{ |
| 318 | cd /c/build/sources |
| 319 | svn co http://svn.osgeo.org/postgis/trunk postgis-svn |
| 320 | export PATH=$PATH:/c/pgsql/bin |
| 321 | }}} |
| 322 | |
| 323 | Before building, edit one file to allow the regression tests to run, edit ./regress/Makefile.in and set |
| 324 | {{{ |
| 325 | REGRESS_INSTALLDIR=C:/build/sources/postgis-svn/regress/00-regress-install |
| 326 | }}} |
| 327 | |
| 328 | Now you can configure and build, |
| 329 | {{{ |
| 330 | CPPFLAGS="-I/c/pgsql/include" LDFLAGS="-L/c/pgsql/lib" ./configure \ |
| 331 | --with-xml2config=/c/pgsql/bin/xml2-config \ |
| 332 | --with-pgconfig=/c/pgsql/bin/pg_config \ |
| 333 | --with-geosconfig=/c/pgsql/bin/geos-config \ |
| 334 | --with-projdir=/c/pgsql \ |
| 335 | --with-gdalconfig=/c/pgsql/bin/gdal-config \ |
| 336 | --with-jsondir=/c/pgsql \ |
| 337 | --with-libintl-prefix=/c/pgsql \ |
| 338 | --with-gui |
| 339 | |
| 340 | make |
| 341 | make check |
| 342 | make install |
| 343 | }}} |