# AUTHOR:      Karl Linden
# DESCRIPTION: Patch to make the build system not detect user space on request
# STATUS:      Applied upstream.

Index: SConstruct
===================================================================
--- SConstruct	(revision 2584)
+++ SConstruct	(revision 2585)
@@ -76,6 +76,7 @@
     BoolVariable( "BUILD_STATIC_TOOLS", "Build a statically linked version of the FFADO tools.", False ),
     EnumVariable('DIST_TARGET', 'Build target for cross compiling packagers', 'auto', allowed_values=('auto', 'i386', 'i686', 'x86_64', 'powerpc', 'powerpc64', 'none' ), ignorecase=2),
     BoolVariable( "ENABLE_OPTIMIZATIONS", "Enable optimizations and the use of processor specific extentions (MMX/SSE/...).", False ),
+    BoolVariable( "DETECT_USERSPACE_ENV", "Try to detect the user space environment and add necessary 32/64 bit machine flags.", True ),
     BoolVariable( "PEDANTIC", "Enable -Werror and more pedantic options during compile.", False ),
     BoolVariable( "CUSTOM_ENV", "Respect CC, CXX, CFLAGS, CXXFLAGS and LDFLAGS.\nOnly meant for distributors and gentoo-users who want to over-optimize their build.\n Using this is not supported by the ffado-devs!", False ),
     ( "COMPILE_FLAGS", "Deprecated (use CFLAGS and CXXFLAGS with CUSTOM_ENV=True instead).  Add additional flags to the environment.\nOnly meant for distributors and gentoo-users who want to over-optimize their build.\n Using this is not supported by the ffado-devs!" ),
@@ -783,25 +784,26 @@
 if '-msse2' in opt_flags:
     env['USE_SSE2'] = 1
 
-m32 = is_userspace_32bit(cpuinfo)
-print 'User space is %s' % (m32 and '32-bit' or '64-bit')
-if cpuinfo.is_powerpc:
-    if m32:
-        print "Doing a 32-bit PowerPC build for %s CPU" % cpuinfo.ppc_type
-        machineflags = { 'CXXFLAGS' : ['-m32'] }
-    else:
-        print "Doing a 64-bit PowerPC build for %s CPU" % cpuinfo.ppc_type
-        machineflags = { 'CXXFLAGS' : ['-m64'] }
-    env.MergeFlags( machineflags )
-elif cpuinfo.is_x86:
-    if m32:
-        print "Doing a 32-bit %s build for %s" % (cpuinfo.machine, cpuinfo.model_name)
-        machineflags = { 'CXXFLAGS' : ['-m32'] }
-    else:
-        print "Doing a 64-bit %s build for %s" % (cpuinfo.machine, cpuinfo.model_name)
-        machineflags = { 'CXXFLAGS' : ['-m64'] }
-        needs_fPIC = True
-    env.MergeFlags( machineflags )
+if env['DETECT_USERSPACE_ENV']:
+    m32 = is_userspace_32bit(cpuinfo)
+    print 'User space is %s' % (m32 and '32-bit' or '64-bit')
+    if cpuinfo.is_powerpc:
+        if m32:
+            print "Doing a 32-bit PowerPC build for %s CPU" % cpuinfo.ppc_type
+            machineflags = { 'CXXFLAGS' : ['-m32'] }
+        else:
+            print "Doing a 64-bit PowerPC build for %s CPU" % cpuinfo.ppc_type
+            machineflags = { 'CXXFLAGS' : ['-m64'] }
+        env.MergeFlags( machineflags )
+    elif cpuinfo.is_x86:
+        if m32:
+            print "Doing a 32-bit %s build for %s" % (cpuinfo.machine, cpuinfo.model_name)
+            machineflags = { 'CXXFLAGS' : ['-m32'] }
+        else:
+            print "Doing a 64-bit %s build for %s" % (cpuinfo.machine, cpuinfo.model_name)
+            machineflags = { 'CXXFLAGS' : ['-m64'] }
+            needs_fPIC = True
+        env.MergeFlags( machineflags )
 #=== End Revised CXXFLAGS =========================================
 
 
