Description: Allow Scons to execute clean without configuring
 Scons was checking for dependencies even for just executing the clean
 target, which is unnecessary. This causes problems when building with
 pbuilder since the clean target is executed before entering the chroot--
 that is, before the build-depends are available. This patch applies
 the workaround described at
 http://www.scons.org/doc/1.2.0/HTML/scons-user/x4105.html
Author: Afif Elghraoui <afif@ghraoui.name>
Forwarded: no
Last-Update: 2015-07-17
--- ori.orig/SConstruct
+++ ori/SConstruct
@@ -205,190 +205,191 @@
     Exit(1)
 
 # Configuration
-conf = env.Configure(custom_tests = { 'CheckPkgConfig' : CheckPkgConfig,
-                                      'CheckPkg' : CheckPkg,
-                                      'CheckPkgMinVersion' : CheckPkgMinVersion })
-
-if not conf.CheckCC():
-    print 'Your C compiler and/or environment is incorrectly configured.'
-    CheckFailed()
-
-if not conf.CheckCXX():
-    print 'Your C++ compiler and/or environment is incorrectly configured.'
-    CheckFailed()
-
-if (sys.platform == "win32") or env["CROSSCOMPILE"]:
-    env["HAS_PKGCONFIG"] = False
-else:
-    env["HAS_PKGCONFIG"] = True
-    if not conf.CheckPkgConfig():
-        print 'pkg-config not found!'
-        Exit(1)
-
-#
-#env.AppendUnique(CXXFLAGS = ['-std=c++11'])
-#if not conf.CheckCXX():
-#    env['CXXFLAGS'].remove('-std=c++11')
-#
-#env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
-#if not conf.CheckCXX():
-#    env['CXXFLAGS'].remove('-std=c++0x')
-#
-
-if conf.CheckCXXHeader('unordered_map'):
-    env.Append(CPPFLAGS = "-DHAVE_CXX11")
-elif conf.CheckCXXHeader('tr1/unordered_map'):
-    env.Append(CPPFLAGS = "-DHAVE_CXXTR1")
-else:
-    print 'Either C++11, C++0x, or C++ TR1 must be present!'
-    CheckFailed()
-
-if not conf.CheckCXXHeader('boost/uuid/uuid.hpp'):
-    print 'Boost UUID headers are missing!'
-    Exit(1)
-
-if not conf.CheckCXXHeader('boost/bind.hpp'):
-    print 'Boost bind headers are missing!'
-    Exit(1)
-
-if not conf.CheckCXXHeader('boost/date_time/posix_time/posix_time.hpp'):
-    print 'Boost posix_time headers are missing!'
-    Exit(1)
-
-if sys.platform.startswith("freebsd"):
-    if not conf.CheckLib('execinfo'):
-        print 'FreeBSD requires libexecinfo to build.'
-        Exit(1)
-
-check_uuid_h = conf.CheckCHeader('uuid.h')
-check_uuid_uuid_h = conf.CheckCHeader('uuid/uuid.h')
-if check_uuid_h:
-    env.Append(CPPFLAGS = "-DHAVE_UUID_H")
-elif check_uuid_uuid_h:
-    env.Append(CPPFLAGS = "-DHAVE_UUID_UUID_H")
-else:
-    print 'Supported UUID header is missing!'
-    Exit(1)
-
-if env["COMPRESSION_ALGO"] == "LZMA":
-    if not conf.CheckLibWithHeader('lzma',
-                                   'lzma.h',
-                                   'C',
-                                   'lzma_version_string();'):
-        print 'Please install liblzma'
-        Exit(1)
+if not env.GetOption('clean'):
+    conf = env.Configure(custom_tests = { 'CheckPkgConfig' : CheckPkgConfig,
+                                          'CheckPkg' : CheckPkg,
+                                          'CheckPkgMinVersion' : CheckPkgMinVersion })
+
+    if not conf.CheckCC():
+        print 'Your C compiler and/or environment is incorrectly configured.'
+        CheckFailed()
+
+    if not conf.CheckCXX():
+        print 'Your C++ compiler and/or environment is incorrectly configured.'
+        CheckFailed()
+
+    if (sys.platform == "win32") or env["CROSSCOMPILE"]:
+        env["HAS_PKGCONFIG"] = False
+    else:
+        env["HAS_PKGCONFIG"] = True
+        if not conf.CheckPkgConfig():
+            print 'pkg-config not found!'
+            Exit(1)
+
+    #
+    #env.AppendUnique(CXXFLAGS = ['-std=c++11'])
+    #if not conf.CheckCXX():
+    #    env['CXXFLAGS'].remove('-std=c++11')
+    #
+    #env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
+    #if not conf.CheckCXX():
+    #    env['CXXFLAGS'].remove('-std=c++0x')
+    #
+
+    if conf.CheckCXXHeader('unordered_map'):
+        env.Append(CPPFLAGS = "-DHAVE_CXX11")
+    elif conf.CheckCXXHeader('tr1/unordered_map'):
+        env.Append(CPPFLAGS = "-DHAVE_CXXTR1")
+    else:
+        print 'Either C++11, C++0x, or C++ TR1 must be present!'
+        CheckFailed()
+
+    if not conf.CheckCXXHeader('boost/uuid/uuid.hpp'):
+        print 'Boost UUID headers are missing!'
+        Exit(1)
+
+    if not conf.CheckCXXHeader('boost/bind.hpp'):
+        print 'Boost bind headers are missing!'
+        Exit(1)
+
+    if not conf.CheckCXXHeader('boost/date_time/posix_time/posix_time.hpp'):
+        print 'Boost posix_time headers are missing!'
+        Exit(1)
+
+    if sys.platform.startswith("freebsd"):
+        if not conf.CheckLib('execinfo'):
+            print 'FreeBSD requires libexecinfo to build.'
+            Exit(1)
+
+    check_uuid_h = conf.CheckCHeader('uuid.h')
+    check_uuid_uuid_h = conf.CheckCHeader('uuid/uuid.h')
+    if check_uuid_h:
+        env.Append(CPPFLAGS = "-DHAVE_UUID_H")
+    elif check_uuid_uuid_h:
+        env.Append(CPPFLAGS = "-DHAVE_UUID_UUID_H")
+    else:
+        print 'Supported UUID header is missing!'
+        Exit(1)
+
+    if env["COMPRESSION_ALGO"] == "LZMA":
+        if not conf.CheckLibWithHeader('lzma',
+                                       'lzma.h',
+                                       'C',
+                                       'lzma_version_string();'):
+            print 'Please install liblzma'
+            Exit(1)
 
-if env["WITH_FUSE"]:
-    if env["HAS_PKGCONFIG"] and not conf.CheckPkg('fuse'):
-        print 'FUSE is not registered in pkg-config'
-        Exit(1)
-
-if env["HAS_PKGCONFIG"]:
-    if not conf.CheckPkg('libevent'):
-        print 'libevent is not registered in pkg-config'
-        Exit(1)
-    if not conf.CheckPkgMinVersion("libevent", "2.0"):
-        print 'libevent version 2.0 or above required'
-        Exit(1)
-    env.ParseConfig('pkg-config --libs --cflags libevent')
-
-has_event = conf.CheckLibWithHeader('', 'event2/event.h', 'C', 'event_init();')
-if not (has_event or (env["CROSSCOMPILE"])):
-    print 'Cannot link test binary with libevent 2.0+'
-    Exit(1)
-
-if (env["WITH_MDNS"]) and (sys.platform != "darwin"):
-    if not conf.CheckLibWithHeader('dns_sd','dns_sd.h','C'):
-	print 'Please install libdns_sd'
-	Exit(1)
-
-if env["HAS_PKGCONFIG"]:
-    if not conf.CheckPkg("openssl"):
-        print 'openssl is not registered in pkg-config'
-        Exit(1)
-    if not conf.CheckPkgMinVersion("openssl", "1.0.0"):
-        print 'openssl version 1.0.0 or above required'
-        Exit(1)
-    env.ParseConfig('pkg-config --libs --cflags openssl')
-
-conf.Finish()
-
-Export('env')
+    if env["WITH_FUSE"]:
+        if env["HAS_PKGCONFIG"] and not conf.CheckPkg('fuse'):
+            print 'FUSE is not registered in pkg-config'
+            Exit(1)
+
+    if env["HAS_PKGCONFIG"]:
+        if not conf.CheckPkg('libevent'):
+            print 'libevent is not registered in pkg-config'
+            Exit(1)
+        if not conf.CheckPkgMinVersion("libevent", "2.0"):
+            print 'libevent version 2.0 or above required'
+            Exit(1)
+        env.ParseConfig('pkg-config --libs --cflags libevent')
+
+    has_event = conf.CheckLibWithHeader('', 'event2/event.h', 'C', 'event_init();')
+    if not (has_event or (env["CROSSCOMPILE"])):
+        print 'Cannot link test binary with libevent 2.0+'
+        Exit(1)
+
+    if (env["WITH_MDNS"]) and (sys.platform != "darwin"):
+        if not conf.CheckLibWithHeader('dns_sd','dns_sd.h','C'):
+            print 'Please install libdns_sd'
+            Exit(1)
+
+    if env["HAS_PKGCONFIG"]:
+        if not conf.CheckPkg("openssl"):
+            print 'openssl is not registered in pkg-config'
+            Exit(1)
+        if not conf.CheckPkgMinVersion("openssl", "1.0.0"):
+            print 'openssl version 1.0.0 or above required'
+            Exit(1)
+        env.ParseConfig('pkg-config --libs --cflags openssl')
+
+    conf.Finish()
+
+    Export('env')
+
+    # Set compile options for binaries
+    env.Append(CPPPATH = ['#public', '#.'])
+    env.Append(LIBS = ["diffmerge", "z"], LIBPATH = ['#build/libdiffmerge'])
+    env.Append(LIBS = ["ori"], LIBPATH = ['#build/libori'])
+    env.Append(LIBS = ["oriutil"], LIBPATH = ['#build/liboriutil'])
+
+    if sys.platform != "win32" and sys.platform != "darwin":
+        env.Append(CPPFLAGS = ['-pthread'])
+        env.Append(LIBS = ["pthread"])
 
-# Set compile options for binaries
-env.Append(CPPPATH = ['#public', '#.'])
-env.Append(LIBS = ["diffmerge", "z"], LIBPATH = ['#build/libdiffmerge'])
-env.Append(LIBS = ["ori"], LIBPATH = ['#build/libori'])
-env.Append(LIBS = ["oriutil"], LIBPATH = ['#build/liboriutil'])
-
-if sys.platform != "win32" and sys.platform != "darwin":
-    env.Append(CPPFLAGS = ['-pthread'])
-    env.Append(LIBS = ["pthread"])
-
-# Optional Components
-if env["WITH_LIBS3"]:
-    env.Append(CPPPATH = '#libs3-2.0/inc')
-    SConscript('libs3-2.0/SConscript', variant_dir='build/libs3-2.0')
-if env["COMPRESSION_ALGO"] == "SNAPPY":
-    env.Append(CPPPATH = ['#snappy-1.0.5'])
-    env.Append(LIBS = ["snappy"], LIBPATH = ['#build/snappy-1.0.5'])
-    SConscript('snappy-1.0.5/SConscript', variant_dir='build/snappy-1.0.5')
-if env["COMPRESSION_ALGO"] == "FASTLZ":
-    env.Append(CPPPATH = ['#libfastlz'])
-    env.Append(LIBS = ["fastlz"], LIBPATH = ['#build/libfastlz'])
-    SConscript('libfastlz/SConscript', variant_dir='build/libfastlz')
-
-# Debugging Tools
-if env["WITH_GOOGLEHEAP"]:
-    env.Append(LIBS = ["tcmalloc"])
-if env["WITH_GOOGLEPROF"]:
-    env.Append(LIBS = ["profiler"])
-if env["WITH_TSAN"]:
-    env.Append(CPPFLAGS = ["-fsanitize=thread", "-fPIE"])
-    env.Append(LINKFLAGS = ["-fsanitize=thread", "-pie"])
-if env["WITH_ASAN"]:
-    env.Append(CPPFLAGS = ["-fsanitize=address"])
-    env.Append(LINKFLAGS = ["-fsanitize=address"])
-if env["WITH_TSAN"] and env["WITH_ASAN"]:
-    print "Cannot set both WITH_TSAN and WITH_ASAN!"
-    sys.exit(-1)
-
-# libori
-SConscript('libdiffmerge/SConscript', variant_dir='build/libdiffmerge')
-SConscript('libori/SConscript', variant_dir='build/libori')
-SConscript('liboriutil/SConscript', variant_dir='build/liboriutil')
-
-# Ori Utilities
-if env["BUILD_BINARIES"]:
-    SConscript('ori/SConscript', variant_dir='build/ori')
-    SConscript('oridbg/SConscript', variant_dir='build/oridbg')
-    SConscript('orisync/SConscript', variant_dir='build/orisync')
+    # Optional Components
     if env["WITH_LIBS3"]:
-        SConscript('oris3/SConscript', variant_dir='build/oris3')
+        env.Append(CPPPATH = '#libs3-2.0/inc')
+        SConscript('libs3-2.0/SConscript', variant_dir='build/libs3-2.0')
+    if env["COMPRESSION_ALGO"] == "SNAPPY":
+        env.Append(CPPPATH = ['#snappy-1.0.5'])
+        env.Append(LIBS = ["snappy"], LIBPATH = ['#build/snappy-1.0.5'])
+        SConscript('snappy-1.0.5/SConscript', variant_dir='build/snappy-1.0.5')
+    if env["COMPRESSION_ALGO"] == "FASTLZ":
+        env.Append(CPPPATH = ['#libfastlz'])
+        env.Append(LIBS = ["fastlz"], LIBPATH = ['#build/libfastlz'])
+        SConscript('libfastlz/SConscript', variant_dir='build/libfastlz')
+
+    # Debugging Tools
+    if env["WITH_GOOGLEHEAP"]:
+        env.Append(LIBS = ["tcmalloc"])
+    if env["WITH_GOOGLEPROF"]:
+        env.Append(LIBS = ["profiler"])
+    if env["WITH_TSAN"]:
+        env.Append(CPPFLAGS = ["-fsanitize=thread", "-fPIE"])
+        env.Append(LINKFLAGS = ["-fsanitize=thread", "-pie"])
+    if env["WITH_ASAN"]:
+        env.Append(CPPFLAGS = ["-fsanitize=address"])
+        env.Append(LINKFLAGS = ["-fsanitize=address"])
+    if env["WITH_TSAN"] and env["WITH_ASAN"]:
+        print "Cannot set both WITH_TSAN and WITH_ASAN!"
+        sys.exit(-1)
+
+    # libori
+    SConscript('libdiffmerge/SConscript', variant_dir='build/libdiffmerge')
+    SConscript('libori/SConscript', variant_dir='build/libori')
+    SConscript('liboriutil/SConscript', variant_dir='build/liboriutil')
+
+    # Ori Utilities
+    if env["BUILD_BINARIES"]:
+        SConscript('ori/SConscript', variant_dir='build/ori')
+        SConscript('oridbg/SConscript', variant_dir='build/oridbg')
+        SConscript('orisync/SConscript', variant_dir='build/orisync')
+        if env["WITH_LIBS3"]:
+            SConscript('oris3/SConscript', variant_dir='build/oris3')
+        if env["WITH_FUSE"]:
+            SConscript('orifs/SConscript', variant_dir='build/orifs')
+        if env["WITH_HTTPD"]:
+            SConscript('ori_httpd/SConscript', variant_dir='build/ori_httpd')
+        if env["WITH_ORILOCAL"]:
+            SConscript('orilocal/SConscript', variant_dir='build/orilocal')
+
+    # Install Targets
     if env["WITH_FUSE"]:
-        SConscript('orifs/SConscript', variant_dir='build/orifs')
+        env.Install('$DESTDIR$PREFIX/bin','build/orifs/orifs')
+    env.Install('$DESTDIR$PREFIX/bin','build/ori/ori')
+    env.Install('$DESTDIR$PREFIX/bin','build/oridbg/oridbg')
+    env.Install('$DESTDIR$PREFIX/bin','build/orisync/orisync')
+    if env["WITH_LIBS3"]:
+        env.Install('$DESTDIR$PREFIX/bin','build/ori/oris3')
     if env["WITH_HTTPD"]:
-        SConscript('ori_httpd/SConscript', variant_dir='build/ori_httpd')
+        env.Install('$DESTDIR$PREFIX/bin','build/ori_httpd/ori_httpd')
     if env["WITH_ORILOCAL"]:
-        SConscript('orilocal/SConscript', variant_dir='build/orilocal')
+        env.Install('$DESTDIR$PREFIX/bin','build/orilocal/orilocal')
 
-# Install Targets
-if env["WITH_FUSE"]:
-    env.Install('$DESTDIR$PREFIX/bin','build/orifs/orifs')
-env.Install('$DESTDIR$PREFIX/bin','build/ori/ori')
-env.Install('$DESTDIR$PREFIX/bin','build/oridbg/oridbg')
-env.Install('$DESTDIR$PREFIX/bin','build/orisync/orisync')
-if env["WITH_LIBS3"]:
-    env.Install('$DESTDIR$PREFIX/bin','build/ori/oris3')
-if env["WITH_HTTPD"]:
-    env.Install('$DESTDIR$PREFIX/bin','build/ori_httpd/ori_httpd')
-if env["WITH_ORILOCAL"]:
-    env.Install('$DESTDIR$PREFIX/bin','build/orilocal/orilocal')
-
-env.Install('$DESTDIR$PREFIX/share/man/man1','docs/ori.1')
-env.Install('$DESTDIR$PREFIX/share/man/man1','docs/orifs.1')
-env.Install('$DESTDIR$PREFIX/share/man/man1','docs/orisync.1')
-env.Install('$DESTDIR$PREFIX/share/man/man1','docs/oridbg.1')
+    env.Install('$DESTDIR$PREFIX/share/man/man1','docs/ori.1')
+    env.Install('$DESTDIR$PREFIX/share/man/man1','docs/orifs.1')
+    env.Install('$DESTDIR$PREFIX/share/man/man1','docs/orisync.1')
+    env.Install('$DESTDIR$PREFIX/share/man/man1','docs/oridbg.1')
 
-env.Alias('install','$DESTDIR$PREFIX')
+    env.Alias('install','$DESTDIR$PREFIX')
 
