summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: dc8bb8299784c1a19e8e3d7748e2d0df9493d64b (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
# Maintainer: Sam Mulvey (Refutationalist) <archlinux@sammulvey.com>

# Build Options
# I'm not going to lie, this is three packages in a coat.
_build_pvh=${build_pvh:-true}
_build_pv32=${build_pv32:-true}
_build_pv64=${build_pv64:-true}

pkgbase=xen-grub
pkgver=2.12.r0.g5ca9db2
_pkgver=2.12
pkgrel=1
pkgdesc="a version of GRUB2 for booting Xen PV and PVH domUs"
arch=(x86_64)
url="https://www.gnu.org/software/grub/"
license=('GPL-3.0-or-later')
makedepends=(git xz python texinfo gettext device-mapper)
depends=(xen)
options=(!buildflags !strip)

# Okay, what packages am I building?
pkgname=()
[ "${_build_pvh}"  == "true" ] && pkgname+=("xen-grub-pvh")
[ "${_build_pv32}" == "true" ] && pkgname+=("xen-grub-pv32")
[ "${_build_pv64}" == "true" ] && pkgname+=("xen-grub-pv64")



source=(
	"git+https://git.savannah.gnu.org/git/grub.git#tag=grub-${_pkgver}"
	"git+https://git.savannah.gnu.org/git/gnulib.git"
	"grub.cfg")

# Add signed commit checking?

sha512sums=('SKIP'
            'SKIP'
            '02976adbf68af0ec13ef8910fc6c409591e9528418e3157adb7d8a4a9ae1a43fed4a2fe372d9df8b0520a9edd7e26cfb22ca101f1c4c9be7e5ace61508fa56c8')


pkgver() {
	cd "${srcdir}/grub"
	git describe --long --abbrev=7 | sed 's/^grub-//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

# Shamelessly stolen from the Arch Linux grub package
_backports=(
	# current git master for loads of security fixes
	# https://lists.gnu.org/archive/html/grub-devel/2025-02/msg00024.html
	"grub-${_pkgver}..56ccc5ed569869fd735074ccebeaa7aab058342d"
)
_reverts=(
)


prepare() {
	cd "$srcdir/grub"


	# Continuing the be shameless stolen from the GRUB in the repos.
	local _c _l 

	echo "--> Apply backports..." 
	for _c in "${_backports[@]}"; do 
		if [[ "${_c}" == *..* ]]; then _l='--reverse'; else _l='--max-count=1'; fi 
		git log --oneline "${_l}" "${_c}" 
		git cherry-pick --mainline 1 --no-commit "${_c}" 
	done 

	echo "--> Apply reverts..." 
	for _c in "${_reverts[@]}"; do 
		if [[ "${_c}" == *..* ]]; then _l='--reverse'; else _l='--max-count=1'; fi
		git log --oneline "${_l}" "${_c}"
		git revert --mainline 1 --no-commit "${_c}"
	done
	
	./bootstrap  \
		--gnulib-srcdir="${srcdir}/gnulib/" \
		--no-git
	cp "${srcdir}/grub.cfg" .

	cd ..
	echo "dividing source trees"
	[ "${_build_pvh}"  == "true" ] && cp -R grub grub-pvh
	[ "${_build_pv32}" == "true" ] && cp -R grub grub-pv32
	[ "${_build_pv64}" == "true" ] && cp -R grub grub-pv64
}

build() {
	cd "${srcdir}"

	if [ "${_build_pvh}" == "true" ]; then

		echo "--> Building PVH"

		cd grub-pvh

		TARGET_LDFLAGS=-static ./configure \
			--with-platform=xen_pvh \
			--enable-device-mapper

		# this will compile a ton of stuff we'll never, ever need.
		make

		# make the bootloader image
		./grub-mkstandalone \
			--grub-mkimage=./grub-mkimage \
			-o pvhgrub \
			-O i386-xen_pvh \
			-d ./grub-core/ "/boot/grub/grub.cfg=./grub.cfg"

		cd ..
	fi

	if [ "${_build_pv32}" == "true" ]; then

		echo "--> Building PV32"

		cd "${srcdir}/grub-pv32"

		TARGET_LDFLAGS=-static ./configure \
			--target=i386 \
			--with-platform=xen \
			--enable-device-mapper

		make

		./grub-mkstandalone \
			--grub-mkimage=./grub-mkimage \
			-o pvgrub32 \
			-O i386-xen \
			-d ./grub-core/ "/boot/grub/grub.cfg=./grub.cfg" \
			--locale-directory=/usr/share/locale

		cd ..


	fi

	if [ "${_build_pv64}" == "true" ]; then

		echo "--> Building PV64"

		cd "${srcdir}/grub-pv64"

		TARGET_LDFLAGS=-static ./configure \
			--target=amd64 \
			--with-platform=xen \
			--enable-device-mapper

		make

		./grub-mkstandalone \
			--grub-mkimage=./grub-mkimage \
			-o pvgrub64 \
			-O x86_64-xen \
			-d ./grub-core/ "/boot/grub/grub.cfg=./grub.cfg" \
			--locale-directory=/usr/share/locale

			cd ..


	fi


}

package_xen-grub-pvh() {
	pkgdesc="GRUB bootloader for Xen PVH domUs"
	provides=(xen-pvhgrub)
	conflicts=(xen-pvhgrub)

	cd "$srcdir/${_srcname}"
	mkdir -p "${pkgdir}/usr/lib/xen/boot"
	install -m644 "${srcdir}/grub-pvh/pvhgrub" "${pkgdir}/usr/lib/xen/boot"
}

package_xen-grub-pv32() {
	pkgdesc="GRUB bootloader for Xen 32bit PV domUs"

	cd "$srcdir/${_srcname}"
	mkdir -p "${pkgdir}/usr/lib/xen/boot"
	install -m644 "${srcdir}/grub-pv32/pvgrub32" "${pkgdir}/usr/lib/xen/boot"

}

package_xen-grub-pv64() {
	pkgdesc="GRUB bootloader for Xen 64bit PV domUs"

	cd "$srcdir/${_srcname}"
	mkdir -p "${pkgdir}/usr/lib/xen/boot"
	install -m644 "${srcdir}/grub-pv64/pvgrub64" "${pkgdir}/usr/lib/xen/boot"

}