~drizzle-trunk/drizzle/development

992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
1
#!/usr/bin/python
2
992.1.25 by Monty Taylor
Moved myisam to new plugin system.
3
#  Copyright (C) 2009 Sun Microsystems
4
#
5
#  This program is free software; you can redistribute it and/or modify
6
#  it under the terms of the GNU General Public License as published by
7
#  the Free Software Foundation; version 2 of the License.
8
#
9
#  This program is distributed in the hope that it will be useful,
10
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#  GNU General Public License for more details.
13
#
14
#  You should have received a copy of the GNU General Public License
15
#  along with this program; if not, write to the Free Software
16
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
19
# Find plugins in the tree and add them to the build system 
20
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
21
import ConfigParser, os, sys
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
22
import datetime, time
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
23
24
top_srcdir='.'
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
25
top_builddir='.'
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
26
plugin_ini_fname='plugin.ini'
27
plugin_list=[]
1192.3.25 by Monty Taylor
It seems to work.
28
plugin_am_file=None
29
plugin_ac_file=None
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
30
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
31
class ChangeProtectedFile(object):
32
33
  def __init__(self, fname):
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
34
    self.bogus_file= False
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
35
    self.real_fname= fname
36
    self.new_fname= "%s.new" % fname
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
37
    try:
38
      self.new_file= open(self.new_fname,'w+')
39
    except IOError:
40
      self.bogus_file= True
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
41
42
  def write(self, text):
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
43
    if not self.bogus_file:
44
      self.new_file.write(text)
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
45
46
  # We've written all of this out into .new files, now we only copy them
47
  # over the old ones if they are different, so that we don't cause 
48
  # unnecessary recompiles
49
  def close(self):
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
50
    """Return True if the file had changed."""
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
51
    if self.bogus_file:
52
      return
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
53
    self.new_file.seek(0)
54
    new_content = self.new_file.read()
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
55
    self.new_file.close()
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
56
    try:
57
        old_file = file(self.real_fname, 'r')
58
        old_content = old_file.read()
59
        old_file.close()
60
    except IOError:
61
        old_content = None
62
    if new_content != old_content:
63
      if old_content != None:
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
64
        os.unlink(self.real_fname)
65
      os.rename(self.new_fname, self.real_fname)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
66
      return True
67
    else:
68
        try:
69
          os.unlink(self.new_fname)
70
        except:
71
          pass
72
73
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
74
def write_external_configure(plugin, plugin_file):
75
  """Write the initial bits of the configure.ac file"""
76
  if not os.path.exists('m4'):
77
    os.mkdir('m4')
78
  plugin_file.write("""
79
AC_PREREQ(2.59)dnl		Minimum Autoconf version required.
80
AC_INIT([%(name)s],[%(version)s],[%(url)s])
81
AC_CONFIG_SRCDIR([%(main_source)s])
82
AC_CONFIG_AUX_DIR(config)
83
AC_CONFIG_HEADERS([config.h])
84
AC_CONFIG_MACRO_DIR([m4])
85
1241.9.5 by Monty Taylor
Fixed the plugin script to not bork plugin visibility.
86
PANDORA_CANONICAL_TARGET(less-warnings, warnings-always-on, require-cxx, force-gcc42,skip-visibility)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
87
88
PANDORA_REQUIRE_LIBPROTOBUF
89
PANDORA_PROTOBUF_REQUIRE_VERSION([2.1.0])
90
PANDORA_REQUIRE_PROTOC
91
92
AC_LANG_PUSH(C++)
93
PANDORA_REQUIRE_PTHREAD
94
PANDORA_REQUIRE_LIBDL
95
AC_LANG_POP
96
97
PANDORA_USE_BETTER_MALLOC
98
99
PANDORA_DRIZZLE_BUILD
100
""" % plugin)
101
102
  write_plugin_ac(plugin, plugin_file)
103
104
  plugin_file.write("""
105
AC_CONFIG_FILES(Makefile)
106
107
AC_OUTPUT
108
109
echo "---"
110
echo "Configuration summary for $PACKAGE_NAME version $VERSION $PANDORA_RELEASE_COMMENT"
111
echo ""
112
echo "   * Installation prefix:       $prefix"
113
echo "   * System type:               $host_vendor-$host_os"
114
echo "   * Host CPU:                  $host_cpu"
115
echo "   * C Compiler:                $CC_VERSION"
116
echo "   * C++ Compiler:              $CXX_VERSION"
117
echo "   * Debug enabled:             $with_debug"
118
echo "   * Warnings as failure:       $ac_cv_warnings_as_errors"
119
echo "   * C++ cstdint location:      $ac_cv_cxx_cstdint"
120
echo "   * C++ hash_map location:     $ac_cv_cxx_hash_map"
121
echo "   * C++ hash namespace:        $ac_cv_cxx_hash_namespace"
122
echo "   * C++ shared_ptr namespace:  $ac_cv_shared_ptr_namespace"
123
echo ""
124
echo "---"
125
126
  """ % plugin)
127
128
def write_external_makefile(plugin, plugin_file):
129
130
  plugin_file.write("""
131
ACLOCAL_AMFLAGS = -I m4 --force
132
VERSION=$(PANDORA_RELEASE_VERSION)
133
134
pkgplugindir=$(libdir)/drizzle/plugin
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
135
EXTRA_DIST = plugin.ini
1192.3.53 by Robert Collins
Build fixes from Robert.
136
137
""" % plugin)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
138
  if plugin['headers'] != "":
139
    plugin_file.write("noinst_HEADERS = %(headers)s\n" % plugin)
140
  if plugin['testsuite']:
141
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
142
      plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
143
  plugin_file.write("""
144
pkgplugin_LTLIBRARIES=lib%(name)s_plugin.la
1192.3.77 by Monty Taylor
Fixed dynamic loading with lcov and gprof.
145
lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
146
lib%(name)s_plugin_la_LIBADD=%(libs)s
147
lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
148
lib%(name)s_plugin_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
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
149
lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
150
lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
151
152
lib%(name)s_plugin_la_SOURCES=%(sources)s
1192.3.53 by Robert Collins
Build fixes from Robert.
153
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
154
""" % plugin)
155
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
156
  if os.path.exists(plugin_am_file):
157
    plugin_file.write('include %s\n' % plugin_am_file)
158
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
159
def write_external_plugin():
160
  """Return True if the plugin had changed."""
161
  plugin = read_plugin_ini('.')
162
  expand_plugin_ini(plugin, '.')
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
163
  plugin_file = ChangeProtectedFile('configure.ac')
164
  write_external_configure(plugin, plugin_file)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
165
  result = plugin_file.close()
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
166
  plugin_file = ChangeProtectedFile('Makefile.am')
167
  write_external_makefile(plugin, plugin_file)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
168
  # Write some stub configure.ac and Makefile.am files that include the above
169
  result = plugin_file.close() or result
170
  return result
171
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
172
def write_plugin(plugin_dir):
173
  """Return True if the plugin had changed."""
174
  plugin = read_plugin_ini(plugin_dir)
175
  expand_plugin_ini(plugin, plugin_dir)
1192.3.25 by Monty Taylor
It seems to work.
176
  write_plugin_ac(plugin, plugin_ac_file)
177
  write_plugin_am(plugin, plugin_am_file)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
178
179
def write_plugin_ac(plugin, plugin_ac):
180
  #
181
  # Write plugin config instructions into plugin.ac file.
182
  #
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
183
  plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
184
  plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
185
  plugin_m4_files=[]
186
  if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
187
    for m4_file in os.listdir(plugin_m4_dir):
188
      if os.path.splitext(m4_file)[-1] == '.m4':
189
        plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
1192.3.25 by Monty Taylor
It seems to work.
190
  plugin_ac.write("""
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
191
dnl Config for %(title)s
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
192
""" % plugin)
193
  for m4_file in plugin_m4_files:
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
194
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
195
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
196
  plugin_ac.write("""
1022.2.4 by Monty Taylor
Fixed turning off plugins.
197
AC_ARG_WITH([%(name_with_dashes)s-plugin],[
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
198
dnl indented werid to make the help output correct
1022.2.4 by Monty Taylor
Fixed turning off plugins.
199
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s and enable it. @<:@default=%(default_yesno)s@:>@])
200
AS_HELP_STRING([--without-%(name_with_dashes)s-plugin],[Disable building %(title)s])
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
201
  ],
202
  [with_%(name)s_plugin="$withval"],
1166.1.1 by Monty Taylor
Fixed an accidental logic error that caused any plugin which was availble to be built to be automatically enabled/builtin.
203
  [AS_IF([test "x$ac_with_all_plugins" = "xyes"],
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
204
         [with_%(name)s_plugin=yes],
205
         [with_%(name)s_plugin=%(default_yesno)s])])
206
""" % plugin)
207
  if os.path.exists(plugin_ac_file):
208
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) 
209
  # The plugin author has specified some check to make to determine
210
  # if the plugin can be built. If the plugin is turned on and this 
211
  # check fails, then configure should error out. If the plugin is not
212
  # turned on, then the normal conditional build stuff should just let
213
  # it silently not build
214
  if plugin['has_build_conditional']:
215
    plugin_ac.write("""
997.2.5 by Monty Taylor
Merged up with trunk properly.
216
AS_IF([test %(build_conditional)s],
1166.1.1 by Monty Taylor
Fixed an accidental logic error that caused any plugin which was availble to be built to be automatically enabled/builtin.
217
      [], dnl build_conditional can only negate
997.2.5 by Monty Taylor
Merged up with trunk properly.
218
      [with_%(name)s_plugin=no])
1192.3.53 by Robert Collins
Build fixes from Robert.
219
220
""" % plugin)
992.1.26 by Monty Taylor
Moved heap.
221
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
222
  if not plugin['unconditional']:
223
    plugin_ac.write("""
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
224
AM_CONDITIONAL([%(build_conditional_tag)s],
225
               [test %(build_conditional)s])
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
226
    """ % plugin)
227
  plugin_ac.write("""
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
228
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
992.1.22 by Monty Taylor
Moved towards having register_plugins.py make builtin plugins, so we can have a first step.
229
      [
1192.3.53 by Robert Collins
Build fixes from Robert.
230
""" % plugin)
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
231
  if plugin['testsuite']:
1099.1.16 by Monty Taylor
Added support for conditionally building plugin's test suite if the plugin is built.
232
    plugin_ac.write("""
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
233
        pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
1099.1.16 by Monty Taylor
Added support for conditionally building plugin's test suite if the plugin is built.
234
    """ % plugin)
235
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
236
  if plugin['static']:
237
    #pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
238
    plugin_ac.write("""
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
239
        pandora_builtin_list="_drizzled_%(name)s_plugin_,${pandora_builtin_list}"
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
240
        pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/plugin/lib%(name)s_plugin.la"
241
	PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
242
""" % plugin)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
243
  else:
244
    plugin_ac.write("""
245
        pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
246
    """ % plugin)
247
  plugin_ac.write("      ])\n")
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
248
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
249
250
def expand_plugin_ini(plugin, plugin_dir):
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
251
    if plugin_dir == ".":
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
252
      plugin['rel_path']= plugin_dir
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
253
      plugin['unconditional']=True
254
    else:
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
255
      plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
256
      plugin['unconditional']=False
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
257
    # TODO: determine path to plugin dir relative to top_srcdir... append it to
258
    # source files if they don't already have it
259
    if plugin['sources'] == "":
260
      plugin['sources']="%s.cc" % plugin['name']
261
    new_sources=""
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
262
    if plugin_dir != ".":
263
      for src in plugin['sources'].split():
264
        if not src.startswith(plugin['rel_path']):
265
          src= os.path.join(plugin['rel_path'], src)
266
          new_sources= "%s %s" % (new_sources, src)
267
      if new_sources != "":
268
        plugin['sources']= new_sources
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
269
    plugin['main_source']= plugin['sources'].split()[0]
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
270
    
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
271
    if plugin_dir != ".":
272
      new_headers=""
273
      for header in plugin['headers'].split():
274
        if not header.startswith(plugin['rel_path']):
275
          header= os.path.join(plugin['rel_path'], header)
276
          new_headers= "%s %s" % (new_headers, header)
277
      plugin['headers']= new_headers
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
278
    
279
    # Make a yes/no version for autoconf help messages
280
    if plugin['load_by_default']:
281
      plugin['default_yesno']="yes"
282
    else:
283
      plugin['default_yesno']="no"
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
284
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
285
    
286
    plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
287
    plugin['name_with_dashes']= plugin['name'].replace('_','-')
288
    if plugin.has_key('build_conditional'):
289
      plugin['has_build_conditional']=True
290
    else:
291
      plugin['has_build_conditional']=False
292
      plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
293
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
294
def find_testsuite(plugin_dir):
295
  for testdir in ['drizzle-tests','tests']:
296
    if os.path.isdir(os.path.join(plugin_dir,testdir)):
297
      return testdir
298
  if os.path.isdir(os.path.join('tests','suite',os.path.basename(plugin_dir))):
299
    return ""
300
  return None
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
301
302
def read_plugin_ini(plugin_dir):
303
    plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
304
    plugin_defaults= dict(sources="",
305
                          headers="",
306
                          cflags="",
307
                          cppflags="",
308
                          cxxflags="",
309
                          libs="",
310
                          ldflags="",
311
                          author="",
312
                          title="",
313
                          description="",
314
                          license="PLUGIN_LICENSE_GPL",
315
                          name=os.path.basename(plugin_dir),
316
                          load_by_default="False",
317
                          static="False")
318
    parser=ConfigParser.ConfigParser(defaults= plugin_defaults)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
319
    parser.read(plugin_file)
320
    plugin=dict(parser.items('plugin'))
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
321
    if plugin_dir == '.':
322
      if not plugin.has_key('url'):
323
        print "External Plugins are required to specifiy a url"
324
        plugin['url']= 'http://launchpad.net/%(name)s' % plugin
325
        sys.exit(1)
326
      if plugin_dir == '.' and not plugin.has_key('version'):
327
        print "External Plugins are required to specifiy a version"
328
        sys.exit(1)
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
329
    if not plugin.has_key('version'):
330
      plugin['version']=datetime.date.fromtimestamp(time.time()).isoformat()
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
331
   
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
332
    if plugin.has_key('load_by_default'):
333
      plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
334
    if plugin.has_key('static'):
335
      plugin['static']= parser.getboolean('plugin','static')
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
336
    if plugin.has_key('testsuite'):
337
      if plugin['testsuite'] == 'disable':
338
        plugin['testsuite']= False
339
    else:
340
      plugin_testsuite= find_testsuite(plugin_dir)
341
      plugin['testsuitedir']=plugin_testsuite
342
      if plugin_testsuite is not None:
343
        plugin['testsuite']=True
344
      else:
345
        plugin['testsuite']=False
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
346
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
347
    return plugin
348
349
350
def write_plugin_am(plugin, plugin_am):
351
  """Write an automake fragment for this plugin.
352
  
353
  :param plugin: The plugin dict.
354
  :param plugin_am: The file to write to.
355
  """
356
  # The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can
357
  # confuse VCS systems.
1192.3.25 by Monty Taylor
It seems to work.
358
  plugin_am.write("""
359
EXTRA_DIST += %(rel_path)s/plugin.ini
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
360
361
# Prevent errors when a plugin dir is removed
362
%(rel_path)s/plugin.ini:
1192.3.53 by Robert Collins
Build fixes from Robert.
363
364
""" % plugin)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
365
  if plugin['headers'] != "":
366
    plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
367
  if plugin['testsuite']:
368
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
369
      plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
370
  if plugin['static']:
371
    plugin_am.write("""
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
372
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
373
EXTRA_DIST += %(rel_path)s/plugin.ini
374
if %(build_conditional_tag)s
375
  noinst_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
376
  plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
377
  plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
1192.3.77 by Monty Taylor
Fixed dynamic loading with lcov and gprof.
378
  plugin_lib%(name)s_plugin_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)  
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
379
  plugin_lib%(name)s_plugin_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
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
380
  plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
381
  plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
382
383
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
384
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/plugin/lib%(name)s_plugin.la
385
endif
386
""" % plugin)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
387
  else:
388
    plugin_am.write("""
389
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
390
EXTRA_DIST += %(rel_path)s/plugin.ini
391
if %(build_conditional_tag)s
392
  pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
1192.3.77 by Monty Taylor
Fixed dynamic loading with lcov and gprof.
393
  plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
394
  plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
395
  plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
396
  plugin_lib%(name)s_plugin_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
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
397
  plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
398
  plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
399
400
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
401
endif
402
""" % plugin)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
403
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
404
  if os.path.exists(plugin_am_file):
405
    plugin_am.write('include %s\n' % plugin_am_file)
406
1192.3.25 by Monty Taylor
It seems to work.
407
#MAIN STARTS HERE:
408
409
actions=[]
410
for arg in sys.argv:
411
  if arg.startswith('--top_srcdir='):
412
    top_srcdir=arg[12:]
413
  elif arg.startswith('--top_builddir='):
414
    top_builddir=arg[14:]
415
  elif arg == "--force-all":
416
    actions=['plugin-list','pandora-plugin.am','write']
417
    break
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
418
  else:
1192.3.25 by Monty Taylor
It seems to work.
419
    actions.append(arg)
420
if len(actions) == 0:
421
  actions.append('write')
422
423
def accumulate_plugins(arg, dirname, fnames):
424
  # plugin_ini_fname is a name in dirname indicating dirname is a plugin.
425
  if plugin_ini_fname in fnames:
426
    arg.append(dirname)
427
os.path.walk(os.path.join(top_srcdir,"plugin"),accumulate_plugins,plugin_list)
428
429
430
if not os.path.exists("config/pandora-plugin.am") or "write" in actions:
431
  plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am'))
432
  plugin_am_file.write("""
433
# always the current list, generated every build so keep this lean.
1192.3.74 by Robert Collins
Finish the renaming of plugin.list -> pandora-plugin.list that mtaylor started.
434
# pandora-plugin.list: datestamp preserved list
435
${srcdir}/config/pandora-plugin.list: .plugin.scan
1192.3.25 by Monty Taylor
It seems to work.
436
.plugin.scan:
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
437
	@cd ${top_srcdir} && python config/pandora-plugin plugin-list
1192.3.25 by Monty Taylor
It seems to work.
438
439
# Plugins affect configure; so to prevent configure running twice in a tarball
440
# build (once up front, once with the right list of plugins, we ship the
441
# generated list of plugins and the housekeeping material for that list so it
442
# is likewise not updated.
443
EXTRA_DIST += \
444
	config/pandora-plugin.am \
445
	config/pandora-plugin.ac \
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
446
	config/pandora-plugin
1192.3.25 by Monty Taylor
It seems to work.
447
448
449
# Seed the list of plugin LDADDS which plugins may extend.
450
PANDORA_DYNAMIC_LDADDS=
451
452
# plugin.stamp: graph dominator for creating all per pandora-plugin.ac/am
453
# files. This is invoked when the code to generate such files has altered.""")
454
455
if not os.path.exists("config/pandora-plugin.ac") or "write" in actions:
456
  plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac'))
457
  plugin_ac_file.write("dnl Generated file, run make to rebuild\n")
458
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
459
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
460
if os.path.exists('plugin.ini'):
461
  # Are we in a plugin dir which wants to have a self-sufficient build system?
1192.3.25 by Monty Taylor
It seems to work.
462
  plugin_list=['.']
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
463
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
464
  write_external_plugin()
465
else:
1192.3.25 by Monty Taylor
It seems to work.
466
  plugin_list_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.list'))
467
  for p in plugin_list:
468
    plugin_list_file.write(p)
469
    plugin_list_file.write("\n")
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
470
  plugin_list.sort()
1192.3.25 by Monty Taylor
It seems to work.
471
  plugin_list_file.close()
472
473
if not os.path.exists("config/pandora-plugin.am") or 'write' in actions:
1192.3.74 by Robert Collins
Finish the renaming of plugin.list -> pandora-plugin.list that mtaylor started.
474
  plugin_am_file.write("\n${top_srcdir}/config/pandora-plugin.am: ${top_srcdir}/config/pandora-plugin.list ${top_srcdir}/config/pandora-plugin ")
1192.3.25 by Monty Taylor
It seems to work.
475
  for plugin_dir in plugin_list:
476
    plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
477
  plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n")
1192.3.25 by Monty Taylor
It seems to work.
478
  for plugin_dir in plugin_list:
479
    write_plugin(plugin_dir)
480
481
if plugin_am_file is not None:
482
  plugin_am_file.close()
483
if plugin_ac_file is not None:
484
  plugin_ac_file.close()