<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', '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
<commit_msg>Install Python modules to site-packages<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 + '/site-packages'
# _csnd.so
pythonDir2  = pythonDir
# 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]:
    try:
        os.makedirs('%s%s' % (pkgDir, i), 0755)
    except:
        pass

# 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

{'fraction_non_alphanumeric': 0.19396039603960397, 'fraction_numerical': 0.01801980198019802, 'mean_word_length': 3.1448502256873203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2855545', 'n_tokens_mistral': 3833, 'n_tokens_neox': 3740, 'n_words': 841}