2018-10-30 16:23:12 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-01-10 18:52:30 +03:00
|
|
|
|
2021-09-24 20:07:06 +00:00
|
|
|
import sys,os
|
2021-09-23 21:15:33 +00:00
|
|
|
from setuptools import setup,Extension
|
2021-09-24 20:07:06 +00:00
|
|
|
from setuptools.command.build_ext import build_ext
|
2021-07-29 14:20:44 +00:00
|
|
|
from subprocess import run,PIPE
|
2019-02-06 10:33:36 +00:00
|
|
|
|
2021-09-24 20:07:06 +00:00
|
|
|
cache_path = os.path.join(os.environ['HOME'],'.cache','mmgen')
|
|
|
|
|
ext_path = os.path.join(cache_path,'secp256k1')
|
|
|
|
|
|
|
|
|
|
def build_libsecp256k1():
|
2023-05-19 20:29:09 +00:00
|
|
|
|
|
|
|
|
def fix_broken_libpython_fn():
|
|
|
|
|
from pathlib import Path
|
2023-05-21 11:34:16 +00:00
|
|
|
path = Path(Path().resolve().anchor) / 'msys64/mingw64/lib'
|
|
|
|
|
old = path / 'libpython3.10.dll.a'
|
|
|
|
|
new = path / 'libpython310.dll.a'
|
|
|
|
|
if old.exists() and not new.exists():
|
2023-05-19 20:29:09 +00:00
|
|
|
import shutil
|
2023-05-21 11:34:16 +00:00
|
|
|
print(f'Fixing broken library filename: {old.name!r} -> {new.name!r}')
|
|
|
|
|
shutil.copy2(old,new)
|
2023-05-19 20:29:09 +00:00
|
|
|
|
|
|
|
|
import platform
|
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
|
fix_broken_libpython_fn()
|
|
|
|
|
|
2021-09-24 20:07:06 +00:00
|
|
|
if not os.path.exists(cache_path):
|
|
|
|
|
os.makedirs(cache_path)
|
2023-05-19 20:29:09 +00:00
|
|
|
|
2021-09-24 20:07:06 +00:00
|
|
|
if not os.path.exists(ext_path):
|
2022-05-06 12:52:41 +00:00
|
|
|
print('\nCloning libsecp256k1')
|
2021-09-24 20:07:06 +00:00
|
|
|
run(['git','clone','https://github.com/bitcoin-core/secp256k1.git'],check=True,cwd=cache_path)
|
2023-05-19 20:29:09 +00:00
|
|
|
|
2021-09-24 20:07:06 +00:00
|
|
|
if not os.path.exists(os.path.join(ext_path,'.libs/libsecp256k1.a')):
|
2022-05-06 12:52:41 +00:00
|
|
|
print('\nBuilding libsecp256k1')
|
2021-09-26 21:16:55 +00:00
|
|
|
cmds = {
|
|
|
|
|
'Windows': (
|
|
|
|
|
['sh','./autogen.sh'],
|
|
|
|
|
['sh','./configure','CFLAGS=-g -O2 -fPIC','--disable-dependency-tracking'],
|
2022-05-03 21:01:05 +00:00
|
|
|
['mingw32-make','MAKE=mingw32-make']
|
2021-09-26 21:16:55 +00:00
|
|
|
),
|
|
|
|
|
'Linux': (
|
|
|
|
|
['./autogen.sh'],
|
|
|
|
|
['./configure','CFLAGS=-g -O2 -fPIC'],
|
2022-05-06 12:52:41 +00:00
|
|
|
['make'] + ([] if have_arm else ['-j4']),
|
2021-09-26 21:16:55 +00:00
|
|
|
),
|
|
|
|
|
}[platform.system()]
|
|
|
|
|
for cmd in cmds:
|
|
|
|
|
print('Executing {}'.format(' '.join(cmd)))
|
|
|
|
|
run(cmd,check=True,cwd=ext_path)
|
2021-09-24 20:07:06 +00:00
|
|
|
|
2022-05-06 12:52:41 +00:00
|
|
|
uname = {k:run(['uname',f'-{k}'],stdout=PIPE,check=True).stdout.strip().decode() for k in ('m','s')}
|
|
|
|
|
|
|
|
|
|
have_arm = uname['m'] in ('aarch64','armv7l') # x86_64, aarch64, armv7l
|
|
|
|
|
have_msys2 = uname['s'].startswith('MSYS_NT') # Linux, MSYS_NT.*
|
2017-07-07 16:09:28 +03:00
|
|
|
|
2021-09-24 20:07:06 +00:00
|
|
|
class my_build_ext(build_ext):
|
|
|
|
|
def build_extension(self,ext):
|
|
|
|
|
build_libsecp256k1()
|
|
|
|
|
build_ext.build_extension(self,ext)
|
|
|
|
|
|
|
|
|
|
setup(
|
|
|
|
|
cmdclass = { 'build_ext': my_build_ext },
|
|
|
|
|
ext_modules = [Extension(
|
2022-10-05 19:22:42 +00:00
|
|
|
name = 'mmgen.proto.secp256k1.secp256k1',
|
2021-09-29 21:17:56 +00:00
|
|
|
sources = ['extmod/secp256k1mod.c'],
|
|
|
|
|
libraries = ([],['gmp'])[have_msys2],
|
2021-09-24 20:07:06 +00:00
|
|
|
extra_objects = [os.path.join(ext_path,'.libs/libsecp256k1.a')],
|
2021-09-29 21:17:56 +00:00
|
|
|
include_dirs = [os.path.join(ext_path,'include')],
|
2021-09-24 20:07:06 +00:00
|
|
|
)]
|
|
|
|
|
)
|