From e5ee1ed6fe07a8be0708a5b367da02cff96065a8 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 25 Feb 2020 15:45:01 +0530 Subject: [PATCH] Initial import of meson build files from upstream Upstream has these build files, but they forgot to dist them while making the last release 0.21.0. These are the meson build files from that git tag. --- fuzz/meson.build | 24 +++++++ include/meson.build | 26 ++++++++ meson.build | 148 ++++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 16 +++++ src/meson.build | 31 ++++++++++ tests/meson.build | 37 +++++++++++ tools/meson.build | 4 ++ 7 files changed, 286 insertions(+) create mode 100644 fuzz/meson.build create mode 100644 include/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 src/meson.build create mode 100644 tests/meson.build create mode 100644 tools/meson.build diff --git a/fuzz/meson.build b/fuzz/meson.build new file mode 100644 index 0000000..fae7cba --- /dev/null +++ b/fuzz/meson.build @@ -0,0 +1,24 @@ +fuzzer_cargs = [ + '-DSRCDIR="@0@"'.format(meson.current_source_dir()), + '-DTEST_RUN', +] + +foreach test_case : ['fuzzer', 'load_fuzzer', 'load_dafsa_fuzzer'] + if enable_runtime == 'libidn2' + test_name = 'libpsl_idn2_' + test_case + elif enable_runtime == 'libicu' + test_name = 'libpsl_icu_' + test_case + elif enable_runtime == 'libidn' + test_name = 'libpsl_idn_' + test_case + else + test_name = 'libpsl_' + test_case + endif + source_file = 'libpsl_@0@.c'.format(test_case) + exe = executable(test_name, source_file, 'main.c', + link_with : libpsl, + c_args : fuzzer_cargs, + include_directories : [configinc, includedir], + dependencies : libicu_dep, + ) + test(test_name, exe) +endforeach diff --git a/include/meson.build b/include/meson.build new file mode 100644 index 0000000..bed5b75 --- /dev/null +++ b/include/meson.build @@ -0,0 +1,26 @@ +version = meson.project_version() +version_arr = version.split('.') +major = version_arr[0].to_int() +minor = version_arr[1].to_int() +patch = version_arr[2].to_int() + +cdata = configuration_data() +cdata.set('LIBPSL_VERSION', version) +cdata.set('LIBPSL_VERSION_MAJOR', major) +cdata.set('LIBPSL_VERSION_MINOR', minor) +cdata.set('LIBPSL_VERSION_PATCH', patch) + +hex = '0123456789abcdef' +ver = '0x@0@@1@@2@@3@@4@@5@' +cdata.set('LIBPSL_VERSION_NUMBER', + ver.format( + hex[major / 16], hex[major % 16], + hex[minor / 16], hex[minor % 16], + hex[patch / 16], hex[minor % 16])) + +libpsl_h = configure_file( + input : 'libpsl.h.in', + output : 'libpsl.h', + configuration : cdata) + +install_headers(libpsl_h) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..773e6af --- /dev/null +++ b/meson.build @@ -0,0 +1,148 @@ +project('libpsl', 'c', + version : '0.20.2', + meson_version : '>=0.47.0') + +cc = meson.get_compiler('c') + +enable_runtime = get_option('runtime') +enable_builtin = get_option('builtin') + +# We need to know the build type to determine what .lib files we need on Visual Studio +# for dependencies that don't normally come with pkg-config files for Visual Studio builds +buildtype = get_option('buildtype') + +notfound = dependency('', required : false) +libidn2_dep = notfound +libicu_dep = notfound +libidn_dep = notfound +libunistring = notfound +networking_deps = notfound + +# FIXME: Cleanup this when Meson gets 'feature-combo': +# https://github.com/mesonbuild/meson/issues/4566 +# Dependency fallbacks would help too: +# https://github.com/mesonbuild/meson/pull/4595 +if ['libidn2', 'auto'].contains(enable_runtime) or ['libidn2', 'auto'].contains(enable_builtin) + libidn2_dep = dependency('libidn2', required : false) + if not libidn2_dep.found() and cc.has_header('idn2.h') + libidn2_dep = cc.find_library('idn2', required : false) + endif + if libidn2_dep.found() + if enable_runtime == 'auto' + enable_runtime = 'libidn2' + endif + if enable_builtin == 'auto' + enable_builtin = 'libidn2' + endif + elif [enable_runtime, enable_builtin].contains('libidn2') + error('You requested libidn2 but it is not installed.') + endif +endif + +if ['libicu', 'auto'].contains(enable_runtime) or ['libicu', 'auto'].contains(enable_builtin) + libicu_dep = dependency('icu-uc', required : false) + if not libicu_dep.found() and cc.has_header('unicode/ustring.h') + # MSVC: the debug configuration of ICU generated the libraries with d suffix + # we must handle this and search for the right library depending on the + # build type. Note debugoptimized is just a release build with .pdb files enabled + if cc.get_id() == 'msvc' and buildtype == 'debug' + libicu_dep = cc.find_library('icuucd', required : false) + else + libicu_dep = cc.find_library('icuuc', required : false) + endif + endif + if libicu_dep.found() + if enable_runtime == 'auto' + enable_runtime = 'libicu' + endif + if enable_builtin == 'auto' + enable_builtin = 'libicu' + endif + elif [enable_runtime, enable_builtin].contains('libicu') + error('You requested libicu but it is not installed.') + endif +endif + +if ['libidn', 'auto'].contains(enable_runtime) or ['libidn', 'auto'].contains(enable_builtin) + libidn_dep = dependency('libidn', required : false) + if not libidn_dep.found() and cc.has_header('idna.h') + libidn_dep = cc.find_library('idn', required : false) + endif + if libidn_dep.found() + if enable_runtime == 'auto' + enable_runtime = 'libidn' + endif + if enable_builtin == 'auto' + enable_builtin = 'libidn' + endif + elif [enable_runtime, enable_builtin].contains('libidn') + error('You requested libidn but it is not installed.') + endif +endif + +if libidn2_dep.found() or libidn_dep.found() + # Check for libunistring, we need it for psl_str_to_utf8lower() + libunistring = cc.find_library('unistring') +endif + +if host_machine.system() == 'windows' + networking_deps = cc.find_library('ws2_32') +endif + +if enable_runtime == 'auto' + enable_runtime = 'no' +endif +if enable_builtin == 'auto' + enable_builtin = 'no' +endif + +config = configuration_data() +config.set_quoted('PACKAGE_VERSION', meson.project_version()) +config.set('WITH_LIBIDN2', enable_runtime == 'libidn2') +config.set('WITH_LIBICU', enable_runtime == 'libicu') +config.set('WITH_LIBIDN', enable_runtime == 'libidn') +config.set('BUILTIN_GENERATOR_LIBIDN2', enable_builtin == 'libidn2') +config.set('BUILTIN_GENERATOR_LIBICU', enable_builtin == 'libicu') +config.set('BUILTIN_GENERATOR_LIBIDN', enable_builtin == 'libidn') +config.set('HAVE_UNISTD_H', cc.check_header('unistd.h')) +config.set('HAVE_STDINT_H', cc.check_header('stdint.h')) +config.set('HAVE_ALLOCA_H', cc.check_header('alloca.h')) +config.set('HAVE_ALLOCA', cc.has_function('alloca')) +config.set('HAVE_STRNDUP', cc.has_function('strndup')) +config.set('HAVE_CLOCK_GETTIME', cc.has_function('clock_gettime')) +config.set('HAVE_FMEMOPEN', cc.has_function('fmemopen')) +config.set('HAVE_NL_LANGINFO', cc.has_function('nl_langinfo')) +configure_file(output : 'config.h', configuration : config) + +configinc = include_directories('.') +includedir = include_directories('include') + +psl_distfile = get_option('psl_distfile') +psl_file = get_option('psl_file') +if psl_file == '' + psl_file = join_paths(meson.current_source_dir(), 'list', 'public_suffix_list.dat') +endif +psl_test_file = get_option('psl_testfile') +if psl_test_file == '' + psl_test_file = join_paths(meson.current_source_dir(), 'list', 'tests', 'tests.txt') +endif + +python = import('python').find_installation() +pkgconfig = import('pkgconfig') + +if cc.get_id() == 'msvc' + if not cc.has_header_symbol('stdio.h', 'snprintf') + if cc.has_header_symbol('stdio.h', '_snprintf') + add_project_arguments('-Dsnprintf=_snprintf', language: 'c') + endif + endif + if cc.has_header_symbol('malloc.h', '_alloca') + add_project_arguments('-Dalloca=_alloca', language: 'c') + endif +endif + +subdir('include') +subdir('src') +subdir('tools') +subdir('tests') +subdir('fuzz') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..eb80489 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,16 @@ +option('runtime', type : 'combo', + choices : ['libidn2', 'libicu', 'libidn', 'no', 'auto'], value : 'auto', + description : 'Specify the IDNA library used for libpsl run-time conversions') + +option('builtin', type : 'combo', + choices : ['libidn2', 'libicu', 'libidn', 'no', 'auto'], value : 'auto', + description : 'Specify the IDNA library used for built-in data generation') + +option('psl_distfile', type : 'string', value : '', + description : 'path to distribution-wide PSL file') + +option('psl_file', type : 'string', value : '', + description : 'path to PSL file') + +option('psl_testfile', type : 'string', value : '', + description : 'path to PSL test file') diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..9bce343 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,31 @@ +psl_make_dafsa = find_program('psl-make-dafsa') + +suffixes_dafsa_h = custom_target('suffixes_dafsa.h', + input : psl_file, + output : 'suffixes_dafsa.h', + command : [psl_make_dafsa, '--output-format=cxx+', '@INPUT@', '@OUTPUT@']) + +sources = [ + 'lookup_string_in_fixed_set.c', + 'psl.c', +] + +cargs = [ + '-DHAVE_CONFIG_H', + '-DBUILDING_PSL', + '-DPSL_DISTFILE="@0@"'.format(psl_distfile), +] + +libpsl = library('psl', sources, suffixes_dafsa_h, + include_directories : [configinc, includedir], + c_args : cargs, + dependencies : [libidn2_dep, libidn_dep, libicu_dep, libunistring, networking_deps], + install: true, +) + +pkgconfig.generate(libpsl, + name : 'libpsl', + description : 'Public Suffix List C library') + +libpsl_dep = declare_dependency(link_with : libpsl, + include_directories : includedir) diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..b0508a1 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,37 @@ +psl_dafsa = custom_target('psl.dafsa', + input : psl_file, + output : 'psl.dafsa', + command : [psl_make_dafsa, '--output-format=binary', '@INPUT@', '@OUTPUT@']) + +psl_ascii_dafsa = custom_target('psl_ascii.dafsa', + input : psl_file, + output : 'psl_ascii.dafsa', + command : [psl_make_dafsa, '--output-format=binary', '--encoding=ascii', '@INPUT@', '@OUTPUT@']) + +tests_cargs = [ + '-DHAVE_CONFIG_H', + '-DSRCDIR="@0@"'.format(meson.current_source_dir()), + '-DPSL_FILE="@0@"'.format(psl_file), + '-DPSL_TESTFILE="@0@"'.format(psl_test_file), + '-DPSL_DAFSA="@0@"'.format(psl_dafsa.full_path()), + '-DPSL_ASCII_DAFSA="@0@"'.format(psl_ascii_dafsa.full_path()), +] + +tests = [ + 'test-is-public', + 'test-is-public-all', + 'test-is-cookie-domain-acceptable', +] + +if enable_builtin != 'no' + tests += ['test-is-public-builtin', 'test-registrable-domain'] +endif + +foreach test_name : tests + source = test_name + '.c' + exe = executable(test_name, source, + c_args : tests_cargs, + link_with : libpsl, + include_directories : [configinc, includedir]) + test(test_name, exe, depends : [psl_dafsa, psl_ascii_dafsa]) +endforeach diff --git a/tools/meson.build b/tools/meson.build new file mode 100644 index 0000000..2cbdae9 --- /dev/null +++ b/tools/meson.build @@ -0,0 +1,4 @@ +psl = executable('psl', 'psl.c', + link_with : libpsl, + include_directories : [configinc, includedir], + c_args : ['-DHAVE_CONFIG_H']) -- 2.24.1