aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
blob: 2fad9c206d2bf075337fcbf7937eeaff6a7ff551 (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
#!/bin/bash
# Copyright (C) 2019 Denis 'GNUtoo' Carikli' <GNUtoo@cyberdimension.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
set -e

supported_machines=" \
    espresso3g \
    espressowifi \
    i9100 \
    i9300 \
    i9305 \
    maguro \
    n5100 \
    n5110 \
    n7000 \
    n7100 \
"

usage()
{
    printf "Usage:\n%s <" "$0"
    for machine in ${supported_machines} ; do
        printf "${machine}|"
    done
    printf "\b>\n"
    printf "%s all      # build all machines\n" "$0"
    printf "%s machines # print all machines supported by this script\n" "$0"
    printf "%s targets  # print the build targets corresponding to the supported machines\n" "$0"
    exit 1
}

print_machines()
{
    for machine in ${supported_machines} ; do
        printf "${machine}\n"
    done
}

print_targets()
{
    for machine in ${supported_machines} ; do
        printf "replicant_${machine}-userdebug\n"
    done
}

build()
{
    machine="$1"
    parallel_tasks=$(echo "$(grep 'processor' /proc/cpuinfo | wc -l ) + 1" | bc)
    mkdir -p logs
    log="logs/build_${machine}_$(date '+%s').log"

    echo "starting to building for ${machine}: ${log}"
    source build/envsetup.sh
    lunch "replicant_${machine}-userdebug"
    time make -j$parallel_tasks bacon 2>&1 | tee "${log}"
    vendor/replicant/sign-build "${machine}" | tee -a "${log}"
    echo "${machine} DONE: ${log}"
}

if [ $# -ne 1 ] ; then
	usage
fi

if [ "$1" = "all" ] ; then
    for machine in ${supported_machines} ; do
	build "${machine}"
    done
elif [ "$1" = "machines" ] ; then
    print_machines
elif [ "$1" = "targets" ] ; then
    print_targets
else
    found=0
    for machine in ${supported_machines} ; do
	if [ "${machine}" = "$1" ] ; then
	    found=1
	fi
    done

    if [ ${found} -eq 0 ] ; then
	printf "machine %s not supported\n" "$1"
	usage
    fi

    build "$1"
fi