build: simplify readline detection

This commit is contained in:
Michael Vetter
2026-02-05 13:35:55 +01:00
parent af0dfcce70
commit 886080dc9b

View File

@@ -122,40 +122,25 @@ endforeach
# we need to declare the variable before # we need to declare the variable before
# using it in the conditional branch. # using it in the conditional branch.
# Later the required is set correctly. # Later the required is set correctly.
readline_dep = dependency('', required: false) readline_dep = dependency('readline', required: false)
if platform == 'osx' if not readline_dep.found()
brew = find_program('brew', required: false, dirs: ['/opt/homebrew/bin', '/usr/local/bin']) if platform == 'osx'
# brew prefix
if brew.found() brew = find_program('brew', required: false)
readline_prefix_cmd = run_command(brew, '--prefix', 'readline', check: false) if brew.found()
if readline_prefix_cmd.returncode() == 0 prefix = run_command(brew, '--prefix', 'readline', check: false).stdout().strip()
readline_prefix = readline_prefix_cmd.stdout().strip() readline_dep = cc.find_library('readline', dirs: [prefix / 'lib'], required: true)
else add_project_arguments('-I' + prefix / 'include', language: 'c')
readline_prefix = '/usr/local'
endif
else
if run_command('test', '-f', '/opt/local/lib/libreadline.dylib', check: false).returncode() == 0
readline_prefix = '/opt/local'
else
readline_prefix = '/usr/local'
endif endif
elif platform == 'openbsd'
# ereadline alias
readline_dep = cc.find_library('ereadline', dirs: ['/usr/local/lib'], required: false)
endif endif
endif
readline_dep = cc.find_library('readline', # regular
dirs: [readline_prefix / 'lib'], if not readline_dep.found()
required: true)
add_project_arguments('-I' + readline_prefix / 'include', language: 'c')
elif platform == 'openbsd'
if run_command('test', '-d', '/usr/local/include/ereadline', check: false).returncode() == 0
readline_dep = cc.find_library('ereadline',
dirs: ['/usr/local/lib'],
required: true)
add_project_arguments('-I/usr/local/include/ereadline', language: 'c')
else
readline_dep = cc.find_library('readline', required: true)
endif
else
readline_dep = cc.find_library('readline', required: true) readline_dep = cc.find_library('readline', required: true)
endif endif