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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#!/usr/bin/python3
"""
Library handling for Fortran dh_fortran_lib
Copyright (C) 2025 Alastair McKinstry <mckinstry@debian.org>
Released under the GPL-3 Gnu Public License.
"""
import os
import sys
import click
import logging
from subprocess import check_output
sys.path.append("/usr/share/dh-python/")
from dhpython import debhelper
log = logging.getLogger("dhfortran")
srcdir = "debian/tmp"
if "SOURCEDIR" in os.environ:
srcdir = os.environ["SOURCEDIR"]
flavor = None
if "FLAVOR" in os.environ:
flavor = os.environ["FLAVOR"]
def get_soname(libfile: str) -> str:
"""Helper: get soname from library"""
res = check_output(["objdump", "-p", libfile])
breakpoint()
def get_preferred(flavor):
# TODO. What if none?
if "PREFERRED" in os.environ:
return os.environ["PREFERRED"]
else:
match get_abi_vendor(flavor):
case "gfortran":
return "gfortran14"
case "flang":
return "flang19"
case "lfortran":
return "lfortran"
case _:
return "gfortran"
def process_static_lib(tmpdir, orig_libname, filename):
"""what to do for a static library"""
flibdir = XXX
dest = f"{tmpdir}/{flibdir}/{filename}"
if os.exists(dest):
log.debug(f"DEBUG: {dest} already exists")
# Flavor from where ? env? if set
pref = get_preferred(flavor)
if os.environ["FLAVOR"] != preferred:
return
log.debug(f"Installing {flavor} as new {dest}")
# doit("cp","--reflink=auto","-a",orig_libname,dest)
return (doit, ["cp", "--reflink=auto", "-a", orig_libname, dest])
def compute_abs_dest(srcdir, libname, target_dest) -> str:
"""Compute the target_dest as an absolute path"""
log.debug(f"compute_dest {srcdir} {libname} {target_dest}")
flibdir = TODO
if target_dest is not None:
if target_dest.startswith("/"):
return target_dest
else:
return f"{flibdir}/{target_dest}"
else:
return flibdir
@click.command()
@click.option("--flavor")
@click.option("--preferred")
@click.option("--sourcedir")
@click.option("--no-orig-library")
@click.option("--no-create-in-sourcedir")
def dh_fortran_lib(
libs=None,
flavor=None,
preferred=None,
sourcedir=None,
no_orig_library=None,
no_create_in_sourcedir=None,
):
"""Install libs in appropriate directory"""
# We need either flavor to be set, or FC
if flavor is None:
if "FC" not in os.environ:
raise Exception(
"Either --flavor is set, or FC is defined in the environment"
)
|