89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
"""
|
|
Linux build target.
|
|
|
|
This module implements the build target for native Linux builds.
|
|
Uses GCC as the default compiler.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from typing import List, Optional
|
|
from .base import Target
|
|
from ..compilers import GCCCompiler, detect_compiler
|
|
from ..config import Config
|
|
|
|
|
|
class LinuxTarget(Target):
|
|
"""
|
|
Linux native build target.
|
|
|
|
Builds executables for Linux using GCC or Clang.
|
|
"""
|
|
|
|
def __init__(self, config: Config, compiler: Optional[GCCCompiler] = None):
|
|
"""
|
|
Initialize Linux target.
|
|
|
|
Args:
|
|
config: Build configuration
|
|
compiler: Compiler to use (default: auto-detect GCC/Clang)
|
|
"""
|
|
super().__init__(config, compiler)
|
|
|
|
def _get_default_compiler(self) -> GCCCompiler:
|
|
"""
|
|
Get the default compiler for Linux.
|
|
|
|
Returns:
|
|
GCC or Clang compiler instance
|
|
"""
|
|
return detect_compiler("linux") # type: ignore
|
|
|
|
def get_name(self) -> str:
|
|
"""Get the target name."""
|
|
return "linux"
|
|
|
|
def get_compile_flags(self, is_test: bool = False) -> List[str]:
|
|
"""
|
|
Get compilation flags for Linux.
|
|
|
|
Args:
|
|
is_test: Whether this is a test compilation
|
|
|
|
Returns:
|
|
List of compiler flags
|
|
"""
|
|
if is_test:
|
|
return self.config.gcc_test_flags.copy()
|
|
else:
|
|
return self.config.gcc_common_flags.copy()
|
|
|
|
def get_link_flags(self) -> List[str]:
|
|
"""
|
|
Get linker flags for Linux.
|
|
|
|
Returns:
|
|
List of linker flags
|
|
"""
|
|
return []
|
|
|
|
def generate_tests(self):
|
|
"""Generate test code from YAML if available."""
|
|
from ..utils import detect_python, run_command
|
|
|
|
script = Path("../SLS_Tests/yaml_to_c_tests.py")
|
|
yaml = Path("../SLS_Tests/cases.yaml")
|
|
out = self.config.test_dir / "lexer_tests.c"
|
|
|
|
if not script.exists() or not yaml.exists():
|
|
if self.config.verbose:
|
|
print("Test generation skipped (missing files).")
|
|
return
|
|
|
|
# Check if regeneration is needed
|
|
if out.exists() and out.stat().st_mtime > yaml.stat().st_mtime:
|
|
return
|
|
|
|
print("Generating tests from YAML...")
|
|
python = detect_python()
|
|
run_command([python, str(script), str(yaml), str(out)])
|