diff options
author | Manuel Bentele | 2021-10-11 11:03:56 +0200 |
---|---|---|
committer | Manuel Bentele | 2021-10-12 13:12:55 +0200 |
commit | 40b844b8e6cf297f53be987ad18eb40cf9ea336e (patch) | |
tree | d591c8ba10851bda98acc5562b0b85fb0505dadb | |
parent | [libvirt-python] Add new module to build python wrapper for libvirt (diff) | |
download | mltk-40b844b8e6cf297f53be987ad18eb40cf9ea336e.tar.gz mltk-40b844b8e6cf297f53be987ad18eb40cf9ea336e.tar.xz mltk-40b844b8e6cf297f53be987ad18eb40cf9ea336e.zip |
[virt-viewer] Add new module to build virt-viewer from source
-rwxr-xr-x | core/bin/pkg-config.sh | 76 | ||||
-rw-r--r-- | core/modules/libvirt-src/module.build | 9 | ||||
-rw-r--r-- | core/modules/virt-viewer/module.build | 25 | ||||
-rw-r--r-- | core/modules/virt-viewer/module.conf | 5 | ||||
-rw-r--r-- | core/modules/virt-viewer/module.conf.ubuntu | 1 |
5 files changed, 113 insertions, 3 deletions
diff --git a/core/bin/pkg-config.sh b/core/bin/pkg-config.sh new file mode 100755 index 00000000..cd6abc0c --- /dev/null +++ b/core/bin/pkg-config.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# Function to check if diretory exists and is not empty +# Param 1: Path to the directory +# Return : True (0) if directory exists and is not empty, otherwise false (1) +function pkg_config_non_empty_dir() { + local DIR="${1}" + + if [ -d "${DIR}" ] && [ -n "$(ls -A "${DIR}")" ]; then + return 0; + else + return 1; + fi +} + +# Function to process given directory and patch system root directory if necessary +# +# First, all system directories (path without system root prefix) are processed. +# Afterwards, all system root directories are checked (path with system root prefix). +# +# Param 1: Option of the argument, e.g. '-I' +# Param 2: Path to the directory (value of the argument) with/without prefixed '${PKG_CONFIG_SYSROOT_DIR}' +function pkg_config_process_dir() { + local DIR_OPTION="${1}" + local DIR_WTH_SYSROOT="${2}" + local DIR_NON_SYSROOT="${DIR_WTH_SYSROOT##${PKG_CONFIG_SYSROOT_DIR}}" + + if pkg_config_non_empty_dir "${DIR_WTH_SYSROOT}"; then + echo -n "${DIR_OPTION}${DIR_WTH_SYSROOT} " + else + if pkg_config_non_empty_dir "${DIR_NON_SYSROOT}"; then + echo -n "${DIR_OPTION}${DIR_NON_SYSROOT} " + else + [[ "${DIR_WTH_SYSROOT}" == "${DIR_NON_SYSROOT}" ]] && \ + echo -n "Directory '${DIR_WTH_SYSROOT}' does not exist!" || \ + echo -n "Directory '${DIR_WTH_SYSROOT}' or '${DIR_NON_SYSROOT}' does not exist!" + exit 1; + fi + fi +} + +# Function to patch output of original pkg-config to fix include and library paths +# Param 1..n: Output of original pkg-config as separated commands +# Return : Patched output of the original pkg-config input. +function pkg_config_patch_sysroot() { + + # process all passed parameters + for PARAM in "${@}"; do + case "${PARAM}" in + -I*) + pkg_config_process_dir "-I" "${PARAM##-I}" + ;; + -L*) + pkg_config_process_dir "-L" "${PARAM##-L}" + ;; + *) + echo -n "${PARAM} " + ;; + esac + done + + echo +} + +# execute original pkg-config and save output and return code +PKG_CONFIG_OUTPUT="$($(which "pkg-config") "${@}")" +PKG_CONFIG_RETVAL=${?} + +# abort with exit code if pkg-config call failed +if [[ ${PKG_CONFIG_RETVAL} -ne 0 ]]; then + echo "${PKG_CONFIG_OUTPUT}" + exit ${PKG_CONFIG_RETVAL} +fi + +# patch system root directory in pkg-config output +pkg_config_patch_sysroot ${PKG_CONFIG_OUTPUT} diff --git a/core/modules/libvirt-src/module.build b/core/modules/libvirt-src/module.build index 05537489..4ccc4373 100644 --- a/core/modules/libvirt-src/module.build +++ b/core/modules/libvirt-src/module.build @@ -32,7 +32,7 @@ build() { --localstatedir="/var" \ -Dsystem=true \ -Dtests=disabled \ - -Ddocs=disabled \ + -Ddocs=enabled \ -Dwireshark_dissector=disabled \ -Dstorage_dir=enabled \ -Dstorage_disk=enabled \ @@ -51,10 +51,15 @@ build() { rm "${DSTDIR}/etc/libvirt/qemu/networks/default.xml" # delete installed test and documentation files - rm -rf "${DSTDIR}/usr/include/libvirt" rm -rf "${DSTDIR}/usr/share/augeas" rm -rf "${DSTDIR}/usr/share/doc/libvirt" + # patch library directory in pkg-config files + sed -i 's/^libdir=.*$/libdir=\/usr\/lib\/x86_64-linux-gnu/g' "${DSTDIR}/usr/lib64/pkgconfig/libvirt.pc" + sed -i 's/^libdir=.*$/libdir=\/usr\/lib\/x86_64-linux-gnu/g' "${DSTDIR}/usr/lib64/pkgconfig/libvirt-admin.pc" + sed -i 's/^libdir=.*$/libdir=\/usr\/lib\/x86_64-linux-gnu/g' "${DSTDIR}/usr/lib64/pkgconfig/libvirt-lxc.pc" + sed -i 's/^libdir=.*$/libdir=\/usr\/lib\/x86_64-linux-gnu/g' "${DSTDIR}/usr/lib64/pkgconfig/libvirt-qemu.pc" + # delete empty run folder to prevent mltk from stopping rm -rf "${DSTDIR}/var/run" } diff --git a/core/modules/virt-viewer/module.build b/core/modules/virt-viewer/module.build index 9c5e89e2..e95d9adf 100644 --- a/core/modules/virt-viewer/module.build +++ b/core/modules/virt-viewer/module.build @@ -11,6 +11,29 @@ build() { # install meson (>= 0.54.0) since packaged version is too old pip3 install "meson>=0.54.0" + # set config paths for additional pkg-config files + export PKG_CONFIG_PATH="${TARGET_BUILD_DIR}/usr/lib/x86_64-linux-gnu/pkgconfig:${TARGET_BUILD_DIR}/usr/lib64/pkgconfig" + # set system root directory for prebuilt headers and libraries, e.g. libvirt-glib + export PKG_CONFIG_SYSROOT_DIR="${TARGET_BUILD_DIR}" + # enable output of all system include directories + export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 + # enable output of all system library directories + export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 + + # create custom pkg-config program to patch paths from pkg-build config files in our build directory + cat > "${SRCDIR}/pkg-config" <<-EOF + #!/bin/bash + + # unset custom path to avoid call recursion of this custom pkg-config script + unset PATH + + # call patched pkg-config wrapper from mltk bin directory + exec "${ROOT_DIR}/core/bin/pkg-config.sh" "\${@}" + EOF + chmod +x "${SRCDIR}/pkg-config" + + # overwrite search path to inject custom pkg-config program + PATH="${SRCDIR}:${PATH}" \ meson build \ --prefix="/usr" \ --sysconfdir="/etc" \ @@ -21,6 +44,8 @@ build() { -Dlibvirt=enabled || perror "'meson' failed." ninja -v -C build || perror "'ninja' failed." DESTDIR="${DSTDIR}" ninja -v -C build install || perror "'ninja install' failed." + + rm "${SRCDIR}/pkg-config" } post_copy() { diff --git a/core/modules/virt-viewer/module.conf b/core/modules/virt-viewer/module.conf index 3dcabb13..98b2bba5 100644 --- a/core/modules/virt-viewer/module.conf +++ b/core/modules/virt-viewer/module.conf @@ -1,5 +1,10 @@ #!/bin/bash +REQUIRED_MODULES=" + libvirt-src + libvirt-glib +" + REQUIRED_GIT=" https://gitlab.com/virt-viewer/virt-viewer.git||v10.0 " diff --git a/core/modules/virt-viewer/module.conf.ubuntu b/core/modules/virt-viewer/module.conf.ubuntu index ab1907e8..434612d4 100644 --- a/core/modules/virt-viewer/module.conf.ubuntu +++ b/core/modules/virt-viewer/module.conf.ubuntu @@ -5,7 +5,6 @@ REQUIRED_INSTALLED_PACKAGES=" python3-pip ninja-build debhelper - libvirt-glib-1.0-dev libgovirt-dev libgtk-vnc-2.0-dev libspice-client-gtk-3.0-dev |