~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
21
import os, ConfigParser, sys
22
23
top_srcdir='.'
24
top_builddir='.'
25
plugin_ini_fname='plugin.ini'
26
plugin_list=[]
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
27
autogen_header="This file is generated, re-run %s to rebuild\n" % sys.argv[0]
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
28
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
29
class ChangeProtectedFile(object):
30
31
  def __init__(self, fname):
32
    self.real_fname= fname
33
    self.new_fname= "%s.new" % fname
34
    self.new_file= open(self.new_fname,'w')
35
36
  def write(self, text):
37
    self.new_file.write(text)
38
39
  # We've written all of this out into .new files, now we only copy them
40
  # over the old ones if they are different, so that we don't cause 
41
  # unnecessary recompiles
42
  def close(self):
43
    self.new_file.close()
44
    if os.system('diff %s %s >/dev/null 2>&1' % (self.new_fname,self.real_fname)):
45
      try:
46
        os.unlink(self.real_fname)
47
      except:
48
        pass
49
      os.rename(self.new_fname, self.real_fname)
50
    try:
51
      os.unlink(self.new_fname)
52
    except:
53
      pass
54
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
55
if len(sys.argv)>1:
56
  top_srcdir=sys.argv[1]
57
  top_builddir=top_srcdir
58
if len(sys.argv)>2:
59
  top_builddir=sys.argv[2]
60
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
61
plugin_ac=ChangeProtectedFile(os.path.join(top_builddir,'config','plugin.ac'))
62
plugin_am=ChangeProtectedFile(os.path.join(top_srcdir,'config','plugin.am'))
63
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
64
plugin_ac.write("dnl %s" % autogen_header)
65
plugin_am.write("# %s" % autogen_header)
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
66
plugin_am.write("PANDORA_DYNAMIC_LDADDS=\n")
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
67
68
def accumulate_plugins(arg, dirname, fnames):
69
  if plugin_ini_fname in fnames:
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
70
    arg.append(dirname)
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
71
72
997.2.8 by Monty Taylor
Fixed a few loose ends.
73
os.path.walk(os.path.join(top_srcdir,"plugin"),accumulate_plugins,plugin_list)
1022.2.41 by Monty Taylor
Ensure that the dirlist is sorted.
74
plugin_list.sort()
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
75
76
for plugin_dir in plugin_list:
77
  plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
1099.1.16 by Monty Taylor
Added support for conditionally building plugin's test suite if the plugin is built.
78
  parser=ConfigParser.ConfigParser(defaults=dict(sources="",headers="", cflags="",cppflags="",cxxflags="", libs="", ldflags="", testsuite=""))
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
79
  parser.read(plugin_file)
80
  plugin=dict(parser.items('plugin'))
992.1.22 by Monty Taylor
Moved towards having register_plugins.py make builtin plugins, so we can have a first step.
81
  plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
82
  # TODO: determine path to plugin dir relative to top_srcdir... append it
83
  # to source files if they don't already have it
992.1.35 by Monty Taylor
Added support for default sources= ... when there is only one file and it's the same name as the plugin, you don't have to say so.
84
  if plugin['sources'] == "":
85
    plugin['sources']="%s.cc" % plugin['name']
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
86
  new_sources=""
87
  for src in plugin['sources'].split():
992.1.22 by Monty Taylor
Moved towards having register_plugins.py make builtin plugins, so we can have a first step.
88
    if not src.startswith(plugin['rel_path']):
992.1.24 by Monty Taylor
Ported InnoDB to register_plugins.
89
      src= os.path.join(plugin['rel_path'], src)
90
      new_sources= "%s %s" % (new_sources, src)
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
91
  plugin['sources']= new_sources
992.1.36 by Monty Taylor
Added support for list of headers in plugin.ini. Migrated md5.
92
93
  new_headers=""
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
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
99
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
100
  if plugin.has_key('load_by_default'):
101
    plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
102
  else:
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"
107
  else:
108
    plugin['default_yesno']="no"
109
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
110
  plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
111
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
112
  plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
113
114
  plugin_m4_files=[]
115
  if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
116
    for m4_file in os.listdir(plugin_m4_dir):
117
      if os.path.splitext(m4_file)[-1] == '.m4':
118
        plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
119
120
  plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
1022.2.4 by Monty Taylor
Fixed turning off plugins.
121
  plugin['name_with_dashes']= plugin['name'].replace('_','-')
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
122
  if plugin.has_key('build_conditional'):
123
    plugin['has_build_conditional']=True
124
  else:
125
    plugin['has_build_conditional']=False
126
    plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
127
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
128
  # Turn this on later plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN %(cppflags)s
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
129
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
130
  #
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
131
  # Write plugin build instructions into plugin.am file.
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
132
  #
992.1.36 by Monty Taylor
Added support for list of headers in plugin.ini. Migrated md5.
133
  if plugin['headers'] != "":
134
    plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
135
  plugin_am.write("""
992.1.22 by Monty Taylor
Moved towards having register_plugins.py make builtin plugins, so we can have a first step.
136
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
992.1.25 by Monty Taylor
Moved myisam to new plugin system.
137
EXTRA_DIST += %(rel_path)s/plugin.ini
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
138
if %(build_conditional_tag)s
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
139
  noinst_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
992.1.24 by Monty Taylor
Ported InnoDB to register_plugins.
140
  plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
1003.2.7 by Monty Taylor
Fixed a race condition build problem that showed up on hades with make -j32.
141
  plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
992.1.24 by Monty Taylor
Ported InnoDB to register_plugins.
142
  plugin_lib%(name)s_plugin_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s
992.1.22 by Monty Taylor
Moved towards having register_plugins.py make builtin plugins, so we can have a first step.
143
  plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) %(cppflags)s
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
144
  plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
145
  plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
146
147
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
148
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/plugin/lib%(name)s_plugin.la
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
149
endif
150
""" % plugin)
151
  # Add this once we're actually doing dlopen (and remove -avoid-version if
152
  # we move to ltdl
153
  #pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
992.1.24 by Monty Taylor
Ported InnoDB to register_plugins.
154
  #plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) %(libs)s
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
155
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
156
157
  if os.path.exists(plugin_am_file):
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
158
    plugin_am.write('include %s\n' % plugin_am_file)
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
159
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
160
  #
161
  # Write plugin config instructions into plugin.am file.
162
  #
163
  plugin_ac.write("\n\ndnl Config for %(title)s\n" % plugin)
164
  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
165
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
166
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
167
  plugin_ac.write("""
1022.2.4 by Monty Taylor
Fixed turning off plugins.
168
AC_ARG_WITH([%(name_with_dashes)s-plugin],[
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
169
dnl indented werid to make the help output correct
1022.2.4 by Monty Taylor
Fixed turning off plugins.
170
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s and enable it. @<:@default=%(default_yesno)s@:>@])
171
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.
172
  ],
173
  [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.
174
  [AS_IF([test "x$ac_with_all_plugins" = "xyes"],
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
175
         [with_%(name)s_plugin=yes],
176
         [with_%(name)s_plugin=%(default_yesno)s])])
177
""" % plugin)
178
  if os.path.exists(plugin_ac_file):
179
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) 
180
  # The plugin author has specified some check to make to determine
181
  # if the plugin can be built. If the plugin is turned on and this 
182
  # check fails, then configure should error out. If the plugin is not
183
  # turned on, then the normal conditional build stuff should just let
184
  # it silently not build
185
  if plugin['has_build_conditional']:
186
    plugin_ac.write("""
997.2.5 by Monty Taylor
Merged up with trunk properly.
187
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.
188
      [], dnl build_conditional can only negate
997.2.5 by Monty Taylor
Merged up with trunk properly.
189
      [with_%(name)s_plugin=no])
190
  """ % plugin)
992.1.26 by Monty Taylor
Moved heap.
191
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
192
  plugin_ac.write("""
193
AM_CONDITIONAL([%(build_conditional_tag)s],
194
               [test %(build_conditional)s])
195
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.
196
      [
1099.1.16 by Monty Taylor
Added support for conditionally building plugin's test suite if the plugin is built.
197
  """ % plugin)
198
  if plugin['testsuite'] != "":
199
    plugin_ac.write("""
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
200
        pandora_plugin_test_list="%(testsuite)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.
201
    """ % plugin)
202
203
  plugin_ac.write("""
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
204
        pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
205
        pandora_builtin_list="builtin_%(name)s_plugin,${pandora_builtin_list}"
206
        pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/plugin/lib%(name)s_plugin.la"
207
	PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
992.1.22 by Monty Taylor
Moved towards having register_plugins.py make builtin plugins, so we can have a first step.
208
      ])
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
209
""" % plugin)
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
210
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
211
plugin_ac.close()
212
plugin_am.close()
213