From 1bbdc8eb3740ab2125ec4eeca0d1c0b090e4939c Mon Sep 17 00:00:00 2001 From: Rasmus Thomsen Date: Thu, 1 Oct 2020 17:53:36 +0200 Subject: [PATCH] build: add option to build apk.static binary --- meson.build | 15 ++++++++++----- meson_options.txt | 1 + src/meson.build | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 4aaf5c5..c2fa337 100644 --- a/meson.build +++ b/meson.build @@ -10,19 +10,24 @@ pkgc = import('pkgconfig') apk_confdir = get_option('sysconfdir') / 'apk' apk_libdir = get_option('libdir') -zlib_dep = dependency('zlib') -openssl_dep = dependency('openssl') lua_bin = find_program('lua' + get_option('lua_version'), required: get_option('help')) lua_dep = dependency('lua' + get_option('lua_version'), required: get_option('lua')) scdoc_dep = dependency('scdoc', version: '>=1.10', required: get_option('docs')) +shared_deps = [ + dependency('zlib'), + dependency('openssl'), +] + +static_deps = [ + dependency('openssl', static: true), + dependency('zlib', static: true), +] + add_project_arguments('-D_GNU_SOURCE', language: 'c') # If we're a subproject we only want the static lib and not files subproject = meson.is_subproject() -if get_option('default_library') == 'static' - add_project_arguments('-DOPENSSL_NO_ENGINE', language: 'c') -endif subdir('doc') subdir('libfetch') diff --git a/meson_options.txt b/meson_options.txt index 5d04e51..0677faa 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,3 +2,4 @@ option('docs', description: 'Build manpages with scdoc', type: 'feature', value: option('help', description: 'Build help into apk binaries, needs lua and lua-zlib', type: 'feature', value: 'auto') option('lua', description: 'Build luaapk (lua bindings)', type: 'feature', value: 'auto') option('lua_version', description: 'Lua version to build against', type: 'string', value: '5.3') +option('static_apk', description: 'Also build apk.static', type: 'boolean', value: true) diff --git a/src/meson.build b/src/meson.build index 233d383..e104a05 100644 --- a/src/meson.build +++ b/src/meson.build @@ -82,26 +82,36 @@ apk_cargs = [ '-D_ATFILE_SOURCE', ] -libapk = library( +libapk_shared = shared_library( 'apk', libapk_src, version: meson.project_version(), - install: true, + install: not subproject, dependencies: [ libfetch_dep, - zlib_dep, - openssl_dep, + shared_deps, ], c_args: apk_cargs, ) +libapk_static = static_library( + 'apk', + libapk_src, + install: not subproject, + dependencies: [ + libfetch_dep, + static_deps, + ], + c_args: [apk_cargs, '-DOPENSSL_NO_ENGINE'], +) + libapk_dep = declare_dependency( - link_with: libapk, + link_with: libapk_shared, ) if not subproject pkgc.generate( - libapk, + libapk_shared, name: 'apk', version: meson.project_version(), ) @@ -133,9 +143,23 @@ apk_exe = executable( install: not subproject, dependencies: [ libapk_dep, - zlib_dep, - openssl_dep, + shared_deps, libfetch_dep.partial_dependency(includes: true), ], c_args: apk_cargs, ) + +if get_option('static_apk') + apk_static_exe = executable( + 'apk.static', + apk_src, + install: not subproject, + dependencies: [ + static_deps, + libfetch_dep.partial_dependency(includes: true), + ], + link_with: libapk_static, + c_args: [apk_cargs, '-DOPENSSL_NO_ENGINE'], + link_args: '-static', + ) +endif