various changes to controls_layout size management
[ardour.git] / SConstruct
index a06f6fad02866ff3e5953afb8748cb76f7edb064..bbabc5d54164c3a85cb2b8586d84e3fc2112119b 100644 (file)
@@ -1,3 +1,5 @@
+# -*- python -*-
+
 import os
 import sys
 import re
@@ -5,6 +7,7 @@ import shutil
 import glob
 import errno
 import time
+from sets import Set
 import SCons.Node.FS
 
 SConsignFile()
@@ -22,7 +25,7 @@ opts = Options('scache.conf')
 opts.AddOptions(
     BoolOption('ALTIVEC', 'Compile using Altivec instructions', 0),
   ('ARCH', 'Set architecture-specific compilation flags by hand (all flags as 1 argument)',''),
-    BoolOption('DEBIAN', 'Debian build options (no internal versions of 3rd party libraries)', 0),
+    BoolOption('SYSLIBS', 'USE AT YOUR OWN RISK: CANCELS ALL SUPPORT FROM ARDOUR AUTHORS: Use existing system versions of various libraries instead of internal ones', 0),
     BoolOption('DEBUG', 'Set to build with debugging information and no optimizations', 0),
     PathOption('DESTDIR', 'Set the intermediate install "prefix"', '/'),
     BoolOption('DEVBUILD', 'Use shared libardour (developers only)', 0),
@@ -30,10 +33,12 @@ opts.AddOptions(
     BoolOption('NOARCH', 'Do not use architecture-specific compilation flags', 0),
     PathOption('PREFIX', 'Set the install "prefix"', '/usr/local'),
     BoolOption('VST', 'Compile with support for VST', 0),
-    BoolOption('VERSIONED', 'Add version information to ardour/gtk executable name inside the build directory', 0)
+    BoolOption('VERSIONED', 'Add version information to ardour/gtk executable name inside the build directory', 0),
+    BoolOption('USE_SSE_EVERYWHERE', 'Ask the compiler to use x86/SSE instructions and also our hand-written x86/SSE optimizations when possible (off by default)', 0),
+    BoolOption('BUILD_SSE_OPTIMIZATIONS', 'Use our hand-written x86/SSE optimizations when possible (off by default)', 0),
+    BoolOption('BUILD_VECLIB_OPTIMIZATIONS', 'Build with Apple Accelerate/vecLib optimizations when possible (off by default)', 0)
   )
 
-
 #----------------------------------------------------------------------
 # a handy helper that provides a way to merge compile/link information
 # from multiple different "environments"
@@ -49,6 +54,10 @@ class LibraryInfo(Environment):
             self.Append (LIBPATH = other.get ('LIBPATH', []))  
             self.Append (CPPPATH = other.get('CPPPATH', []))
             self.Append (LINKFLAGS = other.get('LINKFLAGS', []))
+       self.Replace(LIBPATH = list(Set(self.get('LIBPATH', []))))
+       self.Replace(CPPPATH = list(Set(self.get('CPPPATH',[]))))
+       #doing LINKFLAGS breaks -framework
+        #doing LIBS break link order dependency
 
 
 env = LibraryInfo (options = opts,
@@ -374,10 +383,16 @@ libraries['pango'].ParseConfig ('pkg-config --cflags --libs pango')
 libraries['libgnomecanvas2'] = LibraryInfo()
 libraries['libgnomecanvas2'].ParseConfig ('pkg-config --cflags --libs libgnomecanvas-2.0')
 
-libraries['ardour2'] = LibraryInfo (LIBS='ardour2', LIBPATH='#libs/ardour2', CPPPATH='#libs/ardour2')
+libraries['glade2'] = LibraryInfo()
+libraries['glade2'].ParseConfig ('pkg-config --cflags --libs libglade-2.0')
+
+libraries['flowcanvas'] = LibraryInfo(LIBS='flowcanvas', LIBPATH='#/libs/flowcanvas', CPPPATH='#libs/flowcanvas')
+
+libraries['ardour'] = LibraryInfo (LIBS='ardour', LIBPATH='#libs/ardour', CPPPATH='#libs/ardour')
 libraries['midi++2'] = LibraryInfo (LIBS='midi++', LIBPATH='#libs/midi++2', CPPPATH='#libs/midi++2')
 libraries['pbd3']    = LibraryInfo (LIBS='pbd', LIBPATH='#libs/pbd3', CPPPATH='#libs/pbd3')
 libraries['gtkmm2ext'] = LibraryInfo (LIBS='gtkmm2ext', LIBPATH='#libs/gtkmm2ext', CPPPATH='#libs/gtkmm2ext')
+#libraries['cassowary'] = LibraryInfo(LIBS='cassowary', LIBPATH='#libs/cassowary', CPPPATH='#libs/cassowary')
 
 libraries['fst'] = LibraryInfo()
 if env['VST']:
@@ -396,32 +411,53 @@ if conf.CheckCHeader('alsa/asoundlib.h'):
     subst_dict['%MIDITYPE%'] = "alsa/sequencer"
 elif conf.CheckCHeader('/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h'):
     # this line is needed because scons can't handle -framework in ParseConfig() yet.
-    libraries['sysmidi'] = LibraryInfo (LINKFLAGS= '-framework CoreMIDI -framework CoreFoundation -framework CoreAudio -framework CoreServices -framework AudioUnit')
+    libraries['sysmidi'] = LibraryInfo (LINKFLAGS= '-framework CoreMIDI -framework CoreFoundation -framework CoreAudio -framework CoreServices -framework AudioUnit -bind_at_load')
     env['SYSMIDI'] = 'CoreMIDI'
-    subst_dict['%MIDITAG%'] = "coremidi"
+    subst_dict['%MIDITAG%'] = "ardour"
     subst_dict['%MIDITYPE%'] = "coremidi"
 
 env = conf.Finish()
 
-if env['DEBIAN']:
-
-    libraries['soundtouch'] = LibraryInfo(LIBS='SoundTouch')
-
+if env['SYSLIBS']:
+
+    libraries['sigc2'] = LibraryInfo()
+    libraries['sigc2'].ParseConfig('pkg-config --cflags --libs sigc++-2.0')
+    libraries['glibmm2'] = LibraryInfo()
+    libraries['glibmm2'].ParseConfig('pkg-config --cflags --libs glibmm-2.4')
+    libraries['gdkmm2'] = LibraryInfo()
+    libraries['gdkmm2'].ParseConfig ('pkg-config --cflags --libs gdkmm-2.4')
+    libraries['gtkmm2'] = LibraryInfo()
+    libraries['gtkmm2'].ParseConfig ('pkg-config --cflags --libs gtkmm-2.4')
+    libraries['atkmm'] = LibraryInfo()
+    libraries['atkmm'].ParseConfig ('pkg-config --cflags --libs atkmm-1.6')
+    libraries['pangomm'] = LibraryInfo()
+    libraries['pangomm'].ParseConfig ('pkg-config --cflags --libs pangomm-1.4')
+    libraries['libgnomecanvasmm'] = LibraryInfo()
+    libraries['libgnomecanvasmm'].ParseConfig ('pkg-config --cflags --libs libgnomecanvasmm-2.6')
+    libraries['libglademm'] = LibraryInfo()
+    libraries['libglademm'].ParseConfig ('pkg-config --cflags --libs libglademm-2.4')
+
+    libraries['flowcanvas'] = LibraryInfo(LIBS='flowcanvas', LIBPATH='#/libs/flowcanvas', CPPPATH='#libs/flowcanvas')
+    libraries['soundtouch'] = LibraryInfo(LIBS='soundtouch',
+                                          LIBPATH='#libs/soundtouch',
+                                          CPPPATH=['#libs', '#libs/soundtouch'])
     coredirs = [
         'templates'
     ]
 
-    subdirs2 = [
+    subdirs = [
         'libs/pbd3',
         'libs/midi++2',
+        'libs/ardour'
         ]
 
-    gtk2_subdirs = [
+    gtk_subdirs = [
+        'libs/flowcanvas',
         'libs/gtkmm2ext',
-         ]
-else:
+        'gtk2_ardour'
+        ]
 
+else:
     libraries['sigc2'] = LibraryInfo(LIBS='sigc++2',
                                     LIBPATH='#libs/sigc++2',
                                     CPPPATH='#libs/sigc++2')
@@ -438,44 +474,64 @@ else:
                                       LIBPATH='#libs/gtkmm2/gdk',
                                       CPPPATH='#libs/gtkmm2/gdk')
     libraries['gtkmm2'] = LibraryInfo(LIBS='gtkmm2',
-                                      LIBPATH='#libs/gtkmm2/gtk',
-                                      CPPPATH='#libs/gtkmm2/gtk')
+                                     LIBPATH="#libs/gtkmm2/gtk",
+                                     CPPPATH='#libs/gtkmm2/gtk/')
     libraries['libgnomecanvasmm'] = LibraryInfo(LIBS='libgnomecanvasmm',
                                                 LIBPATH='#libs/libgnomecanvasmm',
                                                 CPPPATH='#libs/libgnomecanvasmm')
+
     libraries['soundtouch'] = LibraryInfo(LIBS='soundtouch',
                                           LIBPATH='#libs/soundtouch',
-                                          CPPPATH='#libs/soundtouch')
+                                          CPPPATH=['#libs', '#libs/soundtouch'])
+    libraries['libglademm'] = LibraryInfo(LIBS='libglademm',
+                                          LIBPATH='#libs/libglademm',
+                                          CPPPATH='#libs/libglademm')
 
     coredirs = [
         'libs/soundtouch',
         'templates'
     ]
 
-    subdirs2 = [
+    subdirs = [
+#      'libs/cassowary',
         'libs/sigc++2',
         'libs/pbd3',
         'libs/midi++2',
+        'libs/ardour'
         ]
 
-    gtk2_subdirs = [
-        'libs/glibmm2', 
-        'libs/gtkmm2/pango', 
-        'libs/gtkmm2/atk', 
-        'libs/gtkmm2/gdk', 
-        'libs/gtkmm2/gtk',
+    gtk_subdirs = [
+       'libs/glibmm2',
+       'libs/gtkmm2/pango',
+       'libs/gtkmm2/atk',
+       'libs/gtkmm2/gdk',
+       'libs/gtkmm2/gtk',
+        'libs/libglademm',
        'libs/libgnomecanvasmm',
+       'libs/flowcanvas',
         'libs/gtkmm2ext',
+        'gtk2_ardour'
         ]
-    
+
 opts.Save('scache.conf', env)
 Help(opts.GenerateHelpText(env))
 
 if os.environ.has_key('PATH'):
     env.Append(PATH = os.environ['PATH'])
+
 if os.environ.has_key('PKG_CONFIG_PATH'):
     env.Append(PKG_CONFIG_PATH = os.environ['PKG_CONFIG_PATH'])
 
+if os.environ.has_key('CC'):
+    env['CC'] = os.environ['CC']
+
+if os.environ.has_key('CXX'):
+    env['CXX'] = os.environ['CXX']
+
+if os.environ.has_key('DISTCC_HOSTS'):
+    env['ENV']['DISTCC_HOSTS'] = os.environ['DISTCC_HOSTS']
+    env['ENV']['HOME'] = os.environ['HOME']
+    
 final_prefix = '$PREFIX'
 install_prefix = '$DESTDIR/$PREFIX'
 
@@ -486,11 +542,26 @@ else:
 
 config_prefix = '$DESTDIR' + final_config_prefix
 
+
+# SCons should really do this for us
+
+conf = Configure (env)
+
+have_cxx = conf.TryAction (Action (env['CXX'] + ' --version'));
+if have_cxx[0] != 1:
+    print "This system has no functional C++ compiler. You cannot build Ardour from source without one."
+    exit (1);
+else:
+    print "Congratulations, you have a functioning C++ compiler."
+    
+env = conf.Finish()
+
 #
 # Compiler flags and other system-dependent stuff
 #
 
 opt_flags = []
+debug_flags = [ '-g' ]
 
 # guess at the platform, used to define compiler flags
 
@@ -506,8 +577,15 @@ config = config_guess.split ("-")
 # on OS X darwinports puts things in /opt/local by default
 #
 if config[config_arch] == 'apple':
-    libraries['core'].Append (LIBPATH = [ '/opt/local/lib' ],
-                              CPPPATH = [ '/opt/local/include' ])
+    if os.path.isdir('/opt/local/lib'):
+        libraries['core'].Append (LIBPATH = [ '/opt/local/lib' ])
+    if os.path.isdir('/opt/local/include'):
+        libraries['core'].Append (CPPPATH = [ '/opt/local/include' ])
+
+    if env['BUILD_VECLIB_OPTIMIZATIONS'] == 1:
+        opt_flags.append ("-DBUILD_VECLIB_OPTIMIZATIONS")
+        debug_flags.append ("-DBUILD_VECLIB_OPTIMIZATIONS")
+        libraries['core'].Append(LINKFLAGS= '-framework Accelerate')
 
 if config[config_cpu] == 'powerpc':
     #
@@ -517,15 +595,23 @@ if config[config_cpu] == 'powerpc':
     #
     if env['NOARCH'] == 0:
         if env['ALTIVEC'] == 1:
-            opt_flags.extend ([ "-mcpu=7400", "-maltivec", "-mabi=altivec" ])
-        else:
+           if config[config_arch] == 'apple':
+                opt_flags.extend ([ "-mcpu=7450", "-faltivec"])
+            else:
+               opt_flags.extend ([ "-mcpu=7400", "-maltivec", "-mabi=altivec"]) 
+       else:
             opt_flags.extend([ "-mcpu=750", "-mmultiple" ])
         opt_flags.extend (["-mhard-float", "-mpowerpc-gfxopt"])
 
-elif re.search ("i[0-9]86", config[config_cpu]) != None :
+elif ((re.search ("i[0-9]86", config[config_cpu]) != None) or (re.search ("x86_64", config[config_cpu]) != None)):
 
+    build_host_supports_sse = 0
+    
     if env['NOARCH'] == 0:
 
+        debug_flags.append ("-DARCH_X86")
+        opt_flags.append ("-DARCH_X86")
+
         if config[config_kernel] == 'linux' :
 
             flag_line = os.popen ("cat /proc/cpuinfo | grep '^flags'").read()[:-1]
@@ -534,7 +620,7 @@ elif re.search ("i[0-9]86", config[config_cpu]) != None :
             if "mmx" in x86_flags:
                 opt_flags.append ("-mmmx")
             if "sse" in x86_flags:
-                opt_flags.extend (["-msse", "-mfpmath=sse"])
+               build_host_supports_sse = 1
             if "3dnow" in x86_flags:
                 opt_flags.append ("-m3dnow")
 
@@ -542,7 +628,21 @@ elif re.search ("i[0-9]86", config[config_cpu]) != None :
                 opt_flags.append ("-march=i586")
             elif config[config_cpu] == "i686":
                 opt_flags.append ("-march=i686")
-        
+
+        if env['USE_SSE_EVERYWHERE'] == 1:
+                opt_flags.extend (["-msse", "-mfpmath=sse"])
+                debug_flags.extend (["-msse", "-mfpmath=sse"])
+                if build_host_supports_sse != 1:
+                    print "\nWarning: you are building Ardour with SSE support even though your system does not support these instructions. (This may not be an error, especially if you are a package maintainer)"
+
+        if env['BUILD_SSE_OPTIMIZATIONS'] == 1:
+                opt_flags.append ("-DBUILD_SSE_OPTIMIZATIONS")
+                debug_flags.append ("-DBUILD_SSE_OPTIMIZATIONS")
+                if build_host_supports_sse != 1:
+                    print "\nWarning: you are building Ardour with SSE support even though your system does not support these instructions. (This may not be an error, especially if you are a package maintainer)"
+                    
+# end of processor-specific section
+
 #
 # ARCH="..." overrides all 
 #
@@ -562,7 +662,7 @@ opt_flags[:0] = [
     ]
 
 if env['DEBUG'] == 1:
-    env.Append(CCFLAGS="-g")
+    env.Append(CCFLAGS=" ".join (debug_flags))
 else:
     env.Append(CCFLAGS=" ".join (opt_flags))
 
@@ -571,6 +671,15 @@ env.Append(CCFLAGS="-Wall")
 if env['VST']:
     env.Append(CCFLAGS="-DVST_SUPPORT")
 
+
+# check endianness
+if sys.byteorder == "big":
+    print "Host is big endian"
+    env.Append(CCFLAGS="-DWORDS_BIGENDIAN")
+else:
+    print "Host is little endian"
+
+
 #
 # everybody needs this
 #
@@ -584,16 +693,24 @@ env.Merge ([ libraries['core'] ])
 conf = Configure (env)
 
 if env['NLS']:
+    print 'Checking for internationalization support ...'
+    have_gettext = conf.TryAction(Action('xgettext --version'))
+    if have_gettext[0] != 1:
+        print 'This system is not configured for internationalized applications (no xgettext command). An english-only version will be built\n'
+        env['NLS'] = 0
+        
     if conf.CheckCHeader('libintl.h') == None:
-        print 'This system is not configured for internationalized applications. An english-only version will be built\n'
+        print 'This system is not configured for internationalized applications (no libintl.h). An english-only version will be built\n'
         env['NLS'] = 0
 
+
 env = conf.Finish()
 
 if env['NLS'] == 1:
     env.Append(CCFLAGS="-DENABLE_NLS")
 
-Export('env install_prefix final_prefix config_prefix final_config_prefix libraries i18n version')
+
+Export('env install_prefix final_prefix config_prefix final_config_prefix libraries i18n version subst_dict')
 
 #
 # the configuration file may be system dependent
@@ -606,6 +723,12 @@ if conf.CheckCHeader('/System/Library/Frameworks/CoreAudio.framework/Versions/A/
 else:
     subst_dict['%JACK_BACKEND%'] = "alsa_pcm:playback_"
 
+# posix_memalign available
+if not conf.CheckFunc('posix_memalign'):
+    print 'Did not find posix_memalign(), using malloc'
+    env.Append(CCFLAGS='-DNO_POSIX_MEMALIGN')
+
+
 env = conf.Finish()
 
 rcbuild = env.SubstInFile ('ardour.rc','ardour.rc.in', SUBST_DICT = subst_dict)
@@ -654,9 +777,9 @@ env.AddPostAction (srcdist, Action ('rm -rf ' + str (File (env['DISTTREE']))))
 for subdir in coredirs:
     SConscript (subdir + '/SConscript')
 
-for sublistdir in [subdirs2, gtk2_subdirs]:
-    for subdir in sublistdir:
-        SConscript (subdir + '/SConscript')
+for sublistdir in [subdirs, gtk_subdirs]:
+       for subdir in sublistdir:
+               SConscript (subdir + '/SConscript')
 
 # cleanup
 env.Clean ('scrub', [ 'scache.conf', '.sconf_temp', '.sconsign.dblite', 'config.log'])