26 lines
827 B
Python
26 lines
827 B
Python
# build/compiler/gcc.py
|
|
from .base import Compiler
|
|
from pathlib import Path
|
|
from ..utils import run
|
|
|
|
class GCCCompiler(Compiler):
|
|
def __init__(self, exe: str | None = None):
|
|
super().__init__(exe or "gcc")
|
|
|
|
def compile(self, src: Path, out: Path, flags: list[str], extra_defines: list[str] | None = None, deps_out: Path | None = None) -> Path:
|
|
cmd = [self.exe] + flags[:]
|
|
if extra_defines:
|
|
cmd += extra_defines
|
|
if deps_out:
|
|
cmd += ["-MMD", "-MP"]
|
|
cmd += ["-c", str(src), "-o", str(out)]
|
|
run(cmd)
|
|
return out
|
|
|
|
def link(self, objects: list[Path], output: Path, libs: list[str] | None = None):
|
|
cmd = [self.exe] + [str(p) for p in objects]
|
|
if libs:
|
|
cmd += libs
|
|
cmd += ["-o", str(output)]
|
|
run(cmd)
|