diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..cafe45cb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +.gitignore export-ignore +.gitattributes export-ignore +nsis/ export-ignore diff --git a/.cvsignore b/.gitignore similarity index 70% rename from .cvsignore rename to .gitignore index f23618fd..6b6b03d7 100644 --- a/.cvsignore +++ b/.gitignore @@ -17,3 +17,11 @@ libtool ltmain.sh Makefile stamp-h1 +.deps +build-aux/compile +build-aux/test-driver +*~ +datrie-*.pc +doc/Doxyfile +*.o + diff --git a/INSTALL b/INSTALL index c8938b3d..decb8a74 100644 --- a/INSTALL +++ b/INSTALL @@ -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 @@ -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 diff --git a/Makefile.am b/Makefile.am index 11974458..3e945564 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/build-aux/test.map b/build-aux/test.map new file mode 100644 index 00000000..9b1f1bee --- /dev/null +++ b/build-aux/test.map @@ -0,0 +1 @@ +{global:hello; local:*;}; diff --git a/configure.ac b/configure.ac index 0b3b897f..0b191201 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/datrie/Makefile.am b/datrie/Makefile.am index e46af461..504906a1 100644 --- a/datrie/Makefile.am +++ b/datrie/Makefile.am @@ -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) diff --git a/datrie/meson.build b/datrie/meson.build new file mode 100644 index 00000000..fa111b1d --- /dev/null +++ b/datrie/meson.build @@ -0,0 +1,86 @@ +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, +) +meson.override_dependency('datrie-0.2', libdatrie_dep) +meson.override_dependency('libdatrie', libdatrie_dep) + +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, +) diff --git a/doc/Makefile.am b/doc/Makefile.am index d9e041b3..f11a8c58 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,3 +1,5 @@ +EXTRA_DIST = meson.build + if ENABLE_DOXYGEN_DOC all-local: doxygen.stamp diff --git a/doc/meson.build b/doc/meson.build new file mode 100644 index 00000000..25c20f45 --- /dev/null +++ b/doc/meson.build @@ -0,0 +1,34 @@ +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.project_build_root()) +doxyfile_data.set('top_srcdir', meson.project_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'), +) diff --git a/man/Makefile.am b/man/Makefile.am index 58a53cba..e46272b0 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -1,4 +1,4 @@ -EXTRA_DIST = trietool.1 +EXTRA_DIST = trietool.1 meson.build man_MANS = trietool.1 diff --git a/man/meson.build b/man/meson.build new file mode 100644 index 00000000..3844714f --- /dev/null +++ b/man/meson.build @@ -0,0 +1,7 @@ +install_man('trietool.1') + +install_symlink( + 'trietool-0.2.1', + pointing_to: 'trietool.1', + install_dir: get_option('mandir') / 'man1', +) diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..9c8dc925 --- /dev/null +++ b/meson.build @@ -0,0 +1,78 @@ +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 +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.project_source_root() / 'build-aux' / 'test.map', + ), +) + +# 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') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..0dec9af5 --- /dev/null +++ b/meson_options.txt @@ -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') diff --git a/tests/Makefile.am b/tests/Makefile.am index 41b55cb8..5ad402eb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,7 @@ AM_CPPFLAGS = -I$(top_srcdir) +EXTRA_DIST = meson.build + TESTS_ENVIRONMENT = top_builddir=$(top_builddir) TESTS = \ diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 00000000..56990f1c --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,22 @@ +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 diff --git a/tools/Makefile.am b/tools/Makefile.am index 992530bc..69778d8b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,5 +1,7 @@ AM_CPPFLAGS = -I$(top_srcdir) +EXTRA_DIST = meson.build + bin_PROGRAMS = trietool trietool_SOURCES = trietool.c diff --git a/tools/meson.build b/tools/meson.build new file mode 100644 index 00000000..7037de8a --- /dev/null +++ b/tools/meson.build @@ -0,0 +1,19 @@ +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.override_find_program('trietool', trietool) + +install_symlink( + 'trietool-0.2', + pointing_to: 'trietool', + install_dir: get_option('bindir'), +)