From 44cd03f4643062be4abd5d05c25e2d2c0bf2ed15 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 14 Jun 2021 21:19:52 +0300 Subject: [PATCH] wscript: refactor opus wscript files, now it builds only if system package wasn't found --- 3rdparty/opus | 1 - 3rdparty/opus/opus | 1 + 3rdparty/opus/wscript | 52 ++++++++++++++++++++++++++++++++++++++++ engine/wscript | 2 +- scripts/waifulib/opus.py | 42 -------------------------------- wscript | 5 ++-- 6 files changed, 56 insertions(+), 47 deletions(-) delete mode 160000 3rdparty/opus create mode 160000 3rdparty/opus/opus create mode 100644 3rdparty/opus/wscript delete mode 100644 scripts/waifulib/opus.py diff --git a/3rdparty/opus b/3rdparty/opus deleted file mode 160000 index dfd6c88a..00000000 --- a/3rdparty/opus +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dfd6c88aaa54a03a61434c413e30c217eb98f1d5 diff --git a/3rdparty/opus/opus b/3rdparty/opus/opus new file mode 160000 index 00000000..16395923 --- /dev/null +++ b/3rdparty/opus/opus @@ -0,0 +1 @@ +Subproject commit 1639592368fc2dadc82d63f3be6f17ed0b554d71 diff --git a/3rdparty/opus/wscript b/3rdparty/opus/wscript new file mode 100644 index 00000000..8f1fe0ca --- /dev/null +++ b/3rdparty/opus/wscript @@ -0,0 +1,52 @@ +#! /usr/bin/env python +# encoding: utf-8 + +import os + +OPUS_CHECK='''#include +#include +int main() +{ + OpusEncoder *oe = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, NULL); + OpusDecoder *od = opus_decoder_create(48000, 2, NULL); + return !oe || !od; +} +''' + +def options(opt): + pass + +def configure(conf): + if conf.check_pkg('opus', 'OPUS', OPUS_CHECK, fatal = False): + conf.env.HAVE_OPUS = True + return + + if not conf.path.find_dir('opus') or not conf.path.find_dir('opus/src'): + conf.fatal('Can\'t find opus submodule. Run `git submodule update --init --recursive`.') + return + + # TODO: ARM/x86 intrinsics detection + # TODO: maybe call autotools/cmake/meson instead? + +def build(bld): + if bld.env.HAVE_OPUS: + return + + sources = bld.path.ant_glob([ + 'opus/src/*.c', + 'opus/celt/*.c', + 'opus/silk/*.c', + 'opus/silk/float/*.c' + ]) + includes = ['opus/include/', 'opus/celt/', 'opus/silk/', 'opus/silk/float/'] + defines = ['USE_ALLOCA', 'OPUS_BUILD', 'FLOAT_APPROX', 'PACKAGE_VERSION="1.3.1"'] + + bld.stlib( + source = sources, + target = 'opus', + features = 'c', + includes = includes, + defines = defines, + subsystem = bld.env.MSVC_SUBSYSTEM, + export_includes = ['opus/include/'] + ) diff --git a/engine/wscript b/engine/wscript index 23ea25bb..2fe54df0 100644 --- a/engine/wscript +++ b/engine/wscript @@ -166,7 +166,7 @@ def build(bld): 'client/vgui/*.c', 'client/avi/*.c']) - libs.append('OPUS') + libs.append('opus') includes = ['common', 'server', 'client', 'client/vgui', 'tests', '.', '../public', '../common', '../filesystem', '../pm_shared' ] diff --git a/scripts/waifulib/opus.py b/scripts/waifulib/opus.py deleted file mode 100644 index d1ef2a07..00000000 --- a/scripts/waifulib/opus.py +++ /dev/null @@ -1,42 +0,0 @@ -# encoding: utf-8 - -import os - -def options(opt): - pass - -def configure(conf): - path = conf.path.find_dir('3rdparty/opus') - conf.env.LIB_OPUS = ['opus'] - conf.env.INCLUDES_OPUS = [path.find_dir('include/').abspath()] - -def build(bld): - path = bld.path.find_dir('3rdparty/opus') - - sources = path.ant_glob([ - 'src/*.c', - 'celt/*.c', - 'silk/*.c', - 'silk/float/*.c']) - - includes = [ - path.find_dir('include/'), - path.find_dir('celt/'), - path.find_dir('silk/'), - path.find_dir('silk/float/') - ] - - defines = [ - 'USE_ALLOCA', - 'OPUS_BUILD', - 'PACKAGE_VERSION="1.3.1"' - ] - - bld.stlib( - source = sources, - target = 'opus', - features = 'c', - includes = includes, - defines = defines, - subsystem = bld.env.MSVC_SUBSYSTEM - ) \ No newline at end of file diff --git a/wscript b/wscript index 2516c722..9b060a4c 100644 --- a/wscript +++ b/wscript @@ -54,6 +54,7 @@ class Subproject: return True SUBDIRS = [ + Subproject('3rdparty/opus'), Subproject('public', dedicated=False, mandatory = True), Subproject('filesystem', dedicated=False, mandatory = True), Subproject('game_launch', singlebin=True), @@ -353,11 +354,9 @@ int main(int argc, char **argv) { strcasestr(argv[1], argv[2]); return 0; }''' continue conf.add_subproject(i.name) - - conf.load('opus') def build(bld): - bld.load('opus xshlib') + bld.load('xshlib') for i in SUBDIRS: if not i.is_enabled(bld):