40
39
# over the old ones if they are different, so that we don't cause
41
40
# unnecessary recompiles
42
"""Return True if the file had changed."""
44
new_content = self.new_file.read()
43
45
self.new_file.close()
44
if os.system('diff %s %s >/dev/null 2>&1' % (self.new_fname,self.real_fname)):
47
old_file = file(self.real_fname, 'r')
48
old_content = old_file.read()
52
if new_content != old_content:
53
if old_content != None:
46
54
os.unlink(self.real_fname)
49
55
os.rename(self.new_fname, self.real_fname)
51
os.unlink(self.new_fname)
56
top_srcdir=sys.argv[1]
57
top_builddir=top_srcdir
59
top_builddir=sys.argv[2]
61
plugin_ac=ChangeProtectedFile(os.path.join(top_builddir,'config','plugin.ac'))
62
plugin_am=ChangeProtectedFile(os.path.join(top_srcdir,'config','plugin.am'))
64
plugin_ac.write("dnl %s" % autogen_header)
65
plugin_am.write("# %s" % autogen_header)
66
plugin_am.write("PANDORA_DYNAMIC_LDADDS=\n")
68
def accumulate_plugins(arg, dirname, fnames):
69
if plugin_ini_fname in fnames:
73
os.path.walk(os.path.join(top_srcdir,"plugin"),accumulate_plugins,plugin_list)
76
for plugin_dir in plugin_list:
77
plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
78
parser=ConfigParser.ConfigParser(defaults=dict(sources="",headers="", cflags="",cppflags="",cxxflags="", libs="", ldflags="", testsuite=""))
79
parser.read(plugin_file)
80
plugin=dict(parser.items('plugin'))
81
plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
82
# TODO: determine path to plugin dir relative to top_srcdir... append it
83
# to source files if they don't already have it
84
if plugin['sources'] == "":
85
plugin['sources']="%s.cc" % plugin['name']
87
for src in plugin['sources'].split():
88
if not src.startswith(plugin['rel_path']):
89
src= os.path.join(plugin['rel_path'], src)
90
new_sources= "%s %s" % (new_sources, src)
91
plugin['sources']= new_sources
94
for header in plugin['headers'].split():
95
if not header.startswith(plugin['rel_path']):
96
header= os.path.join(plugin['rel_path'], header)
97
new_headers= "%s %s" % (new_headers, header)
98
plugin['headers']= new_headers
100
if plugin.has_key('load_by_default'):
101
plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
103
plugin['load_by_default']=False
104
# Make a yes/no version for autoconf help messages
105
if plugin['load_by_default']:
106
plugin['default_yesno']="yes"
108
plugin['default_yesno']="no"
59
os.unlink(self.new_fname)
64
def write_external_plugin():
65
"""Return True if the plugin had changed."""
66
plugin = read_plugin_ini('.')
67
expand_plugin_ini(plugin, '.')
68
plugin_file = ChangeProtectedFile('pandora-plugin.ac')
69
write_plugin_ac(plugin, plugin_file)
70
result = plugin_file.close()
71
plugin_file = ChangeProtectedFile('pandora-plugin.am')
72
write_plugin_am(plugin, plugin_file)
73
# Write some stub configure.ac and Makefile.am files that include the above
74
result = plugin_file.close() or result
77
def write_plugin(plugin_dir):
78
"""Return True if the plugin had changed."""
79
plugin = read_plugin_ini(plugin_dir)
80
expand_plugin_ini(plugin, plugin_dir)
81
plugin_file = ChangeProtectedFile(os.path.join(plugin_dir, 'pandora-plugin.ac'))
82
write_plugin_ac(plugin, plugin_file)
83
result = plugin_file.close()
84
plugin_file = ChangeProtectedFile(os.path.join(plugin_dir, 'pandora-plugin.am'))
85
write_plugin_am(plugin, plugin_file)
86
result = plugin_file.close() or result
89
def write_plugin_ac(plugin, plugin_ac):
91
# Write plugin config instructions into plugin.ac file.
110
93
plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
111
plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
112
94
plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
114
95
plugin_m4_files=[]
115
96
if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
116
97
for m4_file in os.listdir(plugin_m4_dir):
117
98
if os.path.splitext(m4_file)[-1] == '.m4':
118
99
plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
120
plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
121
plugin['name_with_dashes']= plugin['name'].replace('_','-')
122
if plugin.has_key('build_conditional'):
123
plugin['has_build_conditional']=True
125
plugin['has_build_conditional']=False
126
plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
128
# Turn this on later plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN %(cppflags)s
131
# Write plugin build instructions into plugin.am file.
133
if plugin['headers'] != "":
134
plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
136
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
137
EXTRA_DIST += %(rel_path)s/plugin.ini
138
if %(build_conditional_tag)s
139
noinst_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
140
plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
141
plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
142
plugin_lib%(name)s_plugin_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s
143
plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) %(cppflags)s
144
plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
145
plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
147
plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
148
PANDORA_DYNAMIC_LDADDS+=${top_builddir}/plugin/lib%(name)s_plugin.la
100
plugin_ac.write("""dnl Generated file, run make to rebuild
101
dnl Config for %(title)s
151
# Add this once we're actually doing dlopen (and remove -avoid-version if
153
#pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
154
#plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) %(libs)s
157
if os.path.exists(plugin_am_file):
158
plugin_am.write('include %s\n' % plugin_am_file)
161
# Write plugin config instructions into plugin.am file.
163
plugin_ac.write("\n\ndnl Config for %(title)s\n" % plugin)
164
103
for m4_file in plugin_m4_files:
165
104
plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
200
139
pandora_plugin_test_list="%(testsuite)s,${pandora_plugin_test_list}"
204
pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
143
#pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
205
145
pandora_builtin_list="builtin_%(name)s_plugin,${pandora_builtin_list}"
206
146
pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/plugin/lib%(name)s_plugin.la"
207
147
PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
151
pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
153
plugin_ac.write(" ])\n")
156
def expand_plugin_ini(plugin, plugin_dir):
157
plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
158
# TODO: determine path to plugin dir relative to top_srcdir... append it to
159
# source files if they don't already have it
160
if plugin['sources'] == "":
161
plugin['sources']="%s.cc" % plugin['name']
163
for src in plugin['sources'].split():
164
if not src.startswith(plugin['rel_path']):
165
src= os.path.join(plugin['rel_path'], src)
166
new_sources= "%s %s" % (new_sources, src)
167
plugin['sources']= new_sources
170
for header in plugin['headers'].split():
171
if not header.startswith(plugin['rel_path']):
172
header= os.path.join(plugin['rel_path'], header)
173
new_headers= "%s %s" % (new_headers, header)
174
plugin['headers']= new_headers
176
# Make a yes/no version for autoconf help messages
177
if plugin['load_by_default']:
178
plugin['default_yesno']="yes"
180
plugin['default_yesno']="no"
183
plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
184
plugin['name_with_dashes']= plugin['name'].replace('_','-')
185
if plugin.has_key('build_conditional'):
186
plugin['has_build_conditional']=True
188
plugin['has_build_conditional']=False
189
plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
192
def read_plugin_ini(plugin_dir):
193
plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
194
parser=ConfigParser.ConfigParser(defaults=dict(sources="",headers="", cflags="",cppflags="",cxxflags="", libs="", ldflags="", testsuite=""))
195
parser.read(plugin_file)
196
plugin=dict(parser.items('plugin'))
197
plugin['name']= os.path.basename(plugin_dir)
198
if plugin.has_key('load_by_default'):
199
plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
201
plugin['load_by_default']=False
202
if plugin.has_key('static'):
203
plugin['static']= parser.getboolean('plugin','static')
205
plugin['static']= False
210
def write_plugin_am(plugin, plugin_am):
211
"""Write an automake fragment for this plugin.
213
:param plugin: The plugin dict.
214
:param plugin_am: The file to write to.
216
# The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can
217
# confuse VCS systems.
218
plugin_am.write("""## Generated by register_plugins.py
219
EXTRA_DIST += %(rel_path)s/pandora-plugin.ac
221
${top_srcdir}/%(rel_path)s/pandora-plugin.am: ${top_srcdir}/config/register_plugins.py %(rel_path)s/.plugin.ini.stamp
223
${top_srcdir}/%(rel_path)s/pandora-plugin.ac: ${top_srcdir}/config/register_plugins.py %(rel_path)s/.plugin.ini.stamp
225
configure: ${top_srcdir}/%(rel_path)s/pandora-plugin.ac
227
# Prevent errors when a plugin dir is removed
228
%(rel_path)s/plugin.ini:
230
# Failures to update the plugin.ini are ignored to permit plugins to be deleted
232
%(rel_path)s/.plugin.ini.stamp: %(rel_path)s/plugin.ini
233
@if [ ! -e ${top_srcdir}/%(rel_path)s/plugin.ini ]; then \\
234
echo "%(rel_path)s/plugin.ini is missing"; \\
237
if [ $$? -ne 0 ]; then \\
238
echo 'cd ${srcdir} && python config/register_plugins.py ${top_srcdir} ${top_builddir} %(rel_path)s'; \\
239
unchanged=`cd ${srcdir} && python config/register_plugins.py ${top_srcdir} ${top_builddir} %(rel_path)s` ;\\
240
if [ $$? -ne 0 ]; then \\
241
echo "**** register_plugins failed ****"; \\
244
for plugin_dir in $$unchanged; do \\
245
echo "plugin $$plugin_dir unchanged." ; \\
246
touch -f -r $$plugin_dir/pandora-plugin.am $$plugin_dir/.plugin.ini.stamp; \\
248
cp $< $@ || echo "Failed to update $@"; \\
252
if plugin['headers'] != "":
253
plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
256
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
257
EXTRA_DIST += %(rel_path)s/plugin.ini
258
if %(build_conditional_tag)s
259
noinst_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
260
plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
261
plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
262
plugin_lib%(name)s_plugin_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s
263
plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_MODULE_NAME=%(name)s %(cppflags)s
264
plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
265
plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
267
plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
268
PANDORA_DYNAMIC_LDADDS+=${top_builddir}/plugin/lib%(name)s_plugin.la
273
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
274
EXTRA_DIST += %(rel_path)s/plugin.ini
275
if %(build_conditional_tag)s
276
pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
277
plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s
278
plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
279
plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
280
plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(name)s %(cppflags)s
281
plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
282
plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
284
plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
287
plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
288
if os.path.exists(plugin_am_file):
289
plugin_am.write('include %s\n' % plugin_am_file)
293
top_srcdir=sys.argv[1]
294
top_builddir=sys.argv[2]
296
if not os.path.exists("config/plugin.list"):
297
os.system("find plugin -name 'plugin.ini' | xargs -n1 dirname | xargs -n1 basename | sort -b -d > .plugin.scan")
298
os.system("cp .plugin.scan config/plugin.list")
303
plugin_list = [top_srcdir + '/' + plugin_name for plugin_name in sys.argv[3:]]
305
def accumulate_plugins(arg, dirname, fnames):
306
# plugin_ini_fname is a name in dirname indicating dirname is a plugin.
307
if plugin_ini_fname in fnames:
309
os.path.walk(os.path.join(top_srcdir,"plugin"),accumulate_plugins,plugin_list)
311
if os.path.exists('plugin.ini'):
312
# Are we in a plugin dir which wants to have a self-sufficient build system?
313
write_external_plugin()
316
for plugin_dir in plugin_list:
317
if not write_plugin(plugin_dir):
320
if not os.path.exists("config/plugin-list.am"):
321
os.system(r"sed 's,^\(.*\)$,include plugin/\1/pandora-plugin.am,' < config/plugin.list > config/plugin-list.am")
323
if not os.path.exists("config/plugin-list.ac"):
324
os.system(r"sed 's,^\(.*\)$,m4_sinclude(plugin/\1/pandora-plugin.ac),' < config/plugin.list > config/plugin-list.ac")