Download, build and install csound 6.07.0 via a pseudo python package.

looper
Ben Niemann 2016-07-10 16:38:59 +02:00
parent 87f1ae3a5e
commit 81d808e23c
3 changed files with 169 additions and 1 deletions

166
3rdparty/csound/setup.py vendored 100644
View File

@ -0,0 +1,166 @@
from distutils import core
from distutils.command.build import build
from distutils.command.install import install
import urllib.request
import os
import os.path
import subprocess
import sys
import time
import zipfile
VERSION = '6.7.0'
DOWNLOAD_URL = 'https://github.com/csound/csound/archive/6.07.0.zip'
assert os.getenv('VIRTUAL_ENV'), "Not running in a virtualenv."
class CSoundMixin(object):
user_options = [
('build-base=', 'b',
"base directory for build library"),
]
def initialize_options(self):
self.build_base = 'build'
def finalize_options(self):
pass
@property
def zip_path(self):
return os.path.join(self.build_base, 'csound.zip')
@property
def src_dir(self):
return os.path.join(self.build_base, 'src')
@property
def make_dir(self):
return os.path.join(self.build_base, 'cs6make')
class BuildCSound(CSoundMixin, core.Command):
def run(self):
if not os.path.isdir(self.build_base):
os.makedirs(self.build_base)
self._download_zip(self.zip_path)
self._unpack_zip(self.zip_path, self.src_dir)
self._cmake(self.src_dir, self.make_dir)
self._make(self.make_dir)
def _download_zip(self, zip_path):
if os.path.exists(zip_path):
return
total_bytes = 0
with urllib.request.urlopen(DOWNLOAD_URL) as fp_in:
with open(zip_path + '.partial', 'wb') as fp_out:
last_report = time.time()
try:
while True:
dat = fp_in.read(10240)
if not dat:
break
fp_out.write(dat)
total_bytes += len(dat)
if time.time() - last_report > 1:
sys.stderr.write(
'Downloading %s: %d bytes\r'
% (DOWNLOAD_URL, total_bytes))
sys.stderr.flush()
last_report = time.time()
finally:
sys.stderr.write('\033[K')
sys.stderr.flush()
os.rename(zip_path + '.partial', zip_path)
print('Downloaded %s: %d bytes' % (DOWNLOAD_URL, total_bytes))
def _unpack_zip(self, zip_path, src_dir):
if os.path.isdir(src_dir):
return
print("Extracting...")
base_dir = None
with zipfile.ZipFile(zip_path) as fp:
for path in fp.namelist():
while path:
path, b = os.path.split(path)
if not path:
if base_dir is None:
base_dir = b
elif b != base_dir:
raise RuntimeError(
"No common base dir (%s)" % b)
fp.extractall(self.build_base)
os.rename(os.path.join(self.build_base, base_dir), src_dir)
print("Extracted to %s" % src_dir)
return src_dir
def _cmake(self, src_dir, make_dir):
if os.path.exists(os.path.join(make_dir, 'Makefile')):
return
if not os.path.isdir(make_dir):
os.makedirs(make_dir)
print("Running cmake...")
subprocess.run(
['cmake',
'-DBUILD_PYTHON_INTERFACE=0',
'-DCMAKE_INSTALL_PREFIX=' + os.getenv('VIRTUAL_ENV'),
os.path.abspath(src_dir)
],
cwd=make_dir,
check=True)
def _make(self, make_dir):
if os.path.exists(os.path.join(make_dir, '.build.complete')):
return
print("Running make...")
subprocess.run(
['make', '-j8'],
cwd=make_dir,
check=True)
open(os.path.join(make_dir, '.build.complete'), 'w').close()
class InstallCSound(CSoundMixin, core.Command):
@property
def sentinel_path(self):
return os.path.join(
os.getenv('VIRTUAL_ENV'), '.csound-%s-installed' % VERSION)
def run(self):
if os.path.exists(self.sentinel_path):
return
print("Running make install...")
subprocess.run(
['make', 'install'],
cwd=self.make_dir,
check=True)
open(self.sentinel_path, 'w').close()
def get_outputs(self):
return [self.sentinel_path]
build.sub_commands.append(('build_csound', None))
install.sub_commands.insert(0, ('install_csound', None))
core.setup(
name = 'csound',
version = VERSION,
cmdclass = {
'build_csound': BuildCSound,
'install_csound': InstallCSound,
},
)

View File

@ -10,12 +10,13 @@ LIBSDIR="$BASEDIR/libs"
#LILV_DEPS="lv2-dev libserd-dev libsord-dev libsratom-dev swig"
#LADSPA_DEPS="cython3 ladspa-sdk"
CSOUND_DEPS="libsndfile1-dev libsamplerate0-dev libboost-dev flex bison"
PYVERSION=3.5
PACKAGES_QT5="python3-pyqt5 python3-pyqt5.qtsvg"
PACKAGES="python$PYVERSION python$PYVERSION-venv python$PYVERSION-dev libxml2-dev libxslt1-dev portaudio19-dev libavutil-dev libavutil-ffmpeg54 libswresample-dev libswresample-ffmpeg1 libfluidsynth1 libfluidsynth-dev inkscape timgm6mb-soundfont fluid-soundfont-gs fluid-soundfont-gm flac zlib1g-dev $PACKAGES_QT5"
PACKAGES="python$PYVERSION python$PYVERSION-venv python$PYVERSION-dev libxml2-dev libxslt1-dev portaudio19-dev libavutil-dev libavutil-ffmpeg54 libswresample-dev libswresample-ffmpeg1 libfluidsynth1 libfluidsynth-dev inkscape timgm6mb-soundfont fluid-soundfont-gs fluid-soundfont-gm flac zlib1g-dev $PACKAGES_QT5 $CSOUND_DEPS"
function pkg-status() {
PKG="$1"

View File

@ -14,3 +14,4 @@ vext
vext.pyqt5
asynctest
quamash
./3rdparty/csound/