|  | 
| 13 | 13 | from .. import options | 
| 14 | 14 | from ..mesonlib import EnvironmentException, MesonException, Popen_safe_logged, version_compare | 
| 15 | 15 | from ..options import OptionKey | 
| 16 |  | -from .compilers import Compiler, CompileCheckMode, clike_debug_args | 
|  | 16 | +from .compilers import Compiler, CompileCheckMode, clike_debug_args, is_library | 
| 17 | 17 | 
 | 
| 18 | 18 | if T.TYPE_CHECKING: | 
| 19 | 19 |     from ..options import MutableKeyedOptionDictType | 
| @@ -208,6 +208,31 @@ def has_verbatim(self) -> bool: | 
| 208 | 208 |         # being linked.  However, Meson uses "bundle", not "whole_archive". | 
| 209 | 209 |         return False | 
| 210 | 210 | 
 | 
|  | 211 | +    def lib_file_to_l_arg(self, env: Environment, libname: str) -> T.Optional[str]: | 
|  | 212 | +        """Undo the effects of -l on the filename, returning the | 
|  | 213 | +           argument that can be passed to -l, or None if the | 
|  | 214 | +           library name is not supported.""" | 
|  | 215 | +        if not is_library(libname): | 
|  | 216 | +            return None | 
|  | 217 | +        libname, ext = os.path.splitext(libname) | 
|  | 218 | + | 
|  | 219 | +        # On Windows, -lfoo searches either foo.lib or libfoo.a. | 
|  | 220 | +        # Elsewhere, it only searches both static and shared libraries with | 
|  | 221 | +        # the "lib" prefix; for simplicity just skip .lib which is never used. | 
|  | 222 | +        if env.machines[self.for_machine].is_windows(): | 
|  | 223 | +            if ext == 'lib': | 
|  | 224 | +                return libname | 
|  | 225 | +            if ext != 'a': | 
|  | 226 | +                return None | 
|  | 227 | +        else: | 
|  | 228 | +            if ext == 'lib': | 
|  | 229 | +                return None | 
|  | 230 | + | 
|  | 231 | +        if not libname.startswith('lib'): | 
|  | 232 | +            return None | 
|  | 233 | +        libname = libname[3:] | 
|  | 234 | +        return libname | 
|  | 235 | + | 
| 211 | 236 |     def get_debug_args(self, is_debug: bool) -> T.List[str]: | 
| 212 | 237 |         return clike_debug_args[is_debug] | 
| 213 | 238 | 
 | 
|  | 
0 commit comments