Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson build #22

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gitignore export-ignore
.gitattributes export-ignore
nsis/ export-ignore
8 changes: 8 additions & 0 deletions .cvsignore → .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ libtool
ltmain.sh
Makefile
stamp-h1
.deps
build-aux/compile
build-aux/test-driver
*~
datrie-*.pc
doc/Doxyfile
*.o

21 changes: 21 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Basic Installation
==================

libdatrie can be build by Autotools or Meson

Autotools build
------------------

# Build requirements:
# - libtool
# - iconv support (normally from glibc on GNU systems; some systems might
Expand All @@ -25,3 +30,19 @@ make install
# In order to uninstall
make uninstall

Meson build
---------------

# Build requirements:
# - meson 1.0 or better
# - iconv support
# - doxygen (optional, for documentation generation)

# Add -Ddocs=disabled to disable documentation generation
meson setup builddir --buildtype release --default-library both --strip --prefix=...

cd builddir
ninja test

# With elevated permissions if required
ninja install
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ SUBDIRS = datrie tools man doc tests
EXTRA_DIST = \
README.migration \
build-aux/git-version-gen \
build-aux/test.map \
meson.build \
meson_options.txt \
$(NULL)

pkgconfigdir = $(libdir)/pkgconfig
Expand Down
1 change: 1 addition & 0 deletions build-aux/test.map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{global:hello; local:*;};
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fi
dnl where to install the doxygen-generated HTML doc
AC_ARG_WITH(html-docdir,
[AS_HELP_STRING([--with-html-docdir=DIR],
[where to install the doxyten-generated HTML doc [PREFIX/share/doc/datrie/html]])],
[where to install the doxygen-generated HTML doc [PREFIX/share/doc/datrie/html]])],
[htmldocdir="$withval"], [htmldocdir=\$\{prefix\}/share/doc/datrie/html])
AC_SUBST(htmldocdir)

Expand Down
2 changes: 1 addition & 1 deletion datrie/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pkginclude_HEADERS = \
alpha-map.h \
trie.h

EXTRA_DIST = libdatrie.map libdatrie.def
EXTRA_DIST = libdatrie.map libdatrie.def meson.build

AM_CPPFLAGS = -I$(top_srcdir)

Expand Down
78 changes: 78 additions & 0 deletions datrie/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
ldflags = []
link_depends = ['libdatrie.map']

if ld_has_version_script
ldflags += [
'-Wl,--version-script,@0@'.format(meson.current_source_dir() / 'libdatrie.map')
]
endif

if compiler.get_linker_id() in ['link', 'lld-link']
link_def = custom_target(
'link-def',
input : ['libdatrie.def'],
# This use ASCII as some PS version do not have UTF8NoBOM
command : [powershell, '-Command', '''& {
Write-Output "EXPORTS" | Out-File -Encoding ascii -FilePath @OUTPUT0@
Get-Content -Path @INPUT0@ | Out-File -Append -Encoding ascii -FilePath @OUTPUT0@
}'''],
output : 'libdatrie.def',
)
ldflags += [ '/def:@0@'.format(link_def.full_path()) ]
link_depends += [link_def]
endif

datrie_src = files(
'alpha-map-private.h',
'alpha-map.c',
'alpha-map.h',
'darray.c',
'darray.h',
'dstring-private.h',
'dstring.c',
'dstring.h',
'fileutils.c',
'fileutils.h',
'tail.c',
'tail.h',
'trie-private.h',
'trie-string.c',
'trie-string.h',
'trie.c',
'trie.h',
'triedefs.h',
'typedefs.h',
)

datrie = library(
'datrie', datrie_src,

dependencies : deps,
install : true,
link_args : ldflags,
link_depends : link_depends,
version : libversion,
soversion : soversion,
include_directories : configuration_inc,
)
libdatrie_dep = declare_dependency(
include_directories : configuration_inc,
link_with : datrie
)

install_headers(
'alpha-map.h',
'trie.h',
'triedefs.h',
'typedefs.h',
subdir : 'datrie',
)

pkg = import('pkgconfig')
pkg.generate(
datrie,
filebase : 'datrie-0.2',
description : 'Double-array trie library',
url : 'https://github.com/tlwg/libdatrie',
version : version,
)
2 changes: 2 additions & 0 deletions doc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
EXTRA_DIST = meson.build

if ENABLE_DOXYGEN_DOC

all-local: doxygen.stamp
Expand Down
30 changes: 30 additions & 0 deletions doc/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if get_option('docs').disabled()
subdir_done()
endif

doxygen = find_program('doxygen', required : get_option('docs'), version : '>=1.9.1')
if not doxygen.found()
subdir_done()
endif

doxyfile_data = configuration_data()
doxyfile_data.set('VERSION', version)
doxyfile_data.set('PACKAGE', meson.project_name())
doxyfile_data.set('top_builddir', meson.build_root())
doxyfile_data.set('top_srcdir', meson.source_root())

doxyfile = configure_file(
input : 'Doxyfile.in',
output : 'Doxyfile',
configuration : doxyfile_data,
)

custom_target(
'docs',
input : doxyfile,
output : 'html',
command : [doxygen, doxyfile],
depend_files : datrie_src,
install : true,
install_dir: get_option('docsdir'),
)
2 changes: 1 addition & 1 deletion man/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EXTRA_DIST = trietool.1
EXTRA_DIST = trietool.1 meson.build

man_MANS = trietool.1

Expand Down
3 changes: 3 additions & 0 deletions man/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
install_man('trietool.1')

meson.add_install_script(sh, '-c', 'cd ${MESON_INSTALL_DESTDIR_PREFIX}/@0@/man1 && ln -s trietool.1 trietool-0.2.1 || true'.format(get_option('mandir')))
whs marked this conversation as resolved.
Show resolved Hide resolved
63 changes: 63 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
project(
'libdatrie', 'c', meson_version : '>=1.0.0',
version: run_command(files('build-aux/git-version-gen'), check : true).stdout().strip()
)

fs = import('fs')

sh = find_program('sh')
compiler = meson.get_compiler('c')
powershell = find_program('powershell', required : compiler.get_id() == 'msvc')
deps = [
dependency('iconv', required: false)
]

version = run_command(files('build-aux/git-version-gen'), check : true).stdout().strip()
meson.add_dist_script(sh, '-c', 'echo "@0@" > "$MESON_DIST_ROOT/VERSION"'.format(version))
meson.add_dist_script(sh, '-c', 'cd "$MESON_DIST_ROOT" && ./autogen.sh')
meson.add_dist_script(sh, '-c', 'cd "$MESON_DIST_ROOT" && rm -r autom4te.cache autogen.sh || true')

LT_CURRENT = 5
LT_REVISION = 0
LT_AGE = 4

soversion = LT_CURRENT - LT_AGE
libversion = '@0@.@1@.@2@'.format(soversion, LT_AGE, LT_REVISION)

conf_data = configuration_data()
conf_data.set_quoted('VERSION', version)

# Detect for locale_charset
have_locale_charset = compiler.has_function('locale_charset', dependencies : deps)
if have_locale_charset
conf_data.set('HAVE_LOCALE_CHARSET', 1)
endif

# Detect for nl_langinfo(CODESET)
have_langinfo_codeset = compiler.compiles('''
#include <langinfo.h>
void func() { char *codeset = nl_langinfo (CODESET); }
''', name : 'nl_langinfo (CODESET)')
if have_langinfo_codeset
conf_data.set('HAVE_LANGINFO_CODESET', 1)
endif

if not have_locale_charset and not have_langinfo_codeset
warning('No locale_charset() nor nl_langinfo(CODESET) found. Please consider installing GNU libiconv')
endif

# Detect for version-script support
ld_has_version_script = compiler.has_link_argument(
'-Wl,-version-script,@0@'.format(meson.global_source_root() / 'build-aux' / 'test.map')
whs marked this conversation as resolved.
Show resolved Hide resolved
)

# Generate config.h
configure_file(output : 'config.h', configuration: conf_data)
configuration_inc = include_directories('.')

# Build!
subdir('datrie')
subdir('tests')
subdir('tools')
subdir('man')
subdir('doc')
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
option('docs', type : 'feature', value : 'auto', description : 'Build docs')
option('docsdir', type : 'string', value : 'share/doc/datrie', description : 'Where to install the doxygen-generated HTML doc')
2 changes: 2 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AM_CPPFLAGS = -I$(top_srcdir)

EXTRA_DIST = meson.build

TESTS_ENVIRONMENT = top_builddir=$(top_builddir)

TESTS = \
Expand Down
15 changes: 15 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests = [
'walk', 'iterator', 'store-retrieve', 'file',
'serialization', 'nonalpha', 'null_trie',
'term_state', 'byte_alpha', 'byte_list',
]

foreach item : tests
exe = executable(
'test_' + item,
'test_@0@.c'.format(item),
'utils.c',
dependencies : libdatrie_dep,
)
test(item, exe)
endforeach
2 changes: 2 additions & 0 deletions tools/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AM_CPPFLAGS = -I$(top_srcdir)

EXTRA_DIST = meson.build

bin_PROGRAMS = trietool

trietool_SOURCES = trietool.c
Expand Down
14 changes: 14 additions & 0 deletions tools/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if not have_locale_charset and not have_langinfo_codeset
subdir_done()
endif

trietool = executable(
'trietool',
'trietool.c',
dependencies : deps,
link_with : datrie,
install : true,
include_directories : configuration_inc,
)

meson.add_install_script(sh, '-c', 'cd ${MESON_INSTALL_DESTDIR_PREFIX}/@0@ && ln -s trietool trietool-0.2 || true'.format(get_option('bindir')))
whs marked this conversation as resolved.
Show resolved Hide resolved