Porting
Prev | Chapter 4. Internals | Next

## Porting

There are three main files which contain platform specific information. The first is the configuration file used by the setup script. The following code illustrates how this file is selected

    name = sys.platform
    config_name = os.path.join('config', name + '.cfg')

    while len(name) and not os.path.exists(config_name):
        name = name[:-1]
        config_name = os.path.join('config', name + '.cfg')

The net effect of this method is to allow the names of configuration files to proceed from fine to coarse in granularity. For instance, suppose that the "linux-alpha" platform required a special configuration file but all other Linux platforms (linux, linux1, linux2, linux-i386, etc.) used the same configuration file. To cover both of these cases one would create two configuration files: `config/linux.cfg` and `config/linux-alpha.cfg`.

This configuration file controls various build options, such as include directories or lib directories. For example, here is a verbatim copy of this file for the "linux" platform:

    ; General config options
    ;
    ; Setting build_togl to zero will avoid trying to build Togl
    ;
    ; gl_platform is the name of the platform specific OpenGL module
    ; For X-windows this GLX, Windows has WGL, etc.
    ;
    ; include_dirs and library_dirs are a sys.pathsep separated list of
    ; additional directories for headers and libraries.  No quotes
    ; are needed
    [General]
    build_togl=1
    gl_platform=GLX
    include_dirs=/usr/include:/usr/local/include:/usr/X11/include
    library_dirs=/usr/lib:/usr/local/lib:/usr/X11/lib

    ; a sys.pathsep separated list of the libs needed when linking GL
    [GL]
    libs=GL:X11:Xext

    ; a sys.pathsep separated list of the libs needed when linking GLU
    ; the GL libraries are included automatically
    [GLU]
    libs=GLU

    ; a sys.pathsep separated list of the libs needed when linking GLUT
    ; the GL and GLU libraries are included automatically
    [GLUT]
    libs=glut:Xi:Xmu

    ; a comma separated list of the libs needed when linking Togl
    ; the GL and GLU libraries are included automatically
    [Togl]
    libs=Xmu:Xt:m

Most of the entries are explained by the embedded comments, but one is worth commenting on further. This is the "gl_platform" entry. This entry is used tell the setup script the name of the platform specific GL platform. This name is used in the `src/config.h` and the `src/interface_util/platform.c` files to include the right code for that platform. For instance in `src/config.h`

    #if defined(WGL_PLATFORM)

    #include <windows.h>

    /* Do extension definitions define the C prototype
       or just the enumerants? */
    #define EXT_DEFINES_PROTO 0

    /* A function which returns true if the current
       context is valid */
    #define CurrentContextIsValid() wglGetCurrentContext()

    /* Get a hash code (long) corresponding to the
       current context */
    #define GetCurrentContext() ((long)wglGetCurrentContext())

    /* Does the platform have a dynamic extension loading
       mechanism? */
    #define HAS_DYNAMIC_EXT 1

    #elif defined(AGL_PLATFORM)

    .
    .
    .

The last platform specific file is the `src/interface_util/platform.c` file. This file defines functions to retrieve platform specific extension addresses and extension strings. For more information see the source code.

Prev | Home | Next
Chapter 4. Internals | Up | Contributing