diff --git a/meson.build b/meson.build index 2db5138147..02fe41b32b 100644 --- a/meson.build +++ b/meson.build @@ -1028,9 +1028,8 @@ libm = cc.find_library('m') # On some architectures, libatomic is required. But on some installations, # it is found, but actual linking fails. So let's try to use it opportunistically. # If it is installed, but not needed, it will be dropped because of --as-needed. -if cc.links('''int main(int argc, char **argv) { return 0; }''', - args : '-latomic', - name : 'libatomic') +basic_c_prog = '''int main(int argc, char **argv) { return 0; }''' +if cc.links(basic_c_prog, args : '-latomic', name : 'libatomic') libatomic = declare_dependency(link_args : '-latomic') else libatomic = [] diff --git a/src/core/meson.build b/src/core/meson.build index e8d6563803..80418bfe57 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -219,13 +219,24 @@ if conf.get('SYSTEMD_MULTICALL_BINARY') == 1 ] endif +if get_option('build-static') + if (get_option('b_pie') and + cc.links(basic_c_prog, args : '-static-pie', name : '-static-pie')) + systemd_link_args = ['-static-pie', '-Wl,-static,-pie'] + else + systemd_link_args = ['-static'] + endif +else + systemd_link_args = [] +endif + executables += [ libexec_template + { 'name' : 'systemd', 'dbus' : true, 'public' : true, 'sources' : systemd_sources, - 'link_args_static' : get_option('build-static') ? ['-static'] : [], + 'link_args_static' : systemd_link_args, 'link_with' : [ libcore, libshared,