summaryrefslogtreecommitdiffstats
path: root/core/modules/systemd/module.build
blob: 5d634f0e10d241725e1905e3ab1433abd5fd1de9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#tool/distro specific functions for fetching, building and installing dependencies

fetch_source () {
	# systemd
	download_untar "$REQUIRED_URL" "src/"

	# starting with systemd 212 a new way of setting global environment is supported
	# meaning we don't have to apply the patch needed til that version.
	# patch src/core/socket.c if activated in the config file
	if [ "x$REQUIRED_XATTR_PATCH" = "xyes" ]; then
		pinfo "Patching 'src/core/socket.c' ..."
		# patch it
		if [ -e "src/systemd-$REQUIRED_VERSION/src/core/socket.c" ]; then
			sed -i 's/^#include <attr\/xattr.h>$/#include <sys\/xattr.h>\n#include <attr\/xattr.h>/g' "src/systemd-$REQUIRED_VERSION/src/core/socket.c" \
				|| perror "Could not patch 'src/systemd-$REQUIRED_VERSION/src/core/socket.c'"
		else
			perror "'src/systemd-$REQUIRED_VERSION/src/core/socket.c' does not exist."
		fi
	fi
	# now check if the old fix needs to be applied
	# NOTE: only for systemd-204
	if [ "x${REQUIRED_VERSION#systemd-}" = "x204" ]; then
		# Patch PATH, HOME, USER environment
		# TODO: Newer systemd versions support DefaultEnvironment=xxx in /etc/systemd/system.conf
		# However, there were lots of changes after systemd 204, so we didn't update yet
		# See http://cgit.freedesktop.org/systemd/systemd/tree/NEWS for changes.
		patch -p0 src/systemd-*/src/core/main.c < ${MODULE_DIR}/systemd-openslx.patch || perror "Failed to apply openslx systemd patch."
		# fix mtd_probe.h missing an include for stdint.h, those types probably used to
		# be defined elsewhere and that was change with newer libc versions
		patch -p0 src/systemd-*/src/udev/mtd_probe/mtd_probe.h < ${MODULE_DIR}/systemd-204-mtd_probe.patch || perror "Failed to apply mtd_probe.h patch."
		# systemd-204 requires gperf 3.0.4 for generating internal code,
		# starting with ubuntu 17.10, gperf is only available in version 3.1.1.
		# launchpad has the correct version: https://launchpad.net/ubuntu/artful/amd64/gperf/3.0.4-2
		if which gperf &> /dev/null; then
			LOCAL_GPERF_VER="$(gperf --version | head -1 | awk '{print $3}')"
			if [ "x${LOCAL_GPERF_VER}" != "x3.0.4" ]; then
				# bad version, no force removal
				perror "gperf version '3.0.4' expected but '${LOCAL_GPERF_VER}' is installed. Please remove it and try again."
			fi
		else
			# no gperf installed, install it from launchpad
			REQUIRED_GPERF_URL="http://launchpadlibrarian.net/214035609/gperf_3.0.4-2_amd64.deb"
			pinfo "Downloading gperf from '${REQUIRED_GPERF_URL}'..."
			if ! wget -P "${MODULE_WORK_DIR}" "${REQUIRED_GPERF_URL}"; then
				perror "Failed to download '${REQUIRED_GPERF_URL}'."
			fi
			pinfo "Installing gperf from '${MODULE_WORK_DIR}/${REQUIRED_GPERF_URL##*/}'..."
			if ! dpkg -i "${MODULE_WORK_DIR}/${REQUIRED_GPERF_URL##*/}"; then
				perror "Failed to install '${MODULE_WORK_DIR}/${REQUIRED_GPERF_URL##*/}'."
			fi
		fi

	elif  [ -e "${MODULE_DIR}/systemd-openslx-${REQUIRED_VERSION#systemd-}.patch" ]; then
		patch -p0 src/systemd-*/src/basic/path-util.h < "${MODULE_DIR}/systemd-openslx-${REQUIRED_VERSION#systemd-}.patch" || perror "Failed to apply openslx systemd patch."
	else
		# TODO use the above hint for setting environmenet through /etc/systemd/system.conf
		pwarning "OpenSLX patch for systemd missing..."
	fi

	# libkmod
	download_untar "$REQUIRED_LIBKMOD_URL" "src/"
}

build () {
	#build libkmod
	pinfo "Building libkmod"
	cd "${MODULE_WORK_DIR}/src/$REQUIRED_LIBKMOD_VERSION"
	./configure || perror "./configure kmod failed."
	make || perror "kmod make failed."
	DESTDIR="${MODULE_BUILD_DIR}" make install || perror "kmod make install failed."
	cd - &> /dev/null

	#build systemd
	pinfo "Building systemd"
	cd "${MODULE_WORK_DIR}/src/systemd-$REQUIRED_VERSION"
	pinfo "calling configure in ${MODULE_WORK_DIR}/src/systemd-$REQUIRED_VERSION"

	# Save potentially pre-used paths/flages
	OLDLDFLAGS="$LDFLAGS"
	OLDCPPFLAGS="$CPPFLAGS"
	OLDPKG_CONFIG_PATH="$PKG_CONFIG_PATH"
	OLDLD_LIBRARY_PATH="$LD_LIBRARY_PATH"

	export LDFLAGS="$LDFLAGS -L${MODULE_BUILD_DIR}/usr/lib"
	export CPPFLAGS="-I${MODULE_BUILD_DIR}/usr/include"
	export PKG_CONFIG_PATH="${MODULE_BUILD_DIR}/usr/lib64/pkgconfig:${MODULE_BUILD_DIR}/usr/lib/pkgconfig"
	export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${MODULE_BUILD_DIR}/usr/lib:${MODULE_BUILD_DIR}/usr/lib64"

	[ ! -e "./configure" ] && ./autogen.sh

	./configure \
		--disable-manpages \
		--enable-split-usr \
		--sysconfdir="/etc" \
		--enable-gtk-doc-html=no \
		--disable-nls \
		--disable-microhttpd \
		--disable-bootchart \
		--disable-quotacheck \
		--disable-hostnamed \
		--disable-timedated \
		--disable-localed \
		--disable-coredump \
		--disable-keymap \
		--disable-hwdb \
		--disable-ldconfig \
		--disable-networkd \
		--disable-resolved \
		--disable-timesyncd \
		--disable-importd \
		--disable-rfkill \
		--disable-backlight \
		--disable-firstboot \
		--disable-nss-systemd \
		--without-python \
		--enable-blkid \
		--enable-acl \
		--enable-pam \
		--enable-kmod \
		--with-pamlibdir="$SYS_PAM_MODULES_PATH" \
			|| perror "configure failed."

	pinfo "calling make"
	make || perror "make failed."
	pinfo "calling make install"
	DESTDIR="${MODULE_BUILD_DIR}" make install || perror "make install failed."
	cd - &> /dev/null
	# Nonsense in our env
	rm -f -- "${MODULE_BUILD_DIR}/usr/lib/tmpfiles.d/etc.conf"
	rm -f -- "${MODULE_BUILD_DIR}/usr/lib/tmpfiles.d/systemd-remote.conf"

	# Restore used flags/paths:
	export LDFLAGS="$OLDLDFLAGS"
	export CPPFLAGS="$OLDCPPFLAGS"
	export PKG_CONFIG_PATH="$OLDPKG_CONFIG_PATH"
	export LD_LIBRARY_PATH="$OLDLD_LIBRARY_PATH"
}

post_copy() {
	add_user "kvm"
	add_user "systemd-journal-upload"
}