[GRASS-SVN] r35275 - grass/trunk/swig/python

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 7 14:29:30 EST 2009


Author: glynn
Date: 2009-01-07 14:29:30 -0500 (Wed, 07 Jan 2009)
New Revision: 35275

Added:
   grass/trunk/swig/python/__init__.py
   grass/trunk/swig/python/common.i
   grass/trunk/swig/python/display.i
   grass/trunk/swig/python/grass.i
   grass/trunk/swig/python/imagery.i
   grass/trunk/swig/python/math.i
   grass/trunk/swig/python/proj.i
   grass/trunk/swig/python/raster.i
   grass/trunk/swig/python/stats.i
   grass/trunk/swig/python/vector.i
Removed:
   grass/trunk/swig/python/python_grass7.i
Modified:
   grass/trunk/swig/python/Makefile
Log:
Create a separate module for each library
Add more libraries


Modified: grass/trunk/swig/python/Makefile
===================================================================
--- grass/trunk/swig/python/Makefile	2009-01-07 19:27:36 UTC (rev 35274)
+++ grass/trunk/swig/python/Makefile	2009-01-07 19:29:30 UTC (rev 35275)
@@ -3,28 +3,52 @@
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 include $(MODULE_TOPDIR)/include/Make/Doxygen.make
 
-LIB_NAME = python_grass7
-
 CFLAGS=-c -fpic -I. $(ARCH_INC) $(GDALCFLAGS) $(PYTHONCFLAGS)
-LDFLAGS=-shared -L$(ARCH_LIBDIR) $(GDALLIBS) $(PYTHONLDFLAGS) $(VECTLIB) $(IMAGERYLIB) $(GMATHLIB) $(GISLIB)
+LDFLAGS=-shared -L$(ARCH_LIBDIR) $(GDALLIBS) $(PYTHONLDFLAGS)
 
+MODULES = grass math imagery vector proj raster display stats
 
-EXTRA_CLEAN_FILES = $(LIB_NAME)_wrap.o _$(LIB_NAME).so $(LIB_NAME)_wrap.c $(LIB_NAME).pyc $(LIB_NAME).py
+vector_LIBS = $(VECTLIB)
+imagery_LIBS = $(IMAGERYLIB)
+grass_LIBS = $(GISLIB)
+math_LIBS = $(GMATHLIB)
+proj_LIBS = $(GPROJLIB)
+raster_LIBS = $(RASTERLIB)
+display_LIBS = $(DISPLAYLIB)
+stats_LIBS = $(STATSLIB)
+
+EXTRA_CLEAN_FILES := $(foreach M,$(MODULES),$(M)_wrap.o $(M)_wrap.c $(M).pyc $(M).py)
 CLEAN_SUBDIRS = NumPtr
 
-default: _$(LIB_NAME).so numptr
+DSTDIR = $(ARCH_DISTDIR)/etc/python/swig
 
-%_wrap.c: %.i my_typemaps.i renames.i
+LIBFILES := $(patsubst %,$(DSTDIR)/_%.so,$(MODULES))
+PYFILES  := $(patsubst %,$(DSTDIR)/%.py,$(MODULES))
+PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES))
+
+default: $(LIBFILES) $(PYFILES) $(DSTDIR)/__init__.pyc numptr
+
+%_wrap.c %.py: %.i my_typemaps.i renames.i common.i
 	$(SWIG) $(ARCH_INC) -python -shadow $<
 
-%_wrap.o: %_wrap.c
-	$(CC) $(CFLAGS) $(INCLUDE_DIRS) $<
+$(OBJDIR)/%_wrap.o: %_wrap.c
+	test -d $(OBJDIR) || $(MKDIR) -p $(OBJDIR)
+	$(CC) $(CFLAGS) $(INCLUDE_DIRS) -o $@ $<
 
-_%.so: %_wrap.o
-	$(LD) $(LDFLAGS) $< -o $@
-	# build bytecode .pyc file; ignore undefined symbol error
-	echo "import $*" | python; true
+$(DSTDIR)/_%.so: $(OBJDIR)/%_wrap.o
+	test -d $(DSTDIR) || $(MKDIR) -p $(DSTDIR)
+	$(SHLIB_LD) -o $@ $(LDFLAGS) $^ $($*_LIBS)
 
+$(DSTDIR)/%.py: %.py
+	test -d $(DSTDIR) || $(MKDIR) -p $(DSTDIR)
+	$(INSTALL_DATA) $< $@
+
+$(DSTDIR)/%.pyc: $(DSTDIR)/%.py $(DSTDIR)/_%.so
+	cd $(DSTDIR) && echo "import $*" | python; true
+
+$(DSTDIR)/__init__.pyc: $(DSTDIR)/__init__.py $(LIBFILES) $(PYCFILES)
+	cd $(DSTDIR) && echo "import __init__" | python; true
+
 numptr:
 	$(MAKE) -C NumPtr
 
@@ -34,10 +58,15 @@
 DOXNAME=
 DOXINPUT=grasspython.dox
 
-$(LIB_NAME)_wrap.c: $(ARCH_INCDIR)/gis.h
-$(LIB_NAME)_wrap.c: $(ARCH_INCDIR)/gisdefs.h
-$(LIB_NAME)_wrap.c: $(ARCH_INCDIR)/imagery.h
-$(LIB_NAME)_wrap.c: $(ARCH_INCDIR)/imagedefs.h
-$(LIB_NAME)_wrap.c: $(ARCH_INCDIR)/Vect.h
-$(LIB_NAME)_wrap.c: $(ARCH_INCDIR)/vect/dig_structs.h
-$(LIB_NAME)_wrap.c: $(ARCH_INCDIR)/vect/dig_defines.h
+display_wrap.c: $(ARCH_INCDIR)/display.h
+grass_wrap.c: $(ARCH_INCDIR)/gis.h
+grass_wrap.c: $(ARCH_INCDIR)/gisdefs.h
+imagery_wrap.c: $(ARCH_INCDIR)/imagedefs.h
+imagery_wrap.c: $(ARCH_INCDIR)/imagery.h
+math_wrap.c: $(ARCH_INCDIR)/gmath.h
+proj_wrap.c: $(ARCH_INCDIR)/gprojects.h
+raster_wrap.c: $(ARCH_INCDIR)/raster.h
+stats_wrap.c: $(ARCH_INCDIR)/stats.h
+vector_wrap.c: $(ARCH_INCDIR)/Vect.h
+vector_wrap.c: $(ARCH_INCDIR)/vect/dig_defines.h
+vector_wrap.c: $(ARCH_INCDIR)/vect/dig_structs.h

Added: grass/trunk/swig/python/__init__.py
===================================================================
--- grass/trunk/swig/python/__init__.py	                        (rev 0)
+++ grass/trunk/swig/python/__init__.py	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,8 @@
+import grass
+import math
+import imagery
+import vector
+import proj
+import stats
+import raster
+import display

Added: grass/trunk/swig/python/common.i
===================================================================
--- grass/trunk/swig/python/common.i	                        (rev 0)
+++ grass/trunk/swig/python/common.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,7 @@
+%{
+#include <stdio.h>
+#include <grass/gis.h>
+%}
+
+%include "my_typemaps.i"
+%include "renames.i"

Added: grass/trunk/swig/python/display.i
===================================================================
--- grass/trunk/swig/python/display.i	                        (rev 0)
+++ grass/trunk/swig/python/display.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,9 @@
+%module display
+
+%include "common.i"
+
+%{
+#include <grass/display.h>
+%}
+
+%include "grass/display.h"

Added: grass/trunk/swig/python/grass.i
===================================================================
--- grass/trunk/swig/python/grass.i	                        (rev 0)
+++ grass/trunk/swig/python/grass.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,22 @@
+%module grass
+
+%include "common.i"
+
+%include "carrays.i"
+%array_functions(int, intArray);
+%array_functions(float, floatArray);
+%array_functions(double, doubleArray);
+
+%include "cpointer.i"
+%pointer_functions(int, intp);
+%pointer_functions(float, floatp);
+%pointer_functions(double, doublep);
+
+%include "grass/gis.h"
+%include "grass/gisdefs.h"
+
+%pythoncode %{
+def G_gisinit(pgm):
+    G__gisinit(GIS_H_VERSION, pgm)
+
+%}

Added: grass/trunk/swig/python/imagery.i
===================================================================
--- grass/trunk/swig/python/imagery.i	                        (rev 0)
+++ grass/trunk/swig/python/imagery.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,11 @@
+%module imagery
+
+%include "common.i"
+
+%{
+#include <grass/imagery.h>
+#include <grass/imagedefs.h>
+%}
+
+%include "grass/imagery.h"
+%include "grass/imagedefs.h"

Added: grass/trunk/swig/python/math.i
===================================================================
--- grass/trunk/swig/python/math.i	                        (rev 0)
+++ grass/trunk/swig/python/math.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,9 @@
+%module math
+
+%include "common.i"
+
+%{
+#include <grass/gmath.h>
+%}
+
+%include "grass/gmath.h"

Added: grass/trunk/swig/python/proj.i
===================================================================
--- grass/trunk/swig/python/proj.i	                        (rev 0)
+++ grass/trunk/swig/python/proj.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,9 @@
+%module proj
+
+%include "common.i"
+
+%{
+#include <grass/gprojects.h>
+%}
+
+%include "grass/gprojects.h"

Deleted: grass/trunk/swig/python/python_grass7.i
===================================================================
--- grass/trunk/swig/python/python_grass7.i	2009-01-07 19:27:36 UTC (rev 35274)
+++ grass/trunk/swig/python/python_grass7.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -1,39 +0,0 @@
-//File : python_grass7.i
-
-%include "carrays.i"
-%array_functions(int, intArray);
-%array_functions(float, floatArray);
-%array_functions(double, doubleArray);
-
-%include "cpointer.i"
-%pointer_functions(int, intp);
-%pointer_functions(float, floatp);
-%pointer_functions(double, doublep);
-
-%module python_grass7
-%{
-#include <stdio.h>
-#include <stdarg.h>
-#include <grass/gis.h>
-#include <grass/gisdefs.h>
-#include <grass/imagery.h>
-#include <grass/imagedefs.h>
-#include <grass/Vect.h>
-#include <grass/vect/dig_structs.h>
-%}
-
-%include "my_typemaps.i"
-%include "renames.i"
-%include "grass/gis.h"
-%include "grass/gisdefs.h"
-%include "grass/imagery.h"
-%include "grass/imagedefs.h"
-%include "grass/Vect.h"
-%include "grass/vect/dig_structs.h"
-%include "grass/vect/dig_defines.h"
-
-%pythoncode %{
-def G_gisinit(pgm):
-    G__gisinit(GIS_H_VERSION, pgm)
-
-%}

Added: grass/trunk/swig/python/raster.i
===================================================================
--- grass/trunk/swig/python/raster.i	                        (rev 0)
+++ grass/trunk/swig/python/raster.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,9 @@
+%module raster
+
+%include "common.i"
+
+%{
+#include <grass/raster.h>
+%}
+
+%include "grass/raster.h"

Added: grass/trunk/swig/python/stats.i
===================================================================
--- grass/trunk/swig/python/stats.i	                        (rev 0)
+++ grass/trunk/swig/python/stats.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,10 @@
+%module stats
+
+%include "common.i"
+
+%{
+#undef c_sum
+#include <grass/stats.h>
+%}
+
+%include "grass/stats.h"

Added: grass/trunk/swig/python/vector.i
===================================================================
--- grass/trunk/swig/python/vector.i	                        (rev 0)
+++ grass/trunk/swig/python/vector.i	2009-01-07 19:29:30 UTC (rev 35275)
@@ -0,0 +1,12 @@
+%module vector
+
+%include "common.i"
+
+%{
+#include <grass/Vect.h>
+#include <grass/vect/dig_structs.h>
+%}
+
+%include "grass/Vect.h"
+%include "grass/vect/dig_structs.h"
+%include "grass/vect/dig_defines.h"



More information about the grass-commit mailing list