Jelajahi Sumber

Replace SWIG with ctypesgen for Python bindings

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42262 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 15 tahun lalu
induk
melakukan
1fd2f4de5c
5 mengubah file dengan 110 tambahan dan 1 penghapusan
  1. 6 0
      include/gisdefs.h
  2. 3 0
      lib/python/Makefile
  3. 84 0
      lib/python/ctypes/Makefile
  4. 16 0
      lib/python/ctypes/__init__.py
  5. 1 1
      swig/Makefile

+ 6 - 0
include/gisdefs.h

@@ -64,9 +64,15 @@ void G_free(void *);
 void *G_incr_void_ptr(const void *, size_t);
 #endif
 
+#ifndef CTYPESGEN
 #define G_malloc(n)     G__malloc(__FILE__, __LINE__, (n))
 #define G_calloc(m, n)  G__calloc(__FILE__, __LINE__, (m), (n))
 #define G_realloc(p, n) G__realloc(__FILE__, __LINE__, (p), (n))
+#else
+#define G_malloc(n)     G__malloc("<ctypesgen>", 0, (n))
+#define G_calloc(m, n)  G__calloc("<ctypesgen>", 0, (m), (n))
+#define G_realloc(p, n) G__realloc("<ctypesgen>", 0, (p), (n))
+#endif
 
 /* area.c */
 int G_begin_cell_area_calculations(void);

+ 3 - 0
lib/python/Makefile

@@ -13,7 +13,10 @@ MODULES = core db raster vector array
 PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
 PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
 
+CLEAN_SUBDIRS = ctypes
+
 default: $(PYFILES) $(PYCFILES) $(GDIR)/__init__.py $(GDIR)/__init__.pyc
+	$(MAKE) -C ctypes
 
 $(PYDIR):
 	$(MKDIR) $@

+ 84 - 0
lib/python/ctypes/Makefile

@@ -0,0 +1,84 @@
+MODULE_TOPDIR = ../../..
+
+PACKAGE = "grasslibs"
+
+include $(MODULE_TOPDIR)/include/Make/Other.make
+include $(MODULE_TOPDIR)/include/Make/Doxygen.make
+
+# doxygen:
+DOXNAME=
+DOXINPUT=grasspython.dox
+
+MODULES = date grass raster gmath proj imagery vector display stats \
+	dbmi g3d arraystats cluster trans vedit
+
+date_LIBS       = $(DATETIMELIB)
+grass_LIBS      = $(GISLIB)
+raster_LIBS     = $(RASTERLIB)
+gmath_LIBS      = $(GMATHLIB)
+proj_LIBS       = $(GPROJLIB)
+imagery_LIBS    = $(IMAGERYLIB)
+vector_LIBS     = $(VECTLIB)
+display_LIBS    = $(DISPLAYLIB)
+stats_LIBS      = $(STATSLIB)
+dbmi_LIBS       = $(DBMILIB)
+g3d_LIBS        = $(G3DLIB)
+arraystats_LIBS = $(ARRAYSTATSLIB)
+cluster_LIBS    = $(CLUSTERLIB)
+trans_LIBS      = $(TRANSLIB)
+vedit_LIBS      = $(VEDITLIB)
+
+date_INC        = datetime.h P_datetime.h
+grass_INC       = gis.h gisdefs.h
+raster_INC      = raster.h rasterdefs.h
+gmath_INC       = gmath.h
+proj_INC        = gprojects.h
+imagery_INC     = imagery.h imagedefs.h
+vector_INC      = vector.h vect/dig_structs.h vect/dig_defines.h
+display_INC     = display.h
+stats_INC       = stats.h
+dbmi_INC        = dbmi.h
+g3d_INC         = G3d.h
+arraystats_INC  = arraystats.h
+cluster_INC     = cluster.h
+trans_INC       = transform.h
+vedit_INC       = vedit.h
+
+CTYPESGEN = ctypesgen.py
+CTYPESFLAGS = $(INC) $(LIBPATH)
+EXTRA_CLEAN_FILES := $(foreach M,$(MODULES),$(M).pyc $(M).py)
+
+ifneq ($(MINGW),)
+EXTRA_LIBS = $(INTLLIB)
+endif
+
+include $(MODULE_TOPDIR)/include/Make/Python.make
+
+PYDIR = $(ETC)/python
+GDIR = $(PYDIR)/grass
+DSTDIR = $(GDIR)/lib
+
+PYFILES  := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
+PYCFILES  := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
+LPYFILES := $(patsubst %,%.py,$(MODULES))
+
+default:
+	$(MAKE) $(DSTDIR)
+	$(MAKE) $(LPYFILES) $(PYFILES) $(PYCFILES)
+
+$(DSTDIR)/%.py: %.py | $(DSTDIR)
+	$(INSTALL_DATA) $< $@
+
+%.py: $(%_INC) $(%_LIBS)
+	$(CTYPESGEN) $(CTYPESFLAGS) $($*_LIBS) $(EXTRA_LIBS) $(patsubst %.h,$(ARCH_INCDIR)/%.h,$($*_INC)) -o $@
+
+$(PYDIR):
+	$(MKDIR) $@
+
+$(GDIR): | $(PYDIR)
+	$(MKDIR) $@
+
+$(DSTDIR): | $(GDIR)
+	$(MKDIR) $@
+
+.SECONDARY: $(patsubst %,%.py,$(MODULES))

+ 16 - 0
lib/python/ctypes/__init__.py

@@ -0,0 +1,16 @@
+import date
+import grass
+import raster
+import gmath
+import proj
+import imagery
+import vector
+import display
+import stats
+import dbmi
+import g3d
+import arraystats
+import cluster
+import trans
+import vedit
+

+ 1 - 1
swig/Makefile

@@ -5,7 +5,7 @@ include $(MODULE_TOPDIR)/include/Make/Vars.make
 #compile if PYTHON present:
 ifneq ($(USE_PYTHON),)
 ifneq ($(strip $(CXX)),)
-    SUBDIRS += python
+#    SUBDIRS += python
 endif
 endif