# Building and Maintenance

## Building OpenEV from scratch

### Linux/Unix

1. First, download the source for Mesa, gtkglarea, python, pygtk, gtk/gdk/glib, gtk+extra, python-gtkextra, gnuplot, and proj (for gnuplot and proj, just the binary executables and library are fine). Note that OpenEV uses gtk 1.2.x and pygtk 0.6.x, not gtk 2.x and pygtk 1.99.x.
2. Optionally, create a new directory to install the libraries in. You could install directly to your system directories, but new versions of gtk/Mesa in particular might not mesh with other applications, so a new directory is safest.
3. Create a "build_setup.csh" setup file to set your paths to point to the new installation directory first. This is important for ensuring that the correct libraries are found for those packages that depend on others (eg. pygtk). The following example assumes that the newly-built libraries have been installed in /data/local_installations.:

       # setup for openev/gdal, other builds

       setenv PATH "/data/local_installations/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/bin:/opt/bin:/usr/X11R6/bin:/usr/X11R6/bin"
       setenv PYTHONHOME "/data/local_installations"
       setenv LD_LIBRARY_PATH "/data/local_installations/lib"

   On solaris and irix, the standard directories will be different, and you may have to add other paths to your LD_LIBRARY_PATH (after the new directory path). Source this setup script before doing any building.
4. On irix, you may also have to set the environment variable CPP to be "gcc -E" if the default preprocessor is a Kernaghan & Ritchie one (this might be the case if configure complains about the presence of elif's in headers).
5. On solaris, if the build stops with messages about "Relocation errors", you might have to add "-fPIC" to the C and C++ compile options in the Makefile.
6. On irix or solaris, if you get messages about "Undefined symbols", make sure that all the necessary headers are in the include path in the Makefile, and that the most up-to-date header is the one being used by the Makefile (directories with the latest builds should be first in the include list).
7. You may also have to play with the CC, CXX/CPP, and LD_SHARED variables in the Makefile if OpenEV is to work with applications built with a specific version of C/C++ compilers.
8. Configure and build and install glib:

       ./configure  --prefix=/data/local_installations
       make
       make install

9. Configure and build and install gtk:

       ./configure  --prefix=/data/local_installations --with-glib-prefix=/data/local_installations
       make
       make install

10. Configure and build and install Mesa

         ./configure  --prefix=/data/local_installations
        make
        make install

11. Configure and build and install gtkglarea

         ./configure  --prefix=/data/local_installations --with-gtk-prefix=/data/local_installations --with-GL-prefix=/data/local_installations --with-lib-GL
        make
        make install

12. Configure and build Python, (this configuration is without threads).

         ./configure  --with-threads=no  --prefix=/data/local_installations
        make
        make install

13. Install the python extensions:

        python setup.py install

14. Download and install Numeric python.

        python setup.py install

15. Configure and make and install pygtk:

         ./configure  --prefix=/data/local_installations --with-gtk-prefix=/data/local_installations --with-gl-prefix=/data/local_installations --with-gtkgl-prefix=/data/local_installations --disable-imlibtest --disable-gdk-pixbuftest --disable-thread
        make
        make install

16. Configure and make and install gtk+extra:

         ./configure  --prefix=/data/local_installations --with-gtk-prefix=/data/local_installations
        make
        make install

17. Install python-gtkextra:

        python setup.py install
        cd /data/local_installations/lib/python?.?/site-packages
        mv gtkextra pygtkextra

    The last move avoids namespace conflicts with OpenEV's GtkExtra on Windows.
18. Configure and make and install proj:

        ./configure  --prefix=/data/local_installations
        make
        make install

19. Check out and build GDAL:

        setenv CVSROOT :pserver:anonymous@cvs.remotesensing.org:/cvsroot
        cvs login
        password: anonymous
        cvs checkout gdal
        cd gdal
        ./configure --with-libz=internal --with-png=internal --with-libtiff=internal --with-geotiff=internal
        make

    The options included here force gdal to compile with internal code rather than using other libraries for png/libz/libtiff/geotiff (in case end users do not have these libraries installed).
20. Check out and build OpenEV:

        cvs -d:pserver:anonymous@cvs.OpenEV.sourceforge.net:/cvsroot/openev login
        password:
        cvs -z3 -d:pserver:anonymous@cvs.OpenEV.sourceforge.net:/cvsroot/openev co openev
        ./configure  --with-gtk-prefix=/data/local_installations --with-gl-prefix=/data/local_installations --with-gtkgl-prefix=/data/local_installations --prefix=/data/local_installations --with-ogr
        make

    You may have to adjust the makefiles (Makefile and pymod/Makefile) to find the necessary headers on solaris/irix (configure doesn't always work properly). In particular, "-I/data/local_installations/include" may need to be added to Makefile and pymod/Makefile depending on where gtk/glib installed the headers.
21. Creating a distribution: There is a "mkdist" script in OpenEV's "delivery" directory that will copy the necessary files into two directories under "delivery"- "common", and "(Platform)", where (Platform) is either Linux, IRIX64, or SunOS. You will have to edit mkdist to find the libraries properly on your machine before running it, and may have to change the version numbers. Prior to running mkdist, you should make sure that none of your local files are in the openev directories (especially pymod), as they will be copied to the distribution. It is best to build a release from clean openev/gdal builds. After this, you will need to set the permissions on the files properly, eg.:

        #!/bin/sh

        # Sets file permissions in deliverable.

        openev_DIR=`pwd`
        platform_NAME=`uname -s`

        case "${platform_NAME}" in
            "Linux")  plat_DIR="${openev_DIR}/Linux";;
            "SunOS")  plat_DIR="${openev_DIR}/SunOS";;
            "IRIX64") plat_DIR="${openev_DIR}/IRIX64";;
            *) echo "Unknown Platform! Exiting..."; exit 1;;
        esac

        common_DIR="${openev_DIR}/common"

        cd "${plat_DIR}"
        find . -type f -exec chmod a+r {} \;
        find . -type d -exec chmod 755 {} \;
        find . -name "*.so*" -exec chmod 755 {} \;
        find . -name "openev.py" -exec chmod 755 {} \;
        find . -name "openev" -exec chmod 755 {} \;
        find . -name "python" -exec chmod 755 {} \;
        find . -name "gdaladdo" -exec chmod 755 {} \;
        find . -name "gdalinfo" -exec chmod 755 {} \;
        find . -name "gdal_translate" -exec chmod 755 {} \;
        find . -name "gvtest" -exec chmod 755 {} \;

        cd "${common_DIR}"
        find . -type f -exec chmod a+r {} \;
        find . -type d -exec chmod 755 {} \;

    After running mkdist, you must also be sure to create links in the lib directory to match those in the installation you copied from, and to change the ownership and group of both common and (Platform) recursively to "root". The common and (Platform) directories can then be tarred up for distribution.

### Windows

1. The following steps should be done in a DOS command shell. This description is for compiling with Microsoft Visual C++ version 6.0:
2. Download python source and follow the build instructions for windows.
3. Download and Mesa and follow the build instructions for windows (the OpenGL headers in MSVC++ may be too old- need at least OpenGL 1.1 for raster symbols to work in openev).
4. Check out pkgsrc from sourceforge:

       setenv CVSROOT :pserver:anonymous@cvs.OpenEV.sourceforge.net:/cvsroot/openev
       cvs checkout pkgsrc

   This contains versions of glib, gtk, etc. that have been slightly modified to compile and work properly on windows.
5. Edit pkgsrc's nmake.opt to point to the correct directories on your machine.
6. Find Microsoft Visual C++ (MSVC++)'s VCVARS32.BAT file and run it (this sets up the environment variables that MSVC++ needs).
7. nmake /f makefile.vc
8. Check out gdal, update the directory locations in nmake.opt for your machine.
9. nmake /f makefile.vc (at the top level of gdal)
10. Check out openev parallel to gdal and pkgsrc
11. nmake /f makefile.vc

Note that sometimes windows makefiles get messed up (something to do with linefeeds). If you get a cryptic error, open the file in MSVC++, accept its changes if it beeps at you, delete extra lines that shouldn't be there, and save. The windows makefiles are also not always updated properly. You may have to add/remove things based on the linux/unix versions if the problem isn't the linefeeds.

## Maintenance Issues

- Updating- Often people work with different versions of proj, GDAL, and even python/gtk. If you see an error message that mentions something beginning with "pj", eg. "pj_get_defs", you may need to update your proj library.
- New modules- Before using new python modules (or other open source software) found on the web, check to ensure that their licenses are LGPL-compliant (Library or Lesser GNU Public License).

Developer Course Outline
OpenEV Help