[GRASS-SVN] r36785 - in grass/branches/releasebranch_6_4/gui/wxpython: . nviz vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 18 17:51:11 EDT 2009


Author: martinl
Date: 2009-04-18 17:51:11 -0400 (Sat, 18 Apr 2009)
New Revision: 36785

Added:
   grass/branches/releasebranch_6_4/gui/wxpython/build_ext.py
Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/nviz/Makefile
   grass/branches/releasebranch_6_4/gui/wxpython/nviz/setup.py
   grass/branches/releasebranch_6_4/gui/wxpython/vdigit/Makefile
   grass/branches/releasebranch_6_4/gui/wxpython/vdigit/setup.py
Log:
Build wxGUI Python extension using distutils
     (merge from trunk, r36782)


Copied: grass/branches/releasebranch_6_4/gui/wxpython/build_ext.py (from rev 36784, grass/branches/develbranch_6/gui/wxpython/build_ext.py)
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/build_ext.py	                        (rev 0)
+++ grass/branches/releasebranch_6_4/gui/wxpython/build_ext.py	2009-04-18 21:51:11 UTC (rev 36785)
@@ -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)

Modified: grass/branches/releasebranch_6_4/gui/wxpython/nviz/Makefile
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/nviz/Makefile	2009-04-18 21:44:13 UTC (rev 36784)
+++ grass/branches/releasebranch_6_4/gui/wxpython/nviz/Makefile	2009-04-18 21:51:11 UTC (rev 36785)
@@ -2,28 +2,12 @@
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 
-SHLIB_LD = $(CXX) -shared
-
 LIB_NAME = grass6_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)
-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
-
 default:
 
 ifneq ($(USE_WXWIDGETS),)
@@ -41,24 +25,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/branches/releasebranch_6_4/gui/wxpython/nviz/setup.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/nviz/setup.py	2009-04-18 21:44:13 UTC (rev 36784)
+++ grass/branches/releasebranch_6_4/gui/wxpython/nviz/setup.py	2009-04-18 21:51:11 UTC (rev 36785)
@@ -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(
-			'_grass6_wxnviz',
-			sources=[
-				"grass6_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 = '_grass6_wxnviz',
+            sources=["change_view.cpp",
+                     "draw.cpp",
+                     "init.cpp",
+                     "lights.cpp",
+                     "load.cpp",
+                     "surface.cpp",
+                     "vector.cpp",
+                     "volume.cpp",
+                     "grass6_wxnviz.i"],
+            swig_opts = ['-c++',
+                         '-shadow'],
+            define_macros = macros,
+            include_dirs = inc_dirs,
+            library_dirs = lib_dirs,
+            libraries = libs,
+            )
 	]
-)
+    )
+

Modified: grass/branches/releasebranch_6_4/gui/wxpython/vdigit/Makefile
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/vdigit/Makefile	2009-04-18 21:44:13 UTC (rev 36784)
+++ grass/branches/releasebranch_6_4/gui/wxpython/vdigit/Makefile	2009-04-18 21:51:11 UTC (rev 36785)
@@ -2,28 +2,12 @@
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 
-SHLIB_LD = $(CXX) -shared
-
 LIB_NAME = grass6_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)
-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
-
 default:
 
 ifneq ($(USE_WXWIDGETS),)
@@ -39,18 +23,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/branches/releasebranch_6_4/gui/wxpython/vdigit/setup.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/vdigit/setup.py	2009-04-18 21:44:13 UTC (rev 36784)
+++ grass/branches/releasebranch_6_4/gui/wxpython/vdigit/setup.py	2009-04-18 21:51:11 UTC (rev 36785)
@@ -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(
-			'_grass6_wxvdigit',
-			sources=[
-				"grass6_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 = '_grass6_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",
+                       "grass6_wxvdigit.i"],
+            swig_opts = ['-c++',
+                         '-shadow'],
+            define_macros = macros,
+            include_dirs = inc_dirs,
+            library_dirs = lib_dirs,
+            libraries = libs,
+            )
 	]
-)
+    )



More information about the grass-commit mailing list