aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/c.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-03-18 14:23:06 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2019-03-20 18:45:56 +0200
commitac627bcea723b12e17822c18cccc9dbdeaee8b8f (patch)
tree66999769a73d0f923389f1d2ddec898421a204a1 /mesonbuild/compilers/c.py
parent44dd5535f056922294867bac2eb07b57f21bede6 (diff)
downloadmeson-ac627bcea723b12e17822c18cccc9dbdeaee8b8f.zip
meson-ac627bcea723b12e17822c18cccc9dbdeaee8b8f.tar.gz
meson-ac627bcea723b12e17822c18cccc9dbdeaee8b8f.tar.bz2
replace library type strings with an enum
This patch creates an enum for selecting libtype as static, shared, prefer-static, or prefer-shared. This also renames 'static-shared' with 'prefer_static' and 'shared-static' with 'prefer_shared'. This is just a refactor with no behavioral changes or user facing changes.
Diffstat (limited to 'mesonbuild/compilers/c.py')
-rw-r--r--mesonbuild/compilers/c.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 6ab14d2..cac27ad 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -27,7 +27,7 @@ from . import compilers
from ..mesonlib import (
EnvironmentException, MachineChoice, MesonException, Popen_safe, listify,
version_compare, for_windows, for_darwin, for_cygwin, for_haiku,
- for_openbsd, darwin_get_object_archs
+ for_openbsd, darwin_get_object_archs, LibType
)
from .c_function_attributes import C_FUNC_ATTRIBUTES
@@ -905,7 +905,7 @@ class CCompiler(Compiler):
patterns.append(p + '{}.so.[0-9]*.[0-9]*')
return patterns
- def get_library_naming(self, env, libtype, strict=False):
+ def get_library_naming(self, env, libtype: LibType, strict=False):
'''
Get library prefixes and suffixes for the target platform ordered by
priority
@@ -938,18 +938,17 @@ class CCompiler(Compiler):
# Linux/BSDs
shlibext = ['so']
# Search priority
- if libtype == 'shared-static':
+ if libtype is LibType.PREFER_SHARED:
patterns = self._get_patterns(env, prefixes, shlibext, True)
patterns.extend([x for x in self._get_patterns(env, prefixes, stlibext, False) if x not in patterns])
- elif libtype == 'static-shared':
+ elif libtype is LibType.PREFER_STATIC:
patterns = self._get_patterns(env, prefixes, stlibext, False)
patterns.extend([x for x in self._get_patterns(env, prefixes, shlibext, True) if x not in patterns])
- elif libtype == 'shared':
+ elif libtype is LibType.SHARED:
patterns = self._get_patterns(env, prefixes, shlibext, True)
- elif libtype == 'static':
- patterns = self._get_patterns(env, prefixes, stlibext, False)
else:
- raise AssertionError('BUG: unknown libtype {!r}'.format(libtype))
+ assert libtype is LibType.STATIC
+ patterns = self._get_patterns(env, prefixes, stlibext, False)
return tuple(patterns)
@staticmethod
@@ -1011,13 +1010,13 @@ class CCompiler(Compiler):
'''
return self.sizeof('void *', '', env) == 8
- def find_library_real(self, libname, env, extra_dirs, code, libtype):
+ def find_library_real(self, libname, env, extra_dirs, code, libtype: LibType):
# First try if we can just add the library as -l.
# Gcc + co seem to prefer builtin lib dirs to -L dirs.
# Only try to find std libs if no extra dirs specified.
# The built-in search procedure will always favour .so and then always
- # search for .a. This is only allowed if libtype is 'shared-static'
- if ((not extra_dirs and libtype == 'shared-static') or
+ # search for .a. This is only allowed if libtype is LibType.PREFER_SHARED
+ if ((not extra_dirs and libtype is LibType.PREFER_SHARED) or
libname in self.internal_libs):
args = ['-l' + libname]
largs = self.linker_to_compiler_args(self.get_allow_undefined_link_args())
@@ -1051,7 +1050,7 @@ class CCompiler(Compiler):
return [trial.as_posix()]
return None
- def find_library_impl(self, libname, env, extra_dirs, code, libtype):
+ def find_library_impl(self, libname, env, extra_dirs, code, libtype: LibType):
# These libraries are either built-in or invalid
if libname in self.ignore_libs:
return []
@@ -1067,7 +1066,7 @@ class CCompiler(Compiler):
return None
return value[:]
- def find_library(self, libname, env, extra_dirs, libtype='shared-static'):
+ def find_library(self, libname, env, extra_dirs, libtype: LibType = LibType.PREFER_SHARED):
code = 'int main(int argc, char **argv) { return 0; }'
return self.find_library_impl(libname, env, extra_dirs, code, libtype)