summaryrefslogtreecommitdiffstats
path: root/bashrc
blob: e3ef84b042b67a528f2771d610bc122cd6b97ef9 (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
#!/bin/bash

if ! type einfo >/dev/null 2>&1 ; then
	. /etc/init.d/functions.sh
fi

autopatch() {
	local diff level p patches patchdir

	[[ ! -d "$PATCH_OVERLAY" ]] && return

	patchdir="${PATCH_OVERLAY}/${CATEGORY}/${PN}"
	patches=$(ls -1 ${patchdir}/{${PN},${P},${PF}}-[^0-9]*.{patch,diff} 2>/dev/null)
	[[ $patches == "" ]] && return

	if ! pushd ${S} &>/dev/null; then
		eerror "FAILED TO cd $S"
		return
	fi

	for p in ${patches}; do
		p=$(basename $p)
		diff=${patchdir}/${p}
		if [[ -e $diff ]] && [ ! -e ${S}/.${p} ]; then
			for level in 0 1 2 3 4; do
				patch -g0 --dry -p${level} >/dev/null < $diff

				if [ $? = 0 ]; then
					ebegin "auto patching (-p${level}) ${p}"
					patch -g0 -p${level} < $diff > /dev/null
					eend $?
					touch ${S}/.${p}

					continue 2
				fi
			done

			eerror "FAILED auto patching $p"
		else
			[[ ! -e $diff ]] && eerror "$diff does not exist, unable to auto patch"
		fi
	done

	popd &>/dev/null
}

#ewarn "at $EBUILD_PHASE"

case $EBUILD_PHASE in
	compile)	
		einfo "Checking for auto patches in ${PATCH_OVERLAY}/${CATEGORY}/${PN}"

		if [[ ! -d "$PATCH_OVERLAY" ]]; then
			eerror "PATCH_OVERLAY=$PATCH_OVERLAY is not a dir"
		else
			PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin
			autopatch
		fi
	;;
esac