chiark / gitweb /
meson: use "args" for setting _GNU_SOURCE when checking for functions
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Dec 2017 11:01:14 +0000 (12:01 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:41 +0000 (07:49 +0200)
This reworks how we set _GNU_SOURCE when checking for the availability
of functions:

1. We set it for most of the functions we look for. After all we set it
for our entire built anyway, and it's usually how Linux-specific
definitions in glibc are protected these days. Given that we usually
have checks for such modern stuff only anyway, let's just blanket enable
it.

2. Use "args" instead of "prefix" to set the macro. This is what is
suggested in the meson docs, hence let's do it.

meson.build

index c9ce60a97b5af0266a02845c966708f2f10542b0..aea61990c5751947d3ab20495944f8ec48a84101 100644 (file)
@@ -518,33 +518,29 @@ foreach ident : ['secure_getenv', '__secure_getenv']
 endforeach
 
 foreach ident : [
-        ['memfd_create',      '''#define _GNU_SOURCE
-//                                 #include <sys/mman.h>'''],
+        ['memfd_create',      '''#include <sys/mman.h>'''],
         ['gettid',            '''#include <sys/types.h>'''],
         ['pivot_root',        '''#include <stdlib.h>'''],     # no known header declares pivot_root
-        ['name_to_handle_at', '''#define _GNU_SOURCE
-                                 #include <sys/types.h>
+        ['name_to_handle_at', '''#include <sys/types.h>
                                  #include <sys/stat.h>
                                  #include <fcntl.h>'''],
-        ['setns',             '''#define _GNU_SOURCE
-                                 #include <sched.h>'''],
+        ['setns',             '''#include <sched.h>'''],
         ['renameat2',         '''#include <stdio.h>'''],
         ['kcmp',              '''#include <linux/kcmp.h>'''],
         ['keyctl',            '''#include <sys/types.h>
                                  #include <keyutils.h>'''],
-        ['copy_file_range',   '''#define _GNU_SOURCE
-//                                 #include <sys/syscall.h>
+        ['copy_file_range',   '''#include <sys/syscall.h>
                                  #include <unistd.h>'''],
         ['bpf',               '''#include <sys/syscall.h>
                                  #include <unistd.h>'''],
         ['explicit_bzero' ,   '''#include <string.h>'''],
 ]
 
-        have = cc.has_function(ident[0], prefix : ident[1])
+        have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
         conf.set10('HAVE_' + ident[0].to_upper(), have)
 endforeach
 
-if cc.has_function('getrandom', prefix : '''#include <sys/random.h>''')
+if cc.has_function('getrandom', prefix : '''#include <sys/random.h>''', args : '-D_GNU_SOURCE')
         conf.set10('USE_SYS_RANDOM_H', true)
         conf.set10('HAVE_GETRANDOM', true)
 else