wafsamba: fix generic_cc.py to work with waf 2
authorStefan Metzmacher <metze@samba.org>
Fri, 7 Sep 2018 14:27:58 +0000 (16:27 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 10 Sep 2018 17:28:15 +0000 (19:28 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
buildtools/wafsamba/generic_cc.py
buildtools/wafsamba/samba_autoconf.py

index f6f8b180f45ae6c35e267aecbe360b3aef881fdf..1352c547acf6fb9a673db1a09a706c7b84be652c 100644 (file)
@@ -3,70 +3,68 @@
 # based on suncc.py from waf
 
 import os, optparse
-from waflib import Utils, Options, Configure
+from waflib import Errors
 from waflib.Tools import ccroot, ar
-from waflib.Configure import conftest
+from waflib.Configure import conf
 
+#
+# Let waflib provide useful defaults, but
+# provide generic_cc as last resort fallback on
+# all platforms
+#
 from waflib.Tools.compiler_c import c_compiler
+for key in c_compiler.keys():
+    c_compiler[key].append('generic_cc')
 
-c_compiler['default'] = ['gcc', 'generic_cc', 'clang']
-c_compiler['freebsd'] = ['clang', 'generic_cc', 'gcc']
-c_compiler['hpux'] = ['gcc', 'generic_cc']
-
-@conftest
+@conf
 def find_generic_cc(conf):
     v = conf.env
     cc = None
-    if v['CC']: cc = v['CC']
-    elif 'CC' in conf.environ: cc = conf.environ['CC']
-    if not cc: cc = conf.find_program('cc', var='CC')
-    if not cc: conf.fatal('generic_cc was not found')
-    cc = conf.cmd_to_list(cc)
-    v['CC']  = cc
-    v['CC_NAME'] = 'generic'
-
-@conftest
-def generic_cc_common_flags(conf):
-    v = conf.env
+    if v.CC:
+        cc = v.CC
+    elif 'CC' in conf.environ:
+        cc = conf.environ['CC']
+    if not cc:
+        cc = conf.find_program('cc', var='CC')
+    if not cc:
+        conf.fatal('generic_cc was not found')
 
-    v['CC_SRC_F']            = ''
-    v['CC_TGT_F']            = ['-c', '-o', '']
-    v['CPPPATH_ST']          = '-I%s' # template for adding include paths
+    try:
+        conf.cmd_and_log(cc + ['--version'])
+    except Errors.WafError:
+        conf.fatal('%r --version could not be executed' % cc)
 
-    # linker
-    if not v['LINK_CC']: v['LINK_CC'] = v['CC']
-    v['CCLNK_SRC_F']         = ''
-    v['CCLNK_TGT_F']         = ['-o', '']
+    v.CC = cc
+    v.CC_NAME = 'generic_cc'
 
-    v['LIB_ST']              = '-l%s' # template for adding libs
-    v['LIBPATH_ST']          = '-L%s' # template for adding libpaths
-    v['STATICLIB_ST']        = '-l%s'
-    v['STATICLIBPATH_ST']    = '-L%s'
-    v['CCDEFINES_ST']        = '-D%s'
+@conf
+def generic_cc_common_flags(conf):
+    v = conf.env
 
-#    v['SONAME_ST']           = '-Wl,-h -Wl,%s'
-#    v['SHLIB_MARKER']        = '-Bdynamic'
-#    v['STATICLIB_MARKER']    = '-Bstatic'
+    v.CC_SRC_F            = ''
+    v.CC_TGT_F            = ['-c', '-o']
+    v.CPPPATH_ST          = '-I%s'
+    v.DEFINES_ST          = '-D%s'
 
-    # program
-    v['program_PATTERN']     = '%s'
+    if not v.LINK_CC:
+        v.LINK_CC = v.CC
 
-    # shared library
-#    v['shlib_CCFLAGS']       = ['-Kpic', '-DPIC']
-#    v['shlib_LINKFLAGS']     = ['-G']
-    v['shlib_PATTERN']       = 'lib%s.so'
+    v.CCLNK_SRC_F         = ''
+    v.CCLNK_TGT_F         = ['-o']
 
-    # static lib
-#    v['staticlib_LINKFLAGS'] = ['-Bstatic']
-#    v['staticlib_PATTERN']   = 'lib%s.a'
+    v.LIB_ST              = '-l%s' # template for adding libs
+    v.LIBPATH_ST          = '-L%s' # template for adding libpaths
+    v.STLIB_ST            = '-l%s'
+    v.STLIBPATH_ST        = '-L%s'
 
-detect = '''
-find_generic_cc
-find_cpp
-find_ar
-generic_cc_common_flags
-cc_load_tools
-cc_add_flags
-link_add_flags
-'''
+    v.cprogram_PATTERN    = '%s'
+    v.cshlib_PATTERN      = 'lib%s.so'
+    v.cstlib_PATTERN      = 'lib%s.a'
 
+def configure(conf):
+    conf.find_generic_cc()
+    conf.find_ar()
+    conf.generic_cc_common_flags()
+    conf.cc_load_tools()
+    conf.cc_add_flags()
+    conf.link_add_flags()
index ced824d593d07733ca3ada2259f0e8f90e17a857..5f203fc7d36adcc6985787d3b84b085a7ae66af3 100644 (file)
@@ -897,9 +897,6 @@ def CHECK_CC_ENV(conf):
     The build farm sometimes puts a space at the start"""
     if os.environ.get('CC'):
         conf.env.CC = TO_LIST(os.environ.get('CC'))
-        if len(conf.env.CC) == 1:
-            # make for nicer logs if just a single command
-            conf.env.CC = conf.env.CC[0]
 
 
 @conf