[GRASS-SVN] r36782 - in grass/trunk/gui/wxpython: . nviz vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 18 17:08:29 EDT 2009


Author: martinl
Date: 2009-04-18 17:08:29 -0400 (Sat, 18 Apr 2009)
New Revision: 36782

Added:
   grass/trunk/gui/wxpython/build_ext.py
Modified:
   grass/trunk/gui/wxpython/nviz/Makefile
   grass/trunk/gui/wxpython/nviz/setup.py
   grass/trunk/gui/wxpython/vdigit/Makefile
   grass/trunk/gui/wxpython/vdigit/setup.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
Build wxGUI Python extension using distutils


Added: grass/trunk/gui/wxpython/build_ext.py
===================================================================
--- grass/trunk/gui/wxpython/build_ext.py	                        (rev 0)
+++ grass/trunk/gui/wxpython/build_ext.py	2009-04-18 21:08:29 UTC (rev 36782)
@@ -0,0 +1,53 @@
+# Build wxGUI extensions (vdigit and nviz)
+
+import os
+import sys
+
+def __read_variables(file, dict={}):
+    """Read variables from file (e.g. Platform.make)
+    
+    @param file file descriptor
+    @param dict dictionary to store (variable, value)
+    """
+    for line in file.readlines():
+        if len(line) < 1:
+            continue # skip empty lines
+        if line[0] == '#':
+            continue # skip comments
+        try:
+            var, val = line.split('=', 1)
+        except ValueError:
+            continue
+        
+        dict[var.strip()] = val.strip()
+        
+def update_opts(flag, macros, inc_dirs, lib_dirs, libs):
+    """Update Extension options"""
+    global variables
+    line = variables[flag]
+    for val in line.split(' '):
+        key = val[:2]
+        if key == '-I': # includes
+            inc_dirs.append(val[2:])
+        elif key == '-D': # macros
+            if '=' in val[2:]:
+                macros.append(tuple(val[2:].split('=')))
+            else:
+                macros.append((val[2:], None))
+        elif key == '-L': # libs dir
+            lib_dirs.append(val[2:])
+        elif key == '-l':
+            libs.append(val[2:])
+
+try:
+    Platform_make = open(os.path.join('..', '..', '..',
+                                      'include', 'Make', 'Platform.make'))
+    Grass_make = open(os.path.join('..', '..', '..',
+                                   'include', 'Make', 'Grass.make'))
+except IOError, e:
+    print 'Unable to compile wxGUI vdigit extension.\n\n', e
+    sys.exit(1)
+
+variables = {}
+__read_variables(Platform_make, variables)
+__read_variables(Grass_make, variables)


Property changes on: grass/trunk/gui/wxpython/build_ext.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Modified: grass/trunk/gui/wxpython/nviz/Makefile
===================================================================
--- grass/trunk/gui/wxpython/nviz/Makefile	2009-04-18 12:36:33 UTC (rev 36781)
+++ grass/trunk/gui/wxpython/nviz/Makefile	2009-04-18 21:08:29 UTC (rev 36782)
@@ -2,30 +2,12 @@
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 
-SHLIB_LD = $(CXX) -shared
-
 LIB_NAME = grass7_wxnviz
-SOURCES := $(wildcard *.cpp) $(LIB_NAME)_wrap.cpp
-SHLIB_OBJS := $(patsubst %.cpp, $(OBJDIR)/%.o, $(SOURCES))
 
-EXTRA_CFLAGS = $(SHLIB_CFLAGS) $(GDALCFLAGS) $(PYTHONCFLAGS) $(WXWIDGETSCXXFLAGS) $(XCFLAGS) $(XMINC)
-EXTRA_LIBS = $(GISLIB) $(OGSFLIB) $(NVIZLIB) $(OPENGLLIB) $(OPENGLULIB)
-ifeq ($(findstring darwin,$(ARCH)),darwin)
-EXTRA_LIBS := -bundle -undefined dynamic_lookup $(EXTRA_LIBS)
-CXXFLAGS := $(subst -arch ppc64,,$(subst -arch x86_64,,$(CXXFLAGS)))
-LDFLAGS := $(subst -arch ppc64,,$(subst -arch x86_64,,$(LDFLAGS)))
-else
-EXTRA_LIBS := $(PYTHONLDFLAGS) $(WXWIDGETSLIB) $(EXTRA_LIBS)
-endif
+SHLIB = $(OBJDIR)/_$(LIB_NAME).so
 
-LOCAL_HEADERS = nviz.h
-
 ETCDIR = $(ETC)/wxpython
 
-SHLIB = $(OBJDIR)/_$(LIB_NAME).so
-
-EXTRA_CLEAN_FILES = $(SHLIB) $(LIB_NAME).i $(LIB_NAME).py $(LIB_NAME)_wrap.cpp
-
 ifneq ($(USE_WXWIDGETS),)
 ifneq ($(USE_PYTHON),)
 ifneq ($(strip $(CXX)),)
@@ -41,24 +23,18 @@
 	echo "/* auto-generated swig typedef file */" >> $(LIB_NAME).i
 	cat nviz.h >> $(LIB_NAME).i
 
-$(LIB_NAME).py $(LIB_NAME)_wrap.cpp: $(LIB_NAME).i
-	$(SWIG) -c++ -python -shadow -o $(LIB_NAME)_wrap.cpp $<
+$(LIB_NAME).py: $(SHLIB)
 
-$(SHLIB): $(SHLIB_OBJS)
-ifeq ($(findstring darwin,$(ARCH)),darwin)
-	$(CXX) -o $@ $(LDFLAGS) $^ $(EXTRA_LIBS)
-else
-	$(SHLIB_LD) -o $@ $(LDFLAGS) $^ $(EXTRA_LIBS)
-endif
+$(SHLIB): $(LIB_NAME).i
+	python setup.py build_ext --swig=$(SWIG) --build-lib=$(OBJDIR) --build-temp=$(OBJDIR)
 
-install_nviz:
-	$(MAKE) $(ETCDIR)/nviz/_$(LIB_NAME).so $(ETCDIR)/nviz/$(LIB_NAME).py
+.NOTPARALLEL: $(LIB_NAME).py $(LIB_NAME)_wrap.cpp
 
+install_nviz: $(ETCDIR)/nviz/_$(LIB_NAME).so $(ETCDIR)/nviz/$(LIB_NAME).py
+
 $(ETCDIR)/nviz/_$(LIB_NAME).so: $(SHLIB)
 	$(INSTALL) $< $@
 
 $(ETCDIR)/nviz/$(LIB_NAME).py: $(LIB_NAME).py
 	$(INSTALL_DATA) $< $@
 
-.PHONY: install_nviz
-

Modified: grass/trunk/gui/wxpython/nviz/setup.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/setup.py	2009-04-18 12:36:33 UTC (rev 36781)
+++ grass/trunk/gui/wxpython/nviz/setup.py	2009-04-18 21:08:29 UTC (rev 36782)
@@ -1,24 +1,56 @@
-# currently used only for osgeo4w
-# TODO: use instead of Makefile
+#!/usr/bin/env python
+ 
+# Setup script for wxGUI vdigit extension.
+
+import os
+import sys
+
+sys.path.append('..')
+from build_ext import variables
+from build_ext import update_opts
+
 from distutils.core import setup, Extension
 
+macros = [('PACKAGE', '"grasslibs"')]
+inc_dirs = [os.path.join(variables['GRASS_HOME'],
+                         'dist.' + variables['ARCH'],
+                         'include')]
+lib_dirs = [os.path.join(variables['GRASS_HOME'],
+                         'dist.' + variables['ARCH'],
+                         'lib')]
+
+
+libs = ['grass_gis',
+        'grass_nviz',
+        'grass_ogsf',
+        'grass_g3d']
+
+for flag in ('GDALCFLAGS',
+             'GDALLIBS',
+             'WXWIDGETSCXXFLAGS',
+             'WXWIDGETSLIB'):
+    update_opts(flag, macros, inc_dirs, lib_dirs, libs)
+
 setup(
-	ext_modules= [
-		Extension(
-			'_grass7_wxnviz',
-			sources=[
-				"grass7_wxnviz.i",
-				"change_view.cpp",
-				"draw.cpp",
-				"init.cpp",
-				"lights.cpp",
-				"load.cpp",
-				"surface.cpp",
-				"vector.cpp",
-				"volume.cpp",
-				],
-			swig_opts=['-c++','-shadow'],
-			libraries=['grass_gis','grass_nviz','grass_ogsf','grass_g3d']
-		)
+    ext_modules= [
+        Extension(
+            name = '_grass7_wxnviz',
+            sources=["change_view.cpp",
+                     "draw.cpp",
+                     "init.cpp",
+                     "lights.cpp",
+                     "load.cpp",
+                     "surface.cpp",
+                     "vector.cpp",
+                     "volume.cpp",
+                     "grass7_wxnviz.i"],
+            swig_opts = ['-c++',
+                         '-shadow'],
+            define_macros = macros,
+            include_dirs = inc_dirs,
+            library_dirs = lib_dirs,
+            libraries = libs,
+            )
 	]
-)
+    )
+

Modified: grass/trunk/gui/wxpython/vdigit/Makefile
===================================================================
--- grass/trunk/gui/wxpython/vdigit/Makefile	2009-04-18 12:36:33 UTC (rev 36781)
+++ grass/trunk/gui/wxpython/vdigit/Makefile	2009-04-18 21:08:29 UTC (rev 36782)
@@ -2,30 +2,12 @@
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 
-SHLIB_LD = $(CXX) -shared
-
 LIB_NAME = grass7_wxvdigit
-SOURCES := $(wildcard *.cpp) $(LIB_NAME)_wrap.cpp
-SHLIB_OBJS := $(patsubst %.cpp, $(OBJDIR)/%.o, $(SOURCES))
 
-EXTRA_CFLAGS = $(SHLIB_CFLAGS) $(GDALCFLAGS) $(PYTHONCFLAGS) $(WXWIDGETSCXXFLAGS)
-EXTRA_LIBS = $(VECTLIB) $(GISLIB) $(GDALLIBS) $(VEDITLIB)
-ifeq ($(findstring darwin,$(ARCH)),darwin)
-EXTRA_LIBS := -bundle -undefined dynamic_lookup $(EXTRA_LIBS)
-CXXFLAGS := $(subst -arch ppc64,,$(subst -arch x86_64,,$(CXXFLAGS)))
-LDFLAGS := $(subst -arch ppc64,,$(subst -arch x86_64,,$(LDFLAGS)))
-else
-EXTRA_LIBS := $(PYTHONLDFLAGS) $(WXWIDGETSLIB) $(EXTRA_LIBS)
-endif
+SHLIB = $(OBJDIR)/_$(LIB_NAME).so
 
-LOCAL_HEADERS = digit.h driver.h pseudodc.h
-
 ETCDIR = $(ETC)/wxpython
 
-SHLIB = $(OBJDIR)/_$(LIB_NAME).so
-
-EXTRA_CLEAN_FILES = $(SHLIB) $(LIB_NAME).i $(LIB_NAME).py $(LIB_NAME)_wrap.cpp
-
 ifneq ($(USE_WXWIDGETS),)
 ifneq ($(USE_PYTHON),)
 ifneq ($(strip $(CXX)),)
@@ -39,18 +21,13 @@
 	echo "/* auto-generated swig typedef file */" >> $(LIB_NAME).i
 	cat driver.h digit.h >> $(LIB_NAME).i
 
-$(LIB_NAME).py $(LIB_NAME)_wrap.cpp: $(LIB_NAME).i
-	$(SWIG) -c++ -python -shadow -o $(LIB_NAME)_wrap.cpp $<
+$(LIB_NAME).py: $(SHLIB)
 
+$(SHLIB): $(LIB_NAME).i
+	python setup.py build_ext --swig=$(SWIG) --build-lib=$(OBJDIR) --build-temp=$(OBJDIR)
+
 .NOTPARALLEL: $(LIB_NAME).py $(LIB_NAME)_wrap.cpp
 
-$(SHLIB): $(SHLIB_OBJS)
-ifeq ($(findstring darwin,$(ARCH)),darwin)
-	$(CXX) -o $@ $(LDFLAGS) $^ $(EXTRA_LIBS)
-else
-	$(SHLIB_LD) -o $@ $(LDFLAGS) $^ $(EXTRA_LIBS)
-endif
-
 install_vdigit: $(ETCDIR)/vdigit/_$(LIB_NAME).so $(ETCDIR)/vdigit/$(LIB_NAME).py
 
 $(ETCDIR)/vdigit/_$(LIB_NAME).so: $(SHLIB)

Modified: grass/trunk/gui/wxpython/vdigit/setup.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/setup.py	2009-04-18 12:36:33 UTC (rev 36781)
+++ grass/trunk/gui/wxpython/vdigit/setup.py	2009-04-18 21:08:29 UTC (rev 36782)
@@ -1,27 +1,57 @@
-# currently used only for osgeo4w
-# TODO: use instead of Makefile
+#!/usr/bin/env python
+ 
+# Setup script for wxGUI vdigit extension.
+
+import os
+import sys
+
+sys.path.append('..')
+from build_ext import variables
+from build_ext import update_opts
+
 from distutils.core import setup, Extension
 
+macros = [('PACKAGE', '"grasslibs"')]
+inc_dirs = [os.path.join(variables['GRASS_HOME'],
+                         'dist.' + variables['ARCH'],
+                         'include')]
+lib_dirs = [os.path.join(variables['GRASS_HOME'],
+                         'dist.' + variables['ARCH'],
+                         'lib')]
+libs = ['grass_dbmibase',
+        'grass_dbmiclient',
+        'grass_vect',
+        'grass_gis',
+        'grass_vedit']
+
+for flag in ('GDALCFLAGS',
+             'GDALLIBS',
+             'WXWIDGETSCXXFLAGS',
+             'WXWIDGETSLIB'):
+    update_opts(flag, macros, inc_dirs, lib_dirs, libs)
+
 setup(
-	ext_modules= [
-		Extension(
-			'_grass7_wxvdigit',
-			sources=[
-				"grass7_wxvdigit.i",
-				"cats.cpp",
-				"driver.cpp",
-				"driver_draw.cpp",
-				"driver_select.cpp",
-				"line.cpp",
-				"message.cpp",
-				"select.cpp",
-				"undo.cpp",
-				"vertex.cpp",
-				"pseudodc.cpp",
-				"digit.cpp"
-				],
-			swig_opts=['-c++','-shadow'],
-			libraries=['grass_dbmibase', 'grass_dbmiclient', 'grass_vect','grass_gis','grass_vedit','gdal_i', 'wxbase28u', 'wxmsw28u_core']
-		)
+    ext_modules= [
+        Extension(
+            name = '_grass7_wxvdigit',
+            sources = ["cats.cpp",
+                       "driver.cpp",
+                       "driver_draw.cpp",
+                       "driver_select.cpp",
+                       "line.cpp",
+                       "message.cpp",
+                       "select.cpp",
+                       "undo.cpp",
+                       "vertex.cpp",
+                       "pseudodc.cpp",
+                       "digit.cpp",
+                       "grass7_wxvdigit.i"],
+            swig_opts = ['-c++',
+                         '-shadow'],
+            define_macros = macros,
+            include_dirs = inc_dirs,
+            library_dirs = lib_dirs,
+            libraries = libs,
+            )
 	]
-)
+    )

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2009-04-18 12:36:33 UTC (rev 36781)
+++ grass/trunk/gui/wxpython/wxgui.py	2009-04-18 21:08:29 UTC (rev 36782)
@@ -539,7 +539,7 @@
         """Display 'About GRASS' dialog"""
         info = wx.AboutDialogInfo()
 
-        rev = "$Revision$"
+        rev = "$Revision: 36354 $"
         # name
         info.SetName("GRASS GIS")
         # version


Property changes on: grass/trunk/gui/wxpython/wxgui.py
___________________________________________________________________
Name: svn:keywords
   - Author Date Id Revision
   + Author Date Id



More information about the grass-commit mailing list