aboutsummaryrefslogtreecommitdiffhomepage
path: root/setup.py
blob: 4831b6ad038c77f1367c122e30a93232a5c47609 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from contextlib import suppress
from pathlib import Path
from setuptools import Command, setup
from setuptools.command.build import build
import subprocess
import shutil


class CustomTommath(Command):
    def initialize_options(self) -> None:
        self.build_lib = None

    def finalize_options(self) -> None:
        with suppress(Exception):
            self.build_lib = Path(self.get_finalized_command("build").build_lib)

    def run(self) -> None:
        if self.build_lib:
            tommath_dir = Path("..") / self.build_lib / Path("pyecsca/codegen/tommath")
            subprocess.run(["make", "host", "nano", "stm32f0", "stm32f3", f"TOMMATH_DIR={tommath_dir}"], cwd="ext")
            


class CustomBuild(build):
    sub_commands = build.sub_commands + [('build_tommath', None)]


setup(cmdclass={'build': CustomBuild, 'build_tommath': CustomTommath})