~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#!/usr/bin/python

#  Copyright (C) 2009 Sun Microsystems
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; version 2 of the License.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


# Find plugins in the tree and add them to the build system 

import ConfigParser, os, sys
import datetime, time
import subprocess

top_srcdir='.'
top_builddir='.'
plugin_ini_fname='plugin.ini'
plugin_list=[]
plugin_am_file=None
plugin_ac_file=None
plugin_prefix=''
plugin_suffix='_plugin'
extra_cflags=''
extra_cppflags=''
extra_cxxflags=''
root_plugin_dir='plugin'
pkgplugindir='$(libdir)/drizzle'
default_install='True'
default_plugin_version=''

class ChangeProtectedFile(object):

  def __init__(self, fname):
    self.bogus_file= False
    self.real_fname= fname
    self.new_fname= "%s.new" % fname
    try:
      self.new_file= open(self.new_fname,'w+')
    except IOError:
      self.bogus_file= True

  def write(self, text):
    if not self.bogus_file:
      self.new_file.write(text)

  # We've written all of this out into .new files, now we only copy them
  # over the old ones if they are different, so that we don't cause 
  # unnecessary recompiles
  def close(self):
    """Return True if the file had changed."""
    if self.bogus_file:
      return
    self.new_file.seek(0)
    new_content = self.new_file.read()
    self.new_file.close()
    try:
        old_file = file(self.real_fname, 'r')
        old_content = old_file.read()
        old_file.close()
    except IOError:
        old_content = None
    if new_content != old_content:
      if old_content != None:
        os.unlink(self.real_fname)
      os.rename(self.new_fname, self.real_fname)
      return True
    else:
        try:
          os.unlink(self.new_fname)
        except:
          pass


def write_external_configure(plugin, plugin_file):
  """Write the initial bits of the configure.ac file"""
  if not os.path.exists('m4'):
    os.mkdir('m4')
  plugin_file.write("""
AC_PREREQ(2.59)dnl		Minimum Autoconf version required.
AC_INIT([%(name)s],[%(version)s],[%(url)s])
AC_CONFIG_SRCDIR([%(main_source)s])
AC_CONFIG_AUX_DIR(config)

PANDORA_CANONICAL_TARGET(less-warnings, warnings-always-on, require-cxx, force-gcc42,skip-visibility)

PANDORA_REQUIRE_LIBPROTOBUF
PANDORA_PROTOBUF_REQUIRE_VERSION([2.1.0])
PANDORA_REQUIRE_PROTOC

AC_LANG_PUSH(C++)
PANDORA_REQUIRE_PTHREAD
PANDORA_REQUIRE_LIBDL
AC_LANG_POP

PANDORA_USE_BETTER_MALLOC

PANDORA_DRIZZLE_BUILD
""" % plugin)

  write_plugin_ac(plugin, plugin_file)

  plugin_file.write("""
AC_CONFIG_FILES(Makefile)

AC_OUTPUT

echo "---"
echo "Configuration summary for $PACKAGE_NAME version $VERSION $PANDORA_RELEASE_COMMENT"
echo ""
echo "   * Installation prefix:       $prefix"
echo "   * System type:               $host_vendor-$host_os"
echo "   * Host CPU:                  $host_cpu"
echo "   * C Compiler:                $CC_VERSION"
echo "   * C++ Compiler:              $CXX_VERSION"
echo "   * Debug enabled:             $with_debug"
echo "   * Warnings as failure:       $ac_cv_warnings_as_errors"
echo "   * C++ cstdint location:      $ac_cv_cxx_cstdint"
echo "   * C++ hash_map location:     $ac_cv_cxx_hash_map"
echo "   * C++ hash namespace:        $ac_cv_cxx_hash_namespace"
echo "   * C++ shared_ptr namespace:  $ac_cv_shared_ptr_namespace"
echo ""
echo "---"

  """ % plugin)

def write_external_makefile(plugin, plugin_file):

  plugin_file.write("""
ACLOCAL_AMFLAGS = -I m4 --force
VERSION=$(PANDORA_RELEASE_VERSION)

pkgplugindir=%(pkgplugindir)s
EXTRA_DIST = plugin.ini

""" % plugin)
  if plugin['headers'] != "":
    plugin_file.write("noinst_HEADERS = %(headers)s\n" % plugin)
  if plugin['testsuite']:
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
      plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin)
  plugin_file.write("""
pkgplugin_LTLIBRARIES=%(pname)s.la
%(pname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
%(pname)s_la_LIBADD=%(libs)s
%(pname)s_la_DEPENDENCIES=%(libs)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
%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s

%(pname)s_la_SOURCES=%(sources)s

""" % plugin)
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
  if os.path.exists(plugin_am_file):
    plugin_file.write('include %s\n' % plugin_am_file)

def write_external_plugin():
  """Return True if the plugin had changed."""
  plugin = read_plugin_ini('.')
  expand_plugin_ini(plugin, '.')
  plugin_file = ChangeProtectedFile('configure.ac')
  write_external_configure(plugin, plugin_file)
  result = plugin_file.close()
  plugin_file = ChangeProtectedFile('Makefile.am')
  write_external_makefile(plugin, plugin_file)
  # Write some stub configure.ac and Makefile.am files that include the above
  result = plugin_file.close() or result
  return result

def write_plugin(plugin_dir):
  """Return True if the plugin had changed."""
  plugin = read_plugin_ini(plugin_dir)
  expand_plugin_ini(plugin, plugin_dir)
  write_plugin_ac(plugin, plugin_ac_file)
  write_plugin_am(plugin, plugin_am_file)

def write_plugin_ac(plugin, plugin_ac):
  #
  # Write plugin config instructions into plugin.ac file.
  #
  plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
  plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
  plugin_m4_files=[]
  if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
    for m4_file in os.listdir(plugin_m4_dir):
      if os.path.splitext(m4_file)[-1] == '.m4':
        plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
  plugin_ac.write("""
dnl Config for %(title)s
""" % plugin)
  for m4_file in plugin_m4_files:
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])

  if plugin['static']:
    plugin_ac.write("""
dnl This plugin is staticly built, which means we cannot live without and it is not
dnl possible to disable it. Once it is disableable, we will make it non-static.
with_%(name)s_plugin=yes
pandora_builtin_list="_drizzled_%(name)s_plugin_,${pandora_builtin_list}"
pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/%(root_plugin_dir)s/%(pname)s.la"
PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"

""" % plugin)
    if plugin['testsuite']:
      plugin_ac.write("""
pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
""" % plugin)
  else:
    plugin_ac.write("""
AC_ARG_WITH([%(name_with_dashes)s-plugin],[
dnl indented wierd to make the help output correct
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(enabled)s@:>@])
AS_HELP_STRING([--without-%(name_with_dashes)s-plugin],[Disable building %(title)s])
  ],[
    with_%(name)s_plugin="$withval"
    AS_IF([test "x$with_%(name)s_plugin" = "xyes"],[
      requested_%(name)s_plugin="yes"
    ],[
      requested_%(name)s_plugin="no"
    ])
  ],[
    with_%(name)s_plugin="%(enabled)s"
    requested_%(name)s_plugin="no"
  ])
AC_ARG_ENABLE([%(name_with_dashes)s-plugin],[
dnl indented wierd to make the help output correct
AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(default_yesno)s@:>@])
AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable building %(title)s])
  ],
  [enable_%(name)s_plugin="$withval"],
  [enable_%(name)s_plugin=%(default_yesno)s])

""" % plugin)
  if os.path.exists(plugin_ac_file):
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) 
  # The plugin author has specified some check to make to determine
  # if the plugin can be built. If the plugin is turned on and this 
  # check fails, then configure should error out. If the plugin is not
  # turned on, then the normal conditional build stuff should just let
  # it silently not build
  if plugin['has_build_conditional']:
    plugin_ac.write("""
AS_IF([test %(build_conditional)s],
      [], dnl build_conditional can only negate
      [
        AS_IF([test "x${requested_%(name)s_plugin}" = "xyes"],
              [AC_MSG_ERROR([Plugin %(name)s was explicitly requested, yet failed build dependency checks. Aborting!])])
        with_%(name)s_plugin=no
      ])

""" % plugin)
  if not plugin['unconditional']:
    plugin_ac.write("""
AM_CONDITIONAL([%(build_conditional_tag)s],
               [test %(build_conditional)s])
    """ % plugin)
  if not plugin['static']:
    plugin_ac.write("""
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
      [
""" % plugin)
    if plugin['testsuite']:
      plugin_ac.write("""
        pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
      """ % plugin)

    plugin_ac.write("""
        AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
          pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
        ])
    """ % plugin)
    plugin_ac.write("      ])\n")


def expand_plugin_ini(plugin, plugin_dir):
    if plugin['name'] == "**OUT-OF-TREE**":
      print "Out of tree plugins require the name field to be specified in plugin.ini"
      sys.exit(1)

    if plugin_dir == ".":
      plugin['rel_path']= plugin_dir
      plugin['unconditional']=True
    else:
      plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
      plugin['unconditional']=False
    # TODO: determine path to plugin dir relative to top_srcdir... append it to
    # source files if they don't already have it
    if plugin['sources'] == "":
      plugin['sources']="%s.cc" % plugin['name']
    new_sources=""
    if plugin_dir != ".":
      for src in plugin['sources'].split():
        if not src.startswith(plugin['rel_path']):
          src= os.path.join(plugin['rel_path'], src)
          new_sources= "%s %s" % (new_sources, src)
    else:
      new_sources= " ".join(plugin['sources'].split())
    if new_sources != "":
      plugin['sources']= new_sources
    plugin['main_source']= plugin['sources'].split()[0]
    
    new_headers=""
    if plugin_dir != ".":
      for header in plugin['headers'].split():
        if not header.startswith(plugin['rel_path']):
          header= os.path.join(plugin['rel_path'], header)
          new_headers= "%s %s" % (new_headers, header)
    else:
      new_headers= " ".join(plugin['headers'].split())
    if new_headers != "":
      plugin['headers']= new_headers
    
    # Make a yes/no version for autoconf help messages
    if plugin['load_by_default']:
      plugin['default_yesno']="yes"
    else:
      plugin['default_yesno']="no"

    
    plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
    plugin['name_with_dashes']= plugin['name'].replace('_','-')
    if plugin.has_key('build_conditional'):
      plugin['has_build_conditional']=True
      plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes" -a %(build_conditional)s' % plugin
    else:
      plugin['has_build_conditional']=False
      plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin

    if plugin['install']:
      plugin['library_type']= 'pkgplugin';
    else:
      plugin['library_type']= 'noinst';

def find_testsuite(plugin_dir):
  for testdir in ['drizzle-tests','tests']:
    if os.path.isdir(os.path.join(plugin_dir,testdir)):
      return testdir
  if os.path.isdir(os.path.join('tests','suite',os.path.basename(plugin_dir))):
    return ""
  return None

def read_plugin_ini(plugin_dir):
    if plugin_dir == ".":
      plugin_name="**OUT-OF-TREE**"
    else:
      plugin_name=os.path.basename(plugin_dir)

    plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
    plugin_defaults= dict(sources="",
                          headers="",
                          cflags="",
                          cppflags="",
                          cxxflags="",
                          libs="",
                          ldflags="",
                          author="",
                          title="",
                          description="",
                          license="PLUGIN_LICENSE_GPL",
                          name=plugin_name,
                          load_by_default="False",
                          disabled="False",
                          static="False",
                          install=default_install)
    parser=ConfigParser.ConfigParser(defaults= plugin_defaults)
    parser.read(plugin_file)
    plugin=dict(parser.items('plugin'))
    if plugin_dir == '.':
      if not plugin.has_key('url'):
        print "External Plugins are required to specifiy a url"
        plugin['url']= 'http://launchpad.net/%(name)s' % plugin
        sys.exit(1)
      if plugin_dir == '.' and not plugin.has_key('version'):
        print "External Plugins are required to specifiy a version"
        sys.exit(1)
    if not plugin.has_key('version'):
      plugin['version'] = default_plugin_version
   
    if plugin.has_key('load_by_default'):
      plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
    if plugin.has_key('disabled'):
      plugin['disabled']=parser.getboolean('plugin','disabled')
    if plugin['disabled']:
      plugin['enabled']="no"
    else:
      plugin['enabled']="yes"
    if plugin.has_key('static'):
      plugin['static']= parser.getboolean('plugin','static')
    if plugin.has_key('install'):
      plugin['install']= parser.getboolean('plugin','install')
    if plugin.has_key('testsuite'):
      if plugin['testsuite'] == 'disable':
        plugin['testsuite']= False
    else:
      plugin_testsuite= find_testsuite(plugin_dir)
      plugin['testsuitedir']=plugin_testsuite
      if plugin_testsuite is not None:
        plugin['testsuite']=True
      else:
        plugin['testsuite']=False

    plugin['cflags']+= extra_cflags
    plugin['cppflags']+= extra_cppflags
    plugin['cxxflags']+= extra_cxxflags

    plugin['pname']= "lib%s%s%s" % (plugin_prefix, plugin['name'], plugin_suffix)
    plugin['root_plugin_dir']= root_plugin_dir
    plugin['plugin_prefix']= plugin_prefix
    plugin['plugin_suffix']= plugin_suffix
    plugin['pkgplugindir']= pkgplugindir

    return plugin


def write_plugin_am(plugin, plugin_am):
  """Write an automake fragment for this plugin.
  
  :param plugin: The plugin dict.
  :param plugin_am: The file to write to.
  """
  # The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can
  # confuse VCS systems.
  plugin_am.write("""
EXTRA_DIST += %(rel_path)s/plugin.ini

# Prevent errors when a plugin dir is removed
%(rel_path)s/plugin.ini:

""" % plugin)
  if plugin['headers'] != "":
    plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
  if plugin['testsuite']:
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
      plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin)
  if plugin['static']:
    plugin_am.write("""
%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
EXTRA_DIST += %(rel_path)s/plugin.ini
if %(build_conditional_tag)s
  noinst_LTLIBRARIES+=%(root_plugin_dir)s/%(pname)s.la
  %(root_plugin_dir)s_%(pname)s_la_LIBADD=%(libs)s
  %(root_plugin_dir)s_%(pname)s_la_DEPENDENCIES=%(libs)s
  %(root_plugin_dir)s_%(pname)s_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
  %(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
  %(root_plugin_dir)s_%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
  %(root_plugin_dir)s_%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s

  %(root_plugin_dir)s_%(pname)s_la_SOURCES=%(sources)s
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/%(root_plugin_dir)s/%(pname)s.la
endif
""" % plugin)
  else:
    plugin_am.write("""
%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
EXTRA_DIST += %(rel_path)s/plugin.ini
if %(build_conditional_tag)s
  %(library_type)s_LTLIBRARIES+=%(root_plugin_dir)s/%(pname)s.la
  %(root_plugin_dir)s_%(pname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
  %(root_plugin_dir)s_%(pname)s_la_LIBADD=%(libs)s
  %(root_plugin_dir)s_%(pname)s_la_DEPENDENCIES=%(libs)s
  %(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
  %(root_plugin_dir)s_%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
  %(root_plugin_dir)s_%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s

  %(root_plugin_dir)s_%(pname)s_la_SOURCES=%(sources)s
endif
""" % plugin)
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
  if os.path.exists(plugin_am_file):
    plugin_am.write('include %s\n' % plugin_am_file)

#MAIN STARTS HERE:

# I'm 3 seconds away from writing a comprehensive build solution
if not os.path.exists('config/pandora_vc_revinfo'):
  if os.path.exists('.bzr'):
    bzr_revno= subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE).communicate()[0].strip()
    rev_date= datetime.date.fromtimestamp(time.time())
    default_plugin_version = "%d.%02d.%s" % (rev_date.year, rev_date.month, bzr_revno)
  else:
    default_plugin_version=datetime.date.fromtimestamp(time.time()).isoformat()
else:
  # need to read config/pandora_vc_revno
  pandora_vc_revno=open('config/pandora_vc_revinfo','r').read().split()
  rev_date=""
  bzr_revno=""
  for revno_line in pandora_vc_revno:
    (revno_key,revno_val)= revno_line.split("=")
    if revno_key == 'PANDORA_VC_REVNO':
      bzr_revno=revno_val.strip()
    elif revno_key == 'PANDORA_RELEASE_DATE':
      rev_date=revno_val.strip()

  default_plugin_version = "%s.%s" % (rev_date, bzr_revno)

actions=[]
for arg in sys.argv:
  if arg.startswith('--top_srcdir='):
    top_srcdir=arg[12:]
  elif arg.startswith('--top_builddir='):
    top_builddir=arg[14:]
  elif arg == "--force-all":
    actions=['plugin-list','pandora-plugin.am','write']
    break
  else:
    actions.append(arg)
if len(actions) == 0:
  actions.append('write')

def accumulate_plugins(arg, dirname, fnames):
  # plugin_ini_fname is a name in dirname indicating dirname is a plugin.
  if plugin_ini_fname in fnames:
    arg.append(dirname)
os.path.walk(os.path.join(top_srcdir,root_plugin_dir),accumulate_plugins,plugin_list)


if not os.path.exists("config/pandora-plugin.am") or "write" in actions:
  plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am'))
  plugin_am_file.write("""
# always the current list, generated every build so keep this lean.
# pandora-plugin.list: datestamp preserved list
${srcdir}/config/pandora-plugin.list: .plugin.scan
.plugin.scan:
	@cd ${top_srcdir} && python config/pandora-plugin plugin-list

# Plugins affect configure; so to prevent configure running twice in a tarball
# build (once up front, once with the right list of plugins, we ship the
# generated list of plugins and the housekeeping material for that list so it
# is likewise not updated.
EXTRA_DIST += \
	config/pandora-plugin.am \
	config/pandora-plugin.ac \
	config/pandora-plugin


# Seed the list of plugin LDADDS which plugins may extend.
PANDORA_DYNAMIC_LDADDS=

# plugin.stamp: graph dominator for creating all per pandora-plugin.ac/am
# files. This is invoked when the code to generate such files has altered.""")

if not os.path.exists("config/pandora-plugin.ac") or "write" in actions:
  plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac'))
  plugin_ac_file.write("dnl Generated file, run make to rebuild\n")


if os.path.exists('plugin.ini'):
  # Are we in a plugin dir which wants to have a self-sufficient build system?
  plugin_list=['.']

  write_external_plugin()
else:
  plugin_list_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.list'))
  for p in plugin_list:
    plugin_list_file.write(p)
    plugin_list_file.write("\n")
  plugin_list.sort()
  plugin_list_file.close()

if not os.path.exists("config/pandora-plugin.am") or 'write' in actions:
  plugin_am_file.write("\n${top_srcdir}/config/pandora-plugin.am: ${top_srcdir}/config/pandora-plugin.list ${top_srcdir}/config/pandora-plugin ")
  for plugin_dir in plugin_list:
    plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir)
  plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n")
  for plugin_dir in plugin_list:
    write_plugin(plugin_dir)

if plugin_am_file is not None:
  plugin_am_file.close()
if plugin_ac_file is not None:
  plugin_ac_file.close()