Skip to content

Commit e1ccfea

Browse files
akihikodakiMichael Tokarev
authored andcommitted
meson: Share common C source prefixes
gnu_source_prefix defines _GNU_SOURCE for compiler object functions. The definition is universally available in the code base. docs/devel/style.rst also says that the "qemu/osdep.h" header is always included, so files included in the file is also universally available in the code base. Rename gnu_source_prefix to osdep_prefix, and add #include directives that are referred by the users of gnu_source_prefix and contained in qemu/osdep.h to safely de-duplicate #include directives. Cc: [email protected] Signed-off-by: Akihiko Odaki <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Tested-by: Philippe Mathieu-Daudé <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> (cherry picked from commit 797150d) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 1604055 commit e1ccfea

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

meson.build

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,10 +2185,21 @@ if not has_malloc_trim and get_option('malloc_trim').enabled()
21852185
endif
21862186
endif
21872187

2188-
gnu_source_prefix = '''
2188+
osdep_prefix = '''
21892189
#ifndef _GNU_SOURCE
21902190
#define _GNU_SOURCE
21912191
#endif
2192+
2193+
#include <stddef.h>
2194+
#include <sys/types.h>
2195+
2196+
#include <limits.h>
2197+
/* Put unistd.h before time.h as that triggers localtime_r/gmtime_r
2198+
* function availability on recentish Mingw-w64 platforms. */
2199+
#include <unistd.h>
2200+
#include <time.h>
2201+
#include <errno.h>
2202+
#include <fcntl.h>
21922203
'''
21932204

21942205
have_vhost_user_blk_server = get_option('vhost_user_blk_server') \
@@ -2703,7 +2714,7 @@ config_host_data.set('CONFIG_FIEMAP',
27032714
cc.has_header('linux/fiemap.h') and
27042715
cc.has_header_symbol('linux/fs.h', 'FS_IOC_FIEMAP'))
27052716
config_host_data.set('CONFIG_GETCPU',
2706-
cc.has_header_symbol('sched.h', 'getcpu', prefix: gnu_source_prefix))
2717+
cc.has_header_symbol('sched.h', 'getcpu', prefix: osdep_prefix))
27072718
config_host_data.set('CONFIG_GETRANDOM',
27082719
cc.has_function('getrandom') and
27092720
cc.has_header_symbol('sys/random.h', 'GRND_NONBLOCK'))
@@ -2748,8 +2759,7 @@ config_host_data.set('HAVE_UTMPX',
27482759
config_host_data.set('CONFIG_EVENTFD', cc.links('''
27492760
#include <sys/eventfd.h>
27502761
int main(void) { return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); }'''))
2751-
config_host_data.set('CONFIG_FDATASYNC', cc.links(gnu_source_prefix + '''
2752-
#include <unistd.h>
2762+
config_host_data.set('CONFIG_FDATASYNC', cc.links(osdep_prefix + '''
27532763
int main(void) {
27542764
#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
27552765
return fdatasync(0);
@@ -2758,10 +2768,8 @@ config_host_data.set('CONFIG_FDATASYNC', cc.links(gnu_source_prefix + '''
27582768
#endif
27592769
}'''))
27602770

2761-
has_madvise = cc.links(gnu_source_prefix + '''
2762-
#include <sys/types.h>
2771+
has_madvise = cc.links(osdep_prefix + '''
27632772
#include <sys/mman.h>
2764-
#include <stddef.h>
27652773
int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }''')
27662774
missing_madvise_proto = false
27672775
if has_madvise
@@ -2771,21 +2779,18 @@ if has_madvise
27712779
# missing-prototype case, we try again with a definitely-bogus prototype.
27722780
# This will only compile if the system headers don't provide the prototype;
27732781
# otherwise the conflicting prototypes will cause a compiler error.
2774-
missing_madvise_proto = cc.links(gnu_source_prefix + '''
2775-
#include <sys/types.h>
2782+
missing_madvise_proto = cc.links(osdep_prefix + '''>
27762783
#include <sys/mman.h>
2777-
#include <stddef.h>
27782784
extern int madvise(int);
27792785
int main(void) { return madvise(0); }''')
27802786
endif
27812787
config_host_data.set('CONFIG_MADVISE', has_madvise)
27822788
config_host_data.set('HAVE_MADVISE_WITHOUT_PROTOTYPE', missing_madvise_proto)
27832789

2784-
config_host_data.set('CONFIG_MEMFD', cc.links(gnu_source_prefix + '''
2790+
config_host_data.set('CONFIG_MEMFD', cc.links(osdep_prefix + '''
27852791
#include <sys/mman.h>
27862792
int main(void) { return memfd_create("foo", MFD_ALLOW_SEALING); }'''))
2787-
config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(gnu_source_prefix + '''
2788-
#include <fcntl.h>
2793+
config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(osdep_prefix + '''
27892794
#if !defined(AT_EMPTY_PATH)
27902795
# error missing definition
27912796
#else
@@ -2796,13 +2801,12 @@ config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(gnu_source_prefix + '''
27962801
# i.e. errno is set and -1 is returned. That's not really how POSIX defines the
27972802
# function. On the flip side, it has madvise() which is preferred anyways.
27982803
if host_os != 'darwin'
2799-
config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(gnu_source_prefix + '''
2804+
config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(osdep_prefix + '''
28002805
#include <sys/mman.h>
2801-
#include <stddef.h>
28022806
int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }'''))
28032807
endif
28042808

2805-
config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(gnu_source_prefix + '''
2809+
config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(osdep_prefix + '''
28062810
#include <pthread.h>
28072811
28082812
static void *f(void *p) { return NULL; }
@@ -2813,7 +2817,7 @@ config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(gnu_source_pref
28132817
pthread_setname_np(thread, "QEMU");
28142818
return 0;
28152819
}''', dependencies: threads))
2816-
config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(gnu_source_prefix + '''
2820+
config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(osdep_prefix + '''
28172821
#include <pthread.h>
28182822
28192823
static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
@@ -2823,7 +2827,7 @@ config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(gnu_source_pre
28232827
pthread_create(&thread, 0, f, 0);
28242828
return 0;
28252829
}''', dependencies: threads))
2826-
config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(gnu_source_prefix + '''
2830+
config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(osdep_prefix + '''
28272831
#include <pthread.h>
28282832
#include <pthread_np.h>
28292833
@@ -2835,9 +2839,8 @@ config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(gnu_source_prefix +
28352839
pthread_set_name_np(thread, "QEMU");
28362840
return 0;
28372841
}''', dependencies: threads))
2838-
config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(gnu_source_prefix + '''
2842+
config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(osdep_prefix + '''
28392843
#include <pthread.h>
2840-
#include <time.h>
28412844
28422845
int main(void)
28432846
{
@@ -2846,7 +2849,7 @@ config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(gnu_source_pre
28462849
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
28472850
return 0;
28482851
}''', dependencies: threads))
2849-
config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(gnu_source_prefix + '''
2852+
config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(osdep_prefix + '''
28502853
#include <pthread.h>
28512854
28522855
static void *f(void *p) { return NULL; }
@@ -2863,15 +2866,10 @@ config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(gnu_source_prefix +
28632866
CPU_FREE(cpuset);
28642867
return 0;
28652868
}''', dependencies: threads))
2866-
config_host_data.set('CONFIG_SIGNALFD', cc.links(gnu_source_prefix + '''
2869+
config_host_data.set('CONFIG_SIGNALFD', cc.links(osdep_prefix + '''
28672870
#include <sys/signalfd.h>
2868-
#include <stddef.h>
28692871
int main(void) { return signalfd(-1, NULL, SFD_CLOEXEC); }'''))
2870-
config_host_data.set('CONFIG_SPLICE', cc.links(gnu_source_prefix + '''
2871-
#include <unistd.h>
2872-
#include <fcntl.h>
2873-
#include <limits.h>
2874-
2872+
config_host_data.set('CONFIG_SPLICE', cc.links(osdep_prefix + '''
28752873
int main(void)
28762874
{
28772875
int len, fd = 0;
@@ -2880,13 +2878,13 @@ config_host_data.set('CONFIG_SPLICE', cc.links(gnu_source_prefix + '''
28802878
return 0;
28812879
}'''))
28822880

2883-
config_host_data.set('HAVE_MLOCKALL', cc.links(gnu_source_prefix + '''
2881+
config_host_data.set('HAVE_MLOCKALL', cc.links(osdep_prefix + '''
28842882
#include <sys/mman.h>
28852883
int main(void) {
28862884
return mlockall(MCL_FUTURE);
28872885
}'''))
28882886

2889-
config_host_data.set('HAVE_MLOCK_ONFAULT', cc.links(gnu_source_prefix + '''
2887+
config_host_data.set('HAVE_MLOCK_ONFAULT', cc.links(osdep_prefix + '''
28902888
#include <sys/mman.h>
28912889
int main(void) {
28922890
return mlockall(MCL_FUTURE | MCL_ONFAULT);
@@ -2895,7 +2893,7 @@ config_host_data.set('HAVE_MLOCK_ONFAULT', cc.links(gnu_source_prefix + '''
28952893
have_l2tpv3 = false
28962894
if get_option('l2tpv3').allowed() and have_system
28972895
have_l2tpv3 = cc.has_type('struct mmsghdr',
2898-
prefix: gnu_source_prefix + '''
2896+
prefix: osdep_prefix + '''
28992897
#include <sys/socket.h>
29002898
#include <linux/ip.h>''')
29012899
endif
@@ -3011,13 +3009,13 @@ if has_int128_type
30113009
endif
30123010
endif
30133011

3014-
config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
3012+
config_host_data.set('CONFIG_GETAUXVAL', cc.links(osdep_prefix + '''
30153013
#include <sys/auxv.h>
30163014
int main(void) {
30173015
return getauxval(AT_HWCAP) == 0;
30183016
}'''))
30193017

3020-
config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(gnu_source_prefix + '''
3018+
config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(osdep_prefix + '''
30213019
#include <sys/auxv.h>
30223020
int main(void) {
30233021
unsigned long hwcap = 0;
@@ -3130,9 +3128,7 @@ config_host_data.set('CONFIG_MEMBARRIER', get_option('membarrier') \
31303128
.allowed())
31313129

31323130
have_afalg = get_option('crypto_afalg') \
3133-
.require(cc.compiles(gnu_source_prefix + '''
3134-
#include <errno.h>
3135-
#include <sys/types.h>
3131+
.require(cc.compiles(osdep_prefix + '''
31363132
#include <sys/socket.h>
31373133
#include <linux/if_alg.h>
31383134
int main(void) {

0 commit comments

Comments
 (0)