~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to config/register_plugins.py

Merged up with trunk properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
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
 
 
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=[]
 
27
autogen_header="This file is generated, re-run %s to rebuild\n" % sys.argv[0]
 
28
 
 
29
if len(sys.argv)>1:
 
30
  top_srcdir=sys.argv[1]
 
31
  top_builddir=top_srcdir
 
32
if len(sys.argv)>2:
 
33
  top_builddir=sys.argv[2]
 
34
 
 
35
plugin_ac=open(os.path.join(top_builddir,'config','plugin.ac.new'),'w')
 
36
plugin_am=open(os.path.join(top_srcdir,'config','plugin.am.new'),'w')
 
37
plugin_ac.write("dnl %s" % autogen_header)
 
38
plugin_am.write("# %s" % autogen_header)
 
39
 
 
40
def accumulate_plugins(arg, dirname, fnames):
 
41
  if plugin_ini_fname in fnames:
 
42
    arg.append(dirname)
 
43
 
 
44
 
 
45
os.path.walk(top_srcdir,accumulate_plugins,plugin_list)
 
46
 
 
47
for plugin_dir in plugin_list:
 
48
  plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
 
49
  parser=ConfigParser.ConfigParser(defaults=dict(sources="",headers="", cflags="",cppflags="",cxxflags="", libs="", ldflags=""))
 
50
  parser.read(plugin_file)
 
51
  plugin=dict(parser.items('plugin'))
 
52
  plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
 
53
  # TODO: determine path to plugin dir relative to top_srcdir... append it
 
54
  # to source files if they don't already have it
 
55
  if plugin['sources'] == "":
 
56
    plugin['sources']="%s.cc" % plugin['name']
 
57
  new_sources=""
 
58
  for src in plugin['sources'].split():
 
59
    if not src.startswith(plugin['rel_path']):
 
60
      src= os.path.join(plugin['rel_path'], src)
 
61
      new_sources= "%s %s" % (new_sources, src)
 
62
  plugin['sources']= new_sources
 
63
 
 
64
  new_headers=""
 
65
  for header in plugin['headers'].split():
 
66
    if not header.startswith(plugin['rel_path']):
 
67
      header= os.path.join(plugin['rel_path'], header)
 
68
      new_headers= "%s %s" % (new_headers, header)
 
69
  plugin['headers']= new_headers
 
70
  
 
71
  if plugin.has_key('load_by_default'):
 
72
    plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
 
73
  else:
 
74
    plugin['load_by_default']=False
 
75
  # Make a yes/no version for autoconf help messages
 
76
  if plugin['load_by_default']:
 
77
    plugin['default_yesno']="yes"
 
78
  else:
 
79
    plugin['default_yesno']="no"
 
80
 
 
81
  plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
 
82
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
 
83
  plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
 
84
 
 
85
  plugin_m4_files=[]
 
86
  if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
 
87
    for m4_file in os.listdir(plugin_m4_dir):
 
88
      if os.path.splitext(m4_file)[-1] == '.m4':
 
89
        plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
 
90
 
 
91
  plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
 
92
  if plugin.has_key('build_conditional'):
 
93
    plugin['has_build_conditional']=True
 
94
  else:
 
95
    plugin['has_build_conditional']=False
 
96
    plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
 
97
 
 
98
  # Turn this on later plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) -DDRIZZLE_DYNAMIC_PLUGIN %(cppflags)s
 
99
 
 
100
  #
 
101
  # Write plugin build instructions into plugin.am file.
 
102
  #
 
103
  if plugin['headers'] != "":
 
104
    plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
 
105
  plugin_am.write("""
 
106
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
 
107
EXTRA_DIST += %(rel_path)s/plugin.ini
 
108
if %(build_conditional_tag)s
 
109
  noinst_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
 
110
  plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
 
111
  plugin_lib%(name)s_plugin_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s
 
112
  plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) %(cppflags)s
 
113
  plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
 
114
  plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
 
115
 
 
116
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
 
117
  drizzled_drizzled_LDADD+=${top_builddir}/plugin/lib%(name)s_plugin.la
 
118
endif
 
119
""" % plugin)
 
120
  # Add this once we're actually doing dlopen (and remove -avoid-version if
 
121
  # we move to ltdl
 
122
  #pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
 
123
  #plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) %(libs)s
 
124
 
 
125
  if os.path.exists(plugin_am_file):
 
126
    plugin_am.write('include %s\n' % plugin_am_file) 
 
127
 
 
128
  #
 
129
  # Write plugin config instructions into plugin.am file.
 
130
  #
 
131
  plugin_ac.write("\n\ndnl Config for %(title)s\n" % plugin)
 
132
  for m4_file in plugin_m4_files:
 
133
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file) 
 
134
 
 
135
  plugin_ac.write("""
 
136
AC_ARG_WITH([plugin-%(name)s],[
 
137
dnl indented werid to make the help output correct
 
138
AS_HELP_STRING([--with-%(name)s-plugin],[Build %(title)s and enable it. @<:@default=%(default_yesno)s@:>@])
 
139
AS_HELP_STRING([--without-%(name)s-plugin],[Disable building %(title)s])
 
140
  ],
 
141
  [with_%(name)s_plugin="$withval"],
 
142
  [AS_IF([test "x$ac_with_all_plugins" = "yes"],
 
143
         [with_%(name)s_plugin=yes],
 
144
         [with_%(name)s_plugin=%(default_yesno)s])])
 
145
""" % plugin)
 
146
  if os.path.exists(plugin_ac_file):
 
147
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) 
 
148
  # The plugin author has specified some check to make to determine
 
149
  # if the plugin can be built. If the plugin is turned on and this 
 
150
  # check fails, then configure should error out. If the plugin is not
 
151
  # turned on, then the normal conditional build stuff should just let
 
152
  # it silently not build
 
153
  if plugin['has_build_conditional']:
 
154
    plugin_ac.write("""
 
155
AS_IF([test  %(build_conditional)s || "x$with_%(name)s_plugin" = "xyes"],
 
156
      AS_IF([test %(build_conditional)s],
 
157
            [with_%(name)s_plugin=yes],
 
158
            [AC_MSG_ERROR([Build prerequisites not found for %(title)s, yet it was slated to be enabled by default. Aborting!])]))
 
159
AS_IF([test %(build_conditional)s],
 
160
      [with_%(name)s_plugin=yes],
 
161
      [with_%(name)s_plugin=no])
 
162
  """ % plugin)
 
163
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
 
164
  plugin_ac.write("""
 
165
AM_CONDITIONAL([%(build_conditional_tag)s],
 
166
               [test %(build_conditional)s])
 
167
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
 
168
      [
 
169
        drizzled_default_plugin_list="%(name)s,${drizzled_default_plugin_list}"
 
170
        drizzled_builtin_list="builtin_%(name)s_plugin,${drizzled_builtin_list}"
 
171
        DRIZZLED_PLUGIN_DEP_LIBS="${DRIZZLED_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
 
172
      ])
 
173
""" % plugin)
 
174
 
 
175
plugin_ac.close()
 
176
plugin_am.close()
 
177
 
 
178
# We've written all of this out into .new files, now we only copy them
 
179
# over the old ones if they are different, so that we don't cause 
 
180
# unnecessary recompiles
 
181
for f in ('plugin.ac','plugin.am'):
 
182
  fname= os.path.join(top_builddir,'config',f)
 
183
  if os.system('diff %s.new %s >/dev/null 2>&1' % (fname,fname)):
 
184
    try:
 
185
      os.unlink(fname)
 
186
    except:
 
187
      pass
 
188
    os.rename('%s.new' % fname, fname)
 
189
  try:
 
190
    os.unlink("%s.new" % fname)
 
191
  except:
 
192
    pass