[[TOC]] == An overview of the dependencies required for building with MingW == We would like use a simplified approach with pre-built libraries for all the GRASS dependencies but for the moment compiling many of the dependencies is required in order to have the proper files for grass. Still, a few steps are eliminated if compilation is done within the '''OSGeo4W''' directory structure. === Install the OSGeo4W directory structure === OSGeo4W has several of the required dependencies for compiling GRASS: 1. Download the '''OSGeo4W installer''' from [http://download.osgeo.org/osgeo4w/osgeo4w-setup.exe here]. 2. Run the installer. 3. Select Advanced Install, and Next. 4. Set the install directory to c:\OSGeo4W (other directories or fine if there are no spaces in the path but make sure to adjust the instructions below (?)) 5. Select '''grass''' from the desktop section (this is a binary but we'll compile from source later). 6. Also select '''msys''' from the command line section and '''libxdr''' from libs 7. Click next, the selected packages and their required subpackages will be downloaded and installed automatically. === Install the environment for compilation (MingW) === 1. Run msys (there should be an icon on the desktop) 2. type: {{{ mkdir /c/osgeo4w/apps/msys/osgeo4w }}} 3. Open c:\osgeo4w\apps\msys\etc\fstab.sample 4. Add the line below to the end of the file and save as fstab (without .sample) {{{ c:/osgeo4w/ /osgeo4w }}} 5. Restart msys 6. Download the MinGW packages: * '''mingw-runtime''' from [http://downloads.sourceforge.net/mingw/mingwrt-3.15.2-mingw32-dev.tar.gz here] * '''mingw32-make''' from [http://downloads.sourceforge.net/mingw/mingw32-make-3.81-20080326-3.tar.gz here] * '''gcc-core''' from [http://downloads.sourceforge.net/mingw/gcc-core-3.4.5-20060117-3.tar.gz here] * '''gcc-g++''' from [http://downloads.sourceforge.net/mingw/gcc-g++-3.4.5-20060117-3.tar.gz here] * '''w32api''' from [http://downloads.sourceforge.net/mingw/w32api-3.13-mingw32-dev.tar.gz here] * '''mingw-utils''' from [http://downloads.sourceforge.net/mingw/mingw-utils-0.3.tar.gz here] * '''bin-utils''' from [http://downloads.sourceforge.net/mingw/binutils-2.19.1-mingw32-bin.tar.gz here] 6. Unpack all to c:\osgeo4w === Flex & Bison === Download: * '''flex''' from [http://downloads.sourceforge.net/gnuwin32/flex-2.5.4a-1-bin.zip here] * '''bison''' from [http://downloads.sourceforge.net/gnuwin32/bison-2.1-bin.zip here] * '''bison-deps''' from [http://downloads.sourceforge.net/gnuwin32/bison-2.1-dep.zip here] Unpack all to c:\osgeo4w === PDCurses === 1. Download PDCurses from [http://downloads.sourceforge.net/pdcurses/PDCurses-3.3.tar.gz here] 2. Unpack to c:\osgeo4w\usr\src\ 3. open c:\osgeo4w\usr\src\PDCurses-3.3\win32\mingwin32.mak 4. at line 80 replace {{{ -copy }}} with {{{ -cp }}} 5. Run msys (from desktop icon) and at the prompt type: {{{ cd /c/osgeo4w/usr/src/PDCurses-3.3/win32/ make -f mingwin32.mak DLL=Y all cp pdcurses.a libcurses.a install libcurses.a /c/osgeo4w/lib/ install pdcurses.dll /c/osgeo4w/bin/ cd .. install -m 644 curses.h /c/osgeo4w/include/ }}} === Zlib === 1. Download '''zlib'' from [http://www.zlib.net/zlib-1.2.3.tar.gz here] 2. Unpack to c:\osgeo4w\usr\src\ 3. Open c:\osgeo4w\usr\src\zlib-1.2.3\win32\Makefile.gcc 4. Replace line 102 with: {{{ INCLUDE_PATH=/osgeo4w/include LIBRARY_PATH=/osgeo4w/lib SHARED_LIBRARY_PATH=/osgeo4w/bin }}} 5. At lines 109-110 delete: {{{ -@if not exist $(INCLUDE_PATH)/nul mkdir $(INCLUDE_PATH) -@if not exist $(LIBRARY_PATH)/nul mkdir $(LIBRARY_PATH) }}} 6. After line 111 add: {{{ -$(INSTALL) $(SHAREDLIB) $(SHARED_LIBRARY_PATH) }}} 7. After line 118 add: {{{ -$(RM) $(SHARED_LIBRARY_PATH)/$(SHAREDLIB) }}} 8. Run msys (from desktop icon) and at the prompt type: {{{ cd /osgeo4w/usr/src/zlib-1.2.3 make -f win32/Makefile.gcc make install -f win32/Makefile.gcc }}} (As an aside, we could probably put the following files into a zlib-headers package: * /osgeo4w/include/zlib.h * /osgeo4w/include/zconf.h * /osgeo4w/bin/zlib1.dll * /osgeo4w/lib/libz.a * /osgeo4w/lib/libzdll.a) === Regex === 1. Download regex from [http://downloads.sourceforge.net/gnuwin32/regex-2.7-bin.zip here] 2. Unpack to c:\osgeo4w === Libjpeg === 1. Download libjpeg from [http://www.ijg.org/files/jpegsrc.v6b.tar.gz here] 2. Unpack to c:\osgeo4w\usr\src 3. In MSYS console, type: {{{ cd /osgeo4w/usr/src/jpeg-6b ./configure --prefix=/osgeo4w --enable-shared make mkdir /osgeo4w/man/man1 make install }}} 4. Because make procedure doesn't create the shared library (even if enabled by configure), we need to build it manually: (As a hint, you can copy the below and paste int msys with Shift+Insert) {{{ COMOBJECTS="jcomapi.o jutils.o jerror.o jmemmgr.o jmemnobs.o" CLIBOBJECTS="jcapimin.o jcapistd.o jctrans.o jcparam.o \ jdatadst.o jcinit.o jcmaster.o jcmarker.o jcmainct.o \ jcprepct.o jccoefct.o jccolor.o jcsample.o jchuff.o \ jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o jfdctint.o" DLIBOBJECTS="jdapimin.o jdapistd.o jdtrans.o jdatasrc.o \ jdmaster.o jdinput.o jdmarker.o jdhuff.o jdphuff.o \ jdmainct.o jdcoefct.o jdpostct.o jddctmgr.o \ jidctfst.o jidctflt.o jidctint.o jidctred.o \ jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o" LIBOBJECTS="$CLIBOBJECTS $DLIBOBJECTS $COMOBJECTS" COBJECTS="cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o cdjpeg.o" DOBJECTS="djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o cdjpeg.o" TROBJECTS="jpegtran.o rdswitch.o cdjpeg.o transupp.o" for i in *.exe ; do rm /osgeo4w/bin/$i ; done rm *.exe cd .libs rm libjpeg.a rm /osgeo4w/lib/libjpeg.a cd .. gcc -shared -s -o ./.libs/libjpeg.dll -lm -Wl,--out-implib,./.libs/libjpeg.a $LIBOBJECTS gcc -s -g -O2 -o cjpeg.exe $COBJECTS -L./.libs/ -ljpeg gcc -s -g -O2 -o djpeg.exe $DOBJECTS -L./.libs/ -ljpeg gcc -s -g -O2 -o jpegtran.exe $TROBJECTS -L./.libs/ -ljpeg gcc -s -g -O2 -o rdjpgcom.exe rdjpgcom.o -L./.libs/ -ljpeg gcc -s -g -O2 -o wrjpgcom.exe wrjpgcom.o -L./.libs/ -ljpeg cd .libs install libjpeg.a /osgeo4w/lib install libjpeg.dll /osgeo4w/bin cd .. for i in *.exe ; do install $i /osgeo4w/bin ; done }}} (Again as an aside, we could put the following into a jpeg-headers package (with proper attributes?): * /osgeo4w/lib/libjpeg.a * /osgeo4w/bin/libjpeg.dll * /osgeo4w/bin/cjpeg.exe * /osgeo4w/bin/djpeg.exe * /osgeo4w/bin/jpegtran.exe * /osgeo4w/bin/rdjpgcom.exe * /osgeo4w/bin/wrjpgcom.exe) === PostgreSQL === 1. Download pgsql from [http://ftp2.it.postgresql.org/mirrors/postgres/source/v8.3.1/postgresql-8.3.6.tar.gz here] 2. Unpack to c:\osgeo4w 3. Open c:\osgeo4w\postgresql-8.3.6\src\test\regress\pg_regress.c 4. At line 51 change: {{{ char *bindir = PGBINDIR; char *libdir = LIBDIR; char *datadir = PGSHAREDIR; }}} to: {{{ char *bindir = "/osgeo4w/apps/pgsql/bin"; char *libdir = "/osgeo4w/apps/pgsql/lib"; char *datadir = "/osgeo4w/apps/pgsql/share"; }}} 5. In the msys console type: {{{ cd /osgeo4w/postgresql-8.3.6 ./configure --prefix=/osgeo4w/apps/pgsql \ --with-includes=/osgeo4w/include \ --with-libraries=/osgeo4w/lib \ --without-readline make -f GNUmakefile make install -f GNUmakefile }}} === SQLite === 1. Download '''sqlite3''' from [http://www.sqlite.org/sqlite-amalgamation-3.5.9.tar.gz here] 2. Unpack to c:\osgeo4w\usr\src {{{ ./configure --prefix=/osgeo4w/apps/sqlite make make install }}} === PROJ.4 === 1. Download PROJ.4 from [ftp://ftp.remotesensing.org/proj/proj-4.6.0.tar.gz here] 2. Unpack to c:\osgeo4w\usr\src 3. Download the US, Canadian and New Zealand datum shift grids from [ftp://ftp.remotesensing.org/proj/proj-datumgrid-1.3.zip here] 4. Unpack to c:\osgeo4w\usr\src\proj-4.6.0\nad 5. In MSYS console, type: {{{ cd /osgeo4w/usr/src/proj-4.6.0 ./configure --prefix=/osgeo4w --enable-shared --disable-static make make install }}} Because make procedure doesn't create shared library (even if enabled by configure), we need to build it manually: {{{ cd src for i in *.exe ; do rm /osgeo4w/bin/$i ; done rm /osgeo4w/bin/invgeod.exe rm /osgeo4w/bin/invproj.exe rm *.exe cd .libs rm libproj.a rm /osgeo4w/lib/libproj.a gcc -shared -s -o libproj.dll -lm -Wl,--out-implib,libproj.a *.o cd .. gcc -s -g -O2 -o cs2cs.exe cs2cs.o gen_cheb.o p_series.o .libs/emess.o -L./.libs/ -lproj gcc -s -g -O2 -o geod.exe geod.o geod_set.o geod_for.o geod_inv.o .libs/emess.o -L./.libs/ -lproj gcc -s -g -O2 -o nad2bin.exe nad2bin.o -L./.libs/ -lproj gcc -s -g -O2 -o nad2nad.exe nad2nad.o .libs/emess.o -L./.libs/ -lproj gcc -s -g -O2 -o proj.exe proj.o gen_cheb.o p_series.o .libs/emess.o -L./.libs/ -lproj cp proj.exe invproj.exe cp geod.exe invgeod.exe cd .libs install libproj.a /osgeo4w/lib install libproj.dll /osgeo4w/bin cd .. for i in *.exe ; do install $i /osgeo4w/bin ; done }}} === GDAL === '''Untested: so far gdal-1.5.2 won't compile, perhaps try a newer version''' 1. Download '''gdal''' from [http://download.osgeo.org/gdal/gdal-1.5.2.tar.gz here] 2. Unpack to c:\osgeo4w\usr\src 3. Open c:\osgeo4w\usr\src\gdal-1.5.2\configure 4. At line 23832 replace: {{{ expat_lib_flags="-L$expat_prefix/lib -lexpat" }}} with: {{{ LIBS="$LIBS -L$expat_prefix/lib -lexpat" }}} 5. In MSYS console, type: {{{ cd /usr/local/src/gdal-1.5.2 ./configure --prefix=/osego4w \ --without-grass \ --with-sqlite3=/osgeo4w/apps/sqlite \ --with-pg=/osgeo4w/apps/pgsql/bin/pg_config.exe }}} 6. Open c:\msys\local\src\gdal-1.5.2\GNUmakefile 7. After line 4 add: {{{ GDAL_ROOT=. }}} 8. Finally build and install GDAL: {{{ make -f GNUmakefile make install -f GNUmakefile }}} === Tcl/Tk (skip if only compiling grass7) === '''Untested''' 1. Download Tcl from [http://prdownloads.sourceforge.net/tcl/tcl8.5.2-src.tar.gz here] 2. Download Tk from [http://prdownloads.sourceforge.net/tcl/tk8.5.2-src.tar.gz here] 3. Unpack both to c:\osgeo4w\usr\src 4. In the msys console type: {{{ cd /osgeo4w/usr/src/tcl8.5.2/win ./configure --prefix=/osgeo4w/apps/tcl-tk --enable-shared make make install cd /osgeo4w/apps/tcl-tk/bin mv tclsh85.exe tclsh.exe cd /osgeo4w/usr/src/tk8.5.2/win ./configure --prefix=/osgeo4w/apps/tcl-tk --with-tcl=/osgeo4w/usr/src/tcl8.5.2/win --enable-shared make make install cd /osgeo4w/apps/tcl-tk/bin mv wish85.exe wish.exe }}} === Compiling and Installing GRASS (6.4.0) === 1. Download the latest GRASS 6.4.0 source code from [http://grass.osgeo.org/grass64/source/snapshot/ here]. 2. Unpack to c:\osgeo4w\usr\src 3. Download the installer script '''package.sh''' from [http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/mswindows/osgeo4w/package.sh?format=raw here] and put in c:\osgeo4w\usr\src\grass-6.4xxx 4. Open package.sh and at line 12: Change: {{{ --with-libs="/c/OSGeo4W/lib /c/MinGW/lib" \ --with-includes="/c/OSGeo4W/include /c/MinGW/include" \ }}} to: {{{ --with-libs=/c/OSGeo4W/lib \ --with-includes=/c/OSGeo4W/include \ }}} 5. To compile, type in MSYS console: {{{ export PATH="/osgeo4w/bin:/osgeo4w/apps/tcl-tk/bin:/osgeo4w/apps/sqlite/bin:/osgeo4w/apps/pgsql/lib:$PATH" cd /osgeo4w/usr/src/grass-6.4xxx (change to dir of the version you downloaded) package.sh }}} When finished, you should have the following compilation log (c:\osgeo4w\usr\src\grass-6.4xxx\error.log): {{{ GRASS GIS compilation log ------------------------- Started compilation: Mon Feb 16 10:11:17 GMT 2009 -- Errors in: /usr/local/src/grass-6.4.0/raster/r.li/r.li.daemon /usr/local/src/grass-6.4.0/raster/r.li/r.li.edgedensity /usr/local/src/grass-6.4.0/raster/r.li/r.li.patchdensity /usr/local/src/grass-6.4.0/raster/r.li/r.li.patchnum /usr/local/src/grass-6.4.0/raster/r.li/r.li.shape /usr/local/src/grass-6.4.0/raster/r.li/r.li.simpson /usr/local/src/grass-6.4.0/raster/r.li/r.li.shannon /usr/local/src/grass-6.4.0/raster/r.li/r.li.mps /usr/local/src/grass-6.4.0/raster/r.li/r.li.mpa /usr/local/src/grass-6.4.0/raster/r.li/r.li.padcv /usr/local/src/grass-6.4.0/raster/r.li/r.li.padsd /usr/local/src/grass-6.4.0/raster/r.li/r.li.padrange /usr/local/src/grass-6.4.0/raster/r.li/r.li.cwed /usr/local/src/grass-6.4.0/raster/r.li/r.li.richness /usr/local/src/grass-6.4.0/raster/r.li/r.li.dominance -- In case of errors please change into the directory with error and run 'make'. If you get multiple errors, you need to deal with them in the order they appear in the error log. If you get an error building a library, you will also get errors from anything which uses the library. -- Finished compilation: Mon Feb 16 10:11:17 GMT 2009 make: *** [default] Error 1 }}} Currently r.li.* cannot be compiled on Windows. Now GRASS should be installed in c:\osgeo4w\apps\grass-6.4.0\ '''Usage''' The startup '''grass64.bat''' file should be in C:\OSGeo4W\apps\grass\bin Open it and replace the contents with: {{{ @echo off SET OSGEO4W_ROOT=C:\OSGeo4W PATH %OSGEO4W_ROOT%\bin;%PATH% for %%f in ("%OSGEO4W_ROOT%"\etc\ini\*.bat) do call "%%f" rem ######################################################################### rem # rem # GRASS Initialization rem # rem ######################################################################### set WINGISBASE=%OSGEO4W_ROOT%/apps/grass/grass-6.4xxx (change to the appropriate grass version) "%WINGISBASE%"\etc\init.bat %* }}} If you want to be able to use the console from within grass, you'll need a different startup file: Create '''C:\OSGeo4W\apps\grass\bin\grass64''' with the following contents: {{{ #! /bin/sh ############################################################################# # # MODULE: GRASS Initialization # AUTHOR(S): Justin Hickey - Thailand - jhickey@hpcc.nectec.or.th # PURPOSE: The source file for this shell script is in # lib/init/grass.src and is the grass startup script. It # requires a source file because the definition of GISBASE # is not known until compile time and is substituted from the # Makefile. Any command line options are passed to Init.sh. # COPYRIGHT: (C) 2000-2005 by the GRASS Development Team # # This program is free software under the GNU General Public # License (>=v2). Read the file COPYING that comes with GRASS # for details. # ############################################################################# trap "echo 'User break!' ; exit" 2 3 9 15 # Set the GISBASE variable GISBASE=/c/OSGeo4W/apps/grass/grass-6.4xxx (change to the appropriate grass version) export GISBASE # Set the PATH variable PATH="/osgeo4w/apps/tcl-tk/bin:/osgeo4w/apps/sqlite/bin:/osgeo4w/apps/pgsql/lib:$PATH" export PATH # Set the PYTHONPATH PYTHONPATH="$GISBASE/etc/python:$PYTHONPATH" exec "$GISBASE/etc/Init.sh" "$@" }}} === TODO === Describe installations of: * other deps? == Building with MS Visual Studio == * TODO - see [http://wiki.qgis.org/qgiswiki/BuildingFromSource#head-696307823157d4af8ddd12c81acdbea284576a5f building QGIS instructions] == See also == * [http://trac.osgeo.org/osgeo4w/wiki/pkg-grass GRASS package page in OSGeo4W] (including [http://trac.osgeo.org/osgeo4w/wiki/pkg-grass#PackagerNotes packaging notes]) * [wiki:BuildingOnWindows Develop your own GRASS modules on MS-Windows] * http://wiki.qgis.org/qgiswiki/BuildingFromSource by QGIS Team * http://www.webalice.it/marco.pasetti/grass/BuildFromSource.html by Marco Pasetti * http://www.webalice.it/marco.pasetti/qgis+grass/BuildFromSource.html by Marco Pasetti