1# SPDX-License-Identifier: MIT 2# 3# Copyright (c) 2025, Oracle and/or its affiliates. 4# 5# Permission is hereby granted, free of charge, to any person obtaining a 6# copy of this software and associated documentation files (the "Software"), 7# to deal in the Software without restriction, including without limitation 8# the rights to use, copy, modify, merge, publish, distribute, sublicense, 9# and/or sell copies of the Software, and to permit persons to whom the 10# Software is furnished to do so, subject to the following conditions: 11# 12# The above copyright notice and this permission notice (including the next 13# paragraph) shall be included in all copies or substantial portions of the 14# Software. 15# 16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22# DEALINGS IN THE SOFTWARE. 23# 24 25project( 26 'sessreg', 27 'c', 28 version: '1.1.4', 29 license: 'MIT AND MIT-open-group', 30 license_files: 'COPYING', 31 meson_version: '>= 1.1.0', 32) 33 34cc = meson.get_compiler('c') 35 36conf = configuration_data() 37conf.set_quoted('PACKAGE_STRING', 38 ' '.join(meson.project_name(), meson.project_version())) 39 40# Replaces AC_USE_SYSTEM_EXTENSIONS 41if host_machine.system() == 'sunos' 42 system_extensions = '__EXTENSIONS__' 43elif host_machine.system() == 'netbsd' 44 system_extensions = '_OPENBSD_SOURCE' 45else 46 system_extensions = '_GNU_SOURCE' 47endif 48conf.set(system_extensions, 1, 49 description: 'Enable non-standardized system API extensions') 50 51# Replacement for XORG_DEFAULT_OPTIONS 52if cc.has_argument('-fno-strict-aliasing') 53 add_project_arguments('-fno-strict-aliasing', language: 'c') 54endif 55 56# Checks for header files. 57conf.set('HAVE_LASTLOG_H', cc.has_header('lastlog.h') ? '1' : false) 58conf.set('HAVE_PWD_H', cc.has_header('pwd.h') ? '1' : false) 59conf.set('HAVE_UTMP_H', cc.has_header('utmp.h') ? '1' : false) 60conf.set('HAVE_UTMPX_H', cc.has_header('utmpx.h') ? '1' : false) 61conf.set('HAVE_SYS_PARAM_H', cc.has_header('sys/param.h') ? '1' : false) 62 63# Checks for typedefs, structures, and compiler characteristics. 64if cc.has_header('utmp.h') 65 foreach m : ['ut_host', 'ut_id', 'ut_pid', 'ut_type'] 66 conf.set( 67 'HAVE_STRUCT_UTMP_' + m.to_upper(), 68 cc.has_member( 69 'struct utmp', 70 m, 71 prefix: ['#include <sys/types.h>', '#include <utmp.h>'] 72 ) ? '1' : false 73 ) 74 endforeach 75endif 76if cc.has_header('utmpx.h') 77 conf.set( 78 'HAVE_STRUCT_UTMPX_UT_SYSLEN', 79 cc.has_member( 80 'struct utmpx', 81 'ut_syslen', 82 prefix: ['#include <sys/types.h>', '#include <utmpx.h>'] 83 ) ? '1' : false 84 ) 85endif 86conf.set( 87 'HAVE_STRUCT_LASTLOG', 88 cc.has_type( 89 'struct lastlog', 90 prefix: [ 91 '#include <sys/types.h>', 92 cc.has_header('utmp.h') ? '#include <utmp.h>' : '', 93 cc.has_header('lastlog.h') ? '#include <lastlog.h>' : '', 94 ] 95 ) ? '1' : false 96) 97 98# Checks for library functions. 99conf.set('HAVE_PUTUTLINE', cc.has_function('pututline') ? '1' : false) 100conf.set('HAVE_UPDWTMPX', cc.has_function('updwtmpx') ? '1' : false) 101conf.set('HAVE_UTMPXNAME', cc.has_function('utmpxname') ? '1' : false) 102 103# Obtain compiler/linker options for dependencies 104dep_xproto = dependency('xproto', required: true, version: '>= 7.0.25') 105 106config_h = configure_file(output: 'config.h', configuration: conf) 107add_project_arguments('-DHAVE_CONFIG_H', language: ['c']) 108 109executable( 110 'sessreg', 111 [config_h, 'sessreg.h', 'sessreg.c'], 112 dependencies: [dep_xproto], 113 install: true 114) 115 116prog_sed = find_program('sed') 117 118filenames_sed_in = cc.preprocess( 119 'man/filenames.sed.c', 120 output: 'filenames.sed.in' 121) 122 123filenames_sed = custom_target( 124 'filenames.sed', 125 input: filenames_sed_in, 126 output: 'filenames.sed', 127 command: [prog_sed, '-n', '-f', files('man/extract.sed'), '@INPUT@'], 128 capture: true, 129 install: false 130) 131 132custom_target( 133 'sessreg.man', 134 input: 'man/sessreg.man', 135 output: 'sessreg.1', 136 depends: filenames_sed, 137 command: [ 138 prog_sed, 139 '-e', 's/__xorgversion__/"sessreg @0@" "X Version 11"/'.format(meson.project_version()), 140 '-e', 's/__appmansuffix__/1/g', 141 '-e', 's/__libmansuffix__/3/g', 142 '-e', 's/__filemansuffix__/5/g', 143 '-f', filenames_sed, 144 '@INPUT@', 145 ], 146 capture: true, 147 install: true, 148 install_dir: get_option('prefix') / get_option('mandir') / 'man1', 149) 150