blob: 30703f26a30b1236b18d58ffd7302513dff71f8d [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=();
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030010CCACHE_DIR=""
Stewart Smithc4b9bf62018-08-24 13:30:15 +100011SDK_DIR=""
12
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030013opt=$(getopt -o 'o:Ss:p:r' -- "$@")
14if [ $? -ne 0 ] ; then
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030015 echo "Invalid arguments"
16 exit 1
17fi
18
19eval set -- "$opt"
20unset opt
21
22while true; do
23 case "$1" in
24 '-o')
25 shift
26 echo "Output directory: $1"
27 OUTDIR="$1"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100028 ;;
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030029 '-S')
30 echo "Build SDK Only"
31 SDK_ONLY=1
32 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030033 '-s')
34 shift
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030035 echo "SDK cache dir is in: $1"
36 SDK_CACHE=$1
Stewart Smithc4b9bf62018-08-24 13:30:15 +100037 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030038 '-p')
39 shift
40 echo "Platforms to build: $1"
41 PLATFORM_LIST="$1"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100042 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030043 '-r')
Stewart Smithc4b9bf62018-08-24 13:30:15 +100044 echo "Build legal-info etc for release"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100045 BUILD_INFO=1
46 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030047 '--')
48 shift
49 break
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100050 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030051 *)
52 echo "Internal error!"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100053 exit 1
54 ;;
55 esac
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030056 shift
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100057done
58
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030059function get_major_minor_release
Joel Stanleya81c1242018-11-01 13:19:58 +103060{
61 IFS=. read major minor macro <<<"$1"
62 echo -n "${major}_${minor}"
63}
64
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030065function get_major_release
66{
67 IFS=. read major minor macro <<<"$1"
68 echo -n "${major}"
69}
70
71function build_sdk
72{
73# $1 is the defconfig
74# $2 is the SDK output directory
75# writes the output SDK pathname in global $SDK_DIR
76# also considers global var $CCACHE_DIR
77 SDK_BUILD_DIR=`mktemp -d`
78 op-build O=$SDK_BUILD_DIR $1
79
80 # Accumulate the SDK properties we want to hash to make it unique, but
81 # just so. Start with the buildroot version and machine/OS
82 HASH_PROPERTIES="$(git submodule) $(uname -mo)"
83
84 # Even if they should be interchangeable, we want to force the sdk
85 # build on every supported OS variations
86 HASH_PROPERTIES="$(HASH PROPERTIES) $(lsb_release -as | tr -d '/n[:space:]')"
87
88 # Disable things not necessary for the sdk
89 # (Buildroot manual section 6.1.3 plus a few more things)
90 buildroot/utils/config --file $SDK_BUILD_DIR/.config --disable INIT_BUSYBOX \
91 --enable INIT_NONE \
92 --disable SYSTEM_BIN_SH_BUSYBOX \
93 --disable TARGET_ROOTFS_TAR \
94 --disable SYSTEM_BIN_SH_DASH \
95 --enable SYSTEM_BIN_SH_NONE
96
97 # We don't need the Linux Kernel or eudev (they'll be rebuilt anyway), but we need
98 # to preserve the custom kernel version (if defined) for headers consistency, and
99 # since we're at it, enabling CPP won't hurt and will make the SDK more general
100 buildroot/utils/config --file $SDK_BUILD_DIR/.config --disable LINUX_KERNEL \
101 --disable ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV \
102 --enable INSTALL_LIBSTDCPP
103
104 # As we are disabling BR2_LINUX_KERNEL, capture Kernel version if any
105 # to prevent it from defaulting to the last on olddefconfig
106 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state LINUX_KERNEL_CUSTOM_VERSION_VALUE)
107 if [ "$KERNEL_VER" != "undef" ]; then
108 KERNEL="KERNEL_HEADERS_$(get_major_minor_release $KERNEL_VER)"
109 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable "$KERNEL"
110 fi
111
112 # Disable packages we won't pull into the SDK to speed it's build
113 buildroot/utils/config --file $SDK_BUILD_DIR/.config --package \
114 --disable BUSYBOX \
115 --disable KEXEC_LITE \
116 --disable LINUX_FIRMWARE \
117 --disable CRYPTSETUP \
118 --disable IPMITOOL \
119 --disable LVM2 \
120 --disable MDADM \
121 --disable NVME \
122 --disable PCIUTILS \
123 --disable ZLIB \
124 --disable LIBZLIB \
125 --disable DTC \
126 --disable LIBAIO \
127 --disable JSON_C \
128 --disable ELFUTILS \
129 --disable NCURSES \
130 --disable POPT \
131 --disable DROPBEAR --disable DROPBEAR_CLIENT \
132 --disable ETHTOOL \
133 --disable IFUPDOWN_SCRIPTS \
134 --disable LRZSZ \
135 --disable NETCAT \
136 --disable RSYNC \
137 --disable SUDO \
138 --disable KMOD \
139 --disable POWERPC_UTILS \
140 --disable UTIL_LINUX \
141 --disable IPRUTILS
142
143 # Additionally, disable ROOTFS stuff that we won't need
144 # Including the OpenPower Packages
145 buildroot/utils/config --file $SDK_BUILD_DIR/.config --undefine ROOTFS_USERS_TABLES \
146 --undefine ROOTFS_OVERLAY \
147 --undefine ROOTFS_POST_BUILD_SCRIPT \
148 --undefine ROOTFS_POST_FAKEROOT_SCRIPT \
149 --undefine ROOTFS_POST_IMAGE_SCRIPT \
150 --undefine ROOTFS_POST_SCRIPT_ARGS \
151 --undefine OPENPOWER_PLATFORM \
152 --undefine BR2_OPENPOWER_POWER8 \
153 --undefine BR2_OPENPOWER_POWER9
154
155 # Enable CCACHE
156 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable CCACHE \
157 --set-str CCACHE_DIR $CCACHE_DIR
158
159 op-build O=$SDK_BUILD_DIR olddefconfig
160
161 # Ideally this woulnd't matter, but to be safe, include Kernel
162 # Headers and GCC version as part of the SDK Hash, so that we
163 # don't have Full builds and SDK builds potentially diverging
164 # on the headers/compiler versions each uses
165 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state DEFAULT_KERNEL_HEADERS)
166 HASH_PROPERTIES="$HASH_PROPERTIES $KERNEL_VER"
167 echo "SDK KERNEL Version: $KERNEL_VER"
168 GCC_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state GCC_VERSION)
169 echo "SDK GCC Version: $GCC_VER"
170 HASH_PROPERTIES="$HASH_PROPERTIES $GCC_VER"
171
172 # sha1sum our properties and check if a matching sdk exists
173 # A potential caveat he is if op-build is patching any of the
174 # HASH_PROPERTIES content at build time
175 HASH_VAL=$(echo -n "$HASH_PROPERTIES" | sha1sum | sed -e 's/ .*//')
176
177 SDK_DIR="$2/toolchain-${HASH_VAL}"
178
179 if [ -e "$SDK_DIR" ]; then
180 echo "Acceptable SDK for $i exists in $SDK_DIR - skipping build"
181 else
182 op-build O=$SDK_BUILD_DIR sdk
183 if [ $? -ne 0 ]; then
184 rm -rf $SDK_DIR
185 return 1
186 fi
187
188 # Move sdk to resting location and adjust paths
189 mv $SDK_BUILD_DIR $SDK_DIR
190 $SDK_DIR/host/relocate-sdk.sh
191 fi
192 export SDK_DIR
193}
194
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +1000195if [ -z "${PLATFORM_LIST}" ]; then
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530196 echo "Using all the defconfigs for all the platforms"
197 DEFCONFIGS=`(cd openpower/configs; ls -1 *_defconfig)`
198else
199 IFS=', '
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +1000200 for p in ${PLATFORM_LIST};
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530201 do
202 DEFCONFIGS+=($p$CONFIGTAG)
203 done
204fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100205
Stewart Smith098d03e2016-03-01 13:59:42 +1100206if [ -z "$CCACHE_DIR" ]; then
207 CCACHE_DIR=`pwd`/.op-build_ccache
208fi
209
210shopt -s expand_aliases
211source op-build-env
212
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000213if [ -n "$DL_DIR" ]; then
214 unset BR2_DL_DIR
215 export BR2_DL_DIR=${DL_DIR}
216fi
217
Klaus Heinrich Kiwi04ce68e2020-04-16 15:17:50 -0300218if [ -f "$(ldconfig -p | grep libeatmydata.so | tr ' ' '\n' | grep /|head -n1)" ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000219 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so
Klaus Heinrich Kiwib0cfd8e2020-04-20 23:18:30 -0300220elif [ -f "/usr/lib64/nosync/nosync.so" ]; then
221 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}/usr/lib64/nosync/nosync.so
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000222fi
223
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530224for i in ${DEFCONFIGS[@]}; do
Klaus Heinrich Kiwia1f404a2020-04-16 14:24:30 -0300225 export O=${OUTDIR}/$i
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000226 rm -rf $O
Joel Stanleya81c1242018-11-01 13:19:58 +1030227
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300228 SDK_DIR=""
229 build_sdk $i $SDK_CACHE
230 if [ $? -ne 0 ]; then
231 echo "Error building SDK"
232 exit 1
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000233 fi
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300234
235 if [ $SDK_ONLY -ne 0 ]; then
236 continue
237 fi
238
239 op-build O=$O $i
240 buildroot/utils/config --file $O/.config --enable CCACHE \
241 --set-str CCACHE_DIR $CCACHE_DIR
242 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL \
243 --set-str TOOLCHAIN_EXTERNAL_PATH $SDK_DIR/host \
244 --enable TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC
245
246 # Our SDK will always have CPP enabled, but avoid potentially
247 # diverging with the Full build by only enabling it
248 # conditionally
249 CPP_REQUIRED=$(buildroot/utils/config --file $O/.config --state INSTALL_LIBSTDCPP)
250 if [ "$CPP_REQUIRED" = "y" ]; then
251 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL_CXX
252 fi
253
254 # The Kernel Headers requested MUST be the same as the one
255 # provided by the SDK (i.e., it's part of the hash)
256 HEADERS_VER=$(buildroot/utils/config --file $O/.config --state TOOLCHAIN_HEADERS_AT_LEAST)
257 echo "Toolchain Headers Version Requested: $HEADERS_VER"
258 HEADERS="TOOLCHAIN_EXTERNAL_HEADERS_$(get_major_minor_release $HEADERS_VER)"
259 buildroot/utils/config --file $O/.config --enable "$HEADERS"
260
261 # Same for the GCC version
262 EXTERNAL_GCC_VER=$(buildroot/utils/config --file $O/.config --state GCC_VERSION)
263 echo "GCC Version Requested: $EXTERNAL_GCC_VER"
264 EXTERNAL_GCC="TOOLCHAIN_EXTERNAL_GCC_$(get_major_release $EXTERNAL_GCC_VER)"
265 buildroot/utils/config --file $O/.config --enable "$EXTERNAL_GCC"
266
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000267 op-build O=$O olddefconfig
268 op-build O=$O
Stewart Smith098d03e2016-03-01 13:59:42 +1100269 r=$?
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300270 if [ ${BUILD_INFO} -eq 1 ] && [ $r -eq 0 ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000271 op-build O=$O legal-info
272 op-build O=$O graph-build
273 op-build O=$O graph-size
274 op-build O=$O graph-depends
275 fi
276 lsb_release -a > $O/lsb_release
Stewart Smith098d03e2016-03-01 13:59:42 +1100277 if [ $r -ne 0 ]; then
278 exit $r
279 fi
280done
281