diff --git a/.cvsignore b/.cvsignore deleted file mode 100644 index a2c5f15..0000000 --- a/.cvsignore +++ /dev/null @@ -1,25 +0,0 @@ -*.lo -libtool -ltmain.sh -configure -config.cache -config.guess -config.h -config.h.in -config.log -config.status -config.sub -stamp-h -stamp-h.in -Makefile -Makefile.in -aclocal.m4 -autom4te.cache -m4 -depcomp -missing -INSTALL -install-sh -mkinstalldirs -ChangeLog -libthai.pc diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8370d90 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +.gitignore export-ignore +.gitattributes export-ignore +nsis/ export-ignore +data/references/ export-ignore diff --git a/.gitignore b/.gitignore index 8c46ff5..f2bb6f9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /libtool /ltmain.sh /configure +/configure~ /config.cache /config.guess /config.h diff --git a/INSTALL b/INSTALL index a9af056..9a80ff0 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,11 @@ Basic Installation ================== +libthai can be built by Autotools or Meson + +Autotools build +--------------- + # Build requirements: # - libtool # - libdatrie development package (or https://github.com/tlwg/libdatrie) @@ -24,3 +29,21 @@ make install # In order to uninstall make uninstall +Meson build +----------- + +# Build requirements: +# - meson 1.0 or better +# - doxygen (optional, for documentation generation) +# +# Meson will use local libdatrie if installed, otherwise will automatically +# download and build libdatrie. + +# 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 8eba43a..bb2abd3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,10 @@ SUBDIRS = include src data tests doc EXTRA_DIST = \ build-aux/git-version-gen \ + build-aux/test.map \ + meson.build \ + meson_options.txt \ + subprojects/libdatrie.wrap \ $(NULL) MAINTAINERCLEANFILES = Makefile.in diff --git a/build-aux/.gitignore b/build-aux/.gitignore new file mode 100644 index 0000000..94fb547 --- /dev/null +++ b/build-aux/.gitignore @@ -0,0 +1,8 @@ +compile +config.guess +config.sub +depcomp +install-sh +ltmain.sh +missing +test-driver diff --git a/build-aux/test.map b/build-aux/test.map new file mode 100644 index 0000000..9b1f1be --- /dev/null +++ b/build-aux/test.map @@ -0,0 +1 @@ +{global:hello; local:*;}; diff --git a/data/.cvsignore b/data/.gitignore similarity index 100% rename from data/.cvsignore rename to data/.gitignore diff --git a/data/Makefile.am b/data/Makefile.am index c33bd62..54db90f 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -27,7 +27,7 @@ TDICT_SRC = \ $(srcdir)/tdict-std.txt \ $(srcdir)/tdict-std-compound.txt -EXTRA_DIST = thbrk.abm $(TDICT_SRC) +EXTRA_DIST = thbrk.abm $(TDICT_SRC) meson.build tdict.txt: $(TDICT_SRC) cat $(TDICT_SRC) | LC_ALL=C sort -u > tdict.txt diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..574b9a0 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,51 @@ +dict_dir = get_option('datadir') / 'libthai' + +if not get_option('dict') + subdir_done() +endif + +sort = find_program('sort') +cp = find_program('cp') +trietool = find_program('trietool') + +dictionary = custom_target( + 'tdict', + command: [sort, '-u', '-o', '@OUTPUT@', '@INPUT@'], + env: {'LC_ALL': 'C'}, + input: [ + 'tdict-common.txt', + 'tdict-collection.txt', + 'tdict-currency.txt', + 'tdict-district.txt', + 'tdict-city.txt', + 'tdict-country.txt', + 'tdict-geo.txt', + 'tdict-history.txt', + 'tdict-ict.txt', + 'tdict-lang-ethnic.txt', + 'tdict-proper.txt', + 'tdict-science.txt', + 'tdict-slang.txt', + 'tdict-spell.txt', + 'tdict-std.txt', + 'tdict-std-compound.txt', + ], + output: ['tdict.txt'], +) +# trietool look for thbrk.abm in the directory of thbrk.tri +# so we need to copy thbrk.abm into the build directory +alphamap = custom_target( + 'alphabet_map', + command: [cp, '@INPUT@', '@OUTPUT@'], + input: ['thbrk.abm'], + output: ['thbrk.abm'], +) +tri = custom_target( + 'tri', + command: [trietool, 'data/thbrk', 'add-list', '-e', 'utf-8', '@INPUT0@'], + input: [dictionary], + depends: [alphamap], + output: ['thbrk.tri'], + install: true, + install_dir: dict_dir, +) diff --git a/doc/.cvsignore b/doc/.gitignore similarity index 100% rename from doc/.cvsignore rename to doc/.gitignore diff --git a/doc/Makefile.am b/doc/Makefile.am index f191042..0ff44b2 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 0000000..2db43eb --- /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: thai_src + headers_src, + install: true, + install_dir: get_option('docsdir'), +) diff --git a/include/.cvsignore b/include/.gitignore similarity index 100% rename from include/.cvsignore rename to include/.gitignore diff --git a/include/Makefile.am b/include/Makefile.am index 7d0c75c..6701ecc 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -2,3 +2,4 @@ SUBDIRS = thai MAINTAINERCLEANFILES = Makefile.in +EXTRA_DIST = meson.build diff --git a/include/meson.build b/include/meson.build new file mode 100644 index 0000000..d45dd34 --- /dev/null +++ b/include/meson.build @@ -0,0 +1,22 @@ +headers_src = files( + 'thai/thailib.h', + 'thai/thbrk.h', + 'thai/thcell.h', + 'thai/thcoll.h', + 'thai/thctype.h', + 'thai/thinp.h', + 'thai/thrend.h', + 'thai/thstr.h', + 'thai/thwbrk.h', + 'thai/thwchar.h', + 'thai/thwcoll.h', + 'thai/thwctype.h', + 'thai/thwinp.h', + 'thai/thwrend.h', + 'thai/thwstr.h', + 'thai/tis.h', + 'thai/wtt.h', +) +install_headers(headers_src, subdir: 'thai') + +include_dir = include_directories('.') diff --git a/include/thai/.cvsignore b/include/thai/.gitignore similarity index 100% rename from include/thai/.cvsignore rename to include/thai/.gitignore diff --git a/man/.cvsignore b/man/.gitignore similarity index 100% rename from man/.cvsignore rename to man/.gitignore diff --git a/man/Makefile.am b/man/Makefile.am index 4c2a734..147a4db 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -2,3 +2,4 @@ SUBDIRS = man3 MAINTAINERCLEANFILES = Makefile.in +EXTRA_DIST = meson.build diff --git a/man/man3/.cvsignore b/man/man3/.gitignore similarity index 100% rename from man/man3/.cvsignore rename to man/man3/.gitignore diff --git a/man/meson.build b/man/meson.build new file mode 100644 index 0000000..c157889 --- /dev/null +++ b/man/meson.build @@ -0,0 +1 @@ +install_man('man3/libthai.3', 'man3/thctype.3', 'man3/wtt.3') diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..3ca49cf --- /dev/null +++ b/meson.build @@ -0,0 +1,48 @@ +project( + 'libthai', + 'c', + meson_version: '>=1.0.0', + version: run_command(files('build-aux/git-version-gen'), check: true).stdout().strip(), +) + +sh = find_program('sh') +compiler = meson.get_compiler('c') +datrie = dependency('datrie-0.2') + +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 = 3 +LT_REVISION = 1 +LT_AGE = 3 + +soversion = LT_CURRENT - LT_AGE +libversion = '@0@.@1@.@2@'.format(soversion, LT_AGE, LT_REVISION) + +# 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', + ), +) + +if get_option('buildtype') in ['debug', 'debugoptimized'] + add_project_arguments('-DNDEBUG', language: ['c']) +endif + +subdir('data') +subdir('include') +subdir('src') +subdir('man') +subdir('doc') +subdir('tests') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..8a213fc --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,3 @@ +option('docs', type : 'feature', value : 'auto', description : 'Generate documents with Doxygen') +option('docsdir', type : 'string', value : 'share/doc/libthai', description : 'Where to install the Doxygen-generated HTML doc') +option('dict', type : 'boolean', value : true, description : 'Enable dictionary data generation (require libdatrie)') diff --git a/src/.cvsignore b/src/.gitignore similarity index 100% rename from src/.cvsignore rename to src/.gitignore diff --git a/src/Makefile.am b/src/Makefile.am index cdb0d4f..c3b6e00 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = thctype thstr thcell thinp thrend thcoll thbrk thwchar thwctype \ MAINTAINERCLEANFILES = Makefile.in -EXTRA_DIST = libthai.map libthai.def +EXTRA_DIST = libthai.map libthai.def meson.build AM_CPPFLAGS = -I. -I$(top_srcdir)/include $(DATRIE_CFLAGS) diff --git a/src/libthai.c b/src/libthai.c index 8065c1f..efd2772 100644 --- a/src/libthai.c +++ b/src/libthai.c @@ -90,8 +90,10 @@ #include "thbrk/thbrk-priv.h" -__attribute__ ((destructor)) void -_libthai_on_unload () +#if defined (__GNUC__) || defined (__clang__) +__attribute__ ((destructor)) +#endif +void _libthai_on_unload () { brk_free_shared_brk (); } diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..04dc3d7 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,85 @@ +ldflags = [] +link_depends = ['libthai.map', 'libthai.def'] + +if ld_has_version_script + ldflags += [ + '-Wl,--version-script,@0@'.format( + meson.current_source_dir() / 'libthai.map', + ), + ] +elif compiler.get_linker_id() in ['link', 'lld-link'] + link_def = custom_target( + 'link-def', + input: ['libthai.def'], + # This use ASCII as some PS version do not have UTF8NoBOM + command: [ + find_program('powershell'), + '-Command', + '''& { + Write-Output "EXPORTS" | Out-File -Encoding ascii -FilePath @OUTPUT0@ + Get-Content -Path @INPUT0@ | Out-File -Append -Encoding ascii -FilePath @OUTPUT0@ + }''', + ], + output: 'libthai.def', + ) + ldflags += ['/def:@0@'.format(link_def.full_path())] + link_depends += [link_def] +else + ldflags += [ + '-export-symbols @0@'.format(meson.current_source_dir() / 'libthai.def'), + ] +endif + +thai_src = files( + 'thbrk/brk-common.c', + 'thbrk/brk-common.h', + 'thbrk/brk-ctype.c', + 'thbrk/brk-ctype.h', + 'thbrk/brk-maximal.c', + 'thbrk/brk-maximal.h', + 'thbrk/thbrk-priv.h', + 'thbrk/thbrk-utils.h', + 'thbrk/thbrk.c', + 'thcell/thcell.c', + 'thcoll/cweight.c', + 'thcoll/cweight.h', + 'thcoll/thcoll.c', + 'thctype/thctype.c', + 'thctype/wtt.c', + 'thinp/thinp.c', + 'thrend/thrend.c', + 'thstr/thstr.c', + 'thwbrk/thwbrk.c', + 'thwchar/thwchar.c', + 'thwctype/thwctype.c', + 'thwstr/thwstr.c', + 'libthai.c', +) + +thai = library( + 'thai', + thai_src, + install: true, + link_args: ldflags, + link_depends: link_depends, + c_args: ['-DDICT_DIR="@0@"'.format(dict_dir)], + dependencies: [datrie], + version: libversion, + soversion: soversion, + include_directories: include_dir, +) +libthai_dep = declare_dependency( + include_directories: include_dir, + link_with: thai, +) +meson.override_dependency('libthai', libthai_dep) + +pkg = import('pkgconfig') +pkg.generate( + thai, + filebase: 'libthai', + name: 'libthai', + description: 'Thai support library', + version: version, + requires_private: ['datrie-0.2'], +) diff --git a/src/thbrk/.cvsignore b/src/thbrk/.gitignore similarity index 100% rename from src/thbrk/.cvsignore rename to src/thbrk/.gitignore diff --git a/src/thcell/.cvsignore b/src/thcell/.gitignore similarity index 100% rename from src/thcell/.cvsignore rename to src/thcell/.gitignore diff --git a/src/thcoll/.cvsignore b/src/thcoll/.gitignore similarity index 100% rename from src/thcoll/.cvsignore rename to src/thcoll/.gitignore diff --git a/src/thctype/.cvsignore b/src/thctype/.gitignore similarity index 100% rename from src/thctype/.cvsignore rename to src/thctype/.gitignore diff --git a/src/thinp/.cvsignore b/src/thinp/.gitignore similarity index 100% rename from src/thinp/.cvsignore rename to src/thinp/.gitignore diff --git a/src/thrend/.cvsignore b/src/thrend/.gitignore similarity index 100% rename from src/thrend/.cvsignore rename to src/thrend/.gitignore diff --git a/src/thstr/.cvsignore b/src/thstr/.gitignore similarity index 100% rename from src/thstr/.cvsignore rename to src/thstr/.gitignore diff --git a/src/thwbrk/.cvsignore b/src/thwbrk/.gitignore similarity index 100% rename from src/thwbrk/.cvsignore rename to src/thwbrk/.gitignore diff --git a/src/thwchar/.cvsignore b/src/thwchar/.gitignore similarity index 100% rename from src/thwchar/.cvsignore rename to src/thwchar/.gitignore diff --git a/src/thwctype/.cvsignore b/src/thwctype/.gitignore similarity index 100% rename from src/thwctype/.cvsignore rename to src/thwctype/.gitignore diff --git a/src/thwstr/.cvsignore b/src/thwstr/.gitignore similarity index 100% rename from src/thwstr/.cvsignore rename to src/thwstr/.gitignore diff --git a/subprojects/libdatrie.wrap b/subprojects/libdatrie.wrap new file mode 100644 index 0000000..8cad4d6 --- /dev/null +++ b/subprojects/libdatrie.wrap @@ -0,0 +1,8 @@ +[wrap-git] +url = https://github.com/tlwg/libdatrie.git +revision = 3985d6f7b5e56bc60bb9581337bf6a3782bd71be +depth = 1 + +[provide] +dependency_names = datrie-0.2 +program_names = trietool diff --git a/tests/.cvsignore b/tests/.gitignore similarity index 100% rename from tests/.cvsignore rename to tests/.gitignore diff --git a/tests/Makefile.am b/tests/Makefile.am index 4492507..30f404c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,7 @@ MAINTAINERCLEANFILES = Makefile.in AM_CPPFLAGS = -I$(top_srcdir)/include -EXTRA_DIST = sorttest.txt sorted.txt test-thcoll.sh test-thbrk.sh test-thwbrk.sh +EXTRA_DIST = sorttest.txt sorted.txt test-thcoll.sh test-thbrk.sh test-thwbrk.sh meson.build TESTS_ENVIRONMENT = top_builddir=$(top_builddir) diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..c82ffe4 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,40 @@ +fs = import('fs') + +tests = ['thctype', 'thcell', 'thinp', 'thrend', 'thstr', 'thwchar'] + +foreach item : tests + exe = executable( + 'test_' + item, + 'test_@0@.c'.format(item), + dependencies: [libthai_dep], + ) + test(item, exe) +endforeach + +# thcoll +thsort = executable('thsort', 'thsort.c', dependencies: [libthai_dep]) +test( + 'thcoll', + find_program('test-thcoll.sh'), + depends: [thsort], + env: { + 'srcdir' : meson.current_source_dir(), + 'top_builddir' : meson.project_build_root(), + }, +) + +if get_option('dict') + foreach item : ['thbrk', 'thwbrk'] + exe = executable( + 'test_' + item, + 'test_@0@.c'.format(item), + dependencies: [libthai_dep, dependency('iconv')], + ) + test( + item, + exe, + depends: [tri], + env: {'LIBTHAI_DICTDIR' : fs.parent(tri.full_path())}, + ) + endforeach +endif