-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-build.sh
executable file
·149 lines (125 loc) · 4.19 KB
/
create-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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
#
# Create and initialize a directory for building a fwup example.
#
# Inputs:
# $1 = the path to the configuration file (a _defconfig file)
# $2 = the build directory
#
# Output:
# An initialized build directory on success
#
set -e
#set -x
BUILDROOT_VERSION=2021.02.1
DEFCONFIG=$1
BUILD_DIR=$2
# "readlink -f" implementation for BSD
# This code was extracted from the Elixir shell scripts
readlink_f () {
cd "$(dirname "$1")" > /dev/null
filename="$(basename "$1")"
if [[ -h "$filename" ]]; then
readlink_f "$(readlink "$filename")"
else
echo "$(pwd -P)/$filename"
fi
}
if [[ -z $DEFCONFIG ]]; then
echo "Usage:"
echo
echo " $0 <defconfig> [build directory]"
exit 1
fi
if [[ -z $BUILD_DIR ]]; then
BUILD_DIR=o/$(basename -s _defconfig "$DEFCONFIG")
fi
# Create the build directory if it doesn't already exist
mkdir -p "$BUILD_DIR"
# Normalize paths that were specified
ABS_DEFCONFIG=$(readlink_f "$DEFCONFIG")
ABS_DEFCONFIG_DIR=$(dirname "$ABS_DEFCONFIG")
ABS_BUILD_DIR=$(readlink_f "$BUILD_DIR")
if [[ ! -f "$ABS_DEFCONFIG" ]]; then
echo "ERROR: Can't find "$ABS_DEFCONFIG". Please check that it exists."
exit 1
fi
# Check that the host can build an image
HOST_OS=$(uname -s)
HOST_ARCH=$(uname -m)
if [[ $HOST_OS != "Linux" ]]; then
echo "ERROR: This only works on Linux"
exit 1
fi
if [[ $HOST_ARCH != "x86_64" ]]; then
echo "ERROR: 64-bit Linux probably required for running cross-compilers"
exit 1
fi
# Determine the BASE_DIR source directory
BASE_DIR=$(dirname $(readlink_f "${BASH_SOURCE[0]}"))
if [[ ! -e $BASE_DIR ]]; then
echo "ERROR: Can't determine script directory!"
exit 1
fi
# Location to download files to so that they don't need
# to be redownloaded when working a lot with buildroot
#
# NOTE: If you are a heavy Buildroot user and have an alternative location,
# override this environment variable or symlink this directory.
if [[ -z $BUILDROOT_DL_DIR ]]; then
if [[ -e $HOME/dl ]]; then
BUILDROOT_DL_DIR=$HOME/dl
else
BUILDROOT_DL_DIR="$BASE_DIR/dl"
mkdir -p "$BASE_DIR/dl"
fi
fi
BUILDROOT_STATE_FILE=$BASE_DIR/buildroot-$BUILDROOT_VERSION/.fwup-examples-br-state
BUILDROOT_EXPECTED_STATE_FILE=$BUILD_DIR/.fwup-examples-expected-br-state
"$BASE_DIR/scripts/buildroot-state.sh" $BUILDROOT_VERSION "$BASE_DIR/patches" > "$BUILDROOT_EXPECTED_STATE_FILE"
create_buildroot_dir() {
# Clean up any old versions of Buildroot
rm -fr "$BASE_DIR"/buildroot*
# Download and extract Buildroot
"$BASE_DIR/scripts/download-buildroot.sh" $BUILDROOT_VERSION $BUILDROOT_DL_DIR $BASE_DIR
# Apply patches
"$BASE_DIR/buildroot/support/scripts/apply-patches.sh" "$BASE_DIR/buildroot" "$BASE_DIR/patches/buildroot"
if ! [[ -z $BUILDROOT_DL_DIR ]]; then
# Symlink Buildroot's dl directory so that it can be cached between builds
ln -sf $BUILDROOT_DL_DIR $BASE_DIR/buildroot/dl
fi
cp $BUILDROOT_EXPECTED_STATE_FILE $BUILDROOT_STATE_FILE
}
if [[ ! -e $BUILDROOT_STATE_FILE ]]; then
create_buildroot_dir
elif ! diff "$BUILDROOT_STATE_FILE" "$BUILDROOT_EXPECTED_STATE_FILE" >/dev/null; then
echo "Detected a difference in the Buildroot source tree either due"
echo "to an change in Buildroot or a change in the patches that get"
echo "applied to Buildroot. The Buildroot source tree will be updated."
echo
echo "It is highly recommended to rebuild clean."
echo "To do this, go to $BUILD_DIR, and run 'make clean'."
echo
echo "Press return to acknowledge or CTRL-C to stop"
read -r
create_buildroot_dir
fi
# Configure the build directory - finally!
make -C $BASE_DIR/buildroot BR2_EXTERNAL=$BASE_DIR O=$ABS_BUILD_DIR \
BR2_DEFCONFIG=$ABS_DEFCONFIG \
DEFCONFIG=$ABS_DEFCONFIG \
defconfig
echo "------------"
echo
echo "Build directory successfully created."
echo
echo "Configuration: $ABS_DEFCONFIG"
echo
echo "Next, do the following:"
echo " 1. cd $ABS_BUILD_DIR"
echo " 2. make"
echo
echo "For additional options, run 'make help' in the build directory."
echo
echo "IMPORTANT: If you update fwup-examples, you should rerun this script."
echo " It will refresh the configuration in the build directory."