summaryrefslogtreecommitdiff
path: root/eclass/spl-zfs-userspace.eclass
blob: 33c211a6c985c2899f1002318c6a227dfd79f76b (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright 2004-2012 Sabayon Linux
# Distributed under the terms of the GNU General Public License v2
# $

AT_M4DIR="config"
AUTOTOOLS_AUTORECONF="1"
AUTOTOOLS_IN_SOURCE_BUILD="1"

inherit eutils flag-o-matic git-2 linux-mod autotools-utils

# export all the available functions here
EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install src_test

# @ECLASS-VARIABLE: ZFS_GIT_REPO
# @DESCRIPTION:
# Identified the ZFS Git repo from where to pull
ZFS_GIT_REPO="${ZFS_GIT_REPO:-}"

# @ECLASS-VARIABLE: ZFS_GIT_BRANCH
# @DESCRIPTION:
# Identified the ZFS Git branch from where to pull
ZFS_GIT_BRANCH="${ZFS_GIT_BRANCH:-}"

# @ECLASS-VARIABLE: ZFS_GIT_COMMIT
# @DESCRIPTION:
# Identified the ZFS Git commit from where to pull
ZFS_GIT_COMMIT="${ZFS_GIT_COMMIT:-}"

# @ECLASS-VARIABLE: SPL_GIT_REPO
# @DESCRIPTION:
# Identified the SPL Git repo from where to pull
SPL_GIT_REPO="${SPL_GIT_REPO:-}"

# @ECLASS-VARIABLE: SPL_GIT_BRANCH
# @DESCRIPTION:
# Identified the SPL Git branch from where to pull
SPL_GIT_BRANCH="${SPL_GIT_BRANCH:-}"

# @ECLASS-VARIABLE: SPL_GIT_COMMIT
# @DESCRIPTION:
# Identified the SPL Git commit from where to pull
SPL_GIT_COMMIT="${SPL_GIT_COMMIT:-}"

SRC_URI=""

DESCRIPTION="The Solaris Porting Layer and ZFS Filesystem userspace utilities"
HOMEPAGE="http://zfsonlinux.org/"

LICENSE="|| ( GPL-2 GPL-3 ) CDDL"
SLOT="0"
KEYWORDS="~amd64 ~x86"

IUSE="custom-cflags debug dracut +rootfs test test-suite static-libs"
DEPEND+=" sys-apps/util-linux[static-libs?]
	sys-libs/zlib[static-libs(+)?]"
RDEPEND+=" ${DEPEND}
	!sys-fs/zfs-fuse
	!prefix? ( sys-fs/udev )
	test-suite? (
		sys-apps/gawk
		sys-apps/util-linux
		sys-devel/bc
		sys-block/parted
		sys-fs/lsscsi
		sys-fs/mdadm
		sys-process/procps
		virtual/modutils
		)
	rootfs? (
		app-arch/cpio
		app-misc/pax-utils
	)"
DEPEND+=" test? ( sys-fs/mdadm )"

SPL_S="${S}/spl-src"
ZFS_S="${S}/zfs-src"

spl-zfs-userspace_pkg_setup() {
	CONFIG_CHECK="
		!DEBUG_LOCK_ALLOC
		BLK_DEV_LOOP
		EFI_PARTITION
		MODULES
		KALLSYMS
		ZLIB_DEFLATE
		ZLIB_INFLATE"
	kernel_is ge 2 6 26 || die "Linux 2.6.26 or newer required"
	check_extra_config
}

spl-zfs-userspace_src_unpack() {
	# unpack spl
	EGIT_REPO_URI="${SPL_GIT_REPO}" \
	EGIT_BRANCH="${SPL_GIT_BRANCH}" \
	EGIT_COMMIT="${SPL_GIT_COMMIT}" \
	EGIT_SOURCEDIR="${SPL_S}" \
		git-2_src_unpack

	# unpack zfs
	EGIT_REPO_URI="${ZFS_GIT_REPO}" \
	EGIT_BRANCH="${ZFS_GIT_BRANCH}" \
	EGIT_COMMIT="${ZFS_GIT_COMMIT}" \
	EGIT_SOURCEDIR="${ZFS_S}" \
		git-2_src_unpack
}

_zfs_src_prepare() {
	# Workaround for hard coded path
	sed -i "s|/sbin/lsmod|/bin/lsmod|" "${ZFS_S}"/scripts/common.sh.in || die
	# Workaround rename
	sed -i "s|/usr/bin/scsi-rescan|/usr/sbin/rescan-scsi-bus|" "${ZFS_S}"/scripts/common.sh.in || die
	cd "${ZFS_S}" && ECONF_SOURCE="${ZFS_S}" autotools-utils_src_prepare
}

_spl_src_prepare() {
	# Workaround for hard coded path
	sed -i "s|/sbin/lsmod|/bin/lsmod|" "${SPL_S}"/scripts/check.sh || die
	cd "${SPL_S}" && ECONF_SOURCE="${SPL_S}" autotools-utils_src_prepare
}

spl-zfs-userspace_src_prepare() {
	_spl_src_prepare
	_zfs_src_prepare
}

_zfs_src_configure() {
	use custom-cflags || strip-flags
	set_arch_to_kernel

	local myeconfargs=(
		--bindir="${EPREFIX}/bin"
		--sbindir="${EPREFIX}/sbin"
		--with-config=user
		--with-linux="${KV_DIR}"
		--with-linux-obj="${KV_OUT_DIR}"
		--with-udevdir="${EPREFIX}/lib/udev"
		$(use_enable debug)
		--with-spl="${SPL_S}"
	)
	cd "${ZFS_S}" && ECONF_SOURCE="${ZFS_S}" autotools-utils_src_configure
}

_spl_src_configure() {
	use custom-cflags || strip-flags
	set_arch_to_kernel

	local myeconfargs=(
		--bindir="${EPREFIX}/bin"
		--sbindir="${EPREFIX}/sbin"
		--with-config=all
		--with-linux="${KV_DIR}"
		--with-linux-obj="${KV_OUT_DIR}"
		$(use_enable debug)
		--with-config=user
	)
	cd "${SPL_S}" && ECONF_SOURCE="${SPL_S}" autotools-utils_src_configure
}

spl-zfs-userspace_src_configure() {
	_spl_src_configure
	_zfs_src_configure
}

_zfs_src_compile() {
	cd "${ZFS_S}" && ECONF_SOURCE="${ZFS_S}" autotools-utils_src_compile
}

_spl_src_compile() {
	cd "${SPL_S}" && ECONF_SOURCE="${SPL_S}" autotools-utils_src_compile
}

spl-zfs-userspace_src_compile() {
	_spl_src_compile
	_zfs_src_compile
}

_zfs_src_install() {
	cd "${ZFS_S}" && ECONF_SOURCE="${ZFS_S}" autotools-utils_src_install
	gen_usr_ldscript -a uutil nvpair zpool zfs
	use dracut || rm -rf "${ED}usr/share/dracut"
	use test-suite || rm -rf "${ED}usr/libexec"

	if use rootfs
	then
		doinitd "${FILESDIR}/zfs-shutdown"
		exeinto /usr/share/zfs
		doexe "${FILESDIR}/linuxrc"
	fi
}

_spl_src_install() {
	cd "${SPL_S}" && ECONF_SOURCE="${SPL_S}" autotools-utils_src_install
	rm -rf "${ED}"/usr # make sure
}

spl-zfs-userspace_src_install() {
	_spl_src_install
	_zfs_src_install
}

spl-zfs-userspace_src_test() {
	if [[ ! -e /proc/modules ]]
	then
		die  "Missing /proc/modules"
	elif [[ $UID -ne 0 ]]
	then
		ewarn "Cannot run make check tests with FEATURES=userpriv."
		ewarn "Skipping make check tests."
	elif grep -q '^spl ' /proc/modules
	then
		ewarn "Cannot run make check tests with module spl loaded."
		ewarn "Skipping make check tests."
	else
		cd "${SPL_S}" && ECONF_SOURCE="${SPL_S}" autotools-utils_src_test
		cd "${ZFS_S}" && ECONF_SOURCE="${ZFS_S}" autotools-utils_src_test
	fi
}