3
# Copyright (C) 2009 Sun Microsystems
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.
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.
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
19
# Find plugins in the tree and add them to the build system
21
import os, ConfigParser, sys
25
plugin_ini_fname='plugin.ini'
27
autogen_header="This file is generated, re-run %s to rebuild\n" % sys.argv[0]
30
top_srcdir=sys.argv[1]
31
top_builddir=top_srcdir
33
top_builddir=sys.argv[2]
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)
40
def accumulate_plugins(arg, dirname, fnames):
41
if plugin_ini_fname in fnames:
45
os.path.walk(top_srcdir,accumulate_plugins,plugin_list)
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']
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
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
71
if plugin.has_key('load_by_default'):
72
plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
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"
79
plugin['default_yesno']="no"
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')
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))
91
plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
92
if plugin.has_key('build_conditional'):
93
plugin['has_build_conditional']=True
95
plugin['has_build_conditional']=False
96
plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
98
# Turn this on later plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) -DDRIZZLE_DYNAMIC_PLUGIN %(cppflags)s
101
# Write plugin build instructions into plugin.am file.
103
if plugin['headers'] != "":
104
plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
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
116
plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
117
drizzled_drizzled_LDADD+=${top_builddir}/plugin/lib%(name)s_plugin.la
120
# Add this once we're actually doing dlopen (and remove -avoid-version if
122
#pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
123
#plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) %(libs)s
125
if os.path.exists(plugin_am_file):
126
plugin_am.write('include %s\n' % plugin_am_file)
129
# Write plugin config instructions into plugin.am file.
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)
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])
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])])
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']:
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])
163
plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
165
AM_CONDITIONAL([%(build_conditional_tag)s],
166
[test %(build_conditional)s])
167
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
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"
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)):
188
os.rename('%s.new' % fname, fname)
190
os.unlink("%s.new" % fname)