-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
build.sh
executable file
·99 lines (89 loc) · 2.77 KB
/
build.sh
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
#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2018, Tom Hiller <[email protected]>
set -e
## import variables
. ./common/variables.sh
################################################################################
## Menu
################################################################################
## Parse avialble models from directory names
AVAILABLE_MODELS=$(find ./ -maxdepth 1 -mindepth 1 -type d | sed 's/\.\///g' | grep -Ev "common|git")
## Help menu
usage()
{
echo "Usage: "
echo
echo " $0 [-t <TAG>] [-c <COMMIT>] [--config] [--bleeding-edge] [--clean-slate] <model>"
echo
echo " --bleeding-edge Build from the latest commit"
echo " --clean-slate Purge previous build directory and config"
echo " -c, --commit <commit> Git commit hash"
echo " -h, --help Show this help"
echo " -i, --config Execute with interactive make config"
echo " -t, --tag <tag> Git tag/version"
echo
echo "If a tag, commit or bleeding-edge flag is not given, the latest Coreboot release will be built."
echo
echo
echo "Available models:"
for AVAILABLE_MODEL in $AVAILABLE_MODELS; do
echo "$(printf '\t')$AVAILABLE_MODEL"
done
}
## Iterate through command line parameters
while :
do
case "$1" in
--bleeding-edge)
COREBOOT_COMMIT="master"
shift 1;;
--clean-slate)
CLEAN_SLATE=true
shift 1;;
-c | --commit)
COREBOOT_COMMIT="$2"
shift 2;;
-h | --help)
usage >&2
exit 0;;
-i | --config)
COREBOOT_CONFIG=true
shift 1;;
-t | --tag)
COREBOOT_TAG="$2"
shift 2;;
-*)
echo "Error: Unknown option: $1" >&2
usage >&2
exit 1;;
*)
break;;
esac
done
## Validate and normalize given model number
MODEL=$(echo "$@" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]');
## Check if valid model
if [ -z "$MODEL" ] || [ ! -d "$PWD/$MODEL" ]; then
usage
exit 1;
fi;
################################################################################
################################################################################
if [ ! -d "$PWD/$MODEL/build" ]; then
mkdir "$PWD/$MODEL/build"
elif [ "$CLEAN_SLATE" ]; then
rm -rf "$PWD/$MODEL/build" || true
mkdir "$PWD/$MODEL/build"
fi
## Run Docker
docker run --rm -it \
--user "$(id -u):$(id -g)" \
-v "$PWD/$MODEL/build:$DOCKER_COREBOOT_DIR" \
-v "$PWD/$MODEL:$DOCKER_SCRIPT_DIR" \
-v "$PWD/common:$DOCKER_COMMON_SCRIPT_DIR" \
-e COREBOOT_COMMIT="$COREBOOT_COMMIT" \
-e COREBOOT_TAG="$COREBOOT_TAG" \
-e COREBOOT_CONFIG="$COREBOOT_CONFIG" \
coreboot/coreboot-sdk:"$COREBOOT_SDK_VERSION" \
/home/coreboot/scripts/compile.sh