~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to scripts/setup-partial-armhf-chroot.sh

  • Committer: Tarmac
  • Author(s): Simon Fels
  • Date: 2016-03-02 14:25:01 UTC
  • mfrom: (119.2.3 support-cross-compile)
  • Revision ID: tarmac-20160302142501-wfzthvz4e91grs7w
Add cross-compilation support.

Approved by PS Jenkins bot, Thomas Voß.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
# TODO: Rename this file without "armhf" when it's safe to do so.
 
4
#
 
5
 
 
6
set -e
 
7
 
 
8
name=${0}
 
9
 
 
10
usage() {
 
11
    echo "Usage: ${name} [options] mychroot-dir"
 
12
    echo "options:"
 
13
    echo "      -a arch Select architecture, i.e. armhf, arm64, ppc... Default is armhf"
 
14
    echo "      -d dist Select distribution, i.e. vivid, wily. Default is vivid"
 
15
    echo "      -r rep  Select an additional repository for bootstrap. Default is none"
 
16
    echo
 
17
    echo "please supply at least a directory to create partial chroot in. (eg, ./setup-partial-armhf-chroot.sh mychroot-dir)"
 
18
}
 
19
 
 
20
# Default to vivid as we don't seem to have any working wily devices right now.
 
21
# Also Jenkins expects this script to default to vivid (TODO: update CI?)
 
22
arch=armhf
 
23
dist=vivid
 
24
sourceid=0
 
25
repositories=
 
26
sources=
 
27
 
 
28
while getopts a:d:r:h opt; do
 
29
    case $opt in
 
30
        a)
 
31
            arch=$OPTARG
 
32
            ;;
 
33
        d)
 
34
            dist=$OPTARG
 
35
            ;;
 
36
        r)
 
37
            repositories="$repositories $OPTARG"
 
38
            ((++sourceid))
 
39
            sources="$sources source$sourceid"
 
40
            ;;
 
41
        :)
 
42
            echo "Option -$OPTARG requires an argument" 
 
43
            usage
 
44
            exit 1
 
45
            ;;
 
46
        h)
 
47
            usage
 
48
            exit 0
 
49
            ;;
 
50
        \?)
 
51
            echo "Invalid option: -$OPTARG" 
 
52
            usage
 
53
            exit 1
 
54
            ;;
 
55
    esac
 
56
done
 
57
 
 
58
shift $((OPTIND-1))
 
59
 
 
60
if [ -z ${1} ]; then
 
61
    usage
 
62
    exit 1
 
63
fi
 
64
 
 
65
directory=${1}
 
66
echo "creating phablet-compatible $arch partial chroot for aethercast compilation in directory ${directory}"
 
67
 
 
68
if [ ! -d ${directory} ]; then
 
69
    mkdir -p ${directory} 
 
70
fi
 
71
 
 
72
DEBCONTROL=$(pwd)/../debian/control
 
73
 
 
74
pushd ${directory} > /dev/null
 
75
 
 
76
# Empty dpkg status file, so that ALL dependencies are listed with dpkg-checkbuilddeps
 
77
echo "" > status
 
78
 
 
79
# Manual error code checking is needed for dpkg-checkbuilddeps
 
80
set +e
 
81
 
 
82
# Parse dependencies from debian/control
 
83
# dpkg-checkbuilddeps returns non-zero when dependencies are not met and the list is sent to stderr
 
84
builddeps=$(dpkg-checkbuilddeps -a ${arch} --admindir=. ${DEBCONTROL} 2>&1 )
 
85
if [ $? -eq 0 ] ; then
 
86
    exit 0 
 
87
fi
 
88
echo "${builddeps}"
 
89
 
 
90
# now turn exit on error option
 
91
set -e
 
92
 
 
93
# Sanitize dependencies list for submission to multistrap
 
94
# build-essential is not needed as we are cross-compiling
 
95
builddeps=$(echo ${builddeps} | sed -e 's/dpkg-checkbuilddeps://g' \
 
96
                                    -e 's/error://g' \
 
97
                                    -e 's/Unmet build dependencies://g' \
 
98
                                    -e 's/build-essential:native//g')
 
99
builddeps=$(echo ${builddeps} | sed 's/([^)]*)//g')
 
100
builddeps=$(echo ${builddeps} | sed -e 's/abi-compliance-checker//g')
 
101
builddeps=$(echo ${builddeps} | sed -e 's/multistrap//g')
 
102
 
 
103
case ${arch} in
 
104
    amd64 | i386 )
 
105
        source_url=http://archive.ubuntu.com/ubuntu
 
106
        ;;
 
107
    * )
 
108
        source_url=http://ports.ubuntu.com/ubuntu-ports
 
109
        ;;
 
110
esac
 
111
 
 
112
echo "[General]
 
113
arch=${arch}
 
114
directory=${directory}
 
115
unpack=false
 
116
noauth=true
 
117
bootstrap=Ubuntu ${sources}
 
118
 
 
119
[Ubuntu]
 
120
packages=${builddeps}
 
121
source=${source_url}
 
122
suite=${dist}
 
123
" > mstrap.conf
 
124
 
 
125
sourceid=0
 
126
for x in ${repositories};
 
127
do
 
128
    ((++sourceid))
 
129
    echo "[source${sourceid}]
 
130
source=${x}
 
131
suite=${dist}
 
132
" >> mstrap.conf
 
133
done
 
134
 
 
135
multistrap -f mstrap.conf 
 
136
 
 
137
rm -f var/cache/apt/archives/lock
 
138
 
 
139
# Remove libc libraries that confuse the cross-compiler
 
140
rm -f var/cache/apt/archives/libc-dev*.deb
 
141
rm -f var/cache/apt/archives/libc6*.deb
 
142
 
 
143
for deb in var/cache/apt/archives/* ; do
 
144
    if [ ! -d ${deb} ] ; then
 
145
        echo "unpacking: ${deb}"
 
146
        dpkg -x ${deb} .
 
147
    fi
 
148
done
 
149
 
 
150
# Fix up symlinks which asssumed the usual root path
 
151
for broken_symlink in $(find . -name \*.so -type l -xtype l) ; do
 
152
    ln -sf $(pwd)$(readlink ${broken_symlink}) ${broken_symlink}
 
153
done
 
154
 
 
155
popd > /dev/null