build: throw a fatal error for duplicate target declarations
[samba.git] / buildtools / wafsamba / samba_utils.py
index 8016da44bc2205d066973e4eaf2edc680d527839..94975c6519eba5b7ed4c0e37f2b36642765b9332 100644 (file)
@@ -15,11 +15,11 @@ LIB_PATH="shared"
 def SET_TARGET_TYPE(ctx, target, value):
     '''set the target type of a target'''
     cache = LOCAL_CACHE(ctx, 'TARGET_TYPE')
-    if target in cache:
-        ASSERT(ctx, cache[target] == value,
-               "Target '%s' re-defined as %s - was %s" % (target, value, cache[target]))
-        debug("task_gen: Skipping duplicate target %s (curdir=%s)" % (target, ctx.curdir))
-        return False
+    if target in cache and cache[target] != 'EMPTY':
+        Logs.error("ERROR: Target '%s' in directory %s re-defined as %s - was %s" % (target,
+                                                                                     ctx.curdir,
+                                                                                     value, cache[target]))
+        sys.exit(1)
     LOCAL_CACHE_SET(ctx, 'TARGET_TYPE', target, value)
     debug("task_gen: Target '%s' created of type '%s' in %s" % (target, value, ctx.curdir))
     return True
@@ -438,3 +438,29 @@ def RECURSE(ctx, directory):
     raise
 Options.Handler.RECURSE = RECURSE
 Build.BuildContext.RECURSE = RECURSE
+
+
+def CHECK_MAKEFLAGS(bld):
+    '''check for MAKEFLAGS environment variable in case we are being
+    called from a Makefile try to honor a few make command line flags'''
+    if not 'WAF_MAKE' in os.environ:
+        return
+    makeflags = os.environ.get('MAKEFLAGS')
+    jobs_set = False
+    for opt in makeflags.split():
+        # options can come either as -x or as x
+        if opt[0] != '-':
+            for v in opt:
+                if v == 'j':
+                    jobs_set = True
+                elif v == 'k':
+                    Options.options.keep = True                
+        elif opt == '-j':
+            jobs_set = True
+        elif opt == '-k':
+            Options.options.keep = True                
+    if not jobs_set:
+        # default to one job
+        Options.options.jobs = 1
+            
+Build.BuildContext.CHECK_MAKEFLAGS = CHECK_MAKEFLAGS