Selaa lähdekoodia

Create a separate module for each library
Add more libraries


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@35275 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 vuotta sitten
vanhempi
commit
e92b414f2a

+ 48 - 19
swig/python/Makefile

@@ -3,27 +3,51 @@ MODULE_TOPDIR = ../..
 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
 
+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 = $(LIB_NAME)_wrap.o _$(LIB_NAME).so $(LIB_NAME)_wrap.c $(LIB_NAME).pyc $(LIB_NAME).py
+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
+
+LIBFILES := $(patsubst %,$(DSTDIR)/_%.so,$(MODULES))
+PYFILES  := $(patsubst %,$(DSTDIR)/%.py,$(MODULES))
+PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES))
+
+default: $(LIBFILES) $(PYFILES) $(DSTDIR)/__init__.pyc numptr
 
-%_wrap.c: %.i my_typemaps.i renames.i
+%_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 $@ $<
+
+$(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
 
-_%.so: %_wrap.o
-	$(LD) $(LDFLAGS) $< -o $@
-	# build bytecode .pyc file; ignore undefined symbol error
-	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 @@ numptr:
 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

+ 8 - 0
swig/python/__init__.py

@@ -0,0 +1,8 @@
+import grass
+import math
+import imagery
+import vector
+import proj
+import stats
+import raster
+import display

+ 7 - 0
swig/python/common.i

@@ -0,0 +1,7 @@
+%{
+#include <stdio.h>
+#include <grass/gis.h>
+%}
+
+%include "my_typemaps.i"
+%include "renames.i"

+ 9 - 0
swig/python/display.i

@@ -0,0 +1,9 @@
+%module display
+
+%include "common.i"
+
+%{
+#include <grass/display.h>
+%}
+
+%include "grass/display.h"

+ 22 - 0
swig/python/grass.i

@@ -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)
+
+%}

+ 11 - 0
swig/python/imagery.i

@@ -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"

+ 9 - 0
swig/python/math.i

@@ -0,0 +1,9 @@
+%module math
+
+%include "common.i"
+
+%{
+#include <grass/gmath.h>
+%}
+
+%include "grass/gmath.h"

+ 9 - 0
swig/python/proj.i

@@ -0,0 +1,9 @@
+%module proj
+
+%include "common.i"
+
+%{
+#include <grass/gprojects.h>
+%}
+
+%include "grass/gprojects.h"

+ 0 - 39
swig/python/python_grass7.i

@@ -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)
-
-%}

+ 9 - 0
swig/python/raster.i

@@ -0,0 +1,9 @@
+%module raster
+
+%include "common.i"
+
+%{
+#include <grass/raster.h>
+%}
+
+%include "grass/raster.h"

+ 10 - 0
swig/python/stats.i

@@ -0,0 +1,10 @@
+%module stats
+
+%include "common.i"
+
+%{
+#undef c_sum
+#include <grass/stats.h>
+%}
+
+%include "grass/stats.h"

+ 12 - 0
swig/python/vector.i

@@ -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"