26e2527492
Add a new Meson array option, utils, to allow building only selected applets while keeping the default as all. Gate source inclusion, dependencies, symlink/manpage/script install steps, and test registration by enabled util set, and make applet dispatch in src/main.c compile-time conditional via generated config defines. Document selective build usage in README.
420 lines
8.4 KiB
Meson
420 lines
8.4 KiB
Meson
project('vx', 'c',
|
|
version : '0.2.0',
|
|
default_options : [
|
|
'c_std=c11',
|
|
'warning_level=2',
|
|
],
|
|
)
|
|
|
|
all_utils = [
|
|
'patch',
|
|
'diff',
|
|
'cmp',
|
|
'diff3',
|
|
'sdiff',
|
|
'which',
|
|
'gzip',
|
|
'grep',
|
|
'find',
|
|
'xargs',
|
|
'lspci',
|
|
'setpci',
|
|
]
|
|
|
|
requested_utils = get_option('utils')
|
|
if requested_utils.length() == 0
|
|
error('utils option cannot be empty; specify one or more utilities or use "all"')
|
|
endif
|
|
|
|
enabled_utils = []
|
|
if requested_utils.contains('all')
|
|
enabled_utils = all_utils
|
|
else
|
|
enabled_utils = requested_utils
|
|
endif
|
|
|
|
enable_patch = enabled_utils.contains('patch')
|
|
enable_diff = enabled_utils.contains('diff')
|
|
enable_cmp = enabled_utils.contains('cmp')
|
|
enable_diff3 = enabled_utils.contains('diff3')
|
|
enable_sdiff = enabled_utils.contains('sdiff')
|
|
enable_which = enabled_utils.contains('which')
|
|
enable_gzip = enabled_utils.contains('gzip')
|
|
enable_grep = enabled_utils.contains('grep')
|
|
enable_find = enabled_utils.contains('find')
|
|
enable_xargs = enabled_utils.contains('xargs')
|
|
enable_lspci = enabled_utils.contains('lspci')
|
|
enable_setpci = enabled_utils.contains('setpci')
|
|
|
|
vx_cfg = configuration_data()
|
|
vx_cfg.set10('VX_ENABLE_PATCH', enable_patch)
|
|
vx_cfg.set10('VX_ENABLE_DIFF', enable_diff)
|
|
vx_cfg.set10('VX_ENABLE_CMP', enable_cmp)
|
|
vx_cfg.set10('VX_ENABLE_DIFF3', enable_diff3)
|
|
vx_cfg.set10('VX_ENABLE_SDIFF', enable_sdiff)
|
|
vx_cfg.set10('VX_ENABLE_WHICH', enable_which)
|
|
vx_cfg.set10('VX_ENABLE_GZIP', enable_gzip)
|
|
vx_cfg.set10('VX_ENABLE_GREP', enable_grep)
|
|
vx_cfg.set10('VX_ENABLE_FIND', enable_find)
|
|
vx_cfg.set10('VX_ENABLE_XARGS', enable_xargs)
|
|
vx_cfg.set10('VX_ENABLE_LSPCI', enable_lspci)
|
|
vx_cfg.set10('VX_ENABLE_SETPCI', enable_setpci)
|
|
configure_file(output : 'vx-config.h', configuration : vx_cfg)
|
|
|
|
# --- Portability shim for building BSD userland on Linux ---
|
|
compat_inc = include_directories('src/compat-headers')
|
|
|
|
compat_src = files(
|
|
'src/compat-headers/fgetln.c',
|
|
'src/compat-headers/strlcpy.c',
|
|
'src/compat-headers/reallocf.c',
|
|
'src/compat-headers/strtonum.c',
|
|
'src/compat-headers/expand_number.c',
|
|
'src/compat-headers/strmode.c',
|
|
'src/compat-headers/ugid.c',
|
|
'src/compat-headers/setmode.c',
|
|
)
|
|
|
|
# Force-include compat.h before every translation unit so that
|
|
# _GNU_SOURCE and type shims are always available.
|
|
compat_args = ['-include', 'compat.h']
|
|
|
|
patch_src = files(
|
|
'src/patch/patch.c',
|
|
'src/patch/pch.c',
|
|
'src/patch/inp.c',
|
|
'src/patch/util.c',
|
|
'src/patch/backupfile.c',
|
|
'src/patch/mkpath.c',
|
|
)
|
|
|
|
diff_src = files(
|
|
'src/diff/diff.c',
|
|
'src/diff/diffdir.c',
|
|
'src/diff/diffreg.c',
|
|
'src/diff/pr.c',
|
|
'src/diff/xmalloc.c',
|
|
)
|
|
|
|
cmp_src = files(
|
|
'src/cmp/cmp.c',
|
|
'src/cmp/link.c',
|
|
'src/cmp/misc.c',
|
|
'src/cmp/regular.c',
|
|
'src/cmp/special.c',
|
|
)
|
|
|
|
diff3_src = files(
|
|
'src/diff3/diff3.c',
|
|
)
|
|
|
|
sdiff_src = files(
|
|
'src/sdiff/sdiff.c',
|
|
'src/sdiff/edit.c',
|
|
)
|
|
|
|
which_src = files(
|
|
'src/which/which.c',
|
|
)
|
|
|
|
gzip_src = files(
|
|
'src/gzip/gzip.c',
|
|
)
|
|
|
|
gzip_inc = include_directories('src/gzip')
|
|
|
|
grep_src = files(
|
|
'src/grep/grep.c',
|
|
'src/grep/file.c',
|
|
'src/grep/queue.c',
|
|
'src/grep/util.c',
|
|
)
|
|
|
|
grep_inc = include_directories('src/grep')
|
|
|
|
find_src = files(
|
|
'src/find/find.c',
|
|
'src/find/function.c',
|
|
'src/find/ls.c',
|
|
'src/find/main.c',
|
|
'src/find/misc.c',
|
|
'src/find/operator.c',
|
|
'src/find/option.c',
|
|
)
|
|
|
|
find_inc = include_directories('src/find')
|
|
|
|
xargs_src = files(
|
|
'src/xargs/xargs.c',
|
|
'src/xargs/strnsubst.c',
|
|
)
|
|
|
|
xargs_inc = include_directories('src/xargs')
|
|
|
|
pci_common_src = files(
|
|
'src/pci/pci.c',
|
|
)
|
|
|
|
lspci_src = files(
|
|
'src/pci/lspci.c',
|
|
)
|
|
|
|
setpci_src = files(
|
|
'src/pci/setpci.c',
|
|
)
|
|
|
|
pci_inc = include_directories('src/pci')
|
|
|
|
gzip_defines = [
|
|
'-DNO_BZIP2_SUPPORT',
|
|
'-DNO_ZSTD_SUPPORT',
|
|
]
|
|
|
|
vx_sources = files('src/main.c')
|
|
vx_sources += compat_src
|
|
vx_include_dirs = [compat_inc]
|
|
vx_c_args = compat_args
|
|
|
|
cc = meson.get_compiler('c')
|
|
libm = cc.find_library('m', required : false)
|
|
vx_dependencies = [libm]
|
|
|
|
if enable_patch
|
|
vx_sources += patch_src
|
|
endif
|
|
|
|
if enable_diff
|
|
vx_sources += diff_src
|
|
endif
|
|
|
|
if enable_cmp
|
|
vx_sources += cmp_src
|
|
endif
|
|
|
|
if enable_diff3
|
|
vx_sources += diff3_src
|
|
endif
|
|
|
|
if enable_sdiff
|
|
vx_sources += sdiff_src
|
|
endif
|
|
|
|
if enable_which
|
|
vx_sources += which_src
|
|
endif
|
|
|
|
if enable_gzip
|
|
vx_sources += gzip_src
|
|
vx_include_dirs += [gzip_inc]
|
|
vx_c_args += gzip_defines
|
|
vx_dependencies += [dependency('zlib'), dependency('liblzma')]
|
|
endif
|
|
|
|
if enable_grep
|
|
vx_sources += grep_src
|
|
vx_include_dirs += [grep_inc]
|
|
endif
|
|
|
|
if enable_find
|
|
# --- yacc generator for find's getdate.y ---
|
|
yacc = find_program('yacc', 'bison')
|
|
getdate_gen = custom_target('getdate',
|
|
input : 'src/find/getdate.y',
|
|
output : 'getdate.c',
|
|
command : [yacc, '-o', '@OUTPUT@', '@INPUT@'],
|
|
)
|
|
|
|
vx_sources += find_src
|
|
vx_sources += [getdate_gen]
|
|
vx_include_dirs += [find_inc]
|
|
vx_dependencies += [cc.find_library('acl', required : true)]
|
|
endif
|
|
|
|
if enable_xargs
|
|
vx_sources += xargs_src
|
|
vx_include_dirs += [xargs_inc]
|
|
endif
|
|
|
|
if enable_lspci or enable_setpci
|
|
vx_sources += pci_common_src
|
|
vx_include_dirs += [pci_inc]
|
|
endif
|
|
|
|
if enable_lspci
|
|
vx_sources += lspci_src
|
|
endif
|
|
|
|
if enable_setpci
|
|
vx_sources += setpci_src
|
|
endif
|
|
|
|
vx = executable('vx',
|
|
vx_sources,
|
|
include_directories : vx_include_dirs,
|
|
c_args : vx_c_args,
|
|
dependencies : vx_dependencies,
|
|
install : true,
|
|
)
|
|
|
|
# Create symlinks for selected applets pointing to the vx binary.
|
|
bindir = get_option('bindir')
|
|
install_applets = []
|
|
if enable_patch
|
|
install_applets += ['patch']
|
|
endif
|
|
if enable_diff
|
|
install_applets += ['diff']
|
|
endif
|
|
if enable_cmp
|
|
install_applets += ['cmp']
|
|
endif
|
|
if enable_diff3
|
|
install_applets += ['diff3']
|
|
endif
|
|
if enable_sdiff
|
|
install_applets += ['sdiff']
|
|
endif
|
|
if enable_which
|
|
install_applets += ['which']
|
|
endif
|
|
if enable_gzip
|
|
install_applets += ['gzip', 'gunzip', 'zcat', 'uncompress']
|
|
endif
|
|
if enable_grep
|
|
install_applets += ['grep', 'egrep', 'fgrep', 'rgrep']
|
|
endif
|
|
if enable_find
|
|
install_applets += ['find']
|
|
endif
|
|
if enable_xargs
|
|
install_applets += ['xargs']
|
|
endif
|
|
if enable_lspci
|
|
install_applets += ['lspci']
|
|
endif
|
|
if enable_setpci
|
|
install_applets += ['setpci']
|
|
endif
|
|
|
|
foreach name : install_applets
|
|
meson.add_install_script('sh', '-c',
|
|
'ln -sf vx "$MESON_INSTALL_DESTDIR_PREFIX/' + bindir + '/' + name + '"',
|
|
)
|
|
endforeach
|
|
|
|
# --- Manpages ---
|
|
manpages = []
|
|
if enable_patch
|
|
manpages += ['src/patch/patch.1']
|
|
endif
|
|
if enable_diff
|
|
manpages += ['src/diff/diff.1']
|
|
endif
|
|
if enable_cmp
|
|
manpages += ['src/cmp/cmp.1']
|
|
endif
|
|
if enable_diff3
|
|
manpages += ['src/diff3/diff3.1']
|
|
endif
|
|
if enable_sdiff
|
|
manpages += ['src/sdiff/sdiff.1']
|
|
endif
|
|
if enable_which
|
|
manpages += ['src/which/which.1']
|
|
endif
|
|
if enable_gzip
|
|
manpages += [
|
|
'src/gzip/gzip.1',
|
|
'src/gzip/gzexe.1',
|
|
'src/gzip/zdiff.1',
|
|
'src/gzip/zforce.1',
|
|
'src/gzip/zmore.1',
|
|
'src/gzip/znew.1',
|
|
'src/gzip/zgrep.1',
|
|
]
|
|
endif
|
|
if enable_grep
|
|
manpages += ['src/grep/grep.1']
|
|
endif
|
|
if enable_find
|
|
manpages += ['src/find/find.1']
|
|
endif
|
|
if enable_xargs
|
|
manpages += ['src/xargs/xargs.1']
|
|
endif
|
|
if enable_lspci
|
|
manpages += ['src/pci/lspci.8']
|
|
endif
|
|
if enable_setpci
|
|
manpages += ['src/pci/setpci.8']
|
|
endif
|
|
|
|
install_man(manpages)
|
|
|
|
if enable_gzip
|
|
# --- Gzip shell script utilities ---
|
|
foreach s : ['zdiff', 'zforce', 'zmore', 'znew', 'gzexe', 'zgrep', 'zless']
|
|
install_data('src/gzip/' + s,
|
|
install_dir : get_option('bindir'),
|
|
install_mode : 'rwxr-xr-x',
|
|
)
|
|
endforeach
|
|
|
|
# Install symlinks for script aliases
|
|
foreach pair : [['zcmp', 'zdiff'], ['zegrep', 'zgrep'], ['zfgrep', 'zgrep']]
|
|
meson.add_install_script('sh', '-c',
|
|
'ln -sf ' + pair[1] + ' "$MESON_INSTALL_DESTDIR_PREFIX/' + bindir + '/' + pair[0] + '"',
|
|
)
|
|
endforeach
|
|
endif
|
|
|
|
# --- Tests ---
|
|
test_env = environment()
|
|
test_env.set('VX', vx.full_path())
|
|
|
|
test_targets = []
|
|
if enable_patch
|
|
test_targets += ['test_patch']
|
|
endif
|
|
if enable_diff
|
|
test_targets += ['test_diff']
|
|
endif
|
|
if enable_cmp
|
|
test_targets += ['test_cmp']
|
|
endif
|
|
if enable_diff3
|
|
test_targets += ['test_diff3']
|
|
endif
|
|
if enable_sdiff
|
|
test_targets += ['test_sdiff']
|
|
endif
|
|
if enable_which
|
|
test_targets += ['test_which']
|
|
endif
|
|
if enable_gzip
|
|
test_targets += ['test_gzip']
|
|
endif
|
|
if enable_grep
|
|
test_targets += ['test_grep']
|
|
endif
|
|
if enable_find
|
|
test_targets += ['test_find']
|
|
endif
|
|
if enable_xargs
|
|
test_targets += ['test_xargs']
|
|
endif
|
|
if enable_lspci
|
|
test_targets += ['test_lspci']
|
|
endif
|
|
if enable_setpci
|
|
test_targets += ['test_setpci']
|
|
endif
|
|
|
|
foreach t : test_targets
|
|
test(t, find_program('tests/' + t + '.sh'),
|
|
env : test_env,
|
|
depends : vx,
|
|
workdir : meson.project_source_root(),
|
|
)
|
|
endforeach
|