From 70848ecfc6306711197394c0926e443e803ae870 Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Mon, 9 Apr 2018 02:43:35 -0700 Subject: [PATCH 1/4] meson: add support for building static libsystemd and libudev --- meson.build | 21 +++++++++++++++++++++ meson_options.txt | 6 ++++++ src/libsystemd/meson.build | 6 ++++-- src/udev/meson.build | 17 ++++++++++++++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 734a289755..b99e9b29fd 100644 --- a/meson.build +++ b/meson.build @@ -1342,6 +1342,27 @@ libsystemd = shared_library( install : true, install_dir : rootlibdir) +static_libsystemd = get_option('static-libsystemd') +static_libsystemd_pic = static_libsystemd == 'true' or static_libsystemd == 'pic' + +install_libsystemd_static = static_library( + 'systemd', + libsystemd_sources, + journal_client_sources, + include_directories : includes, + link_with : [libbasic, + libbasic_gcrypt], + build_by_default : static_libsystemd != 'false', + install : static_libsystemd != 'false', + install_dir : rootlibdir, + pic : static_libsystemd == 'true' or static_libsystemd == 'pic', + dependencies : [threads, + librt, + libxz, + liblz4, + libgcrypt], + c_args : libsystemd_c_args + (static_libsystemd_pic ? [] : ['-fno-PIC'])) + ############################################################ # binaries that have --help and are intended for use by humans, diff --git a/meson_options.txt b/meson_options.txt index a6ea6c498f..61d3381d17 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -13,6 +13,12 @@ option('rootprefix', type : 'string', description : '''override the root prefix''') option('link-udev-shared', type : 'boolean', description : 'link systemd-udev and its helpers to libsystemd-shared.so') +option('static-libsystemd', type : 'combo', + choices : ['false', 'true', 'pic', 'no-pic'], + description : '''install a static library for libsystemd''') +option('static-libudev', type : 'combo', + choices : ['false', 'true', 'pic', 'no-pic'], + description : '''install a static library for libudev''') option('sysvinit-path', type : 'string', value : '/etc/init.d', description : 'the directory where the SysV init scripts are located') diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index 7e55aec35b..ce4cd41844 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -82,15 +82,17 @@ libsystemd_sources = files(''' sd-utf8/sd-utf8.c '''.split()) + id128_sources + sd_daemon_c + sd_event_c + sd_login_c +libsystemd_c_args = ['-fvisibility=default'] + libsystemd_static = static_library( - 'systemd', + 'systemd_static', libsystemd_sources, install : false, include_directories : includes, link_with : libbasic, dependencies : [threads, librt], - c_args : ['-fvisibility=default']) + c_args : libsystemd_c_args) libsystemd_sym = 'src/libsystemd/libsystemd.sym' diff --git a/src/udev/meson.build b/src/udev/meson.build index a58191d4a7..a9b345e70f 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -111,12 +111,27 @@ libudev_basic = static_library( c_args : ['-fvisibility=default']) libudev_static = static_library( - 'udev', + 'udev_static', 'udev.h', include_directories : includes, link_with : udev_link_with, link_whole : libudev_basic) +static_libudev = get_option('static-libudev') +install_libudev_static = static_library( + 'udev', + libudev_sources, + include_directories : includes, + link_with : [libshared_static, + libsystemd_static], + link_whole : libudev_basic, + build_by_default : static_libudev != 'false', + install : static_libudev != 'false', + install_dir : rootlibdir, + link_depends : libudev_sym, + dependencies : [threads], + pic : static_libudev == 'true' or static_libudev == 'pic') + libudev = shared_library( 'udev', 'udev.h', # pick a header file at random to work around old meson bug From 0632b4cd3626695ebe60fbcd1604e737e9a48996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Apr 2018 13:49:27 +0200 Subject: [PATCH 2/4] meson: add test-lib{systemd,udev}-static-sym This is the same as test-lib{systemd,udev}-sym, but linked to the static variants of those libraries. --- meson.build | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index b99e9b29fd..0ebb7b0365 100644 --- a/meson.build +++ b/meson.build @@ -2551,17 +2551,32 @@ foreach tuple : tests endif endforeach -test_libsystemd_sym = executable( +exe = executable( 'test-libsystemd-sym', test_libsystemd_sym_c, include_directories : includes, link_with : [libsystemd], install : install_tests, install_dir : testsdir) -test('test-libsystemd-sym', - test_libsystemd_sym) +test('test-libsystemd-sym', exe) -test_libudev_sym = executable( +exe = executable( + 'test-libsystemd-static-sym', + test_libsystemd_sym_c, + include_directories : includes, + c_args : static_libsystemd_pic ? [] : ['-fno-PIC'], + link_args : static_libsystemd_pic ? [] : ['-fno-PIC'], + link_with : [install_libsystemd_static], + dependencies : [threads], # threads is already included in dependencies on the library, + # but does not seem to get propagated. Add here as a work-around. + build_by_default : static_libsystemd != 'false', + install : install_tests and static_libsystemd != 'false', + install_dir : testsdir) +if static_libsystemd != 'false' + test('test-libsystemd-static-sym', exe) +endif + +exe = executable( 'test-libudev-sym', test_libudev_sym_c, include_directories : includes, @@ -2569,8 +2584,21 @@ test_libudev_sym = executable( link_with : [libudev], install : install_tests, install_dir : testsdir) -test('test-libudev-sym', - test_libudev_sym) +test('test-libudev-sym', exe) + +exe = executable( + 'test-libudev-static-sym', + test_libudev_sym_c, + include_directories : includes, + c_args : ['-Wno-deprecated-declarations'] + + (static_libsystemd_pic ? [] : ['-fno-PIC']), + link_with : [install_libudev_static], + build_by_default : static_libudev != 'false', + install : install_tests and static_libudev != 'false', + install_dir : testsdir) +if static_libudev != 'false' + test('test-libudev-static-sym', exe) +endif ############################################################ From 20f3d32d8d3ce826d509a7e2979d758094ac7cf7 Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Tue, 24 Apr 2018 13:34:48 -0700 Subject: [PATCH 3/4] meson: only build test-lib{systemd,udev}-static-sym for pic --- meson.build | 17 +++++++---------- src/udev/meson.build | 4 +++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 0ebb7b0365..cbe2185ad9 100644 --- a/meson.build +++ b/meson.build @@ -2564,15 +2564,13 @@ exe = executable( 'test-libsystemd-static-sym', test_libsystemd_sym_c, include_directories : includes, - c_args : static_libsystemd_pic ? [] : ['-fno-PIC'], - link_args : static_libsystemd_pic ? [] : ['-fno-PIC'], link_with : [install_libsystemd_static], dependencies : [threads], # threads is already included in dependencies on the library, # but does not seem to get propagated. Add here as a work-around. - build_by_default : static_libsystemd != 'false', - install : install_tests and static_libsystemd != 'false', + build_by_default : static_libsystemd_pic, + install : install_tests and static_libsystemd_pic, install_dir : testsdir) -if static_libsystemd != 'false' +if static_libsystemd_pic test('test-libsystemd-static-sym', exe) endif @@ -2590,13 +2588,12 @@ exe = executable( 'test-libudev-static-sym', test_libudev_sym_c, include_directories : includes, - c_args : ['-Wno-deprecated-declarations'] + - (static_libsystemd_pic ? [] : ['-fno-PIC']), + c_args : ['-Wno-deprecated-declarations'], link_with : [install_libudev_static], - build_by_default : static_libudev != 'false', - install : install_tests and static_libudev != 'false', + build_by_default : static_libudev_pic, + install : install_tests and static_libudev_pic, install_dir : testsdir) -if static_libudev != 'false' +if static_libudev_pic test('test-libudev-static-sym', exe) endif diff --git a/src/udev/meson.build b/src/udev/meson.build index a9b345e70f..613a2e24cd 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -118,6 +118,7 @@ libudev_static = static_library( link_whole : libudev_basic) static_libudev = get_option('static-libudev') +static_libudev_pic = static_libudev == 'true' or static_libudev == 'pic' install_libudev_static = static_library( 'udev', libudev_sources, @@ -130,7 +131,8 @@ install_libudev_static = static_library( install_dir : rootlibdir, link_depends : libudev_sym, dependencies : [threads], - pic : static_libudev == 'true' or static_libudev == 'pic') + c_args : static_libudev_pic ? [] : ['-fno-PIC'], + pic : static_libudev_pic) libudev = shared_library( 'udev', From 975464e0d48b07f1486c61c726823204604cb2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 25 Apr 2018 15:29:48 +0200 Subject: [PATCH 4/4] meson: recompile all sources for install_libudev_static and install_libsystemd_static This means that when those targets are built, all the sources are built again, instead of reusing the work done to create libbasic.a and other convenience static libraries. It would be nice to not do this, but there seems to be no support in our toolchain for joining multiple static libraries into one. When linking a static library, any -l arguments are simply ignored by ar/gcc-ar, and .a libraries given as positional arguments are copied verbatim into the archive so they objects in them cannot be accessed. https://stackoverflow.com/questions/2157629/linking-static-libraries-to-other-static-libraries suggests either unzipping all the archives and putting them back togather, or using a linker script. Unzipping and zipping back together seems ugly. The other option is not very nice. The linker script language does not allow "+" to appear in the filenames, and filenames that meson generates use that, so files would have to be renamed before a linker script was used. And we would have to generate the linker script on the fly. Either way, this doesn't seem attractive. Since those static libraries are a niche use case, it seems reasonable to just go with the easiest and safest solution and recompile all the source files. Thanks to ccache, this is probably almost as cheap as actually reusing the convenience .a libraries. test-libsystemd-sym.c and test-libudev-sym.c compile fine with the generated static libs, so it seems that they indeed provide all the symbols they should. --- meson.build | 8 ++++++-- src/basic/meson.build | 6 ++++-- src/shared/meson.build | 12 ++++++------ src/udev/meson.build | 8 ++++---- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/meson.build b/meson.build index cbe2185ad9..7b8943f67d 100644 --- a/meson.build +++ b/meson.build @@ -1349,9 +1349,9 @@ install_libsystemd_static = static_library( 'systemd', libsystemd_sources, journal_client_sources, + basic_sources, + basic_gcrypt_sources, include_directories : includes, - link_with : [libbasic, - libbasic_gcrypt], build_by_default : static_libsystemd != 'false', install : static_libsystemd != 'false', install_dir : rootlibdir, @@ -1360,6 +1360,10 @@ install_libsystemd_static = static_library( librt, libxz, liblz4, + libcap, + libblkid, + libmount, + libselinux, libgcrypt], c_args : libsystemd_c_args + (static_libsystemd_pic ? [] : ['-fno-PIC'])) diff --git a/src/basic/meson.build b/src/basic/meson.build index 4f63fcef1c..ac954dbcb4 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -303,6 +303,9 @@ foreach item : [['af', af_list_txt, 'af', ''], endforeach basic_sources += [missing_h] + generated_gperf_headers +basic_gcrypt_sources = files( + 'gcrypt-util.c', + 'gcrypt-util.h') libbasic = static_library( 'basic', @@ -320,8 +323,7 @@ libbasic = static_library( # unnecessary linking to libgcrypt. libbasic_gcrypt = static_library( 'basic-gcrypt', - 'gcrypt-util.c', - 'gcrypt-util.h', + basic_gcrypt_sources, include_directories : includes, dependencies : [libgcrypt], c_args : ['-fvisibility=default']) diff --git a/src/shared/meson.build b/src/shared/meson.build index d0cb38650b..e3b076122b 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -2,7 +2,7 @@ # # Copyright 2017 Zbigniew Jędrzejewski-Szmek -shared_sources = ''' +shared_sources = files(''' acl-util.h acpi-fpdt.c acpi-fpdt.h @@ -104,25 +104,25 @@ shared_sources = ''' watchdog.c watchdog.h wireguard-netlink.h -'''.split() +'''.split()) test_tables_h = files('test-tables.h') shared_sources += [test_tables_h] if conf.get('HAVE_ACL') == 1 - shared_sources += ['acl-util.c'] + shared_sources += files('acl-util.c') endif if conf.get('ENABLE_UTMP') == 1 - shared_sources += ['utmp-wtmp.c'] + shared_sources += files('utmp-wtmp.c') endif if conf.get('HAVE_SECCOMP') == 1 - shared_sources += ['seccomp-util.c'] + shared_sources += files('seccomp-util.c') endif if conf.get('HAVE_LIBIPTC') == 1 - shared_sources += ['firewall-util.c'] + shared_sources += files('firewall-util.c') endif libshared_name = 'systemd-shared-@0@'.format(meson.project_version()) diff --git a/src/udev/meson.build b/src/udev/meson.build index 613a2e24cd..8fa0627d00 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -121,16 +121,16 @@ static_libudev = get_option('static-libudev') static_libudev_pic = static_libudev == 'true' or static_libudev == 'pic' install_libudev_static = static_library( 'udev', + basic_sources, + shared_sources, + libsystemd_sources, libudev_sources, include_directories : includes, - link_with : [libshared_static, - libsystemd_static], - link_whole : libudev_basic, build_by_default : static_libudev != 'false', install : static_libudev != 'false', install_dir : rootlibdir, link_depends : libudev_sym, - dependencies : [threads], + dependencies : libshared_deps + [libmount], c_args : static_libudev_pic ? [] : ['-fno-PIC'], pic : static_libudev_pic)