build: Use cc.links to check linker arguments
authorTing-Wei Lan <lantw@src.gnome.org>
Sun, 22 Apr 2018 13:42:03 +0000 (21:42 +0800)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 23 Apr 2018 22:54:43 +0000 (18:54 -0400)
Instead of hard-coding linker flags for a specific operating system and
a specific compiler, we can should cc.links to test them, so they can be
used on more operating systems and compilers.

meson.build

index cdd83e76355569afc83c57b875ddda886010cb04..895cef9fc0618fd634d106a77592c0116afa41c3 100644 (file)
@@ -284,8 +284,12 @@ endif
 
 common_ldflags = []
 
-if host_machine.system() == 'linux' and cc.get_id() == 'gcc'
-  common_ldflags += [ '-Wl,-Bsymbolic', '-Wl,-z,relro', '-Wl,-z,now', ]
+if os_unix and not os_darwin
+  foreach ldflag: [ '-Wl,-Bsymbolic', '-Wl,-z,relro', '-Wl,-z,now', ]
+    if cc.links('int main () { return 0; }', name: ldflag, args: ldflag)
+      common_ldflags += [ ldflag ]
+    endif
+  endforeach
 endif
 
 # Maintain compatibility with autotools