Add meson build system.

This commit is contained in:
Érico Rolim 2020-11-10 22:45:02 -03:00 committed by Érico Nogueira Rolim
parent 158596366a
commit fa1c550090
6 changed files with 100 additions and 5 deletions

View File

@ -18,3 +18,12 @@ jobs:
- uses: actions/checkout@v1
- run: xbps-install -Sy clang make bearssl-devel
- run: CC=clang ci/run.sh
clang-musl-meson:
runs-on: ubuntu-latest
container: voidlinux/voidlinux-musl
steps:
- uses: actions/checkout@v1
- run: |
xbps-install -Syu || xbps-install -yu xbps
xbps-install -y clang meson ninja bearssl-devel
- run: CC=clang ci/run-meson.sh

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
purr
tests
gemi
build/
*.o
*.a
*.d

View File

@ -21,7 +21,15 @@ You can build and install the project with the commands below:
```
$ ./configure # creates config.mk
$ make
$ make install PREFIX=$HOME/.local/bin
$ make install PREFIX=$HOME/.local
```
Alternatively, you can use the Meson build system:
```
$ meson build --prefix $HOME/.local
$ ninja -C build
$ ninja -C install
```
## Programs

4
ci/run-meson.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh -x
meson build/
ninja -C build/ all
RATELIMIT=1 ninja -C build/ test

72
meson.build Normal file
View File

@ -0,0 +1,72 @@
project('purr-c', 'c',
version : '0.1',
default_options : ['warning_level=3'])
compiler = meson.get_compiler('c')
bearssl = compiler.find_library('bearssl', required: true)
gnu_source = '#define _GNU_SOURCE'
getrandom = compiler.has_header_symbol('sys/random.h', 'getrandom')
arc4random = compiler.has_header_symbol('stdlib.h', 'arc4random')
gnu_progname = compiler.has_header_symbol(
'errno.h',
'program_invocation_short_name',
prefix: gnu_source
)
bsd_progname = compiler.has_header_symbol('stdlib.h', 'getprogname')
sock_cloexec = compiler.has_header_symbol('sys/socket.h', 'SOCK_CLOEXEC')
pipe2 = compiler.has_header_symbol('unistd.h', 'pipe2', prefix: gnu_source)
args = []
if arc4random
args += '-DHAVE_ARC4RANDOM'
elif getrandom
args += '-DHAVE_GETRANDOM'
else
error('no random buf impl')
endif
if bsd_progname
args += '-DHAVE_GETPROGNAME'
elif gnu_progname
args += '-DHAVE_PROG_INVOCATION'
elif
error('no progname impl')
endif
if sock_cloexec
args += '-DHAVE_SOCK_CLOEXEC_H'
endif
if pipe2
args += '-DHAVE_PIPE2'
endif
add_project_arguments(args, language: 'c')
purrlib = static_library(
'purrlib',
'mmap_file.c',
'gemini.c',
'read_certs.c',
'urls.c',
'files.c',
'pager.c',
'comm.c',
'formats.c',
'encrypt.c',
'socket.c',
)
executable('purr', 'purr.c', link_with: purrlib, dependencies: bearssl, install: true)
executable('gemi', 'gemi.c', link_with: purrlib, dependencies: bearssl, install: true)
command = 'ln -sf purr ${DESTDIR}/${MESON_INSTALL_PREFIX}/@0@/@1@'
meson.add_install_script('sh', '-c', command.format(get_option('bindir'), 'meow'))
meson.add_install_script('sh', '-c', command.format(get_option('bindir'), 'meowd'))
tests = executable('tests', 'tests.c', link_with: purrlib, dependencies: bearssl, install: false)
test('library-tests', tests)
test(
'executable-tests',
find_program('test.sh'),
args: meson.current_source_dir() / 'README.md',
workdir: meson.current_build_dir()
)

View File

@ -1,4 +1,5 @@
#!/bin/sh
readme="${1:-README.md}"
EXIT=
assert () {
if [ "$1" != "$2" ]; then
@ -21,15 +22,15 @@ r="$(./purr r https://www.wikipedia.org | xbps-digest)"
assert "$e" "$r"
echo "Pastebin and retrieve - unencrypted"
e="$(xbps-digest README.md)"
r="$(./purr r $(./purr s README.md) | xbps-digest)"
e="$(xbps-digest "$readme")"
r="$(./purr r $(./purr s "$readme") | xbps-digest)"
assert "$e" "$r"
rate_limit
echo "Pastebin and retrieve - encrypted"
e="$(xbps-digest README.md)"
r="$(./purr -e r $(./purr -e s README.md) | xbps-digest)"
e="$(xbps-digest "$readme")"
r="$(./purr -e r $(./purr -e s "$readme") | xbps-digest)"
assert "$e" "$r"
# TODO: find some reliable way of testing gemi