Hey guys,I worked out a setup.py script to build the display driver. This makes it easier to configure the installation of python and wxpython. I pulled bits from the MapServer and GDAL Python setup.py scripts.
- no python version needed from configure for the makefile - doesn't hardwire the compile/link flags or grass libs- source compilation and linking is handled externally by python, only the swig step must be handled by the GRASS makefile
A couple things to work out:- the OSX wx-config script is buried in a non-standard location (lib/ wxPython-unicode-[version]/bin). For now, add that to your path before building the driver. Eventually, it needs to be configured with something like a --with-wxpython= option.
- installation - distutils builds in a subfolder, "build", with platform subfolders from that. The distutils install option knows where to find this, but that installs in the python site-packages folder. If we want to keep the driver within the GRASS installation, the makefile needs to figure out the platform folder to find it. Or there may be an option to setup.py to do this - I've only fiddled with distutils and don't know all its capabilities.
- it's currently setup for grass_src/somefolder/gui/display_driver - that is, 3 levels deep. (this is for the MODULE_TOPDIR in the makefile and a couple items in setup.py) This should work with grass_src/swig/python/display_driver, as you seem to have it Martin. Or something like grass_src/gui/wx/display_driver.
Here are the files:
Makefile
Description: Binary data
(note: don't need makefile.in)
#!/usr/bin/env python
#
# setup.py file for wxpython display driver
#
import sys
from distutils.core import setup, Extension
from distutils import sysconfig
from distutils.sysconfig import parse_makefile,expand_makefile_vars
import os.path
import string
# Function needed to make unique lists.
def unique(list):
dict = {}
for item in list:
dict[item] = ''
return dict.keys()
# check for wxpython and get inc/lib
try:
import wx
lib_opts = string.split(os.popen('wx-config --libs').read())
cxx_opts = string.split(os.popen('wx-config --cxxflags').read())
except ImportError, e:
raise ImportError, '%s. %s' % (e, "wxPython missing.")
# Should be created by the GRASS build process.
platformmake = "../../../include/Make/Platform.make"
grassmake = "../../../include/Make/Grass.make"
# Get needed GRASS make vars
try:
pdict = parse_makefile(platformmake)
gdict = parse_makefile(grassmake)
except IOError, e:
raise IOError, '%s. %s' % (e, "It appears GRASS has not been built yet.")
# vars expanded when parsed? merging dicts doesn't work for ARCH_LIBPATH
# so manually construct it
ghome = pdict[expand_makefile_vars("GRASS_HOME",pdict)]
garch = pdict[expand_makefile_vars("ARCH",pdict)]
gdalinc = pdict[expand_makefile_vars("GDALCFLAGS",pdict)]
cxx_opts += [ gdalinc ]
glibpath = [ ghome + "/dist." + garch + "/lib" ]
gincpath = [ ghome + "/dist." + garch + "/include" ]
vlib = string.split(gdict[expand_makefile_vars("VECTLIB",gdict)])
vlib = unique(vlib)
lib_opts += vlib
gversion = gdict[expand_makefile_vars("GRASS_VERSION_NUMBER",gdict)]
# mapserver trick for splitting out options and dropping flags
lib_dirs = [x[2:] for x in lib_opts if x[:2] == "-L"] + glibpath
inc_dirs = [x[2:] for x in cxx_opts if x[:2] == "-I"] + gincpath
macros = []
libs = []
extras = []
ex_next = False
for x in lib_opts:
if ex_next:
extras.append(x)
ex_next = False
elif x[:2] == '-l':
libs.append( x[2:] )
elif x[-4:] == '.lib' or x[-4:] == '.LIB':
dir, lib = os.path.split(x)
libs.append( lib[:-4] )
if len(dir) > 0:
lib_dirs.append( dir )
elif x[-2:] == '.a':
extras.append(x)
elif x[:10] == '-framework':
extras.append(x)
ex_next = True
elif x[:2] == '-F':
extras.append(x)
for x in cxx_opts:
if x[:2] == '-D':
x1 = x[2:].split('=')
if len(x1) == 1:
macros.append((x1[0],''))
else:
macros.append((x1[0],x1[1]))
# Here is the distutils setup function that does all the magic.
setup(name = "grass6_wxdriver",
version = gversion,
description = "wxPython GRASS display driver",
url = "http://grass.itc.it/",
ext_modules = [Extension("grass6_wxdriver",
["grass6_wxdriver_wrap.cxx","driver.cc","pseudodc.cpp"],
include_dirs = inc_dirs,
library_dirs = lib_dirs,
libraries = libs,
define_macros = macros,
extra_link_args = extras,
)
],
py_modules = ["grass6_wxdriver"]
)
----- William Kyngesburye <kyngchaos*at*kyngchaos*dot*com> http://www.kyngchaos.com/"Oh, look, I seem to have fallen down a deep, dark hole. Now what does that remind me of? Ah, yes - life."
- Marvin
_______________________________________________ grassgui mailing list [email protected] http://grass.itc.it/mailman/listinfo/grassgui
