# Archived: Downstream port, only for testing. Use mainline port!
# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/i9100_defconfig

maintainer=""
pkgname=linux-samsung-i9100-downstream
pkgver=3.0.101
pkgrel=0
pkgdesc="Samsung Galaxy SII kernel fork"
arch="armv7"
_carch="arm"
_flavor="samsung-i9100"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev devicepkg-dev
	findutils busybox-static-armv7"

# Source
_repository="android_kernel_samsung_smdk4412"
_commit="349a3e91e76d17e67ef6213e1f6712e700695631"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/LineageOS/$_repository/archive/$_commit.tar.gz
	$_config
	gcc7-give-up-on-ilog2-const-optimizations.patch
	gcc8-fix-put-user.patch
	linux3.0-8933-1-replace-Sun-Solaris-style-flag-on-section.patch
	linux3.4-fix-piggy.gzip.S.patch
	init
"

builddir="$srcdir/$_repository-$_commit"

prepare_isorec() {
	# Use Alpine's busybox.static instead of the pre-compiled busybox shipped
	# with the source
	cp -v /usr/$(arch_to_hostspec $arch)/bin/busybox.static \
		"$builddir"/usr/galaxys2_initramfs_files/busybox

	# do not use ramdisk.cpio and ramdisk-recovery-device.cpio, always use
	# the initramfs from the recovery partition ("isorec"), so we can build
	# it later and independently from the kernel. also directly boot that
	# partition, not only when the recovery key combination was used.
	cd "$builddir"/usr/
	mv galaxys2_initramfs.list galaxys2_initramfs.list_old
	grep -v "../../ramdisk" galaxys2_initramfs.list_old > galaxys2_initramfs.list
	cp -v "$srcdir"/init "$builddir"/usr/galaxys2_initramfs_files/init

	# Paths supplied to gen_initramfs_list.sh are prefixed with "source/".
	ln -s "$builddir" "$builddir"/source

	cd "$builddir"
}

prepare() {
	default_prepare
	prepare_isorec

	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS

	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor"
}

sha512sums="
285ffd2c82d0444b99da583573d19443b73de22d7382aae54413af229a28bebf4ea32ecbe248ae54ae64bbbc0af7d722b1ef86d5dd099e2990dcc6284fb195fa  linux-samsung-i9100-downstream-349a3e91e76d17e67ef6213e1f6712e700695631.tar.gz
da19880398a1ed7728da141fb74c49d21111757c1aa64f9e86f8ab6ca743f9b0f7bf22d9142aadee93157ff597ff495df30ceeca92b050c8cc3e7d13a7e8fbf9  config-samsung-i9100.armv7
77eba606a71eafb36c32e9c5fe5e77f5e4746caac292440d9fb720763d766074a964db1c12bc76fe583c5d1a5c864219c59941f5e53adad182dbc70bf2bc14a7  gcc7-give-up-on-ilog2-const-optimizations.patch
197d40a214ada87fcb2dfc0ae4911704b9a93354b75179cd6b4aadbb627a37ec262cf516921c84a8b1806809b70a7b440cdc8310a4a55fca5d2c0baa988e3967  gcc8-fix-put-user.patch
66ab793bb1fa50a07f10e2cdb0f49ea05a787c6b1fe5358e69a76e43295ac5be3b68cdf6a882e868bfe6969cac981c5545587cd57eee4b5cec26078ae0ecaa1c  linux3.0-8933-1-replace-Sun-Solaris-style-flag-on-section.patch
080745ca4ecaa804ee1df26ea81975ca93b74372e0c08322a6c481e97807495ae6ceb6cc77653afa24f9f2df45da8ebf8e5de6b06037fbb08e0279877ce42188  linux3.4-fix-piggy.gzip.S.patch
dd4094d5f4ec281d32f12af88cb22a782e497c8e52f69cf60b73ac7d6171fc95f1f8040b3d0ad2ff3f016d22ac1d91c5b522e5d03203534a76742bc55a082af5  init
"
