diff --git a/setup.py b/setup.py index 6f6bb3813..ceb408e33 100644 --- a/setup.py +++ b/setup.py @@ -26,11 +26,44 @@ '\nuse it. Set WALLY_ABI_PY_WHEEL_USE_LIB=static to link with the static library.\n', file=sys.stderr) +def str_to_bool(str, if_none=ValueError, if_invalid=ValueError): + if str is None: + default = if_none + else: + lstr = str.lower() + if lstr in ('0', 'n', 'no', 'f', 'false', 'off'): + return False + elif lstr in ('1', 'y', 'yes', 't', 'true', 'on'): + return True + default = if_invalid + if isinstance(default, BaseException): + raise default('Invalid flag value: {}'.format(str)) + return default + +def pkg_default(pkg, if_true, if_false=None): + b = str_to_bool(pkg, None, None) + return if_true if b == True else if_false if b == False else pkg + +PKG_SECP256K1 = pkg_default( + os.environ.get('WALLY_ABI_PY_WHEEL_USE_PKG_SECP256K1'), 'libsecp256k1_zkp') + +if PKG_SECP256K1 is not None: + try: + import pkgconfig + except ImportError: + print('Error: You specified WALLY_ABI_PY_WHEEL_USE_PKG_SECP256K1, but you do not have' + '\nthe pkgconfig Python module installed.', + file=sys.stderr) + sys.exit(127) + def call(args, cwd=ABS_PATH): subprocess.check_call(args, cwd=cwd, env=CONFIGURE_ENV) -if not os.path.exists('src/secp256k1/Makefile.am'): - # Sync libsecp-zkp +if (USE_LIB == 'no' or PKG_SECP256K1 is None) and not os.path.exists( + 'src/.libs/libwallycore.so' if USE_LIB == 'shared' else + 'src/secp256k1/.libs/libsecp256k1.a' if USE_LIB == 'static' else + 'src/secp256k1/Makefile.am'): + # Sync libsecp256k1-zkp (only if needed) call(['git','submodule','init']) call(['git','submodule','sync','--recursive']) call(['git','submodule','update','--init','--recursive']) @@ -90,7 +123,6 @@ def call(args, cwd=ABS_PATH): include_dirs=[ './', './src', - './src/secp256k1/include', ] library_dirs = [ ] @@ -103,6 +135,7 @@ def call(args, cwd=ABS_PATH): if USE_LIB == 'no': include_dirs += [ './src/ccan', + './src/secp256k1/include', ] sources += [ 'src/amalgamation/combined.c', @@ -110,6 +143,10 @@ def call(args, cwd=ABS_PATH): 'src/amalgamation/combined_ccan2.c', ] else: + if PKG_SECP256K1 is None: + include_dirs += ['./src/secp256k1/include'] + else: + include_dirs += pkgconfig.parse(PKG_SECP256K1)['include_dirs'] library_dirs += ['src/.libs'] libraries += ['wallycore'] if USE_LIB == 'static':