Hello developers!
Currently the build system does not honour the common build environment variables CC, CXX, CFLAGS, CXXFLAGS and LDFLAGS. When building ffado in Gentoo this becomes a problem since packages should respect the user's (and package managers) build environment.
The current approach is to have a COMPILE_FLAGS option to add custom compiler flags, but this is not sufficient.
I want to be very clear on this point: I _DO NOT_ ask you to support custom compiler flags, I simply ask you to make your build system respect common build environment variables. It would make maintaining ffado much easier downstream in Gentoo.
To fix this issue I have constructed a patch that does the following with the build system:
- Respect CC, CXX, CFLAGS, CXXFLAGS, LDFLAGS.
- Notify the user that specifying CFLAGS, CXXFLAGS or LDFLAGS is not supported by you, the ffado-devs, if any of them is specified.
- Remove the COMPILE_FLAGS variable as CFLAGS and CXXFLAGS supply the same functionality.
- Do not append -O2 from flags if any custom CFLAGS, CXXFLAGS or LDFLAGS are specified.
- Make sure oldcf is not overwritten when checking for lrint.
Since the build system is still clear about that custom flags are not supported I think this patch is suitable to apply here (upstream).
Here is the patch against SVN trunk:
Index: SConstruct
===================================================================
--- SConstruct (revision 2574)
+++ SConstruct (working copy)
@@ -77,7 +77,6 @@
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( "PEDANTIC", "Enable -Werror and more pedantic options during compile.", False ),
- ( "COMPILE_FLAGS", "Add additional flags to the environment.\nOnly meant for distributors and gentoo-users who want to over-optimize their built.\n Using this is not supported by the ffado-devs!" ),
EnumVariable( "ENABLE_SETBUFFERSIZE_API_VER", "Report API version at runtime which includes support for dynamic buffer resizing (requires recent jack).", 'auto', allowed_values=('auto', 'true', 'false', 'force'), ignorecase=2),
)
@@ -87,14 +86,33 @@
env = Environment( tools=['default','scanreplace','pyuic','pyuic4','dbus','doxygen','pkgconfig'], toolpath=['admin'], ENV = buildenv, options=opts )
-if env.has_key('COMPILE_FLAGS') and len(env['COMPILE_FLAGS']) > 0:
+# Honour the user choice of compiler (if any).
+if os.environ.has_key('CC') and len(os.environ['CC']) > 0:
+ env['CC'] = os.environ['CC']
+if os.environ.has_key('CXX') and len(os.environ['CXX']) > 0:
+ env['CXX'] = os.environ['CXX']
+
+# Honour the user supplied flags (if any), but notify the user that this
+# is not supported.
+custom_flags = False
+if os.environ.has_key('CFLAGS') and len(os.environ['CFLAGS']) > 0:
+ custom_flags = True
+ env.Append(CFLAGS = str(os.environ['CFLAGS'].replace('\"', '')))
+if os.environ.has_key('CXXFLAGS') and len(os.environ['CXXFLAGS']) > 0:
+ custom_flags = True
+ env.Append(CXXFLAGS = str(os.environ['CXXFLAGS'].replace('\"', '')))
+if os.environ.has_key('LDFLAGS') and len(os.environ['LDFLAGS']) > 0:
+ custom_flags = True
+ env.Append(LINKFLAGS = str(os.environ['LDFLAGS'].replace('\"', '')))
+if custom_flags:
print '''
* Usage of additional flags is not supported by the ffado-devs.
* Use at own risk!
*
- * Currentl value is '%s'
- ''' % env['COMPILE_FLAGS']
- env.MergeFlags(env['COMPILE_FLAGS'])
+ * CFLAGS = %s
+ * CXXFLAGS = %s
+ * LINKFLAGS = %s
+''' % (env['CFLAGS'], env['CXXFLAGS'], env['LINKFLAGS'])
Help( """
For building ffado you can set different options as listed below. You have to
@@ -331,7 +349,7 @@
oldcf = env['CFLAGS']
else:
oldcf = ""
- oldcf = env.Append(CFLAGS = '-std=c99')
+ env.Append(CFLAGS = '-std=c99')
if conf.CheckLibWithHeader( "m", "math.h", "c", "lrint(3.2);" ):
HAVE_LRINT = 1
else:
@@ -415,7 +433,8 @@
print "Doing a debug build"
env.MergeFlags( "-Wall -g -DDEBUG" )
env['DEBUG_MESSAGES'] = True
-else:
+elif not custom_flags:
+ # Only merge -O2 to flags if the user has not specified custom flags.
env.MergeFlags( "-O2" )
if env['DEBUG_MESSAGES']:
@@ -769,7 +788,7 @@
#=== End Revised CXXFLAGS =========================================
-if needs_fPIC or ( env.has_key('COMPILE_FLAGS') and '-fPIC' in env['COMPILE_FLAGS'] ):
+if needs_fPIC:
env.MergeFlags( "-fPIC" )
# end of processor-specific section
Thanks in advance,
Karl