1 ################################################################################ 36 ################################################################################ 40 ifeq ($(strip $(RNMAKE_SWIG_ENABLED)),y)
42 # Simplified Wrapper and Interface Generator command 45 SWIG_BASES = $(basename $(SWIG_FILES))
46 SWIG_FILES_C = $(addsuffix _wrap.c,$(SWIG_BASES))
47 SWIG_FILES_O = $(addprefix $(OBJDIR)/,$(subst .c,.o,$(SWIG_FILES_C)))
48 SWIG_FILES_PY = $(addprefix $(SWIG_EXTMOD_DIR)/,$(addsuffix .py,$(SWIG_BASES)))
49 SWIG_EXTMODS = $(addprefix $(SWIG_EXTMOD_DIR)/_,\
50 $(addsuffix $(SHLIB_SUFFIX),$(SWIG_BASES)))
52 # Get python version stripped of revision number.
53 # Examples outputs from python --version:
56 PYTHON_VER = $(shell python --version 2>&1 | sed -e
's/Python //' -e
's/\.[0-9]*[\+]*$$//' )
58 ifeq
"$(RNMAKE_ARCH)" "cygwin" 59 SWIG_PYLIB = -lpython$(PYTHON_VER).dll
61 SWIG_PYLIB = -lpython$(PYTHON_VER)
64 ifndef "$(SWIG_INCLUDES)"
65 SWIG_INCLUDES = -I/usr/include/python$(PYTHON_VER)
69 SWIG_LIBS = $(SWIG_EXTMOD_LIBS) $(SWIG_PYLIB)
71 SWIG_DONE = $(RNMAKE_ARCH).done
73 # C and link loader flags 74 CFLAGS := $(EXTRA_CFLAGS) $(RNMAKE_PKG_CFLAGS) $(SWIG_CFLAGS)
75 LDFLAGS := $(EXTRA_LDFLAGS) $(RNMAKE_PKG_LDFLAGS) $(SWIG_LDFLAGS)
80 # Target: swig-all (default) 82 swig-all: echo-swig-all swig-pre swig-mods
83 @$(TOUCH) $(SWIG_DONE)
87 $(call printEchoTgtGoalDesc,Creating python wrappers from C/C++ source)
90 # If targets were made
for another architecture, then clean up so that targets
91 # will be remade
for the target architecture. The file done.<arch> determines
92 # the last made target architecture.
96 @
if [ ! -f $(SWIG_DONE) ]; \
100 printf
"Cleaning previous target: $(basename $(wildcard *.done)).\n"; \
104 $(RM) $(SWIG_FILES_C); \
105 $(RM) $(SWIG_FILES_PY); \
106 $(RM) $(SWIG_EXTMODS); \
110 # Make all swig modules 111 swig-mods: $(SWIG_EXTMODS)
115 $(RM) $(SWIG_FILES_C)
116 $(RM) $(SWIG_FILES_PY)
117 $(RM) $(SWIG_EXTMODS)
121 # Make determines dependency sequence only for the first file (*.i) and the end 122 # file. Itermediates are not factored in. But rnmake supports cross-compiling, 123 # so the <name>.<arch>.done file is used as an artificial end file to force 126 %.$(RNMAKE_ARCH).done: $(SWIG_EXTMOD_DIR)/_%$(SHLIB_SUFFIX)
130 # Swig Architecture-Specific Shared Library Rule: 131 $(SWIG_EXTMOD_DIR)/_%$(SHLIB_SUFFIX) : $(OBJDIR)/%_wrap.o
133 @printf
"$(color_tgt_file) $(<)$(color_end)\n" 134 $(SHLIB_LD) $(LDFLAGS) $(LD_LIBPATHS) $(<) $(SWIG_LIBS) -o $(@)
136 # Swig C Rule: <name>.c -> $(OBJDIR)/<name>.o
140 @printf
"$(color_tgt_file) $(<)$(color_end)\n" 141 $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $(SWIG_INCLUDES) -o $(@) -c $(<)
143 # Swig I Rule: <name>.i -> <name>_wrap.c, <outdir>/<name>.py
147 @printf
"$(color_tgt_file) $(<)$(color_end)\n" 148 $(SWIG) -python $(INCLUDES) $(SWIG_INCLUDES) -v -outdir $(SWIG_EXTMOD_DIR) \
151 # don't autodelete intermediate files 152 .SECONDARY: $(SWIG_FILES_C) $(SWIG_FILES_O) $(SWIG_EXTMODS)
157 @printf
"swig not enabled - ignoring\n"