Scons: added profile build option
[senf.git] / site_scons / senfutil.py
index 3061ab9..7217c84 100644 (file)
@@ -1,4 +1,5 @@
 import os, os.path, site_tools.Yaptu, types, re, fnmatch
+import SCons.Util
 from SCons.Script import *
 
 senfutildir = os.path.dirname(__file__)
@@ -204,6 +205,7 @@ def DefaultOptions(env):
         env,
         BoolVariable('final', 'Build final (optimized) build', False),
         BoolVariable('debug', 'Link in debug symbols', False),
+        BoolVariable('profile', 'compile and link with the profiling enabled option', False),
     )
 
     # Set nice default options
@@ -216,6 +218,11 @@ def DefaultOptions(env):
         LINKFLAGS_normal = [ '-Wl,-S' ],
         LINKFLAGS_debug  = [ '-g' ],
     )
+    if env['profile']:
+        env.Append(
+            LINKFLAGS   = [ '-pg' ],
+            CXXFLAGS    = [ '-pg' ],
+    )
 
     env.Alias('all', '#')
 
@@ -234,6 +241,18 @@ def Glob(env, exclude=[], subdirs=[]):
     testSources.sort()
     return (sources, testSources)
 
+def CleanGlob(env, targets, patterns):
+    if env.GetOption('clean'):
+        targets = SCons.Util.flatten(targets)
+        for target in targets:
+            if target in BUILD_TARGETS:
+                patterns = map(str,SCons.Util.flatten(env.subst_list(patterns)))
+                files = [ os.path.join(path,f)
+                          for path, subdirs, files in os.walk('.')
+                          for pattern in patterns
+                          for f in fnmatch.filter(files,pattern) ]
+                return env.Clean(target, files)
+
 tagfiles = None
 
 def Doxygen(env, doxyheader=None, doxyfooter=None, doxycss=None, mydoxyfile=False, senfdoc_path=[],