2f61f36acc1
[gentoo.git] /
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit eutils flag-o-matic linux-info linux-mod multilib readme.gentoo-r1 toolchain-funcs
7
8 AUFS_VERSION="${PV%%_p*}"
9 # highest branch version
10 PATCH_MAX_VER=13
11 # highest supported version
12 KERN_MAX_VER=14
13 # lowest supported version
14 KERN_MIN_VER=0
15
16 DESCRIPTION="An entirely re-designed and re-implemented Unionfs"
17 HOMEPAGE="http://aufs.sourceforge.net/"
18 SRC_URI="https://dev.gentoo.org/~jlec/distfiles/aufs4-standalone-${PV}.tar.xz"
19
20 LICENSE="GPL-2"
21 SLOT="0"
22 KEYWORDS="~amd64 ~x86"
23 IUSE="debug doc fuse hfs inotify kernel-patch nfs pax_kernel ramfs"
24
25 DEPEND="
26         dev-util/patchutils
27         dev-vcs/git"
28 RDEPEND="
29         sys-fs/aufs-util
30         !sys-fs/aufs
31         !sys-fs/aufs2
32         !sys-fs/aufs3"
33
34 S="${WORKDIR}"/${PN}-standalone
35
36 MODULE_NAMES="aufs(misc:${S})"
37
38 pkg_setup() {
39         CONFIG_CHECK+=" !AUFS_FS"
40         use inotify && CONFIG_CHECK+=" ~FSNOTIFY"
41         use nfs && CONFIG_CHECK+=" EXPORTFS"
42         use fuse && CONFIG_CHECK+=" ~FUSE_FS"
43         use hfs && CONFIG_CHECK+=" ~HFSPLUS_FS"
44         use pax_kernel && CONFIG_CHECK+=" PAX" \
45                 && ERROR_PAX="Please use hardened sources"
46
47         # this is needed so merging a binpkg ${PN} is
48         # possible w/out a kernel unpacked on the system
49         [[ -n "$PKG_SETUP_HAS_BEEN_RAN" ]] && return
50
51         get_version
52         kernel_is lt 4 ${KERN_MIN_VER} 0 && \
53                 die "the kernel version isn't supported by upstream anymore. Please upgrade."
54         kernel_is gt 4 ${KERN_MAX_VER} 99 && die "kernel too new"
55
56         linux-mod_pkg_setup
57
58         if [[ "${KV_MINOR}" -gt "${PATCH_MAX_VER}" ]]; then
59                 PATCH_BRANCH="x-rcN"
60         elif [[ "${KV_MINOR}" == "1" ]] && [[ "${KV_PATCH}" -ge "13" ]]; then
61                 PATCH_BRANCH="${KV_MINOR}".13+
62         else
63                 PATCH_BRANCH="${KV_MINOR}"
64         fi
65
66         case ${KV_EXTRA} in
67                         "")
68                                 elog "It seems you are using vanilla-sources with aufs4"
69                                 elog "Please use sys-kernel/aufs-sources with USE=vanilla"
70                                 elog "This will save you the nasty reemerge of sys-fs/aufs4 on every kernel upgrade"
71                         ;;
72                         "-gentoo")
73                                 elog "It seems you are using gentoo-sources with aufs4"
74                                 elog "Please use sys-kernel/aufs-sources"
75                                 elog "This will save you the nasty reemerge of sys-fs/aufs4 on every kernel upgrade"
76                         ;;
77         esac
78
79         pushd "${T}" &> /dev/null || die
80         unpack ${A}
81
82         cd ${PN}-standalone || die
83
84         local module_branch=origin/${PN}.${PATCH_BRANCH}
85
86         einfo "Using ${module_branch} as patch source"
87         git checkout -q -b local-${PN}.${PATCH_BRANCH} ${module_branch} || die
88
89         combinediff \
90                 ${PN}-base.patch ${PN}-standalone.patch > "${T}"/combined-1.patch
91         combinediff \
92                 "${T}"/combined-1.patch ${PN}-mmap.patch \
93                 > ${PN}-standalone-base-mmap-combined.patch
94
95         if ! ( patch -p1 --dry-run --force -R -d ${KV_DIR} < ${PN}-standalone-base-mmap-combined.patch > /dev/null ); then
96                 if use kernel-patch; then
97                         cd ${KV_DIR}
98                         ewarn "Patching your kernel..."
99                         patch \
100                                 --no-backup-if-mismatch --force -p1 -R -d ${KV_DIR} \
101                                 < "${T}"/${PN}-standalone/${PN}-standalone-base-mmap-combined.patch \
102                                 > /dev/null
103                         epatch "${T}"/${PN}-standalone/${PN}-standalone-base-mmap-combined.patch
104                         ewarn "You need to compile your kernel with the applied patch"
105                         ewarn "to be able to load and use the aufs kernel module"
106                 else
107                         eerror "You need to apply a patch to your kernel to compile and run the ${PN} module"
108                         eerror "Either enable the kernel-patch useflag to do it with this ebuild"
109                         eerror "or apply "${T}"/${PN}-standalone/${PN}-standalone-base-mmap-combined.patch by hand"
110                         die "missing kernel patch, please apply it first"
111                 fi
112         fi
113
114         popd &> /dev/null
115         export PKG_SETUP_HAS_BEEN_RAN=1
116 }
117
118 set_config() {
119         for option in $*; do
120                 grep -q "^CONFIG_AUFS_${option} =" config.mk || \
121                         die "${option} is not a valid config option"
122                 sed "/^CONFIG_AUFS_${option}/s:=:= y:g" -i config.mk || die
123         done
124 }
125
126 src_prepare() {
127         local module_branch=origin/${PN}.${PATCH_BRANCH}
128
129         einfo "Using for module creation branch ${module_branch}"
130         git checkout -q -b local-gentoo ${module_branch} || die
131
132         # All config options to off
133         sed "s:= y:=:g" -i config.mk || die
134
135         set_config RDU BRANCH_MAX_127 SBILIST
136
137         use debug && set_config DEBUG
138         use fuse && set_config BR_FUSE POLL
139         use hfs && set_config BR_HFSPLUS
140         use inotify && set_config HNOTIFY HFSNOTIFY
141         use nfs && set_config EXPORT
142         use nfs && ( use amd64 || use ppc64 ) && set_config INO_T_64
143         use ramfs && set_config BR_RAMFS
144
145         use pax_kernel && epatch "${FILESDIR}"/pax-4.patch
146
147         sed \
148                 -e "s:aufs.ko usr/include/linux/aufs_type.h:aufs.ko:g" \
149                 -i Makefile || die
150
151         eapply_user
152 }
153
154 src_compile() {
155         local ARCH=x86
156
157         emake \
158                 CC=$(tc-getCC) \
159                 LD=$(tc-getLD) \
160                 LDFLAGS="$(raw-ldflags)" \
161                 ARCH=$(tc-arch-kernel) \
162                 CONFIG_AUFS_FS=m \
163                 KDIR="${KV_OUT_DIR}"
164 }
165
166 src_install() {
167         linux-mod_src_install
168
169         use doc && dodoc -r Documentation
170
171         use kernel-patch || \
172                 doins "${T}"/${PN}-standalone/${PN}-standalone-base-mmap-combined.patch
173
174         dodoc \
175                 Documentation/filesystems/aufs/README \
176                 "${T}"/${PN}-standalone/{aufs4-loopback,vfs-ino,tmpfs-idr}.patch
177
178         readme.gentoo_create_doc
179 }
180
181 pkg_postinst() {
182         readme.gentoo_print_elog
183         linux-mod_pkg_postinst
184 }