$NetBSD: patch-ac,v 1.6 2012/06/27 21:26:28 sbd Exp $

--- SConstruct.orig	2006-03-15 15:22:43.000000000 +0000
+++ SConstruct
@@ -50,6 +50,10 @@ def today():
 def getPlatform():
     if sys.platform[:5] == 'linux':
         return 'linux'
+    elif sys.platform[:6] == 'netbsd':
+        return 'netbsd'
+    elif sys.platform[:9] == 'dragonfly':
+        return 'dragonfly'
     elif sys.platform[:3] == 'win':
         return 'mingw'
     elif sys.platform[:6] == 'darwin':
@@ -207,7 +211,7 @@ opts.Add('buildOSXGUI',
 # This section also sets up customized options for third-party libraries, which
 # should take priority over default options.
 
-commonEnvironment = Environment(options = opts, ENV = {'PATH' : os.environ['PATH']})
+commonEnvironment = Environment(options = opts, ENV = os.environ)
 
 customCPPPATH = commonEnvironment['customCPPPATH']
 commonEnvironment.Prepend(CPPPATH = customCPPPATH)
@@ -285,11 +289,11 @@ if commonEnvironment['MSVC'] == '0':
 
 if getPlatform() == 'linux':
     commonEnvironment.Append(CCFLAGS = "-DLINUX")
-    commonEnvironment.Append(CPPPATH = '/usr/local/include')
-    commonEnvironment.Append(CPPPATH = '/usr/include')
-    commonEnvironment.Append(CPPPATH = '/usr/X11R6/include')
     commonEnvironment.Append(CCFLAGS = "-DPIPES")
     commonEnvironment.Append(LINKFLAGS = ['-Wl,-Bdynamic'])
+    commonEnvironment.Append(CCFLAGS = Split(os.environ['CFLAGS']))
+    commonEnvironment.Append(CXXFLAGS = Split(os.environ['CXXFLAGS']))
+    commonEnvironment.Append(LINKFLAGS = Split(os.environ['LDFLAGS']))
 elif getPlatform() == 'darwin':
     commonEnvironment.Append(CCFLAGS = "-DMACOSX")
     commonEnvironment.Append(CPPPATH = '/usr/local/include')
@@ -335,6 +339,15 @@ elif getPlatform() == 'mingw':
     pythonLinkFlags = []
     pythonLibraryPath = []
     pythonLibs = ['python%s' % commonEnvironment['pythonVersion'].replace('.', '')]
+elif getPlatform() == 'netbsd' or getPlatform() == 'dragonfly':
+    commonEnvironment.Append(CCFLAGS = Split(os.environ['CFLAGS']))
+    commonEnvironment.Append(CXXFLAGS = Split(os.environ['CXXFLAGS']))
+    commonEnvironment.Append(LINKFLAGS = Split(os.environ['LDFLAGS']))
+    pythonIncludePath = []
+    pythonLinkFlags = []
+    pythonLibraryPath = []
+    pythonLibs = []
+    SConsignFile("unused-consign-file")
 
 # Check for prerequisites.
 # We check only for headers; checking for libs may fail
@@ -485,7 +498,7 @@ def buildzip(env, target, source):
 # library version is CS_VERSION.CS_APIVERSION
 csoundLibraryVersion = '5.1'
 csoundLibraryName = 'csound'
-if getPlatform() == 'linux' and commonEnvironment['useDouble'] != '0':
+if (getPlatform() == 'linux' or getPlatform() == 'netbsd' or getPlatform() == 'dragonfly') and commonEnvironment['useDouble'] != '0':
     csoundLibraryName += '64'
 # flags for linking with the Csound library
 libCsoundLinkFlags = []
@@ -526,6 +539,12 @@ if commonEnvironment['buildRelease'] !=
             tmp += '64'
         s = '-DCS_DEFAULT_PLUGINDIR=\\"%s\\"' % tmp
         csoundLibraryEnvironment.Append(CPPFLAGS = [s])
+    if getPlatform() == 'netbsd' or getPlatform() == 'dragonfly':
+        tmp = '%s/lib/csound5/plugins' % commonEnvironment['prefix']
+        if commonEnvironment['useDouble'] != '0':
+            tmp += '64'
+        s = '-DCS_DEFAULT_PLUGINDIR=\\"%s\\"' % tmp
+        csoundLibraryEnvironment.Append(CPPFLAGS = [s])
 csoundDynamicLibraryEnvironment = csoundLibraryEnvironment.Copy()
 csoundDynamicLibraryEnvironment.Append(LIBS = ['sndfile'])
 if getPlatform() == 'mingw':
@@ -550,6 +569,11 @@ if getPlatform() == 'mingw':
     csoundDynamicLibraryEnvironment['ENV']['PATH'] = os.environ['PATH']
 elif getPlatform() == 'linux':
     csoundDynamicLibraryEnvironment.Append(LIBS = ['dl', 'm', 'pthread'])
+elif getPlatform() == 'netbsd':
+    csoundDynamicLibraryEnvironment.Append(LIBS = ['m', 'pthread'])
+elif getPlatform() == 'dragonfly':
+    csoundDynamicLibraryEnvironment.Append(LINKFLAGS = ['-pthread'])
+    csoundDynamicLibraryEnvironment.Append(LIBS = ['m'])
 csoundInterfacesEnvironment = csoundDynamicLibraryEnvironment.Copy()
 
 if buildOSXFramework:
@@ -776,9 +800,17 @@ else:
         csoundProgramEnvironment.Append(LIBS = ['dl'])
         vstEnvironment.Append(LIBS = ['dl'])
         guiProgramEnvironment.Append(LIBS = ['dl'])
-    csoundProgramEnvironment.Append(LIBS = ['pthread', 'm'])
-    vstEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm'])
-    guiProgramEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm'])
+    if getPlatform() == 'dragonfly':
+	csoundProgramEnvironment.Append(LIBS = ['m'])
+	csoundProgramEnvironment.Append(LINKFLAGS = ['-pthread'])
+        vstEnvironment.Append(LIBS = ['stdc++', 'm'])
+        vstEnvironment.Append(LINKFLAGS = ['-pthread'])
+        guiProgramEnvironment.Append(LIBS = ['stdc++', 'm'])
+        guiProgramEnvironment.Append(LINKFLAGS = ['-pthread'])
+    else:
+	csoundProgramEnvironment.Append(LIBS = ['pthread', 'm'])
+        vstEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm'])
+        guiProgramEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm'])
     if getPlatform() == 'darwin':
         csoundProgramEnvironment.Append(LINKFLAGS = Split('''
             -framework Carbon -framework CoreAudio -framework CoreMidi
@@ -989,7 +1021,7 @@ makePlugin(pluginEnvironment, 'stdopcod'
 pluginLibraries.append('opcodes.dir')
 MacOSX_InstallPlugin('opcodes.dir')
 
-if getPlatform() == 'linux' or getPlatform() == 'darwin':
+if getPlatform() == 'linux' or getPlatform() == 'darwin' or getPlatform() == 'netbsd' or getPlatform() == 'dragonfly':
     makePlugin(pluginEnvironment, 'control', ['Opcodes/control.c'])
 makePlugin(pluginEnvironment, 'ftest', ['Opcodes/ftest.c'])
 makePlugin(pluginEnvironment, 'mixer', ['Opcodes/mixer.cpp'])
@@ -1042,6 +1074,13 @@ else:
             -framework Carbon -framework CoreAudio -framework CoreMidi
             -framework ApplicationServices
         '''))
+    elif getPlatform() == 'netbsd':
+        widgetsEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags')
+        widgetsEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm'])
+    elif getPlatform() == 'dragonfly':
+        widgetsEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags')
+        widgetsEnvironment.Append(LIBS = ['stdc++', 'm'])
+        widgetsEnvironment.Append(LINKFLAGS = ['-pthread'])
     makePlugin(widgetsEnvironment, 'widgets',
                ['InOut/FL_graph.cpp', 'InOut/winFLTK.c', 'InOut/widgets.cpp'])
 
@@ -1060,7 +1099,11 @@ if not (commonEnvironment['useALSA'] ==
 else:
     print "CONFIGURATION DECISION: Building ALSA plugin."
     alsaEnvironment = pluginEnvironment.Copy()
-    alsaEnvironment.Append(LIBS = ['asound', 'pthread'])
+    if getPlatform() == 'dragonfly':
+        alsaEnvironment.Append(LIBS = ['asound'])
+        alsaEnvironment.Append(LINKFLAGS = ['-pthread'])
+    else:
+        alsaEnvironment.Append(LIBS = ['asound', 'pthread'])
     makePlugin(alsaEnvironment, 'rtalsa', ['InOut/rtalsa.c'])
 
 if getPlatform() == 'mingw':
@@ -1082,6 +1125,8 @@ else:
     elif getPlatform() == 'mingw':
         portaudioEnvironment.Append(LIBS = ['winmm', 'dsound'])
         portaudioEnvironment.Append(LIBS = csoundWindowsLibraries)
+    elif getPlatform() == 'netbsd' or getPlatform() == 'dragonfly':
+        portaudioEnvironment.ParseConfig('pkg-config --cflags --libs portaudio-2.0')
     makePlugin(portaudioEnvironment, 'rtpa', ['InOut/rtpa.c'])
 
 if not (commonEnvironment['useJack'] == '1' and jackFound):
@@ -1091,6 +1136,9 @@ else:
     jackEnvironment = pluginEnvironment.Copy()
     if getPlatform() == 'linux':
         jackEnvironment.Append(LIBS = ['jack', 'asound', 'pthread'])
+    elif getPlatform() == 'dragonfly':
+        jackEnvironment.Append(LIBS = ['jack'])
+        jackEnvironment.Append(LINKFLAGS = ['-pthread'])
     else:
         jackEnvironment.Append(LIBS = ['jack', 'pthread'])
     makePlugin(jackEnvironment, 'rtjack', ['InOut/rtjack.c'])
@@ -1100,7 +1148,11 @@ if not (commonEnvironment['useOSC'] == '
 else:
     print "CONFIGURATION DECISION: Building OSC plugin."
     oscEnvironment = pluginEnvironment.Copy()
-    oscEnvironment.Append(LIBS = ['lo', 'pthread'])
+    if getPlatform() == 'dragonfly':
+        oscEnvironment.Append(LIBS = ['lo'])
+        oscEnvironment.Append(LINKFLAGS = ['-pthread'])
+    else:
+        oscEnvironment.Append(LIBS = ['lo', 'pthread'])
     if getPlatform() == 'mingw':
         oscEnvironment.Append(LIBS = csoundWindowsLibraries)
         oscEnvironment.Append(SHLINKFLAGS = ['-Wl,--enable-stdcall-fixup'])
@@ -1118,8 +1170,10 @@ else:
         fluidEnvironment.Append(CPPFLAGS = ['-DFLUIDSYNTH_NOT_A_DLL'])
         fluidEnvironment.Append(LIBS = ['winmm', 'dsound'])
         fluidEnvironment.Append(LIBS = csoundWindowsLibraries)
-    elif getPlatform() == 'linux' or getPlatform() == 'darwin':
+    elif getPlatform() == 'linux' or getPlatform() == 'darwin' or getPlatform() == 'netbsd':
         fluidEnvironment.Append(LIBS = ['pthread'])
+    elif getPlatform() == 'dragonfly':
+        fluidEnvironment.Append(LINKFLAGS = ['-pthread'])
     makePlugin(fluidEnvironment, 'fluidOpcodes',
                ['Opcodes/fluidOpcodes/fluidOpcodes.c'])
 
@@ -1237,6 +1291,13 @@ else:
         guiProgramEnvironment.Prepend(LINKFLAGS = ['-mwindows'])
         vstEnvironment.Append(LIBS = ['fltk_images', 'fltk'])
         guiProgramEnvironment.Append(LINKFLAGS = '-mwindows')
+    elif getPlatform() == 'netbsd' or getPlatform() == 'dragonfly':
+        vstEnvironment.Append(LIBS = ['m'])
+        vstEnvironment.Append(SHLINKFLAGS = '--no-export-all-symbols')
+        vstEnvironment.Append(LINKFLAGS = ['-Wl,-rpath-link,.'])
+        guiProgramEnvironment.Prepend(LINKFLAGS = ['-Wl,-rpath-link,.'])
+        os.spawnvp(os.P_WAIT, 'rm', ['rm', '-f', '_CsoundVST.so'])
+        os.symlink('lib_CsoundVST.so', '_CsoundVST.so')
     guiProgramEnvironment.Prepend(LIBS = ['_CsoundVST'])
     for option in vstEnvironment['CCFLAGS']:
         if string.find(option, '-D') == 0:
@@ -1420,8 +1481,10 @@ else:
         stkEnvironment.Append(LIBS = ['stdc++'])
     if getPlatform() == 'mingw':
         stkEnvironment.Append(LIBS = csoundWindowsLibraries)
-    elif getPlatform() == 'linux' or getPlatform() == 'darwin':
+    elif getPlatform() == 'linux' or getPlatform() == 'darwin' or getPlatform() == 'netbsd':
         stkEnvironment.Append(LIBS = ['pthread'])
+    elif getPlatform() == 'dragonfly':
+        stkEnvironment.Append(LINKFLAGS = ['-pthread'])
     # This is the one that actually defines the opcodes.
     # They are straight wrappers, as simple as possible.
     stk = makePlugin(stkEnvironment, 'stk', ['Opcodes/stk/stkOpcodes.cpp'])
@@ -1443,6 +1506,8 @@ else:
     elif getPlatform() == 'mingw':
         pyEnvironment['ENV']['PATH'] = os.environ['PATH']
         pyEnvironment.Append(SHLINKFLAGS = '--no-export-all-symbols')
+    elif getPlatform() == 'netbsd' or getPlatform() == 'dragonfly':
+        pyEnvironment.Append(LIBS = ['m'])
     pythonOpcodes = makePlugin(pyEnvironment, 'py',
                                ['Opcodes/py/pythonopcodes.c'])
     if getPlatform() == 'mingw' and pythonLibs[0] < 'python24':
@@ -1461,7 +1526,7 @@ if commonEnvironment['buildPDClass']=='1
         pdClass = pdClassEnvironment.Program(
             'csoundapi~.pd_darwin',
             'frontends/csoundapi_tilde/csoundapi_tilde.c')
-    elif getPlatform() == 'linux':
+    elif getPlatform() == 'linux' or getPlatform() == 'netbsd' or getPlatform() == 'dragonfly':
         pdClass = pdClassEnvironment.SharedLibrary(
             'csoundapi~.pd_linux',
             'frontends/csoundapi_tilde/csoundapi_tilde.c',
@@ -1493,6 +1558,11 @@ if commonEnvironment['buildTclcsound'] =
         '''))
     elif getPlatform() == 'linux':
         csTclEnvironment.Append(LIBS = ['tcl8.4', 'tk8.4', 'dl', 'pthread'])
+    elif getPlatform() == 'netbsd':
+        csTclEnvironment.Append(LIBS = ['tcl8.4', 'tk8.4', 'pthread'])
+    elif getPlatform() == 'dragonfly':
+        csTclEnvironment.Append(LIBS = ['tcl8.4', 'tk8.4'])
+        csTclEnvironment.Append(LINKFLAGS = ['-pthread'])
     elif getPlatform() == 'mingw':
         csTclEnvironment.Append(LIBS = ['tcl84', 'tk84'])
         csTclEnvironment.Append(LIBS = csoundWindowsLibraries)
@@ -1591,18 +1661,18 @@ else:
 
 PREFIX = commonEnvironment['prefix']
 
-BIN_DIR = PREFIX + "/bin"
-INCLUDE_DIR = PREFIX + "/include/csound"
+BIN_DIR = PREFIX + "/lib/csound5"
+INCLUDE_DIR = PREFIX + "/include/csound5"
 
 if (commonEnvironment['Word64'] == '1'):
-    LIB_DIR = PREFIX + "/lib64"
+    LIB_DIR = PREFIX + "/lib64/csound5"
 else:
-    LIB_DIR = PREFIX + "/lib"
+    LIB_DIR = PREFIX + "/lib/csound5"
 
 if commonEnvironment['useDouble'] == '0':
-    PLUGIN_DIR = LIB_DIR + "/csound/plugins"
+    PLUGIN_DIR = LIB_DIR + "/plugins"
 else:
-    PLUGIN_DIR = LIB_DIR + "/csound/plugins64"
+    PLUGIN_DIR = LIB_DIR + "/plugins"
 
 if commonEnvironment['install'] == '1':
     installExecutables = Alias('install-executables',
