~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
#!/usr/bin/python

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

import os, ConfigParser, sys

top_srcdir='.'
top_builddir='.'
plugin_ini_fname='plugin.ini'
plugin_list=[]
autogen_header="This file is generated, re-run %s to rebuild\n" % sys.argv[0]

if len(sys.argv)>1:
  top_srcdir=sys.argv[1]
  top_builddir=top_srcdir
if len(sys.argv)>2:
  top_builddir=sys.argv[2]

plugin_ac=open(os.path.join(top_builddir,'config','plugin.ac.new'),'w')
plugin_am=open(os.path.join(top_srcdir,'config','plugin.am.new'),'w')
plugin_ac.write("dnl %s" % autogen_header)
plugin_am.write("# %s" % autogen_header)

def accumulate_plugins(arg, dirname, fnames):
  if plugin_ini_fname in fnames:
    arg.append(dirname)


os.path.walk(top_srcdir,accumulate_plugins,plugin_list)

for plugin_dir in plugin_list:
  plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
  parser=ConfigParser.ConfigParser(defaults=dict(sources="",cflags="",cppflags="",cxxflags="", libs="", ldflags=""))
  parser.read(plugin_file)
  plugin=dict(parser.items('plugin'))
  plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
  # TODO: determine path to plugin dir relative to top_srcdir... append it
  # to source files if they don't already have it
  new_sources=""
  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)
  plugin['sources']= new_sources
  
  if plugin.has_key('load_by_default'):
    plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
  else:
    plugin['load_by_default']=False
  # Make a yes/no version for autoconf help messages
  if plugin['load_by_default']:
    plugin['default_yesno']="yes"
  else:
    plugin['default_yesno']="no"

  plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
  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['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
  if plugin.has_key('build_conditional'):
    plugin['has_build_conditional']=True
  else:
    plugin['has_build_conditional']=False
    plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin

  # Turn this on later plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) -DDRIZZLE_DYNAMIC_PLUGIN %(cppflags)s

  #
  # Write plugin build instructions into plugin.am file.
  #
  plugin_am.write("""
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
if %(build_conditional_tag)s
  noinst_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
  plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
  plugin_lib%(name)s_plugin_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s
  plugin_lib%(name)s_plugin_la_CPPFLAGS=$(AM_CPPFLAGS) %(cppflags)s
  plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
  plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s

  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
endif
""" % plugin)
  # Add this once we're actually doing dlopen (and remove -avoid-version if
  # we move to ltdl
  #pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
  #plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) %(libs)s
  # Add this and remove $drizzled_plugin_libs once drizzled is built from .
  #drizzled_drizzled_LDADD+=${top_builddir}/plugin/lib%(name)s_plugin.la

  if os.path.exists(plugin_am_file):
    plugin_am.write('include %s\n' % plugin_am_file) 

  #
  # Write plugin config instructions into plugin.am file.
  #
  plugin_ac.write("\n\ndnl Config for %(title)s\n" % plugin)
  for m4_file in plugin_m4_files:
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file) 

  plugin_ac.write("""
AC_ARG_WITH([plugin-%(name)s],[
dnl indented werid to make the help output correct
AS_HELP_STRING([--with-%(name)s-plugin],[Build %(title)s and enable it. @<:@default=%(default_yesno)s@:>@])
AS_HELP_STRING([--without-%(name)s-plugin],[Disable building %(title)s])
  ],
  [with_%(name)s_plugin="$withval"],
  [AS_IF([test "x$ac_with_all_plugins" = "yes"],
         [with_%(name)s_plugin=yes],
         [with_%(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 "x$with_%(name)s_plugin" = "xyes" -a !%(build_conditional)s],
      [Build prerequisites not found for %(title)s, yet it was slated to be enabled by default. Aborting!])""" % plugin)
  plugin_ac.write("""
AM_CONDITIONAL([%(build_conditional_tag)s],
               [test %(build_conditional)s])
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
      [
        drizzled_default_plugin_list="%(name)s,${drizzled_default_plugin_list}"
        drizzled_builtin_list="builtin_%(name)s_plugin,${drizzled_builtin_list}"
        drizzled_plugin_libs="${drizzled_plugin_libs} \${top_builddir}/plugin/lib%(name)s_plugin.la"
	DRIZZLED_PLUGIN_DEP_LIBS="${DRIZZLED_PLUGIN_DEP_LIBS} %(libs)s"
      ])
""" % plugin)
 
plugin_ac.close()
plugin_am.close()

# 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
for f in ('plugin.ac','plugin.am'):
  fname= os.path.join(top_builddir,'config',f)
  if os.system('diff %s.new %s >/dev/null 2>&1' % (fname,fname)):
    try:
      os.unlink(fname)
    except:
      pass
    os.rename('%s.new' % fname, fname)
  try:
    os.unlink("%s.new" % fname)
  except:
    pass