add meson build system

This commit is contained in:
Dylan Baker 2019-06-05 13:32:35 -07:00
parent 9780d98afb
commit 736902410a
5 changed files with 197 additions and 1 deletions

View File

@ -120,6 +120,8 @@ EXTRA_DIST = \
manual.pdf \
manual.ps \
manual.xml \
meson.build \
meson_options.txt \
mk251.c \
sample1.bz2 \
sample1.ref \

129
meson.build Normal file
View File

@ -0,0 +1,129 @@
project(
'bzip2',
['c'],
version : '1.0.7',
meson_version : '>= 0.48.0',
default_options : ['c_std=c89', 'warning_level=1'],
)
cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments([
'-Winline',
]),
language : 'c',
)
add_project_arguments('-D_GNU_SOURCE', language : 'c')
if host_machine.system() == 'windows'
add_project_arguments('-D_WIN32', language : 'c')
endif
c_args = []
if cc.has_function_attribute('visibility')
c_args += '-DBZ_EXTERN=__attribute__((__visibility__("default")))'
endif
libbzip2 = library(
'bzip2',
['blocksort.c', 'huffman.c', 'crctable.c', 'randtable.c', 'compress.c', 'decompress.c', 'bzlib.c'],
c_args : c_args,
gnu_symbol_visibility : 'hidden',
version : meson.project_version(),
install : true,
)
bzip2 = executable(
'bzip2',
['bzip2.c'],
link_with : [libbzip2],
install : true,
)
executable(
'bzip2recover',
['bzip2recover.c'],
link_with : [libbzip2],
install : true,
)
## Install wrapper scripts
install_data(
'bzgrep', 'bzmore', 'bzdiff',
install_dir : get_option('bindir'),
install_mode : 'rwxr-xr-x',
)
## Generate pkg-config automaically from built library information
pkg = import('pkgconfig')
pkg.generate(
libbzip2,
description : 'Lossless, block-sorting data compression',
)
## install headers
install_headers('bzlib.h')
## Install man files
install_man('bzip2.1', 'bzgrep.1', 'bzdiff.1', 'bzmore.1')
# Install copies of some of the man files
man1dir = join_paths(get_option('prefix'), get_option('mandir'), 'man1')
foreach m : [['bzip2.1', ['bunzip2.1', 'bzcat']],
['bzgrep.1', ['bzegrep.1', 'bzfgrep.1']],
['bzmore.1', ['bzless.1']],
['bzdiff.1', ['bzcmp.1']]]
_input = m[0]
foreach o : m[1]
configure_file(
input : _input,
output : o,
copy : true,
install : true,
install_dir : man1dir,
)
endforeach
endforeach
# Generate manual files with xmlproc
build_docs = get_option('docs')
docs = find_program('xsltproc', required : build_docs).found()
docs = docs and find_program('perl', required : build_docs).found()
docs = docs and find_program('xmllint', required : build_docs).found()
docs = docs and find_program('egrep', required : build_docs).found()
docs = docs and find_program('pdfxmltex', required : build_docs).found()
docs = docs and find_program('pdftops', required : build_docs).found()
prog_sh = find_program('sh', required : build_docs)
if docs and prog_sh.found()
foreach t : ['pdf', 'ps', 'html']
custom_target(
'manual.' + t,
command : [prog_sh, 'xmlproc.sh', '-' + t, '@OUTPUT@'],
output : 'manual.' + t,
)
endforeach
endif
# Unit tests
prog_python = import('python').find_installation('python3')
# Tuple in the form (args, input, expected)
foreach t : [['-1', 'sample1.ref', 'sample1.bz2'],
['-2', 'sample2.ref', 'sample2.bz2'],
['-3', 'sample3.ref', 'sample3.bz2']]
test(
t[1],
prog_python,
args : [files('runtest.py'), '--mode', 'compress', bzip2, t[0], files(t[1]), files(t[2])],
)
endforeach
# Tuple in the form (args, input)
foreach t : [['-1', 'sample1.ref'],
['-2', 'sample2.ref'],
['-3', 'sample3.ref']]
test(
t[1],
prog_python,
args : [files('runtest.py'), '--mode', 'decompress', bzip2, t[0], files(t[1])],
)
endforeach

5
meson_options.txt Normal file
View File

@ -0,0 +1,5 @@
option(
'docs',
type : 'feature',
description : 'generate documentation in html, pdf, and ps format',
)

60
runtest.py Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python3
import argparse
import subprocess
import sys
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--mode', choices={'compress', 'decompress'})
parser.add_argument('bzip2')
parser.add_argument('bzip_arg')
parser.add_argument('input')
parser.add_argument('reference', nargs='?')
args = parser.parse_args()
if args.mode == 'compress':
test_compress(args)
else:
test_decompress(args)
def test_compress(args: argparse.Namespace) -> None:
with open(args.reference, 'rb') as f:
expected = f.read()
with open(args.input, 'rb') as f:
input_ = f.read()
p = subprocess.run(
[args.bzip2, args.bzip_arg],
stdout=subprocess.PIPE,
input=input_)
if p.returncode != 0:
sys.exit(1)
def test_decompress(args: argparse.Namespace) -> None:
with open(args.input, 'rb') as f:
input_ = f.read()
p = subprocess.run(
[args.bzip2, args.bzip_arg],
stdout=subprocess.PIPE,
input=input_)
if p.returncode != 0:
sys.exit(2)
compressed = p.stdout
dargs = '-d' if args.bzip_arg != '-3' else '-ds'
p = subprocess.run(
[args.bzip2, dargs],
stdout=subprocess.PIPE,
input=compressed,
)
if p.returncode != 0:
sys.exit(1)
if __name__ == "__main__":
main()