[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v4 14/15] autoconf: xen: add systemd support into the build system



On 30/04/14 03:12, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@xxxxxxxx>
> 
> This adds autoconf systemd support into the build system.
> Autoconf support for system has been split up as much as
> possible into its own set of helpers in hopes that this
> might be useful for other daemons and I was unable to
> find anything generic. You can use either one of two
> helpers depending on whether or not you want to make
> systemd required or optional:
> 
>   * AX_ENABLE_SYSTEMD() - requires systemd
>   * AX_ALLOW_SYSTEMD()  - lets you enable systemd with configure
> 
> This then lets you use the variables in your build system:
> 
>   * SYSTEMD_CFLAGS
>   * SYSTEMD_LIBS
>   * SYSTEMD_DIR
>   * SYSTEMD_MODULES_LOAD
> 
> Systemd support is left disabled by default given xen can
> be built for non-systemd systems and enabling systemd support
> will require support of having libsystemd-daemon present
> in order to use active sockets. We use AX_ALLOW_SYSTEMD() then,
> you can enable systemd support into the build system by using
> the --enable-systemd configure flag, you will have been expected
> to have installed your distribution's version of the package
> systemd-devel.
> 
> This integration currently does not make use of
> 
> pkg-config --variable=systemdsystemunitdir systemd
> 
> for setting of the SYSTEMD_DIR where the unit files are
> stored given upstream systemd pc files it do not respect the
> ${prefix} overriding and fixing that upstream on system is
> a bit complicated, to account for that we provide a path
> helper --with-systemd which can be used to override the path
> to the service files. Upstream systemd also lacks a pc file
> placement for a modules load path, we can add that upstream
> but for now we enable overriding through the flag configure
> flag --with-systemd-modules-load. By default you're preferred
> ${prefix} will be respected, this means /usr/local/ will be used
> for both as prefix if none is provided thereby leaving your
> own distribution's files in place if present.
> 
> Enabling systemd will trigger a config.h define for HAVE_SYSTEMD
> which is used by C xensotred and Ocaml oxenstored for active
> socket communication.
> 
> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
> Cc: Jan RÄkorajski <baggins@xxxxxxxxxxxxx>
> Cc: M A Young <m.a.young@xxxxxxxxxxxx>
> Cc: Jacek Konieczny <jajcus@xxxxxxxxxx>
> Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
> Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxx>
> ---
>  config/Tools.mk.in             |   6 +++
>  m4/systemd.m4                  | 105 
> +++++++++++++++++++++++++++++++++++++++++
>  tools/configure.ac             |   3 ++
>  tools/hotplug/common/Makefile  |   1 +
>  tools/ocaml/xenstored/Makefile |   5 ++
>  tools/xenstore/Makefile        |   6 +++
>  6 files changed, 126 insertions(+)
>  create mode 100644 m4/systemd.m4
> 
> diff --git a/config/Tools.mk.in b/config/Tools.mk.in
> index 0bdf37a..c47e6af 100644
> --- a/config/Tools.mk.in
> +++ b/config/Tools.mk.in
> @@ -55,6 +55,12 @@ CONFIG_QEMU_TRAD    := @qemu_traditional@
>  CONFIG_QEMU_XEN     := @qemu_xen@
>  CONFIG_BLKTAP1      := @blktap1@
>  
> +CONFIG_SYSTEMD      := @systemd@
> +SYSTEMD_CFLAGS      := @SYSTEMD_CFLAGS@
> +SYSTEMD_LIBS        := @SYSTEMD_LIBS@
> +XEN_SYSTEMD_DIR     := @SYSTEMD_DIR@
> +XEN_SYSTEMD_MODULES_LOAD := @SYSTEMD_MODULES_LOAD@
> +
>  #System options
>  ZLIB                := @zlib@
>  CONFIG_LIBICONV     := @libiconv@
> diff --git a/m4/systemd.m4 b/m4/systemd.m4
> new file mode 100644
> index 0000000..d5734d4
> --- /dev/null
> +++ b/m4/systemd.m4
> @@ -0,0 +1,105 @@
> +# systemd.m4 - Macros to check for and enable systemd          -*- Autoconf 
> -*-
> +#
> +# Copyright (C) 2014 Luis R. Rodriguez <mcgrof@xxxxxxxx>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful, but
> +# WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software Foundation, 
> Inc.,
> +# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
> +
> +dnl Some optional path options
> +AC_DEFUN([AX_SYSTEMD_OPTIONS], [
> +     AC_ARG_WITH(systemd, [  --with-systemd          set directory for 
> systemd service files],
> +             SYSTEMD_DIR="$withval", SYSTEMD_DIR="")
> +     AC_SUBST(SYSTEMD_DIR)
> +
> +     AC_ARG_WITH(systemd, [  --with-systemd-modules-load          set 
> directory for systemd modules load files],
> +             SYSTEMD_MODULES_LOAD="$withval", SYSTEMD_MODULES_LOAD="")
> +     AC_SUBST(SYSTEMD_MODULES_LOAD)
> +])
> +
> +dnl Enables systemd by default and requires a --disable-systemd option flag
> +dnl to configure if you want to disable.
> +AC_DEFUN([AX_ENABLE_SYSTEMD_OPTS], [
> +     AX_ARG_DEFAULT_ENABLE([systemd], [Disable systemd support])
> +     AX_SYSTEMD_OPTIONS()
> +])
> +
> +dnl Systemd will be disabled by default and requires you to run configure 
> with
> +dnl --enable-systemd to look for and enable systemd.
> +AC_DEFUN([AX_ALLOW_SYSTEMD_OPTS], [
> +     AX_ARG_DEFAULT_DISABLE([systemd], [Enable systemd support])
> +     AX_SYSTEMD_OPTIONS()
> +])
> +
> +AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
> +     AC_CHECK_HEADER([systemd/sd-daemon.h], [
> +         AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], 
> [libsystemddaemon="y"])
> +     ])
> +     AS_IF([test "x$libsystemddaemon" = x], [
> +         AC_MSG_ERROR([Unable to find a suitable libsystemd-daemon library])
> +     ])
> +
> +     PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon])
> +     dnl pkg-config older than 0.24 does not set these for
> +     dnl PKG_CHECK_MODULES() worth also noting is that as of version 208
> +     dnl of systemd pkg-config --cflags currently yields no extra flags yet.
> +     AC_SUBST([SYSTEMD_CFLAGS])
> +     AC_SUBST([SYSTEMD_LIBS])
> +
> +     AS_IF([test "x$SYSTEMD_DIR" = x], [
> +         dnl In order to use the line below we need to fix upstream systemd
> +         dnl to properly ${prefix} for child variables in
> +         dnl src/core/systemd.pc.in but this is a bit complex at the
> +         dnl moment as they depend on another rootprefix, which can vary
> +         dnl from prefix in practice. We provide our own definition as we
> +         dnl *know* where systemd will dump this to, but this does limit
> +         dnl us to stick to a non custom systemdsystemunitdir, dnl to work
> +         dnl around this we provide the additional configure option
> +         dnl --with-systemd where you can specify the directory for the unit
> +         dnl files. It would also be best to just extend the upstream
> +         dnl pkg-config  pkg.m4 with an AC_DEFUN() to do this neatly.
> +         dnl SYSTEMD_DIR="`$PKG_CONFIG --define-variable=prefix=$PREFIX 
> --variable=systemdsystemunitdir systemd`"
> +         SYSTEMD_DIR="\$(prefix)/lib/systemd/system/"
> +     ], [])
> +
> +     AS_IF([test "x$SYSTEMD_DIR" = x], [
> +         AC_MSG_ERROR([SYSTEMD_DIR is unset])
> +     ], [])
> +
> +     dnl There is no variable for this yet for some reason
> +     AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
> +         SYSTEMD_MODULES_LOAD="\$(prefix)/lib/modules-load.d/"
> +     ], [])
> +
> +     AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
> +         AC_MSG_ERROR([SYSTEMD_MODULES_LOAD is unset])
> +     ], [])
> +])
> +
> +AC_DEFUN([AX_CHECK_SYSTEMD], [
> +     AS_IF([test "x$systemd" = "xy" ], [
> +         AC_DEFINE([HAVE_SYSTEMD], [1], [Systemd available and enabled])
> +         systemd=y
> +         AX_CHECK_SYSTEMD_LIBS()
> +     ],[systemd=n])
> +])
> +
> +AC_DEFUN([AX_ENABLE_SYSTEMD], [
> +     AX_ENABLE_SYSTEMD_OPTS()
> +     AX_CHECK_SYSTEMD()
> +])
> +
> +AC_DEFUN([AX_ALLOW_SYSTEMD], [
> +     AX_ALLOW_SYSTEMD_OPTS()
> +     AX_CHECK_SYSTEMD()
> +])
> diff --git a/tools/configure.ac b/tools/configure.ac
> index 8a8831f..24d1109 100644
> --- a/tools/configure.ac
> +++ b/tools/configure.ac
> @@ -58,6 +58,7 @@ m4_include([../m4/extfs.m4])
>  m4_include([../m4/fetcher.m4])
>  m4_include([../m4/ax_compare_version.m4])
>  m4_include([../m4/expand_config.m4])
> +m4_include([../m4/systemd.m4])
>  
>  AX_XEN_EXPAND_CONFIG()
>  
> @@ -261,5 +262,7 @@ esac
>  # Checks for header files.
>  AC_CHECK_HEADERS([yajl/yajl_version.h sys/eventfd.h])
>  
> +dnl Once and if systemd is prevalent we can just use AX_ENABLE_SYSTEMD()
> +AX_ALLOW_SYSTEMD()

Shouldn't systemd init scripts be installed by default if systemd is
detect on the host?

Or are there cases of distros that install systemd but don't use it?

If I'm understanding this right, the user has to always pass
--enable-systemd in order to get systemd init scripts installed.

>  AC_OUTPUT()
>  
> diff --git a/tools/hotplug/common/Makefile b/tools/hotplug/common/Makefile
> index 4a63f40..45fd840 100644
> --- a/tools/hotplug/common/Makefile
> +++ b/tools/hotplug/common/Makefile
> @@ -1,5 +1,6 @@
>  XEN_ROOT = $(CURDIR)/../../..
>  include $(XEN_ROOT)/tools/Rules.mk
> +include $(XEN_ROOT)/config/Tools.mk

tools/Rules.mk already includes config/Tools.mk

>  
>  HOTPLUGPATH="hotplugpath.sh"
>  
> diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
> index 382a813..068e04a 100644
> --- a/tools/ocaml/xenstored/Makefile
> +++ b/tools/ocaml/xenstored/Makefile
> @@ -3,6 +3,11 @@ OCAML_TOPLEVEL = $(CURDIR)/..
>  include $(OCAML_TOPLEVEL)/common.make
>  
>  CFLAGS += -I$(XEN_ROOT)/tools/
> +CFLAGS-$(CONFIG_SYSTEMD)  += $(SYSTEMD_CFLAGS)
> +LDFLAGS-$(CONFIG_SYSTEMD) += $(SYSTEMD_LIBS)
> +
> +CFLAGS  += $(CFLAGS-y)
> +LDFLAGS += $(LDFLAGS-y)
>  
>  OCAMLINCLUDE += \
>       -I $(OCAML_TOPLEVEL)/libs/xb \
> diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
> index 21a3f11..6adac7f 100644
> --- a/tools/xenstore/Makefile
> +++ b/tools/xenstore/Makefile
> @@ -9,6 +9,12 @@ CFLAGS += -I.
>  CFLAGS += -I$(XEN_ROOT)/tools/
>  CFLAGS += $(CFLAGS_libxenctrl)
>  
> +CFLAGS-$(CONFIG_SYSTEMD)  += $(SYSTEMD_CFLAGS)
> +LDFLAGS-$(CONFIG_SYSTEMD) += $(SYSTEMD_LIBS)
> +
> +CFLAGS  += $(CFLAGS-y)
> +LDFLAGS += $(LDFLAGS-y)
> +
>  CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm 
> xenstore-chmod
>  CLIENTS += xenstore-write xenstore-ls xenstore-watch
>  
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.