blob: f21b847b9748db39d851073ea199dc05a676aa51 [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
3set -ex
4set -eo pipefail
5
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +10006BUILD_INFO=0
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -03007SDK_ONLY=0
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05308CONFIGTAG="_defconfig"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05309DEFCONFIGS=();
Stewart Smithc4b9bf62018-08-24 13:30:15 +100010SDK_DIR=""
11
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030012opt=$(getopt -o 'o:Ss:p:r' -- "$@")
13if [ $? -ne 0 ] ; then
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030014 echo "Invalid arguments"
15 exit 1
16fi
17
18eval set -- "$opt"
19unset opt
20
21while true; do
22 case "$1" in
23 '-o')
24 shift
25 echo "Output directory: $1"
26 OUTDIR="$1"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100027 ;;
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030028 '-S')
29 echo "Build SDK Only"
30 SDK_ONLY=1
31 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030032 '-s')
33 shift
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030034 echo "SDK cache dir is in: $1"
35 SDK_CACHE=$1
Stewart Smithc4b9bf62018-08-24 13:30:15 +100036 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030037 '-p')
38 shift
39 echo "Platforms to build: $1"
40 PLATFORM_LIST="$1"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100041 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030042 '-r')
Stewart Smithc4b9bf62018-08-24 13:30:15 +100043 echo "Build legal-info etc for release"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100044 BUILD_INFO=1
45 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030046 '--')
47 shift
48 break
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100049 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030050 *)
51 echo "Internal error!"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100052 exit 1
53 ;;
54 esac
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030055 shift
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100056done
57
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030058function get_major_minor_release
Joel Stanleya81c1242018-11-01 13:19:58 +103059{
60 IFS=. read major minor macro <<<"$1"
61 echo -n "${major}_${minor}"
62}
63
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030064function get_major_release
65{
66 IFS=. read major minor macro <<<"$1"
67 echo -n "${major}"
68}
69
70function build_sdk
71{
72# $1 is the defconfig
73# $2 is the SDK output directory
74# writes the output SDK pathname in global $SDK_DIR
75# also considers global var $CCACHE_DIR
76 SDK_BUILD_DIR=`mktemp -d`
77 op-build O=$SDK_BUILD_DIR $1
78
79 # Accumulate the SDK properties we want to hash to make it unique, but
80 # just so. Start with the buildroot version and machine/OS
81 HASH_PROPERTIES="$(git submodule) $(uname -mo)"
82
83 # Even if they should be interchangeable, we want to force the sdk
84 # build on every supported OS variations
Klaus Heinrich Kiwi1c7da102020-05-04 20:50:33 -030085 HASH_PROPERTIES="$HASH_PROPERTIES $(lsb_release -as | tr -d '[:space:]')"
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030086
87 # Disable things not necessary for the sdk
88 # (Buildroot manual section 6.1.3 plus a few more things)
89 buildroot/utils/config --file $SDK_BUILD_DIR/.config --disable INIT_BUSYBOX \
90 --enable INIT_NONE \
91 --disable SYSTEM_BIN_SH_BUSYBOX \
92 --disable TARGET_ROOTFS_TAR \
93 --disable SYSTEM_BIN_SH_DASH \
94 --enable SYSTEM_BIN_SH_NONE
95
96 # We don't need the Linux Kernel or eudev (they'll be rebuilt anyway), but we need
97 # to preserve the custom kernel version (if defined) for headers consistency, and
98 # since we're at it, enabling CPP won't hurt and will make the SDK more general
99 buildroot/utils/config --file $SDK_BUILD_DIR/.config --disable LINUX_KERNEL \
100 --disable ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV \
101 --enable INSTALL_LIBSTDCPP
102
103 # As we are disabling BR2_LINUX_KERNEL, capture Kernel version if any
104 # to prevent it from defaulting to the last on olddefconfig
105 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state LINUX_KERNEL_CUSTOM_VERSION_VALUE)
106 if [ "$KERNEL_VER" != "undef" ]; then
107 KERNEL="KERNEL_HEADERS_$(get_major_minor_release $KERNEL_VER)"
108 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable "$KERNEL"
109 fi
110
111 # Disable packages we won't pull into the SDK to speed it's build
112 buildroot/utils/config --file $SDK_BUILD_DIR/.config --package \
113 --disable BUSYBOX \
114 --disable KEXEC_LITE \
115 --disable LINUX_FIRMWARE \
116 --disable CRYPTSETUP \
117 --disable IPMITOOL \
118 --disable LVM2 \
119 --disable MDADM \
120 --disable NVME \
121 --disable PCIUTILS \
122 --disable ZLIB \
123 --disable LIBZLIB \
124 --disable DTC \
125 --disable LIBAIO \
126 --disable JSON_C \
127 --disable ELFUTILS \
128 --disable NCURSES \
129 --disable POPT \
130 --disable DROPBEAR --disable DROPBEAR_CLIENT \
131 --disable ETHTOOL \
132 --disable IFUPDOWN_SCRIPTS \
133 --disable LRZSZ \
134 --disable NETCAT \
135 --disable RSYNC \
136 --disable SUDO \
137 --disable KMOD \
138 --disable POWERPC_UTILS \
139 --disable UTIL_LINUX \
140 --disable IPRUTILS
141
142 # Additionally, disable ROOTFS stuff that we won't need
143 # Including the OpenPower Packages
144 buildroot/utils/config --file $SDK_BUILD_DIR/.config --undefine ROOTFS_USERS_TABLES \
145 --undefine ROOTFS_OVERLAY \
146 --undefine ROOTFS_POST_BUILD_SCRIPT \
147 --undefine ROOTFS_POST_FAKEROOT_SCRIPT \
148 --undefine ROOTFS_POST_IMAGE_SCRIPT \
149 --undefine ROOTFS_POST_SCRIPT_ARGS \
150 --undefine OPENPOWER_PLATFORM \
151 --undefine BR2_OPENPOWER_POWER8 \
152 --undefine BR2_OPENPOWER_POWER9
153
154 # Enable CCACHE
155 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable CCACHE \
156 --set-str CCACHE_DIR $CCACHE_DIR
157
158 op-build O=$SDK_BUILD_DIR olddefconfig
159
160 # Ideally this woulnd't matter, but to be safe, include Kernel
161 # Headers and GCC version as part of the SDK Hash, so that we
162 # don't have Full builds and SDK builds potentially diverging
163 # on the headers/compiler versions each uses
164 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state DEFAULT_KERNEL_HEADERS)
165 HASH_PROPERTIES="$HASH_PROPERTIES $KERNEL_VER"
166 echo "SDK KERNEL Version: $KERNEL_VER"
167 GCC_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state GCC_VERSION)
168 echo "SDK GCC Version: $GCC_VER"
169 HASH_PROPERTIES="$HASH_PROPERTIES $GCC_VER"
170
171 # sha1sum our properties and check if a matching sdk exists
172 # A potential caveat he is if op-build is patching any of the
173 # HASH_PROPERTIES content at build time
174 HASH_VAL=$(echo -n "$HASH_PROPERTIES" | sha1sum | sed -e 's/ .*//')
175
176 SDK_DIR="$2/toolchain-${HASH_VAL}"
177
178 if [ -e "$SDK_DIR" ]; then
179 echo "Acceptable SDK for $i exists in $SDK_DIR - skipping build"
180 else
181 op-build O=$SDK_BUILD_DIR sdk
182 if [ $? -ne 0 ]; then
183 rm -rf $SDK_DIR
184 return 1
185 fi
186
187 # Move sdk to resting location and adjust paths
188 mv $SDK_BUILD_DIR $SDK_DIR
189 $SDK_DIR/host/relocate-sdk.sh
190 fi
191 export SDK_DIR
192}
193
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300194if [ -z "${PLATFORM_LIST-}" ]; then
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530195 echo "Using all the defconfigs for all the platforms"
196 DEFCONFIGS=`(cd openpower/configs; ls -1 *_defconfig)`
197else
198 IFS=', '
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +1000199 for p in ${PLATFORM_LIST};
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530200 do
201 DEFCONFIGS+=($p$CONFIGTAG)
202 done
203fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100204
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300205if [ -z "${CCACHE_DIR-}" ]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100206 CCACHE_DIR=`pwd`/.op-build_ccache
207fi
208
209shopt -s expand_aliases
210source op-build-env
211
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300212if [ -n "${DL_DIR-}" ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000213 unset BR2_DL_DIR
214 export BR2_DL_DIR=${DL_DIR}
215fi
216
Klaus Heinrich Kiwi04ce68e2020-04-16 15:17:50 -0300217if [ -f "$(ldconfig -p | grep libeatmydata.so | tr ' ' '\n' | grep /|head -n1)" ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000218 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so
Klaus Heinrich Kiwib0cfd8e2020-04-20 23:18:30 -0300219elif [ -f "/usr/lib64/nosync/nosync.so" ]; then
220 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}/usr/lib64/nosync/nosync.so
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000221fi
222
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530223for i in ${DEFCONFIGS[@]}; do
Klaus Heinrich Kiwia1f404a2020-04-16 14:24:30 -0300224 export O=${OUTDIR}/$i
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000225 rm -rf $O
Joel Stanleya81c1242018-11-01 13:19:58 +1030226
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300227 SDK_DIR=""
228 build_sdk $i $SDK_CACHE
229 if [ $? -ne 0 ]; then
230 echo "Error building SDK"
231 exit 1
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000232 fi
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300233
234 if [ $SDK_ONLY -ne 0 ]; then
235 continue
236 fi
237
238 op-build O=$O $i
239 buildroot/utils/config --file $O/.config --enable CCACHE \
240 --set-str CCACHE_DIR $CCACHE_DIR
241 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL \
242 --set-str TOOLCHAIN_EXTERNAL_PATH $SDK_DIR/host \
243 --enable TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC
244
245 # Our SDK will always have CPP enabled, but avoid potentially
246 # diverging with the Full build by only enabling it
247 # conditionally
248 CPP_REQUIRED=$(buildroot/utils/config --file $O/.config --state INSTALL_LIBSTDCPP)
249 if [ "$CPP_REQUIRED" = "y" ]; then
250 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL_CXX
251 fi
252
253 # The Kernel Headers requested MUST be the same as the one
254 # provided by the SDK (i.e., it's part of the hash)
255 HEADERS_VER=$(buildroot/utils/config --file $O/.config --state TOOLCHAIN_HEADERS_AT_LEAST)
256 echo "Toolchain Headers Version Requested: $HEADERS_VER"
257 HEADERS="TOOLCHAIN_EXTERNAL_HEADERS_$(get_major_minor_release $HEADERS_VER)"
258 buildroot/utils/config --file $O/.config --enable "$HEADERS"
259
260 # Same for the GCC version
261 EXTERNAL_GCC_VER=$(buildroot/utils/config --file $O/.config --state GCC_VERSION)
262 echo "GCC Version Requested: $EXTERNAL_GCC_VER"
263 EXTERNAL_GCC="TOOLCHAIN_EXTERNAL_GCC_$(get_major_release $EXTERNAL_GCC_VER)"
264 buildroot/utils/config --file $O/.config --enable "$EXTERNAL_GCC"
265
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000266 op-build O=$O olddefconfig
267 op-build O=$O
Stewart Smith098d03e2016-03-01 13:59:42 +1100268 r=$?
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300269 if [ ${BUILD_INFO} -eq 1 ] && [ $r -eq 0 ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000270 op-build O=$O legal-info
271 op-build O=$O graph-build
272 op-build O=$O graph-size
273 op-build O=$O graph-depends
274 fi
275 lsb_release -a > $O/lsb_release
Stewart Smith098d03e2016-03-01 13:59:42 +1100276 if [ $r -ne 0 ]; then
277 exit $r
278 fi
279done
280