ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/main/config/python_template.tmpl
Revision: 1.9
Committed: Tue Sep 12 11:55:08 2006 UTC (18 years, 8 months ago) by sashby
Branch: MAIN
CVS Tags: V1_0_3-p4, V1_0_3-p3, V1_0_3-p2, before110xmlBRmerge, V1_0_3-p1, V1_0_3
Changes since 1.8: +1 -1 lines
Log Message:
Updates to example templates

File Contents

# User Rev Content
1 sashby 1.2 [%# -*-makefile-*-
2     #____________________________________________________________________
3     # Inserted from file: python_template.tmpl
4     #____________________________________________________________________
5     #
6     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
7     # Update: 2004-05-06 17:33:25+0200
8 sashby 1.9 # Revision: $Id: python_template.tmpl,v 1.8.2.1 2006/09/04 15:58:05 sashby Exp $
9 sashby 1.2 #
10     # Copyright: 2004 (C) Shaun Ashby
11     #
12     #--------------------------------------------------------------------
13     %]
14     [% USE pymodule = PluginCore -%]
15     [% variables = pymodule.variables() -%]
16     [% FOREACH variable IN variables -%]
17     [% variable.key %]:=[% variable.value %]
18     [% END %]
19     # Dump out any data from MAKEFILE tags:
20     [% pymodule.data("MAKEFILE") %]
21     # Compiler flags for this build env. Collect all the flags that are defined. Also collect
22     # from highest level (global defs are made in config/BuildFile so any tools <use>d here
23     # will have their flags propagated everywhere):
24     # Firstly, remove -ansi and -pedantic flags which seem to make Boost unhappy:
25     [% safepath %]_CXXFLAGS := $(filter-out -pedantic-errors -ansi,$(CXXFLAGS)) [% pymodule.flags("CXXFLAGS") %]
26     [% safepath %]_CCFLAGS := $(CCFLAGS) [% pymodule.flags("CCFLAGS") %]
27     [% safepath %]_FFLAGS := $(FFLAGS) [% pymodule.flags("FFLAGS") %]
28     [% safepath %]_CPPDEFINES := $(CPPDEFINES) [% pymodule.flags("CPPDEFINES") %]
29     [% safepath %]_INCLUDE:= $(INCLUDE) [% pymodule.data("INCLUDE") %]
30     [% safepath %]_LIB:=[% pymodule.data("LIB") %]
31     [% safepath %]_LIBDIR:=$(LIBDIR) [% pymodule.data("LIBDIR") %]
32     [% safepath %]_LDLIBS:=$(addprefix -l,$([% safepath %]_LIB))
33     [% safepath %]_ALL_INCLUDES:=$(addprefix -I,$([% safepath %]_INCLUDE))
34     [% safepath %]_CPPFLAGS:=$(addprefix -D,$([% safepath %]_CPPDEFINES)) $([% safepath %]_ALL_INCLUDES)
35 sashby 1.8 [% safepath %]_LDFLAGS:= $(LDFLAGS) [% pymodule.flags("LDFLAGS") %] $(addprefix -L,$([% safepath %]_LIBDIR)) $([% safepath %]_LDLIBS)
36 sashby 1.2 [%# This builds a python module out of all the *_boost.cc files found:
37     %]
38     [% safepath %]_objdir := $(WORKINGDIR)/[% path %]
39     [% safepath %]_srcdir := $(LOCALTOP)/[% path %]
40     [% safepath %]_deps := [% pymodule.pkdeps() %]
41     [% safepath %]_filesuffixes:= cc cpp cxx C
42     [% safepath %]_filesrcdirs = $([% safepath %]_srcdir)
43     [% safepath %]_files += $(notdir $(wildcard $(foreach dir,$([% safepath %]_filesrcdirs),$(foreach ext,$([% safepath %]_filesuffixes),$(dir)/*.$(ext)))))
44    
45     # Add all _boost.cc and pyste files (which are translated to _boost.cc) found:
46     [% safepath %]_files += $(patsubst %.pyste,%_boost.cc,$(notdir $(wildcard $(LOCALTOP)/[% path %]/*.pyste)))
47     [% safepath %]_classnames := $(patsubst %_boost,%,$(filter %_boost,$(basename $(notdir $([% safepath %]_files)))))
48     [% safepath %]_pyname := Py[% pymodule.name() %]
49     [% safepath %]_CXXSharedLink += -rdynamic $([% safepath %]_LDFLAGS)
50    
51     # Configuration dependencies. Always depend on BuildFile in current directory:
52     [% safepath %]_py_BuildFile+=[% path %]/BuildFile
53     [% safepath %]_py_CONFIGDEPS+= $(CONFIGDEPS) $([% safepath %]_py_BuildFile)
54    
55     # Rules for Python modules:
56     ifneq ($(strip $([% safepath %]_files)),)
57     # Only add a wrapper file if there are other files:
58     [% safepath %]_files += $([% safepath %]_objdir)/[% safepath %]_PyWrapper.cc
59     # The object files:
60     [% safepath %]_objs := $(addprefix $([% safepath %]_objdir)/, $(addsuffix .o, $(basename $(notdir $([% safepath %]_files)))))
61    
62 sashby 1.3 .PHONY: [% safepath %]_all [% safepath %] [% safepath %]_help [% safepath %]_clean python_generic
63 sashby 1.2
64 sashby 1.3 python_generic [% safepath %]_all: [% safepath %]
65 sashby 1.2
66     [% safepath %]: $([% safepath %]_deps) $([% safepath %]_objdir)/$([% safepath %]_pyname).$(SHAREDSUFFIX)
67    
68     $([% safepath %]_objdir)/$([% safepath %]_pyname).$(SHAREDSUFFIX): $([% safepath %]_objs)
69     @echo ">> Building Python module $([% safepath %]_pyname).$(SHAREDSUFFIX)"
70     $(VERB)$(CXX) $(CXXSHAREDFLAGS) $^ -o $@ -shared $([% safepath %]_CXXSharedLink)
71     $(VERB)$(copy_py_to_main_productstore)
72    
73 sashby 1.8 [% safepath %]_help::
74 sashby 1.2 @echo "Help for building python modules at [% path %]"
75    
76 sashby 1.7 [% safepath %]_clean::
77 sashby 1.2 @echo "Cleaning local working directory, $(LOCALTOP)/$(SCRAM_INTwork)/[% path %]:"; \
78     /bin/rm -rf $(LOCALTOP)/$(SCRAM_INTwork)/[% path %]
79    
80     [%# We generate an object file from a _boost.cc file that we also generate automatically.
81     # This rule is only for objects created from _boost.cc files created from a %.pyste...phew:
82     %]
83     $([% safepath %]_objdir)/%_boost.o: $([% safepath %]_srcdir)/%.pyste $([% safepath %]_py_CONFIGDEPS)
84     @mkdir -p $(@D)
85     @echo ">> Generating and compiling Boost stub for module $*"
86     python $(PYSTE_EXEC) -D_REENTRANT $([% safepath %]_CPPFLAGS) --out=$([% safepath %]_objdir)/$*_boost.cc --module=$* $<
87     $(VERB)$(CXX) -MMD -c -DSCRAM_PYTHON_MODULE="BOOST_PYTHON_MODULE($*)" $([% safepath %]_CPPFLAGS) $([% safepath %]_CXXFLAGS) $([% safepath %]_CXXOPTIMISEDFLAGS) $(CXXSHAREDOBJECTFLAGS) $([% safepath %]_objdir)/$*_boost.cc -o $@
88    
89     # The object file rule for all _boost.cc found in src dir:
90     $([% safepath %]_objdir)/%_boost.o: $([% safepath %]_srcdir)/%_boost.cc $([% safepath %]_py_CONFIGDEPS)
91     @mkdir -p $(@D)
92     @echo ">> Compiling $< "
93     $(VERB)$(CXX) -MMD -c -DSCRAM_PYTHON_MODULE="BOOST_PYTHON_MODULE($*)" $([% safepath %]_CPPFLAGS) $([% safepath %]_CXXFLAGS) $([% safepath %]_CXXOPTIMISEDFLAGS) $(CXXSHAREDOBJECTFLAGS) $< -o $@
94    
95     $([% safepath %]_objdir)/[% safepath %]_PyWrapper.o: $([% safepath %]_objdir)/[% safepath %]_PyWrapper.cc $([% safepath %]_py_CONFIGDEPS)
96     @echo "Generating and compiling wrapper file: "
97     @mkdir -p $(@D)
98     @echo ">> Compiling $< "
99     $(VERB)$(CXX) -MMD -c -DSCRAM_PYTHON_MODULE="BOOST_PYTHON_MODULE([% safepath %]_PyWrapper)" $([% safepath %]_CPPFLAGS) $([% safepath %]_CXXFLAGS) $([% safepath %]_CXXOPTIMISEDFLAGS) $(CXXSHAREDOBJECTFLAGS) $< -o $@
100    
101     # Generate wrapper code for the list of modules (*_boost.cc in src dir):
102     $([% safepath %]_objdir)/[% safepath %]_PyWrapper.cc:
103     @echo "Generating wrapper code to put the following files in a single module called: $([% safepath %]_pyname)"
104     @exec 5>&1; \
105     ( echo "#include <boost/python.hpp>"; echo; \
106     for c in $([% safepath %]_classnames) ..; do \
107     case $$c in .. ) continue ;; esac ; \
108     echo " $$c" 1>&5; \
109     echo "extern void init_module_$$c ();"; \
110     done; \
111     echo; echo "void init_module_$([% safepath %]_pyname) () {"; \
112     for c in $([% safepath %]_classnames) ..; do \
113     case $$c in .. ) continue ;; esac ; \
114     echo " init_module_$$c ();"; \
115     done; \
116     echo "}"; echo; \
117     echo "extern \"C\" void init$([% safepath %]_pyname) () {"; \
118     echo 'boost::python::detail::init_module("$([% safepath %]_pyname)",'\
119     'init_module_$([% safepath %]_pyname));'; \
120     echo "};"; \
121     ) > $@.tmp
122     @mv $@.tmp $@
123    
124     # Include the object file dependencies:
125     -include $(foreach d,$([% safepath %]_objs:.$(OBJEXT)=.d),$d)
126     else
127 sashby 1.3 python_generic [% safepath %]_all: [% safepath %]
128 sashby 1.2 $([% safepath %]_objdir)/[% safepath %]_PyWrapper.cc:
129     ;
130     [% safepath %]:
131 sashby 1.3 @echo "No source files to compile. Nothing to be done for Python modules at [% path %]."
132 sashby 1.2 endif