summaryrefslogtreecommitdiff
path: root/build_stage1_package.sh
blob: dd49693ae7afe9725a5a295c4dc2d7b4b5f81807 (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
#!/bin/sh

. "./default.conf"

# builds and installs one package for stage 1

if test "$(id -u)" = 0; then
	sudo -u cross "$0" "$1"
	exit 0
fi

PACKAGE=$1

export PATH="$XTOOLS_ARCH/bin:${PATH}"

NEEDS_YAOURT=0
NOPARALLEL_BUILD=0

if test ! -f "$STAGE1_CHROOT/packages/$TARGET_CPU/$PACKAGE.pkg.tar.xz"; then
	echo "Building package $PACKAGE."

	cd $STAGE1_BUILD || exit 1
	
	rm -rf "$PACKAGE"
	
	# source the package specific configuration
	
	PACKAGE_CONF="$SCRIPT_DIR/packages-$TARGET_CPU-stage1/$PACKAGE"
	if test -f "$PACKAGE_CONF"; then
		. "$PACKAGE_CONF"
	fi

	# get the package build description
	
	if test $NEEDS_YAOURT; then
		yaourt -G "$PACKAGE"
	else
		asp export "$PACKAGE"
	fi
	cd "$PACKAGE" || exit 1

	# if exists packages32 diff-PKGBUILD, attach at the end
	# (we assume, we build only 'core' packages)
	DIFF_PKGBUILD="$ARCHLINUX32_PACKAGES/core/$PACKAGE/PKGBUILD"
	if test -f "$DIFF_PKGBUILD"; then
		cat "$DIFF_PKGBUILD" >> PKGBUILD
	fi

	sed -i "/^arch=[^#]*any/!{/^arch=(/s/(/($TARGET_CPU /}" PKGBUILD

	if test $NOPARALLEL_BUILD = 0; then
		CPUS=$(nproc)
	else
		CPUS=1
	fi
	sed -i "s@^#MAKEFLAGS=.*@MAKEFLAGS=\"-j$CPUS\"@" $STAGE1_BUILD/makepkg-$TARGET_CPU.conf

	$STAGE1_BUILD/makepkg-$TARGET_CPU -C --config $STAGE1_BUILD/makepkg-$TARGET_CPU.conf \
		--skipchecksums --skippgpcheck --nocheck > "$PACKAGE.log" 2>&1
	RES=$?
	
	tail "$PACKAGE.log"

	if test $RES = 0; then
		rm -f ./*debug*.pkg.tar.xz
		cp -v ./*.pkg.tar.xz $STAGE1_CHROOT/packages/$TARGET_CPU/.
	fi
fi

echo "Built package $PACKAGE."