Add include/lib folders from the commandline
authorThomas Nagy <tnagy2pow10@gmail.com>
Thu, 17 May 2012 12:49:08 +0000 (14:49 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 18 May 2012 05:44:43 +0000 (15:44 +1000)
By using opt.add_option(..., match=['Checking for library iconv'], dest='iconvdir'),
all configuration tests displaying 'Checking for library iconv' will get
$(iconvdir)/lib and $(iconvdir)/include

buildtools/wafsamba/samba_conftests.py
buildtools/wafsamba/wscript

index 1838b57c9635f068e4b53338d99c5a8dc853636f..3605e33f08b564b2b6d40cccccdc9ac5e22a5027 100644 (file)
@@ -1,10 +1,75 @@
 # a set of config tests that use the samba_autoconf functions
 # to test for commonly needed configuration options
 
-import os, Build, shutil, Utils, re
+import os, shutil, re
+import Build, Configure, Utils
 from Configure import conf
 from samba_utils import *
 
+
+def add_option(self, *k, **kw):
+    '''syntax help: provide the "match" attribute to opt.add_option() so that folders can be added to specific config tests'''
+    match = kw.get('match', [])
+    if match:
+        del kw['match']
+    opt = self.parser.add_option(*k, **kw)
+    opt.match = match
+    return opt
+Options.Handler.add_option = add_option
+
+@conf
+def check(self, *k, **kw):
+    '''Override the waf defaults to inject --with-directory options'''
+
+    if not 'env' in kw:
+        kw['env'] = self.env.copy()
+
+    # match the configuration test with speficic options, for example:
+    # --with-libiconv -> Options.options.iconv_open -> "Checking for library iconv"
+    additional_dirs = []
+    if 'msg' in kw:
+        msg = kw['msg']
+        for x in Options.Handler.parser.parser.option_list:
+             if getattr(x, 'match', None) and msg in x.match:
+                 d = getattr(Options.options, x.dest, '')
+                 if d:
+                     additional_dirs.append(d)
+
+    # we add the additional dirs twice: once for the test data, and again if the compilation test suceeds below
+    def add_options_dir(dirs, env):
+        for x in dirs:
+             if not x in env.CPPPATH:
+                 env.CPPPATH = [os.path.join(x, 'include')] + env.CPPPATH
+             if not x in env.LIBPATH:
+                 env.LIBPATH = [os.path.join(x, 'lib')] + env.LIBPATH
+
+    add_options_dir(additional_dirs, kw['env'])
+
+    self.validate_c(kw)
+    self.check_message_1(kw['msg'])
+    ret = None
+    try:
+        ret = self.run_c_code(*k, **kw)
+    except Configure.ConfigurationError, e:
+        self.check_message_2(kw['errmsg'], 'YELLOW')
+        if 'mandatory' in kw and kw['mandatory']:
+            if Logs.verbose > 1:
+                raise
+            else:
+                self.fatal('the configuration failed (see %r)' % self.log.name)
+    else:
+        kw['success'] = ret
+        self.check_message_2(self.ret_msg(kw['okmsg'], kw))
+
+        # success! keep the CPPPATH/LIBPATH
+        add_options_dir(additional_dirs, self.env)
+
+    self.post_check(*k, **kw)
+    if not kw.get('execute', False):
+        return ret == 0
+    return ret
+
+
 @conf
 def CHECK_ICONV(conf, define='HAVE_NATIVE_ICONV'):
     '''check if the iconv library is installed
index 4db341202ee48be8ac521a6295d83d20ee341343..7bbec946c5b56ddbb796eb4fed2b7d459e722637 100755 (executable)
@@ -77,6 +77,11 @@ def set_options(opt):
                    help=("private library directory [PREFIX/lib/%s]" % Utils.g_module.APPNAME),
                    action="store", dest='PRIVATELIBDIR', default=None)
 
+    opt.add_option('--with-libiconv',
+                   help='installation directory for libiconv',
+                   action='store', dest='iconv_open', default=None,
+                   match = ['Checking for library iconv', 'Checking for iconv_open', 'Checking for header iconv.h'])
+
     gr = opt.option_group('developer options')
 
     gr.add_option('-C',