diff options
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | portability/memrchr.c | 9 | ||||
-rw-r--r-- | portability/meson.build | 35 | ||||
-rw-r--r-- | portability/string.h | 5 | ||||
-rw-r--r-- | src/meson.build | 11 |
5 files changed, 60 insertions, 1 deletions
diff --git a/meson.build b/meson.build index 8d32ad6..1b884c1 100644 --- a/meson.build +++ b/meson.build @@ -33,6 +33,7 @@ add_project_arguments('-D_FILE_OFFSET_BITS=64', language: 'c') subproject = meson.is_subproject() subdir('doc') +subdir('portability') subdir('libfetch') subdir('src') subdir('tests') diff --git a/portability/memrchr.c b/portability/memrchr.c new file mode 100644 index 0000000..70547f9 --- /dev/null +++ b/portability/memrchr.c @@ -0,0 +1,9 @@ +#include <stddef.h> + +void *memrchr(const void *m, int c, size_t n) +{ + const unsigned char *s = m; + c = (unsigned char)c; + while (n--) if (s[n]==c) return (void *)(s+n); + return 0; +} diff --git a/portability/meson.build b/portability/meson.build new file mode 100644 index 0000000..51e4aee --- /dev/null +++ b/portability/meson.build @@ -0,0 +1,35 @@ +cc = meson.get_compiler('c') + + +libportability_src = [] + + +check_functions = [ + ['memrchr', 'memrchr.c', 'NEED_MEMRCHR', 'string.h'], +] + + +foreach f : check_functions + if not cc.has_function(f.get(0), prefix: '#include <' + f.get(3) + '>', args: ['-D_GNU_SOURCE']) or not cc.has_header_symbol(f.get(3), f.get(0), args: ['-D_GNU_SOURCE']) + add_project_arguments('-D' + f.get(2), language: 'c') + libportability_src += [f.get(1)] + endif +endforeach + + +if libportability_src.length() > 0 + libportability = static_library( + 'portability', + libportability_src, + dependencies: static_deps, + ) + + libportability_dep = declare_dependency( + link_whole: libportability, + include_directories: include_directories('.'), + ) +else + libportability_dep = declare_dependency( + include_directories: include_directories('.'), + ) +endif diff --git a/portability/string.h b/portability/string.h new file mode 100644 index 0000000..0b8bb71 --- /dev/null +++ b/portability/string.h @@ -0,0 +1,5 @@ +#include_next <string.h> + +#ifdef NEED_MEMRCHR +extern void *memrchr(const void *m, int c, size_t n); +#endif diff --git a/src/meson.build b/src/meson.build index 3cc4ce0..14a4749 100644 --- a/src/meson.build +++ b/src/meson.build @@ -117,6 +117,7 @@ libapk_shared = shared_library( install: not subproject, dependencies: [ libfetch_dep, + libportability_dep, shared_deps, ], c_args: apk_cargs, @@ -128,6 +129,7 @@ libapk_static = static_library( install: not subproject, dependencies: [ libfetch_dep, + libportability_dep, static_deps, ], c_args: [apk_cargs, '-DOPENSSL_NO_ENGINE'], @@ -158,7 +160,12 @@ if(lua_dep.found()) libluaapk = library( 'luaapk', luaapk_src, - dependencies: [lua_dep, libapk_dep, shared_deps], + dependencies: [ + lua_dep, + libapk_dep, + shared_deps, + libportability_dep.partial_dependency(includes: true), + ], install: true, install_dir: lua_dep.get_pkgconfig_variable('libdir'), c_args: apk_cargs, @@ -173,6 +180,7 @@ apk_exe = executable( libapk_dep, shared_deps, libfetch_dep.partial_dependency(includes: true), + libportability_dep.partial_dependency(includes: true), ], c_args: apk_cargs, ) @@ -185,6 +193,7 @@ if get_option('static_apk') dependencies: [ static_deps, libfetch_dep.partial_dependency(includes: true), + libportability_dep.partial_dependency(includes: true), ], link_with: libapk_static, c_args: [apk_cargs, '-DOPENSSL_NO_ENGINE'], |