<commit_before>#!/usr/bin/env python

###
# Copyright (c) 2003, Daniel DiPaolo
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#   * Redistributions of source code must retain the above copyright notice,
#     this list of conditions, and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright notice,
#     this list of conditions, and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#   * Neither the name of the author of this software nor the name of
#     contributors to this software may be used to endorse or promote products
#     derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###

from test import *

try:
    import sqlite
except ImportError:
    sqlite = None

if sqlite is not None:
    class TodoTestCase(PluginTestCase, PluginDocumentation):
        plugins = ('Todo', 'User')
        def setUp(self):
            PluginTestCase.setUp(self)
            # Create a valid user to use
            self.prefix = 'foo!bar@baz'
            self.assertNotError('register tester moo')

        def testTodo(self):
            # Should not error, but no tasks yet.
            self.assertNotError('todo')
            self.assertRegexp('todo', 'You have no tasks in your todo list.')
            # Add a task
            self.assertNotError('todo add wash my car')
            self.assertRegexp('todo', '#1: wash my car')
            # Check that task
            self.assertRegexp('todo 1',
                              'Todo for tester: wash my car \(Added .*?\)')
            # Check that it lists all my tasks when given my name
            self.assertRegexp('todo tester', 'Todo for tester: '
                              '#1: wash my car')
            # Check pluralization
            self.assertNotError('todo add moo')
            self.assertRegexp('todo tester', 'Todos for tester: '
                              '#1: wash my car and #2: moo')

        def testAddtodo(self):
            self.assertNotError('todo add code a new plugin')
            self.assertNotError('todo add --priority=1000 fix all bugs')

        def testRemovetodo(self):
            self.assertNotError('todo add do something else')
            self.assertNotError('todo remove 1')

        def testSearchtodo(self):
            self.assertNotError('todo add task number one')
            self.assertRegexp('todo search task*', '#1: task number one')
            self.assertNotError('todo add task number two is much longer than'
                                ' task number one')
            self.assertRegexp('todo search task*','#1: task number one and #2:'
                              ' task number two is much longer than task '
                              'number...')
            self.assertRegexp('todo search --exact "task number one"',
                              '#1: task number one')
            self.assertError('todo search --regexp s/bustedregex')
            self.assertRegexp('todo search --regexp m/task/', '#1: task number'
                              ' one and #2: task number two is much longer '
                              'than task number...')

        def testSetPriority(self):
            self.assertNotError('todo add --priority=1 moo')
            self.assertRegexp('todo 1', 'moo, priority: 1 \(Added '
                              'at .*?\)')
            self.assertNotError('setpriority 1 50')
            self.assertRegexp('todo 1', 'moo, priority: 50 \(Added '
                              'at .*?\)')
            self.assertNotError('setpriority 1 0')
            self.assertRegexp('todo 1', 'moo \(Added at .*?\)')

        def testChangeTodo(self):
            self.assertNotError('todo add moo')
            self.assertError('todo change 1 asdfas')
            self.assertError('todo change 1 m/asdfaf//')
            self.assertNotError('todo change 1 s/moo/foo/')
            self.assertRegexp('todo 1', 'Todo for tester: foo \(Added .*?\)')

# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

<commit_msg>Added a test to make sure I don't make that stupid mistake (not including "msg" in irc.error) in the same place again.<commit_after>#!/usr/bin/env python

###
# Copyright (c) 2003, Daniel DiPaolo
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#   * Redistributions of source code must retain the above copyright notice,
#     this list of conditions, and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright notice,
#     this list of conditions, and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#   * Neither the name of the author of this software nor the name of
#     contributors to this software may be used to endorse or promote products
#     derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###

from test import *

try:
    import sqlite
except ImportError:
    sqlite = None

if sqlite is not None:
    class TodoTestCase(PluginTestCase, PluginDocumentation):
        plugins = ('Todo', 'User')
        def setUp(self):
            PluginTestCase.setUp(self)
            # Create a valid user to use
            self.prefix = 'foo!bar@baz'
            self.assertNotError('register tester moo')

        def testTodo(self):
            # Should not error, but no tasks yet.
            self.assertNotError('todo')
            self.assertRegexp('todo', 'You have no tasks in your todo list.')
            # Add a task
            self.assertNotError('todo add wash my car')
            self.assertRegexp('todo', '#1: wash my car')
            # Check that task
            self.assertRegexp('todo 1',
                              'Todo for tester: wash my car \(Added .*?\)')
            # Check that it lists all my tasks when given my name
            self.assertRegexp('todo tester', 'Todo for tester: '
                              '#1: wash my car')
            # Check pluralization
            self.assertNotError('todo add moo')
            self.assertRegexp('todo tester', 'Todos for tester: '
                              '#1: wash my car and #2: moo')
            # Check error
            self.assertError('todo asfas')
            self.assertResponse('todo asfas', 'Error: \'asfas\' is not a '
                                'valid task id or username')

        def testAddtodo(self):
            self.assertNotError('todo add code a new plugin')
            self.assertNotError('todo add --priority=1000 fix all bugs')

        def testRemovetodo(self):
            self.assertNotError('todo add do something else')
            self.assertNotError('todo remove 1')

        def testSearchtodo(self):
            self.assertNotError('todo add task number one')
            self.assertRegexp('todo search task*', '#1: task number one')
            self.assertNotError('todo add task number two is much longer than'
                                ' task number one')
            self.assertRegexp('todo search task*','#1: task number one and #2:'
                              ' task number two is much longer than task '
                              'number...')
            self.assertRegexp('todo search --exact "task number one"',
                              '#1: task number one')
            self.assertError('todo search --regexp s/bustedregex')
            self.assertRegexp('todo search --regexp m/task/', '#1: task number'
                              ' one and #2: task number two is much longer '
                              'than task number...')

        def testSetPriority(self):
            self.assertNotError('todo add --priority=1 moo')
            self.assertRegexp('todo 1', 'moo, priority: 1 \(Added '
                              'at .*?\)')
            self.assertNotError('setpriority 1 50')
            self.assertRegexp('todo 1', 'moo, priority: 50 \(Added '
                              'at .*?\)')
            self.assertNotError('setpriority 1 0')
            self.assertRegexp('todo 1', 'moo \(Added at .*?\)')

        def testChangeTodo(self):
            self.assertNotError('todo add moo')
            self.assertError('todo change 1 asdfas')
            self.assertError('todo change 1 m/asdfaf//')
            self.assertNotError('todo change 1 s/moo/foo/')
            self.assertRegexp('todo 1', 'Todo for tester: foo \(Added .*?\)')

# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

<|endoftext|>


<commit_before>#!/usr/bin/python

import os
import re

CFlags = '-Wall -O3 -fno-inline-functions -march=i686 -mtune=pentium3'
CFlags += ' -fomit-frame-pointer -ffast-math'

# CFlags = '-O0'

# package root directory
pkgDir      = '../__csound5'
# base directory for installation
instPrefix  = '/usr/local'

# frontends
binDir      = instPrefix + '/bin'
# the actual binaries (called by above)
binDir2     = instPrefix + '/lib/csound/bin'
# Csound API header files
includeDir  = instPrefix + '/include/csound'
# Csound API libraries
libDir      = instPrefix + '/lib'
# private libraries for use by Csound
libDir2     = libDir + '/csound/lib'
# single precision plugin libraries
pluginDir32 = libDir + '/csound/plugins'
# double precision plugin libraries
pluginDir64 = libDir + '/csound/plugins64'
# XMG files
xmgDir      = instPrefix + '/share/csound/xmg'
# documentation
docDir      = instPrefix + '/share/doc/csound'
# tclcsound.so
tclDir      = libDir + '/csound/tcl'
# csnd.jar
javaDir     = libDir + '/csound/java'
# LISP interface
lispDir     = libDir + '/csound/lisp'
# STK raw wave files
rawWaveDir  = instPrefix + '/share/csound/rawwaves'

# Python version to use
pyVersion   = '2.4'
# csnd.py
pythonDir   = '/usr/lib/python' + pyVersion
# _csnd.so
pythonDir2  = pythonDir + '/lib-dynload'
# csoundapi~.pd_linux
pdDir       = '/usr/local/lib/pd/extra'

buildOpts = ['buildRelease=1', 'buildUtilities=0', 'useLrint=1', 'noDebug=1']
buildOpts += ['buildPythonOpcodes=1', 'useOSC=1', 'buildCsoundVST=0']
buildOpts += ['buildJavaWrapper=1', 'pythonVersion=%s' % pyVersion]
buildOpts += ['customCCFLAGS=%s' % CFlags, 'customCXXFLAGS=%s' % CFlags]
buildOpts += ['buildCsoundVST=0', 'buildLoris=0', 'buildStkOpcodes=0']
buildOpts += ['prefix=%s' % instPrefix]

headerFiles = ['H/cfgvar.h', 'H/cscore.h', 'H/csdl.h', 'H/csound.h']
headerFiles += ['H/csound.hpp', 'H/csoundCore.h', 'H/cwindow.h']
headerFiles += ['H/msg_attr.h', 'H/OpcodeBase.hpp', 'H/pstream.h']
headerFiles += ['H/pvfileio.h', 'H/soundio.h', 'H/sysdep.h', 'H/text.h']
headerFiles += ['H/version.h']
headerFiles += ['interfaces/CppSound.hpp', 'interfaces/filebuilding.h']
headerFiles += ['interfaces/CsoundFile.hpp']

utils1 = ['csound', 'cvanal', 'dnoise', 'envext', 'extractor',
          'het_export', 'het_import', 'hetro', 'lpanal',
          'lpc_export', 'lpc_import', 'mixer', 'pvanal',
          'pvlook', 'scale', 'sndinfo', 'srconv']

utils2 = ['scsort', 'extract', 'cs', 'csb64enc', 'makecsd', 'scot']

docFiles = ['COPYING', 'ChangeLog', 'INSTALL', 'readme-csound5.txt']

# -----------------------------------------------------------------------------

def runCmd(args):
    return os.spawnvp(os.P_WAIT, args[0], args)

def installFile(src, dst):
    return runCmd(['install', '-p', '-m', '0644', src, '%s%s' % (pkgDir, dst)])

def installFiles(src, dst):
    for i in src:
        err = installFile(i, dst)
        if err != 0:
            return err
    return 0

def installXFile(stripMode, src, dst):
    if stripMode != '':
        err = runCmd(['strip', stripMode, src])
        if err != 0:
            return err
    return runCmd(['install', '-p', '-m', '0755', src, '%s%s' % (pkgDir, dst)])

def findFiles(pat):
    lst = []
    for fName in os.listdir('.'):
        if re.match(pat, fName) != None:
            lst += [fName]
    return lst

def cleanup():
    runCmd(['./cleanup.sh'])

def makeFrontEnd(utilName, is64bit):
    fName = '%s%s/%s%s' % (pkgDir, binDir, utilName, ['', '64'][is64bit])
    f = open(fName, 'w')
    tmp =  '#!/bin/sh\n'
    tmp += '\n'
    tmp += 'export %s="%s"\n'
    tmp += 'export CSSTRNGS="%s"\n'
    tmp += 'export RAWWAVE_PATH="%s"\n'
    tmp += '\n'
    tmp += 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then\n'
    tmp += '    export LD_LIBRARY_PATH="%s"\n'
    tmp += 'else\n'
    tmp += '    export LD_LIBRARY_PATH="%s:${LD_LIBRARY_PATH}"\n'
    tmp += 'fi\n'
    tmp += '\n'
    tmp += 'exec "%s/%s"%s "$@"\n'
    print >> f, tmp % (['OPCODEDIR', 'OPCODEDIR64'][is64bit],
                       [pluginDir32, pluginDir64][is64bit],
                       xmgDir, rawWaveDir, libDir2, libDir2,
                       binDir2, ['csound', 'csound64'][is64bit],
                       ['', ' -U %s' % utilName][int(utilName != 'csound')])
    f.close
    os.chmod(fName, 0755)

# remove old package

runCmd(['rm', '-Rf', pkgDir])

# create directory tree

os.makedirs(pkgDir, 0755)
for i in [binDir, libDir, binDir2, includeDir, libDir2, pluginDir32,
          pluginDir64, xmgDir, docDir, pythonDir, pythonDir2, pdDir, tclDir,
          javaDir, lispDir, rawWaveDir]:
    os.makedirs('%s%s' % (pkgDir, i), 0755)

# copy header files

installFiles(headerFiles, includeDir)

# copy documentation

installFiles(docFiles, docDir)

# create frontends

for i in utils1:
    makeFrontEnd(i, 0)
    makeFrontEnd(i, 1)

# copy scripts

installXFile('', 'brkpt', binDir)
installXFile('', 'linseg', binDir)
installXFile('', 'tabdes', binDir)
installFile('nsliders.tk', tclDir)

# copy STK raw wave files

rawWaveFiles = []
for fName in os.listdir('./Opcodes/stk/rawwaves'):
    if re.match('^.*\.raw$', fName) != None:
        rawWaveFiles += ['./Opcodes/stk/rawwaves/' + fName]
installFiles(rawWaveFiles, rawWaveDir)

# build Csound

buildOpts2 = [['useDouble=0', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=0', 'dynamicCsoundLibrary=1', 'generateXmg=1',
               'buildInterfaces=0', 'buildPDClass=1', 'buildTclcsound=1',
               'buildLoris=1', 'buildStkOpcodes=1'],
              ['useDouble=1', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=1', 'dynamicCsoundLibrary=1', 'generateXmg=0',
               'buildInterfaces=1', 'buildPDClass=0', 'buildTclcsound=1',
               'buildCsoundVST=1', 'buildLoris=1', 'buildStkOpcodes=1']]

for i in range(4):
    cleanup()
    args = ['scons'] + buildOpts + buildOpts2[i]
    if (runCmd(args) != 0):
        print ' *** build failed'
        runCmd(['rm', '-Rf', pkgDir])
        cleanup()
        raise SystemExit(1)
    if i == 0:
        # ------------ single precision, static Csound library ------------
        installXFile('--strip-unneeded', 'csound', binDir2)
        installFile('libcsound.a', libDir)
    elif i == 1:
        # ------------ single precision, dynamic Csound library ------------
        # string database files
        xmgList = findFiles('^.*\.xmg$')
        installFiles(xmgList, xmgDir)
        # plugin libraries
        os.remove('libcsound.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir32)
        # Csound API library
        libraryName = findFiles('^libcsound\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound.so' % (pkgDir, libDir))
        # csoundapi~ for PD
        runCmd(['strip', '--strip-unneeded', 'csoundapi~.pd_linux'])
        installFile('csoundapi~.pd_linux', pdDir)
        # TclCsound
        installXFile('--strip-unneeded', 'cstclsh', binDir)
        installXFile('--strip-unneeded', 'cswish', binDir)
        installXFile('--strip-unneeded', 'tclcsound.so', tclDir)
    elif i == 2:
        # ------------ double precision, static Csound library ------------
        os.rename('csound', 'csound64')
        installXFile('--strip-unneeded', 'csound64', binDir2)
        installFile('libcsound64.a', libDir)
    elif i == 3:
        # ------------ double precision, dynamic Csound library ------------
        installXFile('--strip-unneeded', 'CsoundVST', binDir)
        # plugin libraries
        os.remove('libcsound64.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir64)
        # Csound API library
        libraryName = findFiles('^libcsound64\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound64.so' % (pkgDir, libDir))
        # standalone utilities
        for j in utils2:
            installXFile('--strip-unneeded', j, binDir)
        # TclCsound
        os.rename('cstclsh', 'cstclsh64')
        installXFile('--strip-unneeded', 'cstclsh64', binDir)
        os.rename('cswish', 'cswish64')
        installXFile('--strip-unneeded', 'cswish64', binDir)
        os.rename('tclcsound.so', 'tclcsound64.so')
        installXFile('--strip-unneeded', 'tclcsound64.so', tclDir)
        # Python interface libraries (csnd, CsoundVST, and loris)
        installXFile('--strip-debug', 'lib_csnd.so', libDir)
        os.symlink('%s/lib_csnd.so' % libDir,
                   '%s%s/_csnd.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', 'lib_CsoundVST.so', libDir)
        os.symlink('%s/lib_CsoundVST.so' % libDir,
                   '%s%s/_CsoundVST.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', '_loris.so', pythonDir2)
        f = open('__make_pyc.sh', 'w')
        print >> f, '#!/bin/sh'
        print >> f, 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`"'
        print >> f, 'else'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`:${LD_LIBRARY_PATH}"'
        print >> f, 'fi'
        print >> f, 'python -c "import csnd"'
        print >> f, 'python -O -c "import csnd"'
        print >> f, 'python -c "import CsoundVST"'
        print >> f, 'python -O -c "import CsoundVST"'
        print >> f, 'python -c "import loris"'
        print >> f, 'python -O -c "import loris"'
        print >> f
        f.close()
        os.chmod('__make_pyc.sh', 0755)
        runCmd(['./__make_pyc.sh'])
        os.remove('__make_pyc.sh')
        installFiles(['csnd.py', 'csnd.pyc', 'csnd.pyo',
                      'CsoundVST.py', 'CsoundVST.pyc', 'CsoundVST.pyo',
                      'loris.py', 'loris.pyc', 'loris.pyo'], pythonDir)
        # Java interface library
        installXFile('--strip-debug', 'lib_jcsound.so', libDir)
        installFile('csnd.jar', javaDir)
        # LISP interface
        installFile('interfaces/csound5.lisp', lispDir)

cleanup()

<commit_msg>Updated for the removal of INSTALL<commit_after>#!/usr/bin/python

import os
import re

CFlags = '-Wall -O3 -fno-inline-functions -march=i686 -mtune=pentium3'
CFlags += ' -fomit-frame-pointer -ffast-math'

# CFlags = '-O0'

# package root directory
pkgDir      = '../__csound5'
# base directory for installation
instPrefix  = '/usr/local'

# frontends
binDir      = instPrefix + '/bin'
# the actual binaries (called by above)
binDir2     = instPrefix + '/lib/csound/bin'
# Csound API header files
includeDir  = instPrefix + '/include/csound'
# Csound API libraries
libDir      = instPrefix + '/lib'
# private libraries for use by Csound
libDir2     = libDir + '/csound/lib'
# single precision plugin libraries
pluginDir32 = libDir + '/csound/plugins'
# double precision plugin libraries
pluginDir64 = libDir + '/csound/plugins64'
# XMG files
xmgDir      = instPrefix + '/share/csound/xmg'
# documentation
docDir      = instPrefix + '/share/doc/csound'
# tclcsound.so
tclDir      = libDir + '/csound/tcl'
# csnd.jar
javaDir     = libDir + '/csound/java'
# LISP interface
lispDir     = libDir + '/csound/lisp'
# STK raw wave files
rawWaveDir  = instPrefix + '/share/csound/rawwaves'

# Python version to use
pyVersion   = '2.4'
# csnd.py
pythonDir   = '/usr/lib/python' + pyVersion
# _csnd.so
pythonDir2  = pythonDir + '/lib-dynload'
# csoundapi~.pd_linux
pdDir       = '/usr/local/lib/pd/extra'

buildOpts = ['buildRelease=1', 'buildUtilities=0', 'useLrint=1', 'noDebug=1']
buildOpts += ['buildPythonOpcodes=1', 'useOSC=1', 'buildCsoundVST=0']
buildOpts += ['buildJavaWrapper=1', 'pythonVersion=%s' % pyVersion]
buildOpts += ['customCCFLAGS=%s' % CFlags, 'customCXXFLAGS=%s' % CFlags]
buildOpts += ['buildCsoundVST=0', 'buildLoris=0', 'buildStkOpcodes=0']
buildOpts += ['prefix=%s' % instPrefix]

headerFiles = ['H/cfgvar.h', 'H/cscore.h', 'H/csdl.h', 'H/csound.h']
headerFiles += ['H/csound.hpp', 'H/csoundCore.h', 'H/cwindow.h']
headerFiles += ['H/msg_attr.h', 'H/OpcodeBase.hpp', 'H/pstream.h']
headerFiles += ['H/pvfileio.h', 'H/soundio.h', 'H/sysdep.h', 'H/text.h']
headerFiles += ['H/version.h']
headerFiles += ['interfaces/CppSound.hpp', 'interfaces/filebuilding.h']
headerFiles += ['interfaces/CsoundFile.hpp']

utils1 = ['csound', 'cvanal', 'dnoise', 'envext', 'extractor',
          'het_export', 'het_import', 'hetro', 'lpanal',
          'lpc_export', 'lpc_import', 'mixer', 'pvanal',
          'pvlook', 'scale', 'sndinfo', 'srconv']

utils2 = ['scsort', 'extract', 'cs', 'csb64enc', 'makecsd', 'scot']

docFiles = ['COPYING', 'ChangeLog', 'readme-csound5.txt']

# -----------------------------------------------------------------------------

def runCmd(args):
    return os.spawnvp(os.P_WAIT, args[0], args)

def installFile(src, dst):
    return runCmd(['install', '-p', '-m', '0644', src, '%s%s' % (pkgDir, dst)])

def installFiles(src, dst):
    for i in src:
        err = installFile(i, dst)
        if err != 0:
            return err
    return 0

def installXFile(stripMode, src, dst):
    if stripMode != '':
        err = runCmd(['strip', stripMode, src])
        if err != 0:
            return err
    return runCmd(['install', '-p', '-m', '0755', src, '%s%s' % (pkgDir, dst)])

def findFiles(pat):
    lst = []
    for fName in os.listdir('.'):
        if re.match(pat, fName) != None:
            lst += [fName]
    return lst

def cleanup():
    runCmd(['./cleanup.sh'])

def makeFrontEnd(utilName, is64bit):
    fName = '%s%s/%s%s' % (pkgDir, binDir, utilName, ['', '64'][is64bit])
    f = open(fName, 'w')
    tmp =  '#!/bin/sh\n'
    tmp += '\n'
    tmp += 'export %s="%s"\n'
    tmp += 'export CSSTRNGS="%s"\n'
    tmp += 'export RAWWAVE_PATH="%s"\n'
    tmp += '\n'
    tmp += 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then\n'
    tmp += '    export LD_LIBRARY_PATH="%s"\n'
    tmp += 'else\n'
    tmp += '    export LD_LIBRARY_PATH="%s:${LD_LIBRARY_PATH}"\n'
    tmp += 'fi\n'
    tmp += '\n'
    tmp += 'exec "%s/%s"%s "$@"\n'
    print >> f, tmp % (['OPCODEDIR', 'OPCODEDIR64'][is64bit],
                       [pluginDir32, pluginDir64][is64bit],
                       xmgDir, rawWaveDir, libDir2, libDir2,
                       binDir2, ['csound', 'csound64'][is64bit],
                       ['', ' -U %s' % utilName][int(utilName != 'csound')])
    f.close
    os.chmod(fName, 0755)

# remove old package

runCmd(['rm', '-Rf', pkgDir])

# create directory tree

os.makedirs(pkgDir, 0755)
for i in [binDir, libDir, binDir2, includeDir, libDir2, pluginDir32,
          pluginDir64, xmgDir, docDir, pythonDir, pythonDir2, pdDir, tclDir,
          javaDir, lispDir, rawWaveDir]:
    os.makedirs('%s%s' % (pkgDir, i), 0755)

# copy header files

installFiles(headerFiles, includeDir)

# copy documentation

installFiles(docFiles, docDir)

# create frontends

for i in utils1:
    makeFrontEnd(i, 0)
    makeFrontEnd(i, 1)

# copy scripts

installXFile('', 'brkpt', binDir)
installXFile('', 'linseg', binDir)
installXFile('', 'tabdes', binDir)
installFile('nsliders.tk', tclDir)

# copy STK raw wave files

rawWaveFiles = []
for fName in os.listdir('./Opcodes/stk/rawwaves'):
    if re.match('^.*\.raw$', fName) != None:
        rawWaveFiles += ['./Opcodes/stk/rawwaves/' + fName]
installFiles(rawWaveFiles, rawWaveDir)

# build Csound

buildOpts2 = [['useDouble=0', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=0', 'dynamicCsoundLibrary=1', 'generateXmg=1',
               'buildInterfaces=0', 'buildPDClass=1', 'buildTclcsound=1',
               'buildLoris=1', 'buildStkOpcodes=1'],
              ['useDouble=1', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=1', 'dynamicCsoundLibrary=1', 'generateXmg=0',
               'buildInterfaces=1', 'buildPDClass=0', 'buildTclcsound=1',
               'buildCsoundVST=1', 'buildLoris=1', 'buildStkOpcodes=1']]

for i in range(4):
    cleanup()
    args = ['scons'] + buildOpts + buildOpts2[i]
    if (runCmd(args) != 0):
        print ' *** build failed'
        runCmd(['rm', '-Rf', pkgDir])
        cleanup()
        raise SystemExit(1)
    if i == 0:
        # ------------ single precision, static Csound library ------------
        installXFile('--strip-unneeded', 'csound', binDir2)
        installFile('libcsound.a', libDir)
    elif i == 1:
        # ------------ single precision, dynamic Csound library ------------
        # string database files
        xmgList = findFiles('^.*\.xmg$')
        installFiles(xmgList, xmgDir)
        # plugin libraries
        os.remove('libcsound.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir32)
        # Csound API library
        libraryName = findFiles('^libcsound\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound.so' % (pkgDir, libDir))
        # csoundapi~ for PD
        runCmd(['strip', '--strip-unneeded', 'csoundapi~.pd_linux'])
        installFile('csoundapi~.pd_linux', pdDir)
        # TclCsound
        installXFile('--strip-unneeded', 'cstclsh', binDir)
        installXFile('--strip-unneeded', 'cswish', binDir)
        installXFile('--strip-unneeded', 'tclcsound.so', tclDir)
    elif i == 2:
        # ------------ double precision, static Csound library ------------
        os.rename('csound', 'csound64')
        installXFile('--strip-unneeded', 'csound64', binDir2)
        installFile('libcsound64.a', libDir)
    elif i == 3:
        # ------------ double precision, dynamic Csound library ------------
        installXFile('--strip-unneeded', 'CsoundVST', binDir)
        # plugin libraries
        os.remove('libcsound64.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir64)
        # Csound API library
        libraryName = findFiles('^libcsound64\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound64.so' % (pkgDir, libDir))
        # standalone utilities
        for j in utils2:
            installXFile('--strip-unneeded', j, binDir)
        # TclCsound
        os.rename('cstclsh', 'cstclsh64')
        installXFile('--strip-unneeded', 'cstclsh64', binDir)
        os.rename('cswish', 'cswish64')
        installXFile('--strip-unneeded', 'cswish64', binDir)
        os.rename('tclcsound.so', 'tclcsound64.so')
        installXFile('--strip-unneeded', 'tclcsound64.so', tclDir)
        # Python interface libraries (csnd, CsoundVST, and loris)
        installXFile('--strip-debug', 'lib_csnd.so', libDir)
        os.symlink('%s/lib_csnd.so' % libDir,
                   '%s%s/_csnd.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', 'lib_CsoundVST.so', libDir)
        os.symlink('%s/lib_CsoundVST.so' % libDir,
                   '%s%s/_CsoundVST.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', '_loris.so', pythonDir2)
        f = open('__make_pyc.sh', 'w')
        print >> f, '#!/bin/sh'
        print >> f, 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`"'
        print >> f, 'else'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`:${LD_LIBRARY_PATH}"'
        print >> f, 'fi'
        print >> f, 'python -c "import csnd"'
        print >> f, 'python -O -c "import csnd"'
        print >> f, 'python -c "import CsoundVST"'
        print >> f, 'python -O -c "import CsoundVST"'
        print >> f, 'python -c "import loris"'
        print >> f, 'python -O -c "import loris"'
        print >> f
        f.close()
        os.chmod('__make_pyc.sh', 0755)
        runCmd(['./__make_pyc.sh'])
        os.remove('__make_pyc.sh')
        installFiles(['csnd.py', 'csnd.pyc', 'csnd.pyo',
                      'CsoundVST.py', 'CsoundVST.pyc', 'CsoundVST.pyo',
                      'loris.py', 'loris.pyc', 'loris.pyo'], pythonDir)
        # Java interface library
        installXFile('--strip-debug', 'lib_jcsound.so', libDir)
        installFile('csnd.jar', javaDir)
        # LISP interface
        installFile('interfaces/csound5.lisp', lispDir)

cleanup()

<|endoftext|>


<commit_before>#!/usr/bin/python

import os
import re

CFlags = '-Wall -O3 -fno-inline-functions -march=i686'
# CFlags += ' -mtune=pentium3'
CFlags += ' -fomit-frame-pointer -ffast-math'

# CFlags = '-O0'

# package root directory
pkgDir      = '../__csound5'
# base directory for installation
instPrefix  = '/usr/local'

# frontends
binDir      = instPrefix + '/bin'
# the actual binaries (called by above)
binDir2     = instPrefix + '/lib/csound/bin'
# Csound API header files
includeDir  = instPrefix + '/include/csound'
# Csound API libraries
libDir      = instPrefix + '/lib'
# private libraries for use by Csound
libDir2     = libDir + '/csound/lib'
# single precision plugin libraries
pluginDir32 = libDir + '/csound/plugins'
# double precision plugin libraries
pluginDir64 = libDir + '/csound/plugins64'
# XMG files
xmgDir      = instPrefix + '/share/csound/xmg'
# documentation
docDir      = instPrefix + '/share/doc/csound'
# tclcsound.so
tclDir      = libDir + '/csound/tcl'
# csnd.jar
javaDir     = libDir + '/csound/java'
# LISP interface
lispDir     = libDir + '/csound/lisp'
# STK raw wave files
rawWaveDir  = instPrefix + '/share/csound/rawwaves'

# Python version to use
pyVersion   = '2.4'
# csnd.py
pythonDir   = '/usr/lib/python' + pyVersion + '/site-packages'
# _csnd.so
pythonDir2  = pythonDir
# csoundapi~.pd_linux
pdDir       = '/usr/local/lib/pd/extra'

# uncomment this to install VIM syntax files
vimDir      = '/usr/share/vim/current'
# vimDir    = ''

buildOpts = ['buildRelease=1', 'buildUtilities=0', 'useLrint=1', 'noDebug=1']
buildOpts += ['buildPythonOpcodes=1', 'useOSC=1', 'buildCsoundVST=0']
buildOpts += ['buildJavaWrapper=1', 'pythonVersion=%s' % pyVersion]
buildOpts += ['customCCFLAGS=%s' % CFlags, 'customCXXFLAGS=%s' % CFlags]
buildOpts += ['buildCsoundVST=0', 'buildLoris=0', 'buildStkOpcodes=0']
buildOpts += ['buildCsound5GUI=0', 'prefix=%s' % instPrefix]

headerFiles = ['H/cfgvar.h', 'H/cscore.h', 'H/csdl.h', 'H/csound.h']
headerFiles += ['H/csound.hpp', 'H/csoundCore.h', 'H/cwindow.h']
headerFiles += ['H/msg_attr.h', 'H/OpcodeBase.hpp', 'H/pstream.h']
headerFiles += ['H/pvfileio.h', 'H/soundio.h', 'H/sysdep.h', 'H/text.h']
headerFiles += ['H/version.h']
headerFiles += ['interfaces/CppSound.hpp', 'interfaces/filebuilding.h']
headerFiles += ['interfaces/CsoundFile.hpp']

utils1 = ['csound', 'csound5gui', 'winsound', 'cstclsh', 'cswish',
          'atsa', 'cvanal', 'dnoise', 'envext', 'extractor',
          'het_export', 'het_import', 'hetro', 'lpanal',
          'lpc_export', 'lpc_import', 'mixer', 'pvanal',
          'pvlook', 'pv_export', 'pv_import', 'scale', 'sndinfo',
          'srconv']

utils2 = ['scsort', 'extract', 'cs', 'csb64enc', 'makecsd', 'scot']

docFiles = ['COPYING', 'ChangeLog', 'INSTALL', 'readme-csound5.txt']

# -----------------------------------------------------------------------------

def runCmd(args):
    return os.spawnvp(os.P_WAIT, args[0], args)

def installFile(src, dst):
    return runCmd(['install', '-p', '-m', '0644', src, '%s%s' % (pkgDir, dst)])

def installFiles(src, dst):
    for i in src:
        err = installFile(i, dst)
        if err != 0:
            return err
    return 0

def installXFile(stripMode, src, dst):
    if stripMode != '':
        err = runCmd(['strip', stripMode, src])
        if err != 0:
            return err
    return runCmd(['install', '-p', '-m', '0755', src, '%s%s' % (pkgDir, dst)])

def findFiles(pat):
    lst = []
    for fName in os.listdir('.'):
        if re.match(pat, fName) != None:
            lst += [fName]
    return lst

def cleanup():
    runCmd(['./cleanup.sh'])

def makeFrontEnd(utilName, is64bit):
    precisionSuffix = ''
    if is64bit != 0 and utilName != 'CsoundVST':
        precisionSuffix = '64'
    fName = '%s%s/%s%s' % (pkgDir, binDir, utilName, precisionSuffix)
    if utilName in ['csound', 'csound5gui', 'CsoundVST', 'winsound',
                    'cstclsh', 'cswish', 'pvlook']:
        cmd = '"%s/%s%s"' % (binDir2, utilName, precisionSuffix)
    else:
        cmd = '"%s/csound%s" -U %s' % (binDir2, precisionSuffix, utilName)
    f = open(fName, 'w')
    tmp =  '#!/bin/sh\n'
    tmp += '\n'
    tmp += 'export %s="%s"\n'
    tmp += 'export CSSTRNGS="%s"\n'
    tmp += 'export RAWWAVE_PATH="%s"\n'
    tmp += '\n'
    tmp += 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then\n'
    tmp += '    export LD_LIBRARY_PATH="%s"\n'
    tmp += 'else\n'
    tmp += '    export LD_LIBRARY_PATH="%s:${LD_LIBRARY_PATH}"\n'
    tmp += 'fi\n'
    tmp += '\n'
    tmp += 'exec %s "$@"\n'
    print >> f, tmp % (['OPCODEDIR', 'OPCODEDIR64'][is64bit],
                       [pluginDir32, pluginDir64][is64bit],
                       xmgDir, rawWaveDir, libDir2, libDir2, cmd)
    f.close
    os.chmod(fName, 0755)

# remove old package

runCmd(['rm', '-Rf', pkgDir])

# create directory tree

os.makedirs(pkgDir, 0755)
for i in [binDir, libDir, binDir2, includeDir, libDir2, pluginDir32,
          pluginDir64, xmgDir, docDir, pythonDir, pythonDir2, pdDir, tclDir,
          javaDir, lispDir, rawWaveDir]:
    try:
        os.makedirs('%s%s' % (pkgDir, i), 0755)
    except:
        pass

# copy header files

installFiles(headerFiles, includeDir)

# copy documentation

installFiles(docFiles, docDir)
installFile('frontends/tclcsound/command_summary.txt', tclDir)

# create frontends

for i in utils1:
    makeFrontEnd(i, 0)
    makeFrontEnd(i, 1)
makeFrontEnd('CsoundVST', 1)

# copy scripts

installXFile('', 'brkpt', binDir)
installXFile('', 'linseg', binDir)
installXFile('', 'tabdes', binDir)
installFile('nsliders.tk', tclDir)
installXFile('', 'matrix.tk', binDir)

# copy STK raw wave files

rawWaveFiles = []
for fName in os.listdir('./Opcodes/stk/rawwaves'):
    if re.match('^.*\.raw$', fName) != None:
        rawWaveFiles += ['./Opcodes/stk/rawwaves/' + fName]
installFiles(rawWaveFiles, rawWaveDir)

# copy VIM files if enabled

if vimDir != '':
    for i in ['%s/%s' % (vimDir, 'plugin'), '%s/%s' % (vimDir, 'syntax')]:
        try:
            os.makedirs('%s%s' % (pkgDir, i), 0755)
        except:
            pass
    installXFile('', 'installer/misc/vim/cshelp', binDir)
    installFile('installer/misc/vim/csound.vim', '%s/%s' % (vimDir, 'plugin'))
    for i in ['csound_csd.vim', 'csound_orc.vim', 'csound_sco.vim']:
        installFile('installer/misc/vim/%s' % i, '%s/%s' % (vimDir, 'syntax'))

# build Csound

buildOpts2 = [['useDouble=0', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=0', 'dynamicCsoundLibrary=1', 'generateXmg=1',
               'buildInterfaces=0', 'buildPDClass=1', 'buildTclcsound=1',
               'buildLoris=1', 'buildStkOpcodes=1', 'buildWinsound=1',
               'buildCsound5GUI=1', 'buildUtilities=1'],
              ['useDouble=1', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=1', 'dynamicCsoundLibrary=1', 'generateXmg=0',
               'buildInterfaces=1', 'buildPDClass=0', 'buildTclcsound=1',
               'buildCsoundVST=1', 'buildLoris=1', 'buildStkOpcodes=1',
               'buildWinsound=1', 'buildCsound5GUI=1', 'buildUtilities=1']]

for i in range(4):
    cleanup()
    args = ['scons'] + buildOpts + buildOpts2[i]
    if (runCmd(args) != 0):
        print ' *** build failed'
        runCmd(['rm', '-Rf', pkgDir])
        cleanup()
        raise SystemExit(1)
    if i == 0:
        # ------------ single precision, static Csound library ------------
        installXFile('--strip-unneeded', 'csound', binDir2)
        installFile('libcsound.a', libDir)
    elif i == 1:
        # ------------ single precision, dynamic Csound library ------------
        # string database files
        xmgList = findFiles('^.*\.xmg$')
        installFiles(xmgList, xmgDir)
        # plugin libraries
        os.remove('libcsound.so')
        installFile('opcodes.dir', pluginDir32)
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir32)
        # Csound API library
        libraryName = findFiles('^libcsound\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound.so' % (pkgDir, libDir))
        # csoundapi~ for PD
        runCmd(['strip', '--strip-unneeded', 'csoundapi~.pd_linux'])
        installFile('csoundapi~.pd_linux', pdDir)
        # executables
        for j in ['csound5gui', 'winsound', 'cstclsh', 'cswish', 'pvlook']:
            installXFile('--strip-unneeded', j, binDir2)
        # TclCsound
        installXFile('--strip-unneeded', 'tclcsound.so', tclDir)
    elif i == 2:
        # ------------ double precision, static Csound library ------------
        os.rename('csound', 'csound64')
        installXFile('--strip-unneeded', 'csound64', binDir2)
        installFile('libcsound64.a', libDir)
    elif i == 3:
        # ------------ double precision, dynamic Csound library ------------
        # plugin libraries
        os.remove('libcsound64.so')
        installFile('opcodes.dir', pluginDir64)
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir64)
        # Csound API library
        libraryName = findFiles('^libcsound64\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound64.so' % (pkgDir, libDir))
        # standalone utilities
        for j in utils2:
            installXFile('--strip-unneeded', j, binDir)
        # executables
        installXFile('--strip-unneeded', 'CsoundVST', binDir2)
        for j in ['csound5gui', 'winsound', 'cstclsh', 'cswish', 'pvlook']:
            os.rename(j, j + '64')
            installXFile('--strip-unneeded', j + '64', binDir2)
        # TclCsound
        os.rename('tclcsound.so', 'tclcsound64.so')
        installXFile('--strip-unneeded', 'tclcsound64.so', tclDir)
        # Python interface libraries (csnd, CsoundVST, and loris)
        installXFile('--strip-debug', 'lib_csnd.so', libDir)
        os.symlink('%s/lib_csnd.so' % libDir,
                   '%s%s/_csnd.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', 'lib_CsoundVST.so', libDir)
        os.symlink('%s/lib_CsoundVST.so' % libDir,
                   '%s%s/_CsoundVST.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', '_loris.so', pythonDir2)
        installXFile('--strip-debug', '_scoregen.so', pythonDir2)
        f = open('__make_pyc.sh', 'w')
        print >> f, '#!/bin/sh'
        print >> f, 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`"'
        print >> f, 'else'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`:${LD_LIBRARY_PATH}"'
        print >> f, 'fi'
        print >> f, 'python -c "import csnd"'
        print >> f, 'python -O -c "import csnd"'
        print >> f, 'python -c "import CsoundVST"'
        print >> f, 'python -O -c "import CsoundVST"'
        print >> f, 'python -c "import loris"'
        print >> f, 'python -O -c "import loris"'
        print >> f, 'python -c "import scoregen"'
        print >> f, 'python -O -c "import scoregen"'
        print >> f
        f.close()
        os.chmod('__make_pyc.sh', 0755)
        runCmd(['./__make_pyc.sh'])
        os.remove('__make_pyc.sh')
        installFiles(['csnd.py', 'csnd.pyc', 'csnd.pyo',
                      'loris.py', 'loris.pyc', 'loris.pyo',
                      'CsoundVST.py', 'CsoundVST.pyc', 'CsoundVST.pyo',
                      'scoregen.py', 'scoregen.pyc', 'scoregen.pyo'],
                     pythonDir)
        # Java interface library
        installXFile('--strip-debug', 'lib_jcsound.so', libDir)
        installFile('csnd.jar', javaDir)
        # LISP interface
        installFile('interfaces/csound5.lisp', lispDir)

cleanup()

<commit_msg>added cseditor<commit_after>#!/usr/bin/python

import os
import re

CFlags = '-Wall -O3 -fno-inline-functions -march=i686'
# CFlags += ' -mtune=pentium3'
CFlags += ' -fomit-frame-pointer -ffast-math'

# CFlags = '-O0'

# package root directory
pkgDir      = '../__csound5'
# base directory for installation
instPrefix  = '/usr/local'

# frontends
binDir      = instPrefix + '/bin'
# the actual binaries (called by above)
binDir2     = instPrefix + '/lib/csound/bin'
# Csound API header files
includeDir  = instPrefix + '/include/csound'
# Csound API libraries
libDir      = instPrefix + '/lib'
# private libraries for use by Csound
libDir2     = libDir + '/csound/lib'
# single precision plugin libraries
pluginDir32 = libDir + '/csound/plugins'
# double precision plugin libraries
pluginDir64 = libDir + '/csound/plugins64'
# XMG files
xmgDir      = instPrefix + '/share/csound/xmg'
# documentation
docDir      = instPrefix + '/share/doc/csound'
# tclcsound.so
tclDir      = libDir + '/csound/tcl'
# csnd.jar
javaDir     = libDir + '/csound/java'
# LISP interface
lispDir     = libDir + '/csound/lisp'
# STK raw wave files
rawWaveDir  = instPrefix + '/share/csound/rawwaves'

# Python version to use
pyVersion   = '2.4'
# csnd.py
pythonDir   = '/usr/lib/python' + pyVersion + '/site-packages'
# _csnd.so
pythonDir2  = pythonDir
# csoundapi~.pd_linux
pdDir       = '/usr/local/lib/pd/extra'

# uncomment this to install VIM syntax files
vimDir      = '/usr/share/vim/current'
# vimDir    = ''

buildOpts = ['buildRelease=1', 'buildUtilities=0', 'useLrint=1', 'noDebug=1']
buildOpts += ['buildPythonOpcodes=1', 'useOSC=1', 'buildCsoundVST=0']
buildOpts += ['buildJavaWrapper=1', 'pythonVersion=%s' % pyVersion]
buildOpts += ['customCCFLAGS=%s' % CFlags, 'customCXXFLAGS=%s' % CFlags]
buildOpts += ['buildCsoundVST=0', 'buildLoris=0', 'buildStkOpcodes=0']
buildOpts += ['buildCsound5GUI=0', 'prefix=%s' % instPrefix]

headerFiles = ['H/cfgvar.h', 'H/cscore.h', 'H/csdl.h', 'H/csound.h']
headerFiles += ['H/csound.hpp', 'H/csoundCore.h', 'H/cwindow.h']
headerFiles += ['H/msg_attr.h', 'H/OpcodeBase.hpp', 'H/pstream.h']
headerFiles += ['H/pvfileio.h', 'H/soundio.h', 'H/sysdep.h', 'H/text.h']
headerFiles += ['H/version.h']
headerFiles += ['interfaces/CppSound.hpp', 'interfaces/filebuilding.h']
headerFiles += ['interfaces/CsoundFile.hpp']

utils1 = ['csound', 'csound5gui', 'winsound', 'cstclsh', 'cswish',
          'atsa', 'cvanal', 'dnoise', 'envext', 'extractor',
          'het_export', 'het_import', 'hetro', 'lpanal',
          'lpc_export', 'lpc_import', 'mixer', 'pvanal',
          'pvlook', 'pv_export', 'pv_import', 'scale', 'sndinfo',
          'srconv', 'cseditor']

utils2 = ['scsort', 'extract', 'cs', 'csb64enc', 'makecsd', 'scot']

docFiles = ['COPYING', 'ChangeLog', 'INSTALL', 'readme-csound5.txt']

# -----------------------------------------------------------------------------

def runCmd(args):
    return os.spawnvp(os.P_WAIT, args[0], args)

def installFile(src, dst):
    return runCmd(['install', '-p', '-m', '0644', src, '%s%s' % (pkgDir, dst)])

def installFiles(src, dst):
    for i in src:
        err = installFile(i, dst)
        if err != 0:
            return err
    return 0

def installXFile(stripMode, src, dst):
    if stripMode != '':
        err = runCmd(['strip', stripMode, src])
        if err != 0:
            return err
    return runCmd(['install', '-p', '-m', '0755', src, '%s%s' % (pkgDir, dst)])

def findFiles(pat):
    lst = []
    for fName in os.listdir('.'):
        if re.match(pat, fName) != None:
            lst += [fName]
    return lst

def cleanup():
    runCmd(['./cleanup.sh'])

def makeFrontEnd(utilName, is64bit):
    precisionSuffix = ''
    if is64bit != 0 and utilName != 'CsoundVST':
        precisionSuffix = '64'
    fName = '%s%s/%s%s' % (pkgDir, binDir, utilName, precisionSuffix)
    if utilName in ['csound', 'csound5gui', 'CsoundVST', 'winsound',
                    'cstclsh', 'cswish', 'pvlook']:
        cmd = '"%s/%s%s"' % (binDir2, utilName, precisionSuffix)
    else:
        cmd = '"%s/csound%s" -U %s' % (binDir2, precisionSuffix, utilName)
    f = open(fName, 'w')
    tmp =  '#!/bin/sh\n'
    tmp += '\n'
    tmp += 'export %s="%s"\n'
    tmp += 'export CSSTRNGS="%s"\n'
    tmp += 'export RAWWAVE_PATH="%s"\n'
    tmp += '\n'
    tmp += 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then\n'
    tmp += '    export LD_LIBRARY_PATH="%s"\n'
    tmp += 'else\n'
    tmp += '    export LD_LIBRARY_PATH="%s:${LD_LIBRARY_PATH}"\n'
    tmp += 'fi\n'
    tmp += '\n'
    tmp += 'exec %s "$@"\n'
    print >> f, tmp % (['OPCODEDIR', 'OPCODEDIR64'][is64bit],
                       [pluginDir32, pluginDir64][is64bit],
                       xmgDir, rawWaveDir, libDir2, libDir2, cmd)
    f.close
    os.chmod(fName, 0755)

# remove old package

runCmd(['rm', '-Rf', pkgDir])

# create directory tree

os.makedirs(pkgDir, 0755)
for i in [binDir, libDir, binDir2, includeDir, libDir2, pluginDir32,
          pluginDir64, xmgDir, docDir, pythonDir, pythonDir2, pdDir, tclDir,
          javaDir, lispDir, rawWaveDir]:
    try:
        os.makedirs('%s%s' % (pkgDir, i), 0755)
    except:
        pass

# copy header files

installFiles(headerFiles, includeDir)

# copy documentation

installFiles(docFiles, docDir)
installFile('frontends/tclcsound/command_summary.txt', tclDir)

# create frontends

for i in utils1:
    makeFrontEnd(i, 0)
    makeFrontEnd(i, 1)
makeFrontEnd('CsoundVST', 1)

# copy scripts

installXFile('', 'brkpt', binDir)
installXFile('', 'linseg', binDir)
installXFile('', 'tabdes', binDir)
installFile('nsliders.tk', tclDir)
installXFile('', 'matrix.tk', binDir)

# copy STK raw wave files

rawWaveFiles = []
for fName in os.listdir('./Opcodes/stk/rawwaves'):
    if re.match('^.*\.raw$', fName) != None:
        rawWaveFiles += ['./Opcodes/stk/rawwaves/' + fName]
installFiles(rawWaveFiles, rawWaveDir)

# copy VIM files if enabled

if vimDir != '':
    for i in ['%s/%s' % (vimDir, 'plugin'), '%s/%s' % (vimDir, 'syntax')]:
        try:
            os.makedirs('%s%s' % (pkgDir, i), 0755)
        except:
            pass
    installXFile('', 'installer/misc/vim/cshelp', binDir)
    installFile('installer/misc/vim/csound.vim', '%s/%s' % (vimDir, 'plugin'))
    for i in ['csound_csd.vim', 'csound_orc.vim', 'csound_sco.vim']:
        installFile('installer/misc/vim/%s' % i, '%s/%s' % (vimDir, 'syntax'))

# build Csound

buildOpts2 = [['useDouble=0', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=0', 'dynamicCsoundLibrary=1', 'generateXmg=1',
               'buildInterfaces=0', 'buildPDClass=1', 'buildTclcsound=1',
               'buildLoris=1', 'buildStkOpcodes=1', 'buildWinsound=1',
               'buildCsound5GUI=1', 'buildUtilities=1'],
              ['useDouble=1', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=1', 'dynamicCsoundLibrary=1', 'generateXmg=0',
               'buildInterfaces=1', 'buildPDClass=0', 'buildTclcsound=1',
               'buildCsoundVST=1', 'buildLoris=1', 'buildStkOpcodes=1',
               'buildWinsound=1', 'buildCsound5GUI=1', 'buildUtilities=1']]

for i in range(4):
    cleanup()
    args = ['scons'] + buildOpts + buildOpts2[i]
    if (runCmd(args) != 0):
        print ' *** build failed'
        runCmd(['rm', '-Rf', pkgDir])
        cleanup()
        raise SystemExit(1)
    if i == 0:
        # ------------ single precision, static Csound library ------------
        installXFile('--strip-unneeded', 'csound', binDir2)
        installFile('libcsound.a', libDir)
    elif i == 1:
        # ------------ single precision, dynamic Csound library ------------
        # string database files
        xmgList = findFiles('^.*\.xmg$')
        installFiles(xmgList, xmgDir)
        # plugin libraries
        os.remove('libcsound.so')
        installFile('opcodes.dir', pluginDir32)
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir32)
        # Csound API library
        libraryName = findFiles('^libcsound\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound.so' % (pkgDir, libDir))
        # csoundapi~ for PD
        runCmd(['strip', '--strip-unneeded', 'csoundapi~.pd_linux'])
        installFile('csoundapi~.pd_linux', pdDir)
        # executables
        for j in ['csound5gui', 'winsound', 'cstclsh', 'cswish', 'pvlook']:
            installXFile('--strip-unneeded', j, binDir2)
        # TclCsound
        installXFile('--strip-unneeded', 'tclcsound.so', tclDir)
    elif i == 2:
        # ------------ double precision, static Csound library ------------
        os.rename('csound', 'csound64')
        installXFile('--strip-unneeded', 'csound64', binDir2)
        installFile('libcsound64.a', libDir)
    elif i == 3:
        # ------------ double precision, dynamic Csound library ------------
        # plugin libraries
        os.remove('libcsound64.so')
        installFile('opcodes.dir', pluginDir64)
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            installXFile('--strip-unneeded', j, pluginDir64)
        # Csound API library
        libraryName = findFiles('^libcsound64\.so\..*$')[0]
        installXFile('--strip-debug', libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound64.so' % (pkgDir, libDir))
        # standalone utilities
        for j in utils2:
            installXFile('--strip-unneeded', j, binDir)
        # executables
        installXFile('--strip-unneeded', 'CsoundVST', binDir2)
        for j in ['csound5gui', 'winsound', 'cstclsh', 'cswish', 'pvlook']:
            os.rename(j, j + '64')
            installXFile('--strip-unneeded', j + '64', binDir2)
        # TclCsound
        os.rename('tclcsound.so', 'tclcsound64.so')
        installXFile('--strip-unneeded', 'tclcsound64.so', tclDir)
        # Python interface libraries (csnd, CsoundVST, and loris)
        installXFile('--strip-debug', 'lib_csnd.so', libDir)
        os.symlink('%s/lib_csnd.so' % libDir,
                   '%s%s/_csnd.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', 'lib_CsoundVST.so', libDir)
        os.symlink('%s/lib_CsoundVST.so' % libDir,
                   '%s%s/_CsoundVST.so' % (pkgDir, pythonDir2))
        installXFile('--strip-debug', '_loris.so', pythonDir2)
        installXFile('--strip-debug', '_scoregen.so', pythonDir2)
        f = open('__make_pyc.sh', 'w')
        print >> f, '#!/bin/sh'
        print >> f, 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`"'
        print >> f, 'else'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`:${LD_LIBRARY_PATH}"'
        print >> f, 'fi'
        print >> f, 'python -c "import csnd"'
        print >> f, 'python -O -c "import csnd"'
        print >> f, 'python -c "import CsoundVST"'
        print >> f, 'python -O -c "import CsoundVST"'
        print >> f, 'python -c "import loris"'
        print >> f, 'python -O -c "import loris"'
        print >> f, 'python -c "import scoregen"'
        print >> f, 'python -O -c "import scoregen"'
        print >> f
        f.close()
        os.chmod('__make_pyc.sh', 0755)
        runCmd(['./__make_pyc.sh'])
        os.remove('__make_pyc.sh')
        installFiles(['csnd.py', 'csnd.pyc', 'csnd.pyo',
                      'loris.py', 'loris.pyc', 'loris.pyo',
                      'CsoundVST.py', 'CsoundVST.pyc', 'CsoundVST.pyo',
                      'scoregen.py', 'scoregen.pyc', 'scoregen.pyo'],
                     pythonDir)
        # Java interface library
        installXFile('--strip-debug', 'lib_jcsound.so', libDir)
        installFile('csnd.jar', javaDir)
        # LISP interface
        installFile('interfaces/csound5.lisp', lispDir)

cleanup()

<|endoftext|>


<commit_before>#!/usr/bin/python

import os
import re

CFlags = '-Wall -O3 -fno-inline-functions -march=i686 -mtune=pentium3'
CFlags += ' -fomit-frame-pointer -ffast-math'

# CFlags = '-O0'

# package root directory
pkgDir      = '../__csound5'
# frontends
binDir      = '/usr/local/bin'
# the actual binaries (called by above)
binDir2     = '/usr/local/lib/csound/bin'
# Csound API header files
includeDir  = '/usr/local/include/csound'
# Csound API libraries
libDir      = '/usr/local/lib'
# private libraries for use by Csound
libDir2     = '/usr/local/lib/csound/lib'
# single precision plugin libraries
pluginDir32 = '/usr/local/lib/csound/plugins'
# double precision plugin libraries
pluginDir64 = '/usr/local/lib/csound/plugins64'
# XMG files
xmgDir      = '/usr/local/share/csound/xmg'
# documentation
docDir      = '/usr/local/share/doc/csound'
# csnd.py
pythonDir   = '/usr/lib/python2.4'
# _csnd.so
pythonDir2  = '/usr/lib/python2.4/lib-dynload'
# csoundapi~.pd_linux
pdDir       = '/usr/local/lib/pd/extra'
# tclcsound.so
tclDir      = '/usr/local/lib/csound/tcl'
# csnd.jar
javaDir     = '/usr/local/lib/csound/java'
# LISP interface
lispDir     = '/usr/local/lib/csound/lisp'

buildOpts = ['buildRelease=1', 'buildUtilities=0', 'useLrint=1', 'noDebug=1']
buildOpts += ['buildPythonOpcodes=1', 'useOSC=1', 'buildCsoundVST=0']
buildOpts += ['buildJavaWrapper=1', 'pythonVersion=2.4']
buildOpts += ['customCCFLAGS=%s' % CFlags, 'customCXXFLAGS=%s' % CFlags]

headerFiles = ['H/cfgvar.h', 'H/cscore.h', 'H/csdl.h', 'H/csoundCore.h']
headerFiles += ['H/csound.h', 'H/cwindow.h', 'H/msg_attr.h', 'H/OpcodeBase.hpp']
headerFiles += ['H/pstream.h', 'H/pvfileio.h', 'H/soundio.h', 'H/sysdep.h']
headerFiles += ['H/text.h', 'H/version.h', 'H/csound.hpp']
headerFiles += ['interfaces/CppSound.hpp', 'interfaces/filebuilding.h']
headerFiles += ['interfaces/CsoundFile.hpp']

utils1 = ['csound', 'cvanal', 'dnoise', 'envext', 'extractor',
          'het_export', 'het_import', 'hetro', 'lpanal',
          'lpc_export', 'lpc_import', 'mixer', 'pvanal',
          'pvlook', 'scale', 'sndinfo', 'srconv']

utils2 = ['scsort', 'extract', 'cs', 'csb64enc', 'makecsd']

docFiles = ['COPYING', 'ChangeLog', 'INSTALL', 'readme-csound5.txt']

# -----------------------------------------------------------------------------

def installFile(src, dst):
    return os.spawnvp(os.P_WAIT, 'install', ['install', '-p', '-m', '0644',
                                             src, '%s%s' % (pkgDir, dst)])

def installXFile(src, dst):
    return os.spawnvp(os.P_WAIT, 'install', ['install', '-p', '-m', '0755',
                                             src, '%s%s' % (pkgDir, dst)])

def findFiles(pat):
    lst = []
    for fName in os.listdir('.'):
        if re.match(pat, fName) != None:
            lst += [fName]
    return lst

def cleanup():
    os.spawnvp(os.P_WAIT, './cleanup.sh', ['./cleanup.sh'])

def makeFrontEnd(utilName, is64bit):
    fName = '%s%s/%s%s' % (pkgDir, binDir, utilName, ['', '64'][is64bit])
    f = open(fName, 'w')
    tmp =  '#!/bin/sh\n'
    tmp += '\n'
    tmp += 'export %s="%s"\n'
    tmp += 'export CSSTRNGS="%s"\n'
    tmp += '\n'
    tmp += 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then\n'
    tmp += '    export LD_LIBRARY_PATH="%s"\n'
    tmp += 'else\n'
    tmp += '    export LD_LIBRARY_PATH="%s:${LD_LIBRARY_PATH}"\n'
    tmp += 'fi\n'
    tmp += '\n'
    tmp += 'exec "%s/%s"%s "$@"\n'
    print >> f, tmp % (['OPCODEDIR', 'OPCODEDIR64'][is64bit],
                       [pluginDir32, pluginDir64][is64bit],
                       xmgDir, libDir2, libDir2,
                       binDir2, ['csound', 'csound64'][is64bit],
                       ['', ' -U %s' % utilName][int(utilName != 'csound')])
    f.close
    os.chmod(fName, 0755)

# remove old package

os.spawnvp(os.P_WAIT, 'rm', ['rm', '-Rf', pkgDir])

# create directory tree

os.makedirs(pkgDir, 0755)
for i in [binDir, libDir, binDir2, includeDir, libDir2, pluginDir32,
          pluginDir64, xmgDir, docDir, pythonDir, pythonDir2, pdDir, tclDir,
          javaDir, lispDir]:
    os.makedirs('%s%s' % (pkgDir, i), 0755)

# copy header files

for i in headerFiles:
    installFile(i, includeDir)

# copy documentation

for i in docFiles:
    installFile(i, docDir)

# create frontends

for i in utils1:
    makeFrontEnd(i, 0)
    makeFrontEnd(i, 1)

# copy scripts

installXFile('brkpt', binDir)
installXFile('linseg', binDir)
installXFile('tabdes', binDir)
installFile('nsliders.tk', tclDir)

# build Csound

buildOpts2 = [['useDouble=0', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=0', 'dynamicCsoundLibrary=1', 'generateXmg=1',
               'buildInterfaces=0', 'buildPDClass=1', 'buildTclcsound=1'],
              ['useDouble=1', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=1', 'dynamicCsoundLibrary=1', 'generateXmg=0',
               'buildInterfaces=1', 'buildPDClass=0', 'buildTclcsound=1']]

for i in range(4):
    cleanup()
    args = ['scons'] + buildOpts2[i] + buildOpts
    if (os.spawnvp(os.P_WAIT, 'scons', args) != 0):
        print ' *** build failed'
        os.spawnvp(os.P_WAIT, 'rm', ['rm', '-Rf', pkgDir])
        raise SystemExit(1)
    if i == 0:
        # ------------ single precision, static Csound library ------------
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'csound'])
        installXFile('csound', binDir2)
        installFile('libcsound.a', libDir)
    elif i == 1:
        # ------------ single precision, dynamic Csound library ------------
        # string database files
        xmgList = findFiles('^.*\.xmg$')
        for j in xmgList:
            installFile(j, xmgDir)
        # plugin libraries
        os.remove('libcsound.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-unneeded', j])
            installXFile(j, pluginDir32)
        # Csound API library
        libraryName = findFiles('^libcsound\.so\..*$')[0]
        os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-debug', libraryName])
        installXFile(libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound.so' % (pkgDir, libDir))
        # csoundapi~ for PD
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-unneeded', 'csoundapi~.pd_linux'])
        installFile('csoundapi~.pd_linux', pdDir)
        # TclCsound
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cstclsh'])
        installXFile('cstclsh', binDir)
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cswish'])
        installXFile('cswish', binDir)
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-unneeded', 'tclcsound.so'])
        installXFile('tclcsound.so', tclDir)
    elif i == 2:
        # ------------ double precision, static Csound library ------------
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'csound'])
        os.rename('csound', 'csound64')
        installXFile('csound64', binDir2)
        installFile('libcsound64.a', libDir)
    elif i == 3:
        # ------------ double precision, dynamic Csound library ------------
        # re-run scons to work around bug in building Java wrapper
        os.spawnvp(os.P_WAIT, 'scons', args)
        # plugin libraries
        os.remove('libcsound64.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-unneeded', j])
            installXFile(j, pluginDir64)
        # Csound API library
        libraryName = findFiles('^libcsound64\.so\..*$')[0]
        os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-debug', libraryName])
        installXFile(libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound64.so' % (pkgDir, libDir))
        # standalone utilities
        for j in utils2:
            os.spawnvp(os.P_WAIT, 'strip', ['strip', j])
            installXFile(j, binDir)
        # TclCsound
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cstclsh'])
        os.rename('cstclsh', 'cstclsh64')
        installXFile('cstclsh64', binDir)
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cswish'])
        os.rename('cswish', 'cswish64')
        installXFile('cswish64', binDir)
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-unneeded', 'tclcsound.so'])
        os.rename('tclcsound.so', 'tclcsound64.so')
        installXFile('tclcsound64.so', tclDir)
        # Python interface library
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-debug', '_csnd.so'])
        installXFile('_csnd.so', libDir)
        os.rename('%s%s/_csnd.so' % (pkgDir, libDir),
                  '%s%s/lib_csnd.so' % (pkgDir, libDir))
        os.symlink('%s/lib_csnd.so' % libDir,
                   '%s%s/_csnd.so' % (pkgDir, pythonDir2))
        f = open('__make_pyc.sh', 'w')
        print >> f, '#!/bin/sh'
        print >> f, 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`"'
        print >> f, 'else'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`:${LD_LIBRARY_PATH}"'
        print >> f, 'fi'
        print >> f, 'python -c "import csnd"'
        print >> f, 'python -O -c "import csnd"'
        print >> f
        f.close()
        os.chmod('__make_pyc.sh', 0755)
        os.spawnvp(os.P_WAIT, './__make_pyc.sh', ['./__make_pyc.sh'])
        os.remove('__make_pyc.sh')
        installFile('csnd.py', pythonDir)
        installFile('csnd.pyc', pythonDir)
        installFile('csnd.pyo', pythonDir)
        # Java interface library
        installFile('csnd.jar', javaDir)
        # LISP interface
        installFile('interfaces/csound5.lisp', lispDir)
        installFile('interfaces/support.lisp', lispDir)

cleanup()

<commit_msg>Create interfaces/csnd; do not install filebuilding.lisp<commit_after>#!/usr/bin/python

import os
import re

CFlags = '-Wall -O3 -fno-inline-functions -march=i686 -mtune=pentium3'
CFlags += ' -fomit-frame-pointer -ffast-math'

# CFlags = '-O0'

# package root directory
pkgDir      = '../__csound5'
# frontends
binDir      = '/usr/local/bin'
# the actual binaries (called by above)
binDir2     = '/usr/local/lib/csound/bin'
# Csound API header files
includeDir  = '/usr/local/include/csound'
# Csound API libraries
libDir      = '/usr/local/lib'
# private libraries for use by Csound
libDir2     = '/usr/local/lib/csound/lib'
# single precision plugin libraries
pluginDir32 = '/usr/local/lib/csound/plugins'
# double precision plugin libraries
pluginDir64 = '/usr/local/lib/csound/plugins64'
# XMG files
xmgDir      = '/usr/local/share/csound/xmg'
# documentation
docDir      = '/usr/local/share/doc/csound'
# csnd.py
pythonDir   = '/usr/lib/python2.4'
# _csnd.so
pythonDir2  = '/usr/lib/python2.4/lib-dynload'
# csoundapi~.pd_linux
pdDir       = '/usr/local/lib/pd/extra'
# tclcsound.so
tclDir      = '/usr/local/lib/csound/tcl'
# csnd.jar
javaDir     = '/usr/local/lib/csound/java'
# LISP interface
lispDir     = '/usr/local/lib/csound/lisp'

buildOpts = ['buildRelease=1', 'buildUtilities=0', 'useLrint=1', 'noDebug=1']
buildOpts += ['buildPythonOpcodes=1', 'useOSC=1', 'buildCsoundVST=0']
buildOpts += ['buildJavaWrapper=1', 'pythonVersion=2.4']
buildOpts += ['customCCFLAGS=%s' % CFlags, 'customCXXFLAGS=%s' % CFlags]

headerFiles = ['H/cfgvar.h', 'H/cscore.h', 'H/csdl.h', 'H/csoundCore.h']
headerFiles += ['H/csound.h', 'H/cwindow.h', 'H/msg_attr.h', 'H/OpcodeBase.hpp']
headerFiles += ['H/pstream.h', 'H/pvfileio.h', 'H/soundio.h', 'H/sysdep.h']
headerFiles += ['H/text.h', 'H/version.h', 'H/csound.hpp']
headerFiles += ['interfaces/CppSound.hpp', 'interfaces/filebuilding.h']
headerFiles += ['interfaces/CsoundFile.hpp']

utils1 = ['csound', 'cvanal', 'dnoise', 'envext', 'extractor',
          'het_export', 'het_import', 'hetro', 'lpanal',
          'lpc_export', 'lpc_import', 'mixer', 'pvanal',
          'pvlook', 'scale', 'sndinfo', 'srconv']

utils2 = ['scsort', 'extract', 'cs', 'csb64enc', 'makecsd']

docFiles = ['COPYING', 'ChangeLog', 'INSTALL', 'readme-csound5.txt']

# -----------------------------------------------------------------------------

def installFile(src, dst):
    return os.spawnvp(os.P_WAIT, 'install', ['install', '-p', '-m', '0644',
                                             src, '%s%s' % (pkgDir, dst)])

def installXFile(src, dst):
    return os.spawnvp(os.P_WAIT, 'install', ['install', '-p', '-m', '0755',
                                             src, '%s%s' % (pkgDir, dst)])

def findFiles(pat):
    lst = []
    for fName in os.listdir('.'):
        if re.match(pat, fName) != None:
            lst += [fName]
    return lst

def cleanup():
    os.spawnvp(os.P_WAIT, './cleanup.sh', ['./cleanup.sh'])

def makeFrontEnd(utilName, is64bit):
    fName = '%s%s/%s%s' % (pkgDir, binDir, utilName, ['', '64'][is64bit])
    f = open(fName, 'w')
    tmp =  '#!/bin/sh\n'
    tmp += '\n'
    tmp += 'export %s="%s"\n'
    tmp += 'export CSSTRNGS="%s"\n'
    tmp += '\n'
    tmp += 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then\n'
    tmp += '    export LD_LIBRARY_PATH="%s"\n'
    tmp += 'else\n'
    tmp += '    export LD_LIBRARY_PATH="%s:${LD_LIBRARY_PATH}"\n'
    tmp += 'fi\n'
    tmp += '\n'
    tmp += 'exec "%s/%s"%s "$@"\n'
    print >> f, tmp % (['OPCODEDIR', 'OPCODEDIR64'][is64bit],
                       [pluginDir32, pluginDir64][is64bit],
                       xmgDir, libDir2, libDir2,
                       binDir2, ['csound', 'csound64'][is64bit],
                       ['', ' -U %s' % utilName][int(utilName != 'csound')])
    f.close
    os.chmod(fName, 0755)

# remove old package

os.spawnvp(os.P_WAIT, 'rm', ['rm', '-Rf', pkgDir])

# create directory tree

os.makedirs(pkgDir, 0755)
for i in [binDir, libDir, binDir2, includeDir, libDir2, pluginDir32,
          pluginDir64, xmgDir, docDir, pythonDir, pythonDir2, pdDir, tclDir,
          javaDir, lispDir]:
    os.makedirs('%s%s' % (pkgDir, i), 0755)

# copy header files

for i in headerFiles:
    installFile(i, includeDir)

# copy documentation

for i in docFiles:
    installFile(i, docDir)

# create frontends

for i in utils1:
    makeFrontEnd(i, 0)
    makeFrontEnd(i, 1)

# copy scripts

installXFile('brkpt', binDir)
installXFile('linseg', binDir)
installXFile('tabdes', binDir)
installFile('nsliders.tk', tclDir)

# build Csound

buildOpts2 = [['useDouble=0', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=0', 'dynamicCsoundLibrary=1', 'generateXmg=1',
               'buildInterfaces=0', 'buildPDClass=1', 'buildTclcsound=1'],
              ['useDouble=1', 'dynamicCsoundLibrary=0', 'generateXmg=0',
               'buildInterfaces=0', 'buildPDClass=0', 'csound'],
              ['useDouble=1', 'dynamicCsoundLibrary=1', 'generateXmg=0',
               'buildInterfaces=1', 'buildPDClass=0', 'buildTclcsound=1']]

for i in range(4):
    cleanup()
    os.spawnvp(os.P_WAIT, 'mkdir',
               ['mkdir', '-p', '-m', '0755', 'interfaces/csnd'])
    args = ['scons'] + buildOpts2[i] + buildOpts
    if (os.spawnvp(os.P_WAIT, 'scons', args) != 0):
        print ' *** build failed'
        os.spawnvp(os.P_WAIT, 'rm', ['rm', '-Rf', pkgDir])
        raise SystemExit(1)
    if i == 0:
        # ------------ single precision, static Csound library ------------
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'csound'])
        installXFile('csound', binDir2)
        installFile('libcsound.a', libDir)
    elif i == 1:
        # ------------ single precision, dynamic Csound library ------------
        # string database files
        xmgList = findFiles('^.*\.xmg$')
        for j in xmgList:
            installFile(j, xmgDir)
        # plugin libraries
        os.remove('libcsound.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-unneeded', j])
            installXFile(j, pluginDir32)
        # Csound API library
        libraryName = findFiles('^libcsound\.so\..*$')[0]
        os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-debug', libraryName])
        installXFile(libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound.so' % (pkgDir, libDir))
        # csoundapi~ for PD
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-unneeded', 'csoundapi~.pd_linux'])
        installFile('csoundapi~.pd_linux', pdDir)
        # TclCsound
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cstclsh'])
        installXFile('cstclsh', binDir)
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cswish'])
        installXFile('cswish', binDir)
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-unneeded', 'tclcsound.so'])
        installXFile('tclcsound.so', tclDir)
    elif i == 2:
        # ------------ double precision, static Csound library ------------
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'csound'])
        os.rename('csound', 'csound64')
        installXFile('csound64', binDir2)
        installFile('libcsound64.a', libDir)
    elif i == 3:
        # ------------ double precision, dynamic Csound library ------------
        # re-run scons to work around bug in building Java wrapper
        os.spawnvp(os.P_WAIT, 'scons', args)
        # plugin libraries
        os.remove('libcsound64.so')
        pluginList = findFiles('^lib[A-Za-z].*\.so$')
        for j in pluginList:
            os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-unneeded', j])
            installXFile(j, pluginDir64)
        # Csound API library
        libraryName = findFiles('^libcsound64\.so\..*$')[0]
        os.spawnvp(os.P_WAIT, 'strip', ['strip', '--strip-debug', libraryName])
        installXFile(libraryName, libDir)
        os.symlink(libraryName, '%s%s/libcsound64.so' % (pkgDir, libDir))
        # standalone utilities
        for j in utils2:
            os.spawnvp(os.P_WAIT, 'strip', ['strip', j])
            installXFile(j, binDir)
        # TclCsound
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cstclsh'])
        os.rename('cstclsh', 'cstclsh64')
        installXFile('cstclsh64', binDir)
        os.spawnvp(os.P_WAIT, 'strip', ['strip', 'cswish'])
        os.rename('cswish', 'cswish64')
        installXFile('cswish64', binDir)
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-unneeded', 'tclcsound.so'])
        os.rename('tclcsound.so', 'tclcsound64.so')
        installXFile('tclcsound64.so', tclDir)
        # Python interface library
        os.spawnvp(os.P_WAIT, 'strip',
                   ['strip', '--strip-debug', '_csnd.so'])
        installXFile('_csnd.so', libDir)
        os.rename('%s%s/_csnd.so' % (pkgDir, libDir),
                  '%s%s/lib_csnd.so' % (pkgDir, libDir))
        os.symlink('%s/lib_csnd.so' % libDir,
                   '%s%s/_csnd.so' % (pkgDir, pythonDir2))
        f = open('__make_pyc.sh', 'w')
        print >> f, '#!/bin/sh'
        print >> f, 'if [ "${LD_LIBRARY_PATH}" == "" ] ; then'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`"'
        print >> f, 'else'
        print >> f, '    export LD_LIBRARY_PATH="`pwd`:${LD_LIBRARY_PATH}"'
        print >> f, 'fi'
        print >> f, 'python -c "import csnd"'
        print >> f, 'python -O -c "import csnd"'
        print >> f
        f.close()
        os.chmod('__make_pyc.sh', 0755)
        os.spawnvp(os.P_WAIT, './__make_pyc.sh', ['./__make_pyc.sh'])
        os.remove('__make_pyc.sh')
        installFile('csnd.py', pythonDir)
        installFile('csnd.pyc', pythonDir)
        installFile('csnd.pyo', pythonDir)
        # Java interface library
        installFile('csnd.jar', javaDir)
        # LISP interface
        installFile('interfaces/csound5.lisp', lispDir)

cleanup()

<|endoftext|>


<commit_before>from collections import OrderedDict
import logging
import os
from subprocess import Popen, PIPE
import warnings

import simtk.unit as units

from intermol.utils import run_subprocess, which
from intermol.lammps.lammps_parser import load, save

# Python 2/3 compatibility.
try:
    FileNotFoundError
except NameError:
    FileNotFoundError = OSError

logger = logging.getLogger('InterMolLog')

to_canonical = {
    'Bond': 'bond',

    'Angle': 'angle',

    'Proper Dih.': ['dihedral', 'proper'],
    'Improper': ['dihedral', 'improper'],

    'Dispersive': ['vdw', 'dispersive'],
    'Disper. corr.': ['disper. corr.', 'dispersive'],
    'Electrostatic': 'coulomb',
    'Coul.recip.': 'coulomb',

    'Non-bonded': 'nonbonded',
    'Potential': 'potential'
}

for exe in ['lammps', 'lmp_mpi', 'lmp_serial', 'lmp_openmpi',
            'lmp_mac_mpi']:
    if which(exe):
        LMP_PATH = exe
        break
else:
    warnings.warn('Found no LAMMPS executable.')

def energies(input_file, lmp_path=None):
    """Evaluate energies of LAMMPS files

    Args:
        input_file = path to input file (expects data file in same folder)
        lmp_path = path to LAMMPS binaries
    """
    if lmp_path is None:
        lmp_path = LMP_PATH

    logger.info('Evaluating energy of {0}'.format(input_file))
    directory, input_file = os.path.split(os.path.abspath(input_file))
    stdout_path = os.path.join(directory, 'lammps_stdout.txt')
    stderr_path = os.path.join(directory, 'lammps_stderr.txt')
    # TODO: Read energy info from stdout in memory instead of from log files.
    try:
        os.remove(stdout_path)
    except FileNotFoundError:
        pass
    try:
        os.remove(stderr_path)
    except FileNotFoundError:
        pass

    # Step into the directory.
    saved_path = os.getcwd()
    os.chdir(directory)

    cmd = [lmp_path, '-in', input_file]
    proc = run_subprocess(cmd, 'lammps', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('LAMMPS failed. See %s/lammps_stderr.txt' % directory)

    # Step back out.
    os.chdir(saved_path)

    return _group_energy_terms(stdout_path)

def _group_energy_terms(stdout_path):
    """Parse LAMMPS stdout to extract and group the energy terms in a dict. """
    proc = Popen(["awk '/E_bond/{getline; print}' %s" % stdout_path], stdout=PIPE, shell=True)
    energies, err = proc.communicate()
    if not energies:
        raise Exception('Unable to read LAMMPS energy output')

    energy_values = [float(x) * units.kilocalories_per_mole for x in energies.split()]
    energy_types = ['Bond', 'Angle', 'Proper Dih.', 'Improper', 'Non-bonded',
                    'Dispersive', 'Electrostatic', 'Coul. recip.',
                    'Disper. corr.', 'Potential']
    e_out = OrderedDict(zip(energy_types, energy_values))

    # e_out['Electrostatic'] += e_out['Coul. recip.']
    # e_out['All dihedrals'] = e_out['Proper Dih.'] + e_out['Improper']
    # e_out['All angles'] = e_out['Angle']
    return e_out, stdout_path<commit_msg>Cleanup<commit_after>from collections import OrderedDict
import logging
import os
from subprocess import Popen, PIPE
import warnings

import simtk.unit as units

from intermol.utils import run_subprocess, which
from intermol.lammps.lammps_parser import load, save

# Python 2/3 compatibility.
try:
    FileNotFoundError
except NameError:
    FileNotFoundError = OSError

logger = logging.getLogger('InterMolLog')

to_canonical = {
    'Bond': 'bond',

    'Angle': 'angle',

    'Proper Dih.': ['dihedral', 'proper'],
    'Improper': ['dihedral', 'improper'],

    'Dispersive': ['vdw', 'dispersive'],
    'Disper. corr.': ['disper. corr.', 'dispersive'],
    'Electrostatic': 'coulomb',
    'Coul.recip.': 'coulomb',

    'Non-bonded': 'nonbonded',
    'Potential': 'potential'
}

for exe in ['lammps', 'lmp_mpi', 'lmp_serial', 'lmp_openmpi',
            'lmp_mac_mpi']:
    if which(exe):
        LMP_PATH = exe
        break
else:
    warnings.warn('Found no LAMMPS executable.')

def energies(input_file, lmp_path=None):
    """Evaluate energies of LAMMPS files

    Args:
        input_file = path to input file (expects data file in same folder)
        lmp_path = path to LAMMPS binaries
    """
    if lmp_path is None:
        lmp_path = LMP_PATH

    logger.info('Evaluating energy of {0}'.format(input_file))
    directory, input_file = os.path.split(os.path.abspath(input_file))
    stdout_path = os.path.join(directory, 'lammps_stdout.txt')
    stderr_path = os.path.join(directory, 'lammps_stderr.txt')
    # TODO: Read energy info from stdout in memory instead of from log files.
    try:
        os.remove(stdout_path)
    except FileNotFoundError:
        pass
    try:
        os.remove(stderr_path)
    except FileNotFoundError:
        pass

    # Step into the directory.
    saved_path = os.getcwd()
    os.chdir(directory)

    cmd = [lmp_path, '-in', input_file]
    proc = run_subprocess(cmd, 'lammps', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('LAMMPS failed. See %s/lammps_stderr.txt' % directory)

    # Step back out.
    os.chdir(saved_path)

    return _group_energy_terms(stdout_path)

def _group_energy_terms(stdout_path):
    """Parse LAMMPS stdout to extract and group the energy terms in a dict. """
    proc = Popen(["awk '/E_bond/{getline; print}' %s" % stdout_path], stdout=PIPE, shell=True)
    energies, err = proc.communicate()
    if not energies:
        raise Exception('Unable to read LAMMPS energy output')

    energy_values = [float(x) * units.kilocalories_per_mole for x in energies.split()]
    energy_types = ['Bond', 'Angle', 'Proper Dih.', 'Improper', 'Non-bonded',
                    'Dispersive', 'Electrostatic', 'Coul. recip.',
                    'Disper. corr.', 'Potential']
    e_out = OrderedDict(zip(energy_types, energy_values))
    return e_out, stdout_path<|endoftext|>


<commit_before>#!/usr/bin/python
import os
import subprocess
import sys

# Download Release "Eclipse IDE for Java EE Developers" from
# http://www.eclipse.org/downloads/packages/
#
# Note: jeeeyul themes do not seem to work right now (in 2018-09)

p2repositoryLocations = [
    "http://download.eclipse.org/releases/2018-09",
    "http://download.eclipse.org/eclipse/updates/4.9",
    "http://jeeeyul.github.io/update/",
    "http://andrei.gmxhome.de/eclipse/",
    "http://plantuml.sourceforge.net/updatesitejuno/",
    "http://download.springsource.com/release/TOOLS/update/e4.9/"
]

p2features = [

    # Feature groups
    "org.eclipse.fx.ide.feature" + ".feature.group",
    "org.eclipse.linuxtools.changelog" + ".feature.group",
    "org.eclipse.linuxtools.docker.feature" + ".feature.group",
    "org.springframework.ide.eclipse.autowire.feature" + ".feature.group",
    "org.springframework.ide.eclipse.boot.dash.feature" + ".feature.group",
    "org.springframework.ide.eclipse.boot.feature" + ".feature.group",
    "org.springframework.ide.eclipse.feature" + ".feature.group",
    "org.springframework.ide.eclipse.maven.feature" + ".feature.group",
    "org.springframework.ide.eclipse.webflow.feature" + ".feature.group",
    "net.jeeeyul.eclipse.themes.feature" + ".feature.group",
    "AnyEditTools" + ".feature.group",

    # Direct plugins
    "net.sourceforge.plantuml.eclipse",

]

if len(sys.argv) < 2:
    sys.exit("Location of eclipse installation must be passed as first parameter!")
else:

    eclipseApplicationDirectory = os.path.abspath(sys.argv[1])
    eclipseBinaryCommandFile = os.path.join(eclipseApplicationDirectory, "Contents/MacOS/eclipse");

    subprocess.call([
        eclipseBinaryCommandFile,
        "-profile", "SDKProfile",
        "-noSplash", "-consolelog",
        "-application", "org.eclipse.equinox.p2.director",
        "-repository", ",".join(p2repositoryLocations),
        "-installIU", ",".join(p2features),
        "-destination", eclipseApplicationDirectory
])<commit_msg>New update site<commit_after>#!/usr/bin/python
import os
import subprocess
import sys

# Download Release "Eclipse IDE for Java EE Developers" from
# http://www.eclipse.org/downloads/packages/
#
# Note: jeeeyul themes do not seem to work right now (in 2018-09)

p2repositoryLocations = [
    "http://download.eclipse.org/releases/2018-09",
    "http://download.eclipse.org/eclipse/updates/4.9",
    "http://eclipse.jeeeyul.net/update/",
    "http://andrei.gmxhome.de/eclipse/",
    "http://plantuml.sourceforge.net/updatesitejuno/",
    "http://download.springsource.com/release/TOOLS/update/e4.9/"
]

p2features = [

    # Feature groups
    "org.eclipse.fx.ide.feature" + ".feature.group",
    "org.eclipse.linuxtools.changelog" + ".feature.group",
    "org.eclipse.linuxtools.docker.feature" + ".feature.group",
    "org.springframework.ide.eclipse.autowire.feature" + ".feature.group",
    "org.springframework.ide.eclipse.boot.dash.feature" + ".feature.group",
    "org.springframework.ide.eclipse.boot.feature" + ".feature.group",
    "org.springframework.ide.eclipse.feature" + ".feature.group",
    "org.springframework.ide.eclipse.maven.feature" + ".feature.group",
    "org.springframework.ide.eclipse.webflow.feature" + ".feature.group",
    "net.jeeeyul.eclipse.themes.feature" + ".feature.group",
    "AnyEditTools" + ".feature.group",

    # Direct plugins
    "net.sourceforge.plantuml.eclipse",

]

if len(sys.argv) < 2:
    sys.exit("Location of eclipse installation must be passed as first parameter!")
else:

    eclipseApplicationDirectory = os.path.abspath(sys.argv[1])
    eclipseBinaryCommandFile = os.path.join(eclipseApplicationDirectory, "Contents/MacOS/eclipse");

    subprocess.call([
        eclipseBinaryCommandFile,
        "-profile", "SDKProfile",
        "-noSplash", "-consolelog",
        "-application", "org.eclipse.equinox.p2.director",
        "-repository", ",".join(p2repositoryLocations),
        "-installIU", ",".join(p2features),
        "-destination", eclipseApplicationDirectory
])<|endoftext|>


<commit_before>import simplify
from core import Boolean,Number,Symbol,Wild,symbols,wilds,symbolic,wild,WildResults

import match
<commit_msg>added solvers to import list<commit_after>import simplify
from core import Boolean,Number,Symbol,Wild,symbols,wilds,symbolic,wild,WildResults

import match
import solvers
<|endoftext|>