~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to config/register_plugins.py

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Find plugins in the tree and add them to the build system 
20
20
 
21
21
import ConfigParser, os, sys
22
 
import datetime, time
23
22
 
24
23
top_srcdir='.'
25
24
top_builddir='.'
26
25
plugin_ini_fname='plugin.ini'
27
26
plugin_list=[]
28
 
plugin_am_file=None
29
 
plugin_ac_file=None
30
 
plugin_prefix=''
31
 
plugin_suffix='_plugin'
32
 
extra_cflags=''
33
 
extra_cppflags=''
34
 
extra_cxxflags=''
35
 
root_plugin_dir='plugin'
36
 
pkgplugindir='$(libdir)/drizzle'
37
 
default_install='True'
38
27
 
39
28
class ChangeProtectedFile(object):
40
29
 
41
30
  def __init__(self, fname):
42
 
    self.bogus_file= False
43
31
    self.real_fname= fname
44
32
    self.new_fname= "%s.new" % fname
45
 
    try:
46
 
      self.new_file= open(self.new_fname,'w+')
47
 
    except IOError:
48
 
      self.bogus_file= True
 
33
    self.new_file= open(self.new_fname,'w+')
49
34
 
50
35
  def write(self, text):
51
 
    if not self.bogus_file:
52
 
      self.new_file.write(text)
 
36
    self.new_file.write(text)
53
37
 
54
38
  # We've written all of this out into .new files, now we only copy them
55
39
  # over the old ones if they are different, so that we don't cause 
56
40
  # unnecessary recompiles
57
41
  def close(self):
58
42
    """Return True if the file had changed."""
59
 
    if self.bogus_file:
60
 
      return
61
43
    self.new_file.seek(0)
62
44
    new_content = self.new_file.read()
63
45
    self.new_file.close()
79
61
          pass
80
62
 
81
63
 
82
 
def write_external_configure(plugin, plugin_file):
83
 
  """Write the initial bits of the configure.ac file"""
84
 
  if not os.path.exists('m4'):
85
 
    os.mkdir('m4')
86
 
  plugin_file.write("""
87
 
AC_PREREQ(2.59)dnl              Minimum Autoconf version required.
88
 
AC_INIT([%(name)s],[%(version)s],[%(url)s])
89
 
AC_CONFIG_SRCDIR([%(main_source)s])
90
 
AC_CONFIG_AUX_DIR(config)
91
 
 
92
 
PANDORA_CANONICAL_TARGET(less-warnings, warnings-always-on, require-cxx, force-gcc42,skip-visibility)
93
 
 
94
 
PANDORA_REQUIRE_LIBPROTOBUF
95
 
PANDORA_PROTOBUF_REQUIRE_VERSION([2.1.0])
96
 
PANDORA_REQUIRE_PROTOC
97
 
 
98
 
AC_LANG_PUSH(C++)
99
 
PANDORA_REQUIRE_PTHREAD
100
 
PANDORA_REQUIRE_LIBDL
101
 
AC_LANG_POP
102
 
 
103
 
PANDORA_USE_BETTER_MALLOC
104
 
 
105
 
PANDORA_DRIZZLE_BUILD
106
 
""" % plugin)
107
 
 
108
 
  write_plugin_ac(plugin, plugin_file)
109
 
 
110
 
  plugin_file.write("""
111
 
AC_CONFIG_FILES(Makefile)
112
 
 
113
 
AC_OUTPUT
114
 
 
115
 
echo "---"
116
 
echo "Configuration summary for $PACKAGE_NAME version $VERSION $PANDORA_RELEASE_COMMENT"
117
 
echo ""
118
 
echo "   * Installation prefix:       $prefix"
119
 
echo "   * System type:               $host_vendor-$host_os"
120
 
echo "   * Host CPU:                  $host_cpu"
121
 
echo "   * C Compiler:                $CC_VERSION"
122
 
echo "   * C++ Compiler:              $CXX_VERSION"
123
 
echo "   * Debug enabled:             $with_debug"
124
 
echo "   * Warnings as failure:       $ac_cv_warnings_as_errors"
125
 
echo "   * C++ cstdint location:      $ac_cv_cxx_cstdint"
126
 
echo "   * C++ hash_map location:     $ac_cv_cxx_hash_map"
127
 
echo "   * C++ hash namespace:        $ac_cv_cxx_hash_namespace"
128
 
echo "   * C++ shared_ptr namespace:  $ac_cv_shared_ptr_namespace"
129
 
echo ""
130
 
echo "---"
131
 
 
132
 
  """ % plugin)
133
 
 
134
 
def write_external_makefile(plugin, plugin_file):
135
 
 
136
 
  plugin_file.write("""
137
 
ACLOCAL_AMFLAGS = -I m4 --force
138
 
VERSION=$(PANDORA_RELEASE_VERSION)
139
 
 
140
 
pkgplugindir=%(pkgplugindir)s
141
 
EXTRA_DIST = plugin.ini
142
 
 
143
 
""" % plugin)
144
 
  if plugin['headers'] != "":
145
 
    plugin_file.write("noinst_HEADERS = %(headers)s\n" % plugin)
146
 
  if plugin['testsuite']:
147
 
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
148
 
      plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin)
149
 
  plugin_file.write("""
150
 
pkgplugin_LTLIBRARIES=%(pname)s.la
151
 
%(pname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
152
 
%(pname)s_la_LIBADD=%(libs)s
153
 
%(pname)s_la_DEPENDENCIES=%(libs)s
154
 
%(pname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(name)s -DPANDORA_MODULE_AUTHOR="%(author)s" -DPANDORA_MODULE_TITLE="%(title)s" -DPANDORA_MODULE_VERSION="%(version)s" -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s
155
 
%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
156
 
%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
157
 
 
158
 
%(pname)s_la_SOURCES=%(sources)s
159
 
 
160
 
""" % plugin)
161
 
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
162
 
  if os.path.exists(plugin_am_file):
163
 
    plugin_file.write('include %s\n' % plugin_am_file)
164
 
 
165
64
def write_external_plugin():
166
65
  """Return True if the plugin had changed."""
167
66
  plugin = read_plugin_ini('.')
168
67
  expand_plugin_ini(plugin, '.')
169
 
  plugin_file = ChangeProtectedFile('configure.ac')
170
 
  write_external_configure(plugin, plugin_file)
 
68
  plugin_file = ChangeProtectedFile('pandora-plugin.ac')
 
69
  write_plugin_ac(plugin, plugin_file)
171
70
  result = plugin_file.close()
172
 
  plugin_file = ChangeProtectedFile('Makefile.am')
173
 
  write_external_makefile(plugin, plugin_file)
 
71
  plugin_file = ChangeProtectedFile('pandora-plugin.am')
 
72
  write_plugin_am(plugin, plugin_file)
174
73
  # Write some stub configure.ac and Makefile.am files that include the above
175
74
  result = plugin_file.close() or result
176
75
  return result
179
78
  """Return True if the plugin had changed."""
180
79
  plugin = read_plugin_ini(plugin_dir)
181
80
  expand_plugin_ini(plugin, plugin_dir)
182
 
  write_plugin_ac(plugin, plugin_ac_file)
183
 
  write_plugin_am(plugin, plugin_am_file)
 
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
 
87
  return result
184
88
 
185
89
def write_plugin_ac(plugin, plugin_ac):
186
90
  #
193
97
    for m4_file in os.listdir(plugin_m4_dir):
194
98
      if os.path.splitext(m4_file)[-1] == '.m4':
195
99
        plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
196
 
  plugin_ac.write("""
 
100
  plugin_ac.write("""dnl Generated file, run make to rebuild
197
101
dnl Config for %(title)s
198
102
""" % plugin)
199
103
  for m4_file in plugin_m4_files:
200
104
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
201
 
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
202
 
 
203
 
  if plugin['static']:
204
 
    plugin_ac.write("""
205
 
dnl This plugin is staticly built, which means we cannot live without and it is not
206
 
dnl possible to disable it. Once it is disableable, we will make it non-static.
207
 
with_%(name)s_plugin=yes
208
 
pandora_builtin_list="_drizzled_%(name)s_plugin_,${pandora_builtin_list}"
209
 
pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/%(root_plugin_dir)s/%(pname)s.la"
210
 
PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
211
 
 
212
 
""" % plugin)
213
 
    if plugin['testsuite']:
214
 
      plugin_ac.write("""
215
 
pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
216
 
""" % plugin)
217
 
  else:
218
 
    plugin_ac.write("""
 
105
 
 
106
  plugin_ac.write("""
219
107
AC_ARG_WITH([%(name_with_dashes)s-plugin],[
220
 
dnl indented wierd to make the help output correct
221
 
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(enabled)s@:>@])
 
108
dnl indented werid to make the help output correct
 
109
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s and enable it. @<:@default=%(default_yesno)s@:>@])
222
110
AS_HELP_STRING([--without-%(name_with_dashes)s-plugin],[Disable building %(title)s])
223
 
  ],[
224
 
    with_%(name)s_plugin="$withval"
225
 
    AS_IF([test "x$with_%(name)s_plugin" = "xyes"],[
226
 
      requested_%(name)s_plugin="yes"
227
 
    ],[
228
 
      requested_%(name)s_plugin="no"
229
 
    ])
230
 
  ],[
231
 
    with_%(name)s_plugin="%(enabled)s"
232
 
    requested_%(name)s_plugin="no"
233
 
  ])
234
 
AC_ARG_ENABLE([%(name_with_dashes)s-plugin],[
235
 
dnl indented wierd to make the help output correct
236
 
AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(default_yesno)s@:>@])
237
 
AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable building %(title)s])
238
111
  ],
239
 
  [enable_%(name)s_plugin="$withval"],
240
 
  [enable_%(name)s_plugin=%(default_yesno)s])
241
 
 
 
112
  [with_%(name)s_plugin="$withval"],
 
113
  [AS_IF([test "x$ac_with_all_plugins" = "xyes"],
 
114
         [with_%(name)s_plugin=yes],
 
115
         [with_%(name)s_plugin=%(default_yesno)s])])
242
116
""" % plugin)
243
117
  if os.path.exists(plugin_ac_file):
244
118
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) 
251
125
    plugin_ac.write("""
252
126
AS_IF([test %(build_conditional)s],
253
127
      [], dnl build_conditional can only negate
254
 
      [
255
 
        AS_IF([test "x${requested_%(name)s_plugin}" = "xyes"],
256
 
              [AC_MSG_ERROR([Plugin %(name)s was explicitly requested, yet failed build dependency checks. Aborting!])])
257
 
        with_%(name)s_plugin=no
258
 
      ])
259
 
 
260
 
""" % plugin)
261
 
  if not plugin['unconditional']:
262
 
    plugin_ac.write("""
 
128
      [with_%(name)s_plugin=no])
 
129
  """ % plugin)
 
130
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
 
131
  plugin_ac.write("""
263
132
AM_CONDITIONAL([%(build_conditional_tag)s],
264
133
               [test %(build_conditional)s])
265
 
    """ % plugin)
266
 
  if not plugin['static']:
267
 
    plugin_ac.write("""
268
134
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
269
135
      [
 
136
  """ % plugin)
 
137
  if plugin['testsuite'] != "":
 
138
    plugin_ac.write("""
 
139
        pandora_plugin_test_list="%(testsuite)s,${pandora_plugin_test_list}"
 
140
    """ % plugin)
 
141
 
 
142
  if plugin['static']:
 
143
    #pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
 
144
    plugin_ac.write("""
 
145
        pandora_builtin_list="builtin_%(name)s_plugin,${pandora_builtin_list}"
 
146
        pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/plugin/lib%(name)s_plugin.la"
 
147
        PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
270
148
""" % plugin)
271
 
    if plugin['testsuite']:
272
 
      plugin_ac.write("""
273
 
        pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
274
 
      """ % plugin)
275
 
 
 
149
  else:
276
150
    plugin_ac.write("""
277
 
        AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
278
 
          pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
279
 
        ])
 
151
        pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
280
152
    """ % plugin)
281
 
    plugin_ac.write("      ])\n")
 
153
  plugin_ac.write("      ])\n")
282
154
 
283
155
 
284
156
def expand_plugin_ini(plugin, plugin_dir):
285
 
    if plugin['name'] == "**OUT-OF-TREE**":
286
 
      print "Out of tree plugins require the name field to be specified in plugin.ini"
287
 
      sys.exit(1)
288
 
 
289
 
    if plugin_dir == ".":
290
 
      plugin['rel_path']= plugin_dir
291
 
      plugin['unconditional']=True
292
 
    else:
293
 
      plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
294
 
      plugin['unconditional']=False
 
157
    plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
295
158
    # TODO: determine path to plugin dir relative to top_srcdir... append it to
296
159
    # source files if they don't already have it
297
160
    if plugin['sources'] == "":
298
161
      plugin['sources']="%s.cc" % plugin['name']
299
162
    new_sources=""
300
 
    if plugin_dir != ".":
301
 
      for src in plugin['sources'].split():
302
 
        if not src.startswith(plugin['rel_path']):
303
 
          src= os.path.join(plugin['rel_path'], src)
304
 
          new_sources= "%s %s" % (new_sources, src)
305
 
    else:
306
 
      new_sources= " ".join(plugin['sources'].split())
307
 
    if new_sources != "":
308
 
      plugin['sources']= new_sources
309
 
    plugin['main_source']= plugin['sources'].split()[0]
 
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
310
168
    
311
169
    new_headers=""
312
 
    if plugin_dir != ".":
313
 
      for header in plugin['headers'].split():
314
 
        if not header.startswith(plugin['rel_path']):
315
 
          header= os.path.join(plugin['rel_path'], header)
316
 
          new_headers= "%s %s" % (new_headers, header)
317
 
    else:
318
 
      new_headers= " ".join(plugin['headers'].split())
319
 
    if new_headers != "":
320
 
      plugin['headers']= new_headers
 
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
321
175
    
322
176
    # Make a yes/no version for autoconf help messages
323
177
    if plugin['load_by_default']:
330
184
    plugin['name_with_dashes']= plugin['name'].replace('_','-')
331
185
    if plugin.has_key('build_conditional'):
332
186
      plugin['has_build_conditional']=True
333
 
      plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes" -a %(build_conditional)s' % plugin
334
187
    else:
335
188
      plugin['has_build_conditional']=False
336
189
      plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
337
190
 
338
 
    if plugin['install']:
339
 
      plugin['library_type']= 'pkgplugin';
340
 
    else:
341
 
      plugin['library_type']= 'noinst';
342
 
 
343
 
def find_testsuite(plugin_dir):
344
 
  for testdir in ['drizzle-tests','tests']:
345
 
    if os.path.isdir(os.path.join(plugin_dir,testdir)):
346
 
      return testdir
347
 
  if os.path.isdir(os.path.join('tests','suite',os.path.basename(plugin_dir))):
348
 
    return ""
349
 
  return None
350
191
 
351
192
def read_plugin_ini(plugin_dir):
352
 
    if plugin_dir == ".":
353
 
      plugin_name="**OUT-OF-TREE**"
354
 
    else:
355
 
      plugin_name=os.path.basename(plugin_dir)
356
 
 
357
193
    plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
358
 
    plugin_defaults= dict(sources="",
359
 
                          headers="",
360
 
                          cflags="",
361
 
                          cppflags="",
362
 
                          cxxflags="",
363
 
                          libs="",
364
 
                          ldflags="",
365
 
                          author="",
366
 
                          title="",
367
 
                          description="",
368
 
                          license="PLUGIN_LICENSE_GPL",
369
 
                          name=plugin_name,
370
 
                          load_by_default="False",
371
 
                          disabled="False",
372
 
                          static="False",
373
 
                          install=default_install)
374
 
    parser=ConfigParser.ConfigParser(defaults= plugin_defaults)
 
194
    parser=ConfigParser.ConfigParser(defaults=dict(sources="",headers="", cflags="",cppflags="",cxxflags="", libs="", ldflags="", testsuite=""))
375
195
    parser.read(plugin_file)
376
196
    plugin=dict(parser.items('plugin'))
377
 
    if plugin_dir == '.':
378
 
      if not plugin.has_key('url'):
379
 
        print "External Plugins are required to specifiy a url"
380
 
        plugin['url']= 'http://launchpad.net/%(name)s' % plugin
381
 
        sys.exit(1)
382
 
      if plugin_dir == '.' and not plugin.has_key('version'):
383
 
        print "External Plugins are required to specifiy a version"
384
 
        sys.exit(1)
385
 
    if not plugin.has_key('version'):
386
 
      plugin['version']=datetime.date.fromtimestamp(time.time()).isoformat()
387
 
   
 
197
    plugin['name']= os.path.basename(plugin_dir)
388
198
    if plugin.has_key('load_by_default'):
389
199
      plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
390
 
    if plugin.has_key('disabled'):
391
 
      plugin['disabled']=parser.getboolean('plugin','disabled')
392
 
    if plugin['disabled']:
393
 
      plugin['enabled']="no"
394
200
    else:
395
 
      plugin['enabled']="yes"
 
201
      plugin['load_by_default']=False
396
202
    if plugin.has_key('static'):
397
203
      plugin['static']= parser.getboolean('plugin','static')
398
 
    if plugin.has_key('install'):
399
 
      plugin['install']= parser.getboolean('plugin','install')
400
 
    if plugin.has_key('testsuite'):
401
 
      if plugin['testsuite'] == 'disable':
402
 
        plugin['testsuite']= False
403
204
    else:
404
 
      plugin_testsuite= find_testsuite(plugin_dir)
405
 
      plugin['testsuitedir']=plugin_testsuite
406
 
      if plugin_testsuite is not None:
407
 
        plugin['testsuite']=True
408
 
      else:
409
 
        plugin['testsuite']=False
410
 
 
411
 
    plugin['cflags']+= extra_cflags
412
 
    plugin['cppflags']+= extra_cppflags
413
 
    plugin['cxxflags']+= extra_cxxflags
414
 
 
415
 
    plugin['pname']= "lib%s%s%s" % (plugin_prefix, plugin['name'], plugin_suffix)
416
 
    plugin['root_plugin_dir']= root_plugin_dir
417
 
    plugin['plugin_prefix']= plugin_prefix
418
 
    plugin['plugin_suffix']= plugin_suffix
419
 
    plugin['pkgplugindir']= pkgplugindir
 
205
      plugin['static']= False
420
206
 
421
207
    return plugin
422
208
 
429
215
  """
430
216
  # The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can
431
217
  # confuse VCS systems.
432
 
  plugin_am.write("""
433
 
EXTRA_DIST += %(rel_path)s/plugin.ini
 
218
  plugin_am.write("""## Generated by register_plugins.py
 
219
EXTRA_DIST += %(rel_path)s/pandora-plugin.ac
 
220
 
 
221
${top_srcdir}/%(rel_path)s/pandora-plugin.am: ${top_srcdir}/config/register_plugins.py %(rel_path)s/.plugin.ini.stamp
 
222
 
 
223
${top_srcdir}/%(rel_path)s/pandora-plugin.ac: ${top_srcdir}/config/register_plugins.py %(rel_path)s/.plugin.ini.stamp
 
224
 
 
225
configure: ${top_srcdir}/%(rel_path)s/pandora-plugin.ac
434
226
 
435
227
# Prevent errors when a plugin dir is removed
436
228
%(rel_path)s/plugin.ini:
437
229
 
 
230
# Failures to update the plugin.ini are ignored to permit plugins to be deleted
 
231
# cleanly.
 
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"; \\
 
235
        else \\
 
236
            cmp -s $< $@; \\
 
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 ****"; \\
 
242
                false; \\
 
243
              fi && \\
 
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; \\
 
247
              done && \\
 
248
              cp $< $@ || echo "Failed to update $@"; \\
 
249
            fi; \\
 
250
        fi
438
251
""" % plugin)
439
252
  if plugin['headers'] != "":
440
253
    plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
441
 
  if plugin['testsuite']:
442
 
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
443
 
      plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin)
444
254
  if plugin['static']:
445
255
    plugin_am.write("""
446
 
%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
 
256
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
447
257
EXTRA_DIST += %(rel_path)s/plugin.ini
448
258
if %(build_conditional_tag)s
449
 
  noinst_LTLIBRARIES+=%(root_plugin_dir)s/%(pname)s.la
450
 
  %(root_plugin_dir)s_%(pname)s_la_LIBADD=%(libs)s
451
 
  %(root_plugin_dir)s_%(pname)s_la_DEPENDENCIES=%(libs)s
452
 
  %(root_plugin_dir)s_%(pname)s_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
453
 
  %(root_plugin_dir)s_%(pname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_MODULE_NAME=%(name)s -DPANDORA_MODULE_AUTHOR="%(author)s" -DPANDORA_MODULE_TITLE="%(title)s" -DPANDORA_MODULE_VERSION="%(version)s" -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s
454
 
  %(root_plugin_dir)s_%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
455
 
  %(root_plugin_dir)s_%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)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
456
266
 
457
 
  %(root_plugin_dir)s_%(pname)s_la_SOURCES=%(sources)s
458
 
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/%(root_plugin_dir)s/%(pname)s.la
 
267
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
 
268
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/plugin/lib%(name)s_plugin.la
459
269
endif
460
270
""" % plugin)
461
271
  else:
462
272
    plugin_am.write("""
463
 
%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
 
273
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
464
274
EXTRA_DIST += %(rel_path)s/plugin.ini
465
275
if %(build_conditional_tag)s
466
 
  %(library_type)s_LTLIBRARIES+=%(root_plugin_dir)s/%(pname)s.la
467
 
  %(root_plugin_dir)s_%(pname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
468
 
  %(root_plugin_dir)s_%(pname)s_la_LIBADD=%(libs)s
469
 
  %(root_plugin_dir)s_%(pname)s_la_DEPENDENCIES=%(libs)s
470
 
  %(root_plugin_dir)s_%(pname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(name)s -DPANDORA_MODULE_AUTHOR="%(author)s" -DPANDORA_MODULE_TITLE="%(title)s" -DPANDORA_MODULE_VERSION="%(version)s" -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s
471
 
  %(root_plugin_dir)s_%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
472
 
  %(root_plugin_dir)s_%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)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
473
283
 
474
 
  %(root_plugin_dir)s_%(pname)s_la_SOURCES=%(sources)s
 
284
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
475
285
endif
476
286
""" % plugin)
477
287
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
478
288
  if os.path.exists(plugin_am_file):
479
289
    plugin_am.write('include %s\n' % plugin_am_file)
480
290
 
481
 
#MAIN STARTS HERE:
482
 
 
483
 
actions=[]
484
 
for arg in sys.argv:
485
 
  if arg.startswith('--top_srcdir='):
486
 
    top_srcdir=arg[12:]
487
 
  elif arg.startswith('--top_builddir='):
488
 
    top_builddir=arg[14:]
489
 
  elif arg == "--force-all":
490
 
    actions=['plugin-list','pandora-plugin.am','write']
491
 
    break
 
291
 
 
292
if len(sys.argv)>1:
 
293
  top_srcdir=sys.argv[1]
 
294
  top_builddir=sys.argv[2]
 
295
 
 
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")
 
299
 
 
300
 
 
301
if len(sys.argv)>1:
 
302
  if len(sys.argv)>3:
 
303
    plugin_list = [top_srcdir + '/' + plugin_name for plugin_name in sys.argv[3:]]
492
304
  else:
493
 
    actions.append(arg)
494
 
if len(actions) == 0:
495
 
  actions.append('write')
496
 
 
497
 
def accumulate_plugins(arg, dirname, fnames):
498
 
  # plugin_ini_fname is a name in dirname indicating dirname is a plugin.
499
 
  if plugin_ini_fname in fnames:
500
 
    arg.append(dirname)
501
 
os.path.walk(os.path.join(top_srcdir,root_plugin_dir),accumulate_plugins,plugin_list)
502
 
 
503
 
 
504
 
if not os.path.exists("config/pandora-plugin.am") or "write" in actions:
505
 
  plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am'))
506
 
  plugin_am_file.write("""
507
 
# always the current list, generated every build so keep this lean.
508
 
# pandora-plugin.list: datestamp preserved list
509
 
${srcdir}/config/pandora-plugin.list: .plugin.scan
510
 
.plugin.scan:
511
 
        @cd ${top_srcdir} && python config/pandora-plugin plugin-list
512
 
 
513
 
# Plugins affect configure; so to prevent configure running twice in a tarball
514
 
# build (once up front, once with the right list of plugins, we ship the
515
 
# generated list of plugins and the housekeeping material for that list so it
516
 
# is likewise not updated.
517
 
EXTRA_DIST += \
518
 
        config/pandora-plugin.am \
519
 
        config/pandora-plugin.ac \
520
 
        config/pandora-plugin
521
 
 
522
 
 
523
 
# Seed the list of plugin LDADDS which plugins may extend.
524
 
PANDORA_DYNAMIC_LDADDS=
525
 
 
526
 
# plugin.stamp: graph dominator for creating all per pandora-plugin.ac/am
527
 
# files. This is invoked when the code to generate such files has altered.""")
528
 
 
529
 
if not os.path.exists("config/pandora-plugin.ac") or "write" in actions:
530
 
  plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac'))
531
 
  plugin_ac_file.write("dnl Generated file, run make to rebuild\n")
532
 
 
 
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:
 
308
        arg.append(dirname)
 
309
    os.path.walk(os.path.join(top_srcdir,"plugin"),accumulate_plugins,plugin_list)
533
310
 
534
311
if os.path.exists('plugin.ini'):
535
312
  # Are we in a plugin dir which wants to have a self-sufficient build system?
536
 
  plugin_list=['.']
537
 
 
538
313
  write_external_plugin()
539
314
else:
540
 
  plugin_list_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.list'))
541
 
  for p in plugin_list:
542
 
    plugin_list_file.write(p)
543
 
    plugin_list_file.write("\n")
544
315
  plugin_list.sort()
545
 
  plugin_list_file.close()
546
 
 
547
 
if not os.path.exists("config/pandora-plugin.am") or 'write' in actions:
548
 
  plugin_am_file.write("\n${top_srcdir}/config/pandora-plugin.am: ${top_srcdir}/config/pandora-plugin.list ${top_srcdir}/config/pandora-plugin ")
549
 
  for plugin_dir in plugin_list:
550
 
    plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir)
551
 
  plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n")
552
 
  for plugin_dir in plugin_list:
553
 
    write_plugin(plugin_dir)
554
 
 
555
 
if plugin_am_file is not None:
556
 
  plugin_am_file.close()
557
 
if plugin_ac_file is not None:
558
 
  plugin_ac_file.close()
 
316
  for plugin_dir in plugin_list:
 
317
    if not write_plugin(plugin_dir):
 
318
      print plugin_dir
 
319
 
 
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")
 
322
 
 
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")