summaryrefslogtreecommitdiffstats
path: root/commands/build-arch
blob: 5b910aba61ea78a3dcf06b53b7fde1669cb1fda5 (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
#!/bin/sh
# This is a wrapper script to build a specific architecture.
#
# It takes the architecture to be built as parameter and that architecture
# needs to be listed in kernel-versions.
# It expects to have the unpacked kernel packages for the architecture in
# e.g. ../alpha. modules.dep files have to be put in there too if they are
# not shipped in the .deb (varies)
#
# dpkg-cross must be installed, but you do not need a cross compiler.

set -e

buildpackage () {
	dpkg-buildpackage -d -us -uc -rfakeroot -tc -I $@
}

# Build source package. Binaries are built below.
buildpackage -S

# Directory for stubs, added to PATH.
arch="$1"
trap 'rm -rf $tmpdir' EXIT 
tmpdir=$(mktemp -d)
PATH=$PATH:$tmpdir
export PATH

if [ -z "$arch" ]; then
	echo "** Error: architecture not specified"
	exit 1
fi
if ! cut -d ' ' -f 1 kernel-versions | grep -v "^$arch$"; then
	echo "** Error: arch $arch not listed in kernel-versions"
	exit 1
fi

if [ "$arch" != "`dpkg-architecture -qDEB_BUILD_ARCH`" ]; then
	# Generate cross-compiler stub, this is needed to get the
	# debian build system to cross-build the given arch w/o a
	# real cross compiler.
	CC=$tmpdir/$arch-linux-gcc
	echo "#!/bin/sh" > $CC
	echo "echo $arch-linux" >> $CC
	chmod +x $CC
	# Not only must it be in the path, but CC needs to be
	# exported as well.
	export CC
else
	# native build
	unset CC
fi
	
if [ -d ../$arch ]; then
	export SOURCEDIR=`pwd`/../$arch
else
	unset SOURCEDIR
fi

if [ "$arch" != "`dpkg-architecture -qDEB_BUILD_ARCH`" ]; then
	if [ -z "$SOURCEDIR" ]; then
		echo "** Warning: no SOURCEDIR for arch $arch" >&2
	fi
	buildpackage -b -a$arch
else
	# native build
	buildpackage
fi