1version_split = meson.project_version().split('.')
2major = version_split[0].to_int()
3minor = version_split[1].to_int()
4patch = version_split[2].to_int()
5if version_split.length() == 4
6    subpatch = version_split[3].to_int()
7else
8    subpatch = 0
9endif
10
11release = major * 10000000 + minor * 100000 + patch * 1000 + subpatch
12
13dri_dep = dependency('dri', required: build_dri2 or build_dri3)
14
15conf_data = configuration_data()
16conf_data.set('_DIX_CONFIG_H_', '1')
17
18conf_data.set('HAVE_TYPEOF', cc.compiles('''
19    int foo(int bar) { typeof(bar) baz = 1; return baz; }
20''',
21    name: 'typeof()'))
22
23conf_data.set('MONOTONIC_CLOCK', cc.compiles('''
24    #define _POSIX_C_SOURCE 200112L
25    #include <time.h>
26    #include <unistd.h>
27    #ifndef CLOCK_MONOTONIC
28    #error CLOCK_MONOTONIC not defined
29    #endif
30''',
31    name: 'CLOCK_MONOTONIC'))
32
33#conf_data.set('XSERVER_DTRACE', '1') # XXX
34
35if host_machine.endian() == 'little'
36    conf_data.set('X_BYTE_ORDER', 'X_LITTLE_ENDIAN')
37else
38    conf_data.set('X_BYTE_ORDER', 'X_BIG_ENDIAN')
39endif
40
41glx_align64 = []
42if cc.sizeof('unsigned long') == 8
43   conf_data.set('_XSERVER64', '1')
44   glx_align64 = '-D__GLX_ALIGN64'
45endif
46
47conf_data.set('_GNU_SOURCE', '1')
48# XXX: NO_LOCAL_CLIENT_CRED
49
50# autoconf checks for /dev/xf86 here, but the test should be based on
51# the target, not the build system.  Could we get rid of this and just
52# ifdef for openbsd?
53conf_data.set('HAS_APERTURE_DRV', host_machine.system() == 'openbsd')
54
55# XXX: USE_ALPHA_PIO and other bsd bits
56# XXX: FALLBACK_INPUT_DRIVER
57# XXX: BUNDLE_ID_PREFIX
58# XXX: HAVE_LIBDISPATCH
59conf_data.set_quoted('OSNAME', 'Linux') # XXX
60conf_data.set('HAVE_INPUTTHREAD', '1') # XXX
61conf_data.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', '1') # XXX
62conf_data.set('HAVE_LIBBSD', libbsd_dep.found())
63# XXX: HAVE_SYSTEMD_DAEMON
64# XXX: HAVE_LIBUDEV
65conf_data.set('CONFIG_UDEV', build_udev)
66conf_data.set('CONFIG_UDEV_KMS', build_udev)
67conf_data.set('HAVE_DBUS', build_dbus)
68conf_data.set('CONFIG_HAL', build_hal)
69conf_data.set('SYSTEMD_LOGIND', build_systemd_logind)
70conf_data.set('NEED_DBUS', build_systemd_logind or build_hal)
71conf_data.set('CONFIG_WSCONS', host_machine.system() == 'openbsd')
72
73conf_data.set('HAVE_XSHMFENCE', xshmfence_dep.found())
74conf_data.set('WITH_LIBDRM', libdrm_dep.found())
75conf_data.set('GLAMOR_HAS_EGL_QUERY_DMABUF',
76              epoxy_dep.found() and epoxy_dep.version().version_compare('>= 1.4.4'))
77conf_data.set('GLAMOR_HAS_EGL_QUERY_DRIVER',
78              epoxy_dep.found() and epoxy_dep.version().version_compare('>= 1.5.4'))
79conf_data.set('GLXEXT', build_glx)
80conf_data.set('GLAMOR', build_glamor)
81conf_data.set('GLAMOR_HAS_GBM', gbm_dep.found())
82conf_data.set('GLAMOR_HAS_GBM_LINEAR',
83              build_glamor and gbm_dep.found() and gbm_dep.version().version_compare('>= 10.6'))
84conf_data.set('GBM_BO_WITH_MODIFIERS',
85              build_glamor and gbm_dep.found() and gbm_dep.version().version_compare('>= 17.1'))
86
87conf_data.set_quoted('SERVER_MISC_CONFIG_PATH', serverconfigdir)
88conf_data.set_quoted('PROJECTROOT', get_option('prefix'))
89conf_data.set_quoted('SYSCONFDIR', join_paths(get_option('prefix'), get_option('sysconfdir')))
90conf_data.set_quoted('SUID_WRAPPER_DIR', join_paths(get_option('prefix'), get_option('libexecdir')))
91conf_data.set_quoted('COMPILEDDEFAULTFONTPATH', default_font_path)
92
93conf_data.set('XORG_VERSION_CURRENT', release)
94
95conf_data.set('HASXDMAUTH', has_xdm_auth)
96conf_data.set('SECURE_RPC', get_option('secure-rpc'))
97
98conf_data.set('HAVE_DLFCN_H', cc.has_header('dlfcn.h'))
99conf_data.set('HAVE_EXECINFO_H', cc.has_header('execinfo.h'))
100conf_data.set('HAVE_FCNTL_H', cc.has_header('fcntl.h'))
101conf_data.set('HAVE_FNMATCH_H', cc.has_header('fnmatch.h'))
102conf_data.set('HAVE_LINUX_AGPGART_H', cc.has_header('linux/agpgart.h'))
103conf_data.set('HAVE_STDLIB_H', cc.has_header('stdlib.h'))
104conf_data.set('HAVE_STRING_H', cc.has_header('string.h'))
105conf_data.set('HAVE_STRINGS_H', cc.has_header('strings.h'))
106conf_data.set('HAVE_STROPTS_H', cc.has_header('stropts.h'))
107conf_data.set('HAVE_SYS_AGPGART_H', cc.has_header('sys/agpgart.h'))
108conf_data.set('HAVE_SYS_AGPIO_H', cc.has_header('sys/agpio.h'))
109conf_data.set('HAVE_SYS_UTSNAME_H', cc.has_header('sys/utsname.h'))
110conf_data.set('HAVE_SYS_SYSMACROS_H', cc.has_header('sys/sysmacros.h'))
111conf_data.set('HAVE_UNISTD_H', cc.has_header('unistd.h'))
112
113conf_data.set('HAVE_ARC4RANDOM_BUF', cc.has_function('arc4random_buf', dependencies: libbsd_dep))
114conf_data.set('HAVE_BACKTRACE', cc.has_function('backtrace'))
115conf_data.set('HAVE_CBRT', cc.has_function('cbrt'))
116conf_data.set('HAVE_EPOLL_CREATE1', cc.has_function('epoll_create1'))
117conf_data.set('HAVE_GETUID', cc.has_function('getuid'))
118conf_data.set('HAVE_GETEUID', cc.has_function('geteuid'))
119conf_data.set('HAVE_ISASTREAM', cc.has_function('isastream'))
120conf_data.set('HAVE_ISSETUGID', cc.has_function('issetugid'))
121conf_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
122conf_data.set('HAVE_GETPEEREID', cc.has_function('getpeereid'))
123conf_data.set('HAVE_GETPEERUCRED', cc.has_function('getpeerucred'))
124conf_data.set('HAVE_GETPROGNAME', cc.has_function('getprogname'))
125conf_data.set('HAVE_GETZONEID', cc.has_function('getzoneid'))
126conf_data.set('HAVE_MEMFD_CREATE', cc.has_function('memfd_create'))
127conf_data.set('HAVE_MKOSTEMP', cc.has_function('mkostemp'))
128conf_data.set('HAVE_MMAP', cc.has_function('mmap'))
129conf_data.set('HAVE_POLL', cc.has_function('poll'))
130conf_data.set('HAVE_POLLSET_CREATE', cc.has_function('pollset_create'))
131conf_data.set('HAVE_POSIX_FALLOCATE', cc.has_function('posix_fallocate'))
132conf_data.set('HAVE_PORT_CREATE', cc.has_function('port_create'))
133conf_data.set('HAVE_REALLOCARRAY', cc.has_function('reallocarray', dependencies: libbsd_dep))
134conf_data.set('HAVE_SETEUID', cc.has_function('seteuid'))
135conf_data.set('HAVE_SETITIMER', cc.has_function('setitimer'))
136conf_data.set('HAVE_SHMCTL64', cc.has_function('shmctl64'))
137conf_data.set('HAVE_SIGACTION', cc.has_function('sigaction'))
138conf_data.set('HAVE_STRCASECMP', cc.has_function('strcasecmp'))
139conf_data.set('HAVE_STRCASESTR', cc.has_function('strcasestr'))
140conf_data.set('HAVE_STRLCAT', cc.has_function('strlcat', dependencies: libbsd_dep))
141conf_data.set('HAVE_STRLCPY', cc.has_function('strlcpy', dependencies: libbsd_dep))
142conf_data.set('HAVE_STRNCASECMP', cc.has_function('strncasecmp'))
143conf_data.set('HAVE_STRNDUP', cc.has_function('strndup'))
144conf_data.set('HAVE_TIMINGSAFE_MEMCMP', cc.has_function('timingsafe_memcmp'))
145conf_data.set('HAVE_VASPRINTF', cc.has_function('vasprintf'))
146conf_data.set('HAVE_VSNPRINTF', cc.has_function('vsnprintf'))
147conf_data.set('HAVE_WALKCONTEXT', cc.has_function('walkcontext'))
148
149conf_data.set('BUSFAULT', conf_data.get('HAVE_SIGACTION'))
150
151# Don't let X dependencies typedef 'pointer'
152conf_data.set('_XTYPEDEF_POINTER', '1')
153conf_data.set('_XITYPEDEF_POINTER', '1')
154
155conf_data.set('LISTEN_TCP', get_option('listen_tcp'))
156conf_data.set('LISTEN_UNIX', get_option('listen_unix'))
157conf_data.set('LISTEN_LOCAL', get_option('listen_local'))
158# XXX: Configurable?
159conf_data.set('XTRANS_SEND_FDS', '1')
160
161conf_data.set('TCPCONN', '1')
162conf_data.set('UNIXCONN', '1')
163conf_data.set('IPv6', build_ipv6)
164
165conf_data.set('CLIENTIDS', '1') # XXX
166
167conf_data.set('BIGREQS', '1')
168conf_data.set('COMPOSITE', '1')
169conf_data.set('DAMAGE', '1')
170conf_data.set('DBE', '1')
171conf_data.set('DGA', build_dga)
172conf_data.set('DPMSExtension', build_dpms)
173conf_data.set('DRI2', build_dri2)
174conf_data.set('DRI3', build_dri3)
175conf_data.set_quoted('DRI_DRIVER_PATH', dri_dep.get_pkgconfig_variable('dridriverdir'))
176conf_data.set('HAS_SHM', build_mitshm)
177conf_data.set('MITSHM', build_mitshm)
178conf_data.set('PANORAMIX', build_xinerama)
179conf_data.set('PRESENT', '1')
180conf_data.set('RANDR', '1')
181conf_data.set('RES', build_res)
182conf_data.set('RENDER', '1')
183conf_data.set('SCREENSAVER', build_screensaver)
184conf_data.set('SHAPE', '1')
185conf_data.set('XACE', build_xace)
186conf_data.set('XCMISC', '1')
187conf_data.set('XCSECURITY', build_xsecurity)
188conf_data.set('XDMCP', xdmcp_dep.found())
189conf_data.set('XF86BIGFONT', build_xf86bigfont)
190conf_data.set('XF86DRI', build_dri1)
191conf_data.set('XF86VIDMODE', build_xf86vidmode)
192conf_data.set('XFIXES', '1')
193conf_data.set('XFreeXDGA', build_dga)
194conf_data.set('XINERAMA', build_xinerama)
195conf_data.set('XINPUT', '1')
196conf_data.set('XRECORD', '1')
197conf_data.set('XSELINUX', build_xselinux)
198conf_data.set('XSYNC', '1')
199conf_data.set('XTEST', '1')
200conf_data.set('XV', build_xv)
201conf_data.set('XvExtension', build_xv)
202conf_data.set('XvMCExtension', build_xvmc)
203
204conf_data.set('HAVE_SHA1_IN_LIBNETTLE', '1') # XXX
205
206conf_data.set('HAVE_APM', build_apm or build_acpi)
207conf_data.set('HAVE_ACPI', build_acpi)
208
209enable_debugging = get_option('buildtype') == 'debug'
210conf_data.set('DEBUG', enable_debugging)
211
212conf_data.set_quoted('XVENDORNAME', get_option('vendor_name'))
213conf_data.set_quoted('XVENDORNAMESHORT', get_option('vendor_name_short'))
214conf_data.set_quoted('__VENDORDWEBSUPPORT__', get_option('vendor_web'))
215conf_data.set_quoted('OSVENDOR', get_option('os_vendor'))
216conf_data.set_quoted('BUILDERADDR', get_option('builder_addr'))
217conf_data.set_quoted('BUILDERSTRING', get_option('builder_string'))
218
219#
220# for xorg-server.h only
221#
222defines_svr4 = '''#if !defined(SVR4) && !defined(__svr4__) && !defined(__SVR4)
223#error "I am not SVR4"
224#endif
225'''
226
227# BSD specifics
228supports_pccons = false
229supports_pcvt = false
230supports_syscons = false
231supports_wscons = false
232csrg_based = false
233
234if host_machine.system() == 'freebsd' or host_machine.system() == 'dragonflybsd'
235  supports_pccons = true
236  supports_pcvt = true
237  supports_syscons = true
238  csrg_based = true
239endif
240
241if host_machine.system() == 'kfreebsd'
242  supports_pccons = true
243  supports_pcvt = true
244  supports_syscons = true
245endif
246
247if host_machine.system() == 'netbsd'
248  supports_pccons = true
249  supports_pcvt = true
250  supports_wscons = true
251  csrg_based = true
252endif
253
254if host_machine.system() == 'openbsd'
255  supports_pcvt = true
256  supports_wscons = true
257  csrg_based = true
258endif
259
260conf_data.set('SVR4', cc.compiles(defines_svr4))
261conf_data.set_quoted('XKB_DFLT_RULES', get_option('xkb_default_rules'))
262conf_data.set('XORGSERVER', build_xorg)
263conf_data.set_quoted('XCONFIGFILE', 'xorg.conf')
264conf_data.set_quoted('__XSERVERNAME__', 'Xorg')
265conf_data.set('WITH_VGAHW', build_vgahw)
266conf_data.set('CSRG_BASED', csrg_based)
267conf_data.set('PCCONS_SUPPORT', supports_pccons)
268conf_data.set('PCVT_SUPPORT', supports_pcvt)
269conf_data.set('SYSCONS_SUPPORT', supports_syscons)
270conf_data.set('WSCONS_SUPPORT', supports_wscons)
271conf_data.set('XSERVER_LIBPCIACCESS', get_option('pciaccess'))
272conf_data.set('XSERVER_PLATFORM_BUS', build_udev)
273
274configure_file(output : 'dix-config.h',
275               configuration : conf_data)
276
277configure_file(output : 'xorg-server.h',
278               input : 'xorg-server.h.meson.in',
279               configuration : conf_data,
280               install_dir: xorgsdkdir)
281
282version_data = configuration_data()
283version_data.set('VENDOR_RELEASE', '@0@'.format(release))
284version_data.set_quoted('VENDOR_NAME', get_option('vendor_name'))
285version_data.set_quoted('VENDOR_NAME_SHORT', get_option('vendor_name_short'))
286version_data.set_quoted('VENDOR_WEB', get_option('vendor_web'))
287version_data.set_quoted('VENDOR_MAN_VERSION', 'Version @0@.@1@.@2@'.format(major, minor, patch))
288configure_file(output : 'version-config.h',
289               configuration : version_data)
290
291xkb_data = configuration_data()
292
293xkb_data.set_quoted('XKB_BIN_DIRECTORY', xkb_bin_dir)
294xkb_data.set_quoted('XKB_BASE_DIRECTORY', xkb_dir)
295xkb_data.set_quoted('XKB_DFLT_RULES', get_option('xkb_default_rules'))
296xkb_data.set_quoted('XKB_DFLT_MODEL', get_option('xkb_default_model'))
297xkb_data.set_quoted('XKB_DFLT_LAYOUT', get_option('xkb_default_layout'))
298xkb_data.set_quoted('XKB_DFLT_VARIANT', get_option('xkb_default_variant'))
299xkb_data.set_quoted('XKB_DFLT_OPTIONS', get_option('xkb_default_options'))
300xkb_data.set_quoted('XKM_OUTPUT_DIR', xkb_output_dir)
301
302configure_file(output : 'xkb-config.h',
303               configuration : xkb_data)
304
305xorg_data = configuration_data()
306
307xorg_data.set_quoted('XORG_BIN_DIRECTORY', get_option('bindir'))
308xorg_data.set('XORG_VERSION_CURRENT', release)
309xorg_data.set_quoted('XF86CONFIGFILE', 'xorg.conf')
310xorg_data.set_quoted('XCONFIGFILE', 'xorg.conf')
311xorg_data.set_quoted('XCONFIGDIR', 'xorg.conf.d')
312xorg_data.set_quoted('DEFAULT_XDG_DATA_HOME', '.local/share')
313xorg_data.set_quoted('DEFAULT_XDG_DATA_HOME_LOGDIR', 'xorg')
314xorg_data.set_quoted('DEFAULT_LOGDIR', log_dir)
315xorg_data.set_quoted('DEFAULT_LOGPREFIX', 'Xorg.')
316xorg_data.set_quoted('FALLBACK_INPUT_DRIVER', 'libinput')
317xorg_data.set_quoted('DEFAULT_MODULE_PATH', join_paths(get_option('prefix'), module_dir))
318xorg_data.set_quoted('DEFAULT_LIBRARY_PATH', join_paths(get_option('prefix'), get_option('libdir')))
319xorg_data.set_quoted('__XSERVERNAME__', 'Xorg')
320xorg_data.set('XSERVER_LIBPCIACCESS', get_option('pciaccess'))
321xorg_data.set_quoted('PCI_TXT_IDS_PATH', '')
322xorg_data.set('XSERVER_PLATFORM_BUS', build_udev)
323xorg_data.set('WSCONS_SUPPORT', host_machine.system() == 'netbsd' or host_machine.system() == 'openbsd')
324xorg_data.set('XF86PM', build_apm or build_acpi)
325
326if host_machine.system() == 'freebsd' or host_machine.system() == 'dragonflybsd'
327    if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64'
328        xorg_data.set('USE_DEV_IO', true)
329    endif
330    # XXX: Add link to libio on alpha
331elif host_machine.system() == 'netbsd'
332    # XXX: USE_ALPHA_PIO
333    # XXX: Add link to libi386
334    if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64'
335        xorg_data.set('USE_I386_IOPL', true)
336    endif
337elif host_machine.system() == 'openbsd'
338    # XXX: Add link to libi386, libamd64
339    if host_machine.cpu_family() == 'x86'
340        xorg_data.set('USE_I386_IOPL', true)
341    endif
342    if host_machine.cpu_family() == 'x86_64'
343        xorg_data.set('USE_AMD64_IOPL', true)
344    endif
345endif
346
347configure_file(output : 'xorg-config.h',
348               input : 'xorg-config.h.meson.in',
349               configuration : xorg_data)
350
351xwin_data = configuration_data()
352xwin_data.set_quoted('DEFAULT_LOGDIR', log_dir)
353xwin_data.set('HAS_WINSOCK', host_machine.system() == 'windows', description: 'Use Windows sockets')
354xwin_data.set('HAS_DEVWINDOWS', host_machine.system() == 'cygwin', description: 'Has /dev/windows for signaling new win32 messages')
355xwin_data.set('RELOCATE_PROJECTROOT', host_machine.system() == 'windows', description: 'Make paths relative to the xserver installation location')
356# XXX: these three are all the same as DEBUG so we should just change to that
357xwin_data.set10('CYGDEBUG', enable_debugging)
358xwin_data.set10('CYGWINDOWING_DEBUG',enable_debugging)
359xwin_data.set10('CYGMULTIWINDOW_DEBUG', enable_debugging)
360
361configure_file(output : 'xwin-config.h',
362               input : 'xwin-config.h.meson.in',
363               configuration : xwin_data)
364
365xwayland_data = configuration_data()
366xwayland_data.set('XWL_HAS_GLAMOR', build_glamor and (gbm_dep.found() or build_eglstream))
367xwayland_data.set('XWL_HAS_EGLSTREAM', build_eglstream)
368
369configure_file(output : 'xwayland-config.h',
370               input : 'xwayland-config.h.meson.in',
371               configuration : xwayland_data)
372
373if build_xorg
374    install_data(
375        [
376            'XIstubs.h',
377            'Xprintf.h',
378            'callback.h',
379            'client.h',
380            'closestr.h',
381            'closure.h',
382            'colormap.h',
383            'colormapst.h',
384            'hotplug.h',
385            'cursor.h',
386            'cursorstr.h',
387            'dix.h',
388            'dixaccess.h',
389            'dixevents.h',
390            'dixfont.h',
391            'dixfontstr.h',
392            'dixgrabs.h',
393            'dixstruct.h',
394            'events.h',
395            'exevents.h',
396            'extension.h',
397            'extinit.h',
398            'extnsionst.h',
399            'gc.h',
400            'gcstruct.h',
401            'globals.h',
402            'glx_extinit.h',
403            'glxvndabi.h',
404            'input.h',
405            'inputstr.h',
406            'list.h',
407            'misc.h',
408            'miscstruct.h',
409            'opaque.h',
410            'nonsdk_extinit.h',
411            'optionstr.h',
412            'os.h',
413            'pixmap.h',
414            'pixmapstr.h',
415            'privates.h',
416            'property.h',
417            'propertyst.h',
418            'ptrveloc.h',
419            'region.h',
420            'regionstr.h',
421            'registry.h',
422            'resource.h',
423            'rgb.h',
424            'screenint.h',
425            'scrnintstr.h',
426            'selection.h',
427            'servermd.h',
428            'site.h',
429            'validate.h',
430            'displaymode.h',
431            'window.h',
432            'windowstr.h',
433            'xkbfile.h',
434            'xkbsrv.h',
435            'xkbstr.h',
436            'xkbrules.h',
437            'Xprintf.h',
438            'xserver_poll.h',
439            'xserver-properties.h',
440        ],
441        install_dir: xorgsdkdir,
442    )
443endif
444