build: throw a fatal error for duplicate target declarations
[samba.git] / buildtools / wafsamba / wafsamba.py
index 63d657f3709c3e505a414012b52f0192b11c4a72..633484bd6820b5d64c8223716418f4dcd0fc31f0 100644 (file)
@@ -1,7 +1,7 @@
 # a waf tool to add autoconf-like macros to the configure section
 # and for SAMBA_ macros for building libraries, binaries etc
 
-import Build, os, Options, Task, Utils, cc, TaskGen, fnmatch, re, shutil, Logs
+import Build, os, Options, Task, Utils, cc, TaskGen, fnmatch, re, shutil, Logs, Constants
 from Configure import conf
 from Logs import debug
 from samba_utils import SUBST_VARS_RECURSIVE
@@ -20,6 +20,12 @@ from samba_deps import *
 from samba_bundled import *
 import samba_install
 import samba_conftests
+import tru64cc
+import irixcc
+import generic_cc
+import samba_dist
+
+O644 = 420
 
 # some systems have broken threading in python
 if os.environ.get('WAF_NOTHREADS') == '1':
@@ -29,10 +35,23 @@ LIB_PATH="shared"
 
 os.putenv('PYTHONUNBUFFERED', '1')
 
+
+if Constants.HEXVERSION < 0x105016:
+    Logs.error('''
+Please use the version of waf that comes with Samba, not
+a system installed version. See http://wiki.samba.org/index.php/Waf
+for details.
+
+Alternatively, please use ./autogen-waf.sh, and then
+run ./configure and make as usual. That will call the right version of waf.
+''')
+    sys.exit(1)
+
+
 @conf
 def SAMBA_BUILD_ENV(conf):
     '''create the samba build environment'''
-    conf.env['BUILD_DIRECTORY'] = conf.blddir
+    conf.env.BUILD_DIRECTORY = conf.blddir
     mkdir_p(os.path.join(conf.blddir, LIB_PATH))
     mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
     # this allows all of the bin/shared and bin/python targets
@@ -51,8 +70,6 @@ def SAMBA_BUILD_ENV(conf):
         os.unlink(blib_src)
     elif os.path.exists(blib_src):
         shutil.rmtree(blib_src)
-    os.symlink(blib_bld, blib_src)
-
 
 
 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
@@ -170,12 +187,6 @@ def SAMBA_LIBRARY(bld, libname, source,
     if link_name:
         t.link_name = link_name
 
-    if autoproto is not None:
-        bld.SAMBA_AUTOPROTO(autoproto, source)
-
-    if public_headers is not None:
-        bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
-
     if pc_files is not None:
         bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
 
@@ -193,7 +204,8 @@ def SAMBA_BINARY(bld, binname, source,
                  ldflags=None,
                  cflags='',
                  autoproto=None,
-                 use_hostcc=None,
+                 use_hostcc=False,
+                 use_global_deps=True,
                  compiler=None,
                  group='binaries',
                  manpages=None,
@@ -228,7 +240,9 @@ def SAMBA_BINARY(bld, binname, source,
                         autoproto      = autoproto,
                         subsystem_name = subsystem_name,
                         needs_python   = needs_python,
-                        local_include  = local_include)
+                        local_include  = local_include,
+                        use_hostcc     = use_hostcc,
+                        use_global_deps= use_global_deps)
 
     bld.SET_BUILD_GROUP(group)
 
@@ -258,10 +272,6 @@ def SAMBA_BINARY(bld, binname, source,
     if subsystem_name is not None:
         bld.TARGET_ALIAS(subsystem_name, binname)
 
-    if autoproto is not None:
-        bld.SAMBA_AUTOPROTO(autoproto, source)
-    if public_headers is not None:
-        bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
 
 
@@ -353,6 +363,8 @@ def SAMBA_SUBSYSTEM(bld, modname, source,
                     local_include_first=True,
                     subsystem_name=None,
                     enabled=True,
+                    use_hostcc=False,
+                    use_global_deps=True,
                     vars=None,
                     needs_python=False):
     '''define a Samba subsystem'''
@@ -389,7 +401,9 @@ def SAMBA_SUBSYSTEM(bld, modname, source,
         samba_includes = includes,
         local_include  = local_include,
         local_include_first  = local_include_first,
-        samba_subsystem= subsystem_name
+        samba_subsystem= subsystem_name,
+        samba_use_hostcc = use_hostcc,
+        samba_use_global_deps = use_global_deps
         )
 
     if cflags_end is not None:
@@ -409,7 +423,7 @@ def SAMBA_SUBSYSTEM(bld, modname, source,
 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
 
 
-def SAMBA_GENERATOR(bld, name, rule, source, target,
+def SAMBA_GENERATOR(bld, name, rule, source='', target='',
                     group='generators', enabled=True,
                     public_headers=None,
                     header_path=None,
@@ -440,18 +454,6 @@ Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
 
 
 
-def BUILD_SUBDIR(bld, dir):
-    '''add a new set of build rules from a subdirectory'''
-    path = os.path.normpath(bld.curdir + '/' + dir)
-    cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
-    if path in cache: return
-    cache[path] = True
-    debug("build: Processing subdirectory %s" % dir)
-    bld.add_subdirs(dir)
-Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
-
-
-
 @runonce
 def SETUP_BUILD_GROUPS(bld):
     '''setup build groups used to ensure that the different build
@@ -533,7 +535,7 @@ def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
 
 
-def install_file(bld, destdir, file, chmod=0644, flat=False,
+def install_file(bld, destdir, file, chmod=O644, flat=False,
                  python_fixup=False, destname=None, base_name=None):
     '''install a file'''
     destdir = bld.EXPAND_VARIABLES(destdir)
@@ -555,7 +557,7 @@ def install_file(bld, destdir, file, chmod=0644, flat=False,
     bld.install_as(dest, file, chmod=chmod)
 
 
-def INSTALL_FILES(bld, destdir, files, chmod=0644, flat=False,
+def INSTALL_FILES(bld, destdir, files, chmod=O644, flat=False,
                   python_fixup=False, destname=None, base_name=None):
     '''install a set of files'''
     for f in TO_LIST(files):
@@ -565,7 +567,7 @@ def INSTALL_FILES(bld, destdir, files, chmod=0644, flat=False,
 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
 
 
-def INSTALL_WILDCARD(bld, destdir, pattern, chmod=0644, flat=False,
+def INSTALL_WILDCARD(bld, destdir, pattern, chmod=O644, flat=False,
                      python_fixup=False, exclude=None, trim_path=None):
     '''install a set of files matching a wildcard pattern'''
     files=TO_LIST(bld.path.ant_glob(pattern))
@@ -626,15 +628,21 @@ def subst_at_vars(task):
     # split on the vars
     a = re.split('(@\w+@)', s)
     out = []
+    back_sub = [ ('PREFIX', '${prefix}'), ('EXEC_PREFIX', '${exec_prefix}')]
     for v in a:
         if re.match('@\w+@', v):
             vname = v[1:-1]
             if not vname in task.env and vname.upper() in task.env:
                 vname = vname.upper()
             if not vname in task.env:
-                print "Unknown substitution %s in %s" % (v, task.name)
-                raise
-            v = task.env[vname]
+                Logs.error("Unknown substitution %s in %s" % (v, task.name))
+                sys.exit(1)
+            v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
+            # now we back substitute the allowed pc vars
+            for (b, m) in back_sub:
+                s = task.env[b]
+                if s == v[0:len(s)]:
+                    v = m + v[len(s):]
         out.append(v)
     contents = ''.join(out)
     f = open(tgt, 'w')