From cf914a3a79578bc97d80c3d3a0090b2fab0eb834 Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Thu, 1 Aug 2024 17:00:55 +0700 Subject: [PATCH] fix specs_prefix_format to point to root toolchain's directory --- meson.build | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) --- a/meson.build +++ b/meson.build @@ -500,20 +500,39 @@ endif if sysroot_install + # Get 'sysroot' or 'GCC_EXEC_PREFIX' from GCC output sysroot = run_command(cc.cmd_array() + ['-print-sysroot'], check : true).stdout().split('\n')[0] if sysroot != '' - specs_prefix_format = '%R/@0@' + specs_prefix_format_format = '%R/@0@' + specs_prefix_format_default = '%R/@0@' else - sysroot = cc_install_dir + '../../../..' - specs_prefix_format = '%:getenv(GCC_EXEC_PREFIX ../../@0@)' - endif - if not get_option('sysroot-install-skip-checks') - if sysroot == '' + if not get_option('sysroot-install-skip-checks') error('sysroot install requested, but compiler has no sysroot') endif - if not fs.is_samepath(sysroot, prefix) - error('sysroot install requires --prefix=' + sysroot) + sysroot = run_command(cc.cmd_array() + ['-print-search-dirs'], check : true).stdout().split('\n')[0].split(' ')[1] + specs_prefix_format_format = '%:getenv(GCC_EXEC_PREFIX @0@)' + specs_prefix_format_default = '%:getenv(GCC_EXEC_PREFIX ../../@0@)' + endif + + # Try to calculate relative path from sysroot to prefix + specs_prefix_format = '' + if fs.exists(sysroot) + sysroot_to_prefix_correction = '' + foreach _ : sysroot.split('/') + if fs.is_samepath(sysroot + '/' + sysroot_to_prefix_correction, prefix) + specs_prefix_format = specs_prefix_format_format.format(sysroot_to_prefix_correction + '@0@') + break + endif + sysroot_to_prefix_correction += '../' + endforeach + endif + + # Use default 'specs_prefix_format' if can not have relative sysroot path + if specs_prefix_format == '' + if not get_option('sysroot-install-skip-checks') + error('sysroot install requires sysroot(' + sysroot + ') to be a subdirectory of --prefix=(' + prefix + ')') endif + specs_prefix_format = specs_prefix_format_default endif else specs_prefix_format = prefix + '/@0@'