Skip to content

Commit

Permalink
Add --extra-libs option and group -l flags from LDFLAGS to the end
Browse files Browse the repository at this point in the history
Ref #2622
  • Loading branch information
randombit committed Feb 15, 2021
1 parent 23069a9 commit af63fe8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions configure.py
Expand Up @@ -333,6 +333,9 @@ def process_command_line(args): # pylint: disable=too-many-locals,too-many-state
target_group.add_option('--ldflags', metavar='FLAGS',
help='set linker flags', default=None)

target_group.add_option('--extra-libs', metavar='LIBS',
help='specify extra libraries to link against', default='')

target_group.add_option('--ar-command', dest='ar_command', metavar='AR', default=None,
help='set path to static archive creator')

Expand Down Expand Up @@ -2020,6 +2023,12 @@ def choose_cxx_exe():
else:
return '%s %s' % (options.compiler_cache, cxx)

def extra_libs(libs, cc):
if libs is None:
return ''

return ' '.join([(cc.add_lib_option % lib) for lib in libs.split(',')])

variables = {
'version_major': Version.major(),
'version_minor': Version.minor(),
Expand Down Expand Up @@ -2149,6 +2158,7 @@ def choose_cxx_exe():
'cc_sysroot': sysroot_option(),
'cc_compile_flags': options.cxxflags or cc.cc_compile_flags(options),
'ldflags': options.ldflags or '',
'extra_libs': extra_libs(options.extra_libs, cc),
'cc_warning_flags': cc.cc_warning_flags(options),
'output_to_exe': cc.output_to_exe,
'cc_macro': cc.macro_name,
Expand Down Expand Up @@ -3029,6 +3039,10 @@ def canonicalize_build_targets(options):
if options.build_fuzzers == 'libfuzzer' and options.fuzzer_lib is None:
options.fuzzer_lib = 'Fuzzer'

if options.ldflags is not None:
libs = [m.group(1) for m in re.finditer(r'-l([a-z0-9]+)', options.ldflags)]
options.extra_libs += ','.join(libs)

# Checks user options for consistency
# This method DOES NOT change options on behalf of the user but explains
# why the given configuration does not work.
Expand Down
2 changes: 1 addition & 1 deletion src/build-data/makefile.in
Expand Up @@ -20,7 +20,7 @@ LDFLAGS = %{ldflags}
EXE_LINK_CMD = %{exe_link_cmd}

LIB_LINKS_TO = %{external_link_cmd} %{link_to}
EXE_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO)
EXE_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO) %{extra_libs}

BUILD_FLAGS = $(ABI_FLAGS) $(LANG_FLAGS) $(CXXFLAGS) $(WARN_FLAGS)

Expand Down

0 comments on commit af63fe8

Please sign in to comment.