blob: 0ad613e2d76f6f3424dd88e4d3caaffaee64e0c4 [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
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05307CONFIGTAG="_defconfig"
8
9DEFCONFIGS=();
10
Stewart Smithc4b9bf62018-08-24 13:30:15 +100011SDK_DIR=""
12
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030013opt=$(getopt -o 'o:s:p:r' -- "$@")
14if [ $? != 0 ] ; then
15 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 Kiwi220aeba2020-04-20 17:28:18 -030029 '-s')
30 shift
31 echo "SDK is in: $1"
32 SDK_DIR=$1
Stewart Smithc4b9bf62018-08-24 13:30:15 +100033 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030034 '-p')
35 shift
36 echo "Platforms to build: $1"
37 PLATFORM_LIST="$1"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100038 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030039 '-r')
Stewart Smithc4b9bf62018-08-24 13:30:15 +100040 echo "Build legal-info etc for release"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100041 BUILD_INFO=1
42 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030043 '--')
44 shift
45 break
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100046 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030047 *)
48 echo "Internal error!"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100049 exit 1
50 ;;
51 esac
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030052 shift
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100053done
54
Joel Stanleya81c1242018-11-01 13:19:58 +103055function get_kernel_release
56{
57 IFS=. read major minor macro <<<"$1"
58 echo -n "${major}_${minor}"
59}
60
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100061if [ -z "${PLATFORM_LIST}" ]; then
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053062 echo "Using all the defconfigs for all the platforms"
63 DEFCONFIGS=`(cd openpower/configs; ls -1 *_defconfig)`
64else
65 IFS=', '
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100066 for p in ${PLATFORM_LIST};
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053067 do
68 DEFCONFIGS+=($p$CONFIGTAG)
69 done
70fi
Stewart Smith098d03e2016-03-01 13:59:42 +110071
Stewart Smith098d03e2016-03-01 13:59:42 +110072if [ -z "$CCACHE_DIR" ]; then
73 CCACHE_DIR=`pwd`/.op-build_ccache
74fi
75
76shopt -s expand_aliases
77source op-build-env
78
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +100079if [ -n "$DL_DIR" ]; then
80 unset BR2_DL_DIR
81 export BR2_DL_DIR=${DL_DIR}
82fi
83
Klaus Heinrich Kiwi04ce68e2020-04-16 15:17:50 -030084if [ -f "$(ldconfig -p | grep libeatmydata.so | tr ' ' '\n' | grep /|head -n1)" ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +100085 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so
Klaus Heinrich Kiwib0cfd8e2020-04-20 23:18:30 -030086elif [ -f "/usr/lib64/nosync/nosync.so" ]; then
87 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}/usr/lib64/nosync/nosync.so
Stewart Smithc4b9bf62018-08-24 13:30:15 +100088fi
89
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053090for i in ${DEFCONFIGS[@]}; do
Klaus Heinrich Kiwia1f404a2020-04-16 14:24:30 -030091 export O=${OUTDIR}/$i
Stewart Smithc4b9bf62018-08-24 13:30:15 +100092 rm -rf $O
93 op-build O=$O $i
Klaus Heinrich Kiwi2cc78eb2020-04-17 10:55:50 -030094 ./buildroot/utils/config --file $O/.config --enable CCACHE \
95 --set-str CCACHE_DIR $CCACHE_DIR
Stewart Smithc4b9bf62018-08-24 13:30:15 +100096 if [ -d "$SDK_DIR" ]; then
Klaus Heinrich Kiwi2cc78eb2020-04-17 10:55:50 -030097 ./buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL \
98 --set-str TOOLCHAIN_EXTERNAL_PATH $SDK_DIR \
99 --enable TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC \
100 --enable TOOLCHAIN_EXTERNAL_CXX
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000101 # FIXME: How do we work this out programatically?
Klaus Heinrich Kiwi2cc78eb2020-04-17 10:55:50 -0300102 ./buildroot/utils/config --file $O/.config --enable BR2_TOOLCHAIN_EXTERNAL_GCC_6
Joel Stanleya81c1242018-11-01 13:19:58 +1030103
104 KERNEL_VER=$(./buildroot/utils/config --file $O/.config --state BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE)
105 echo "KERNEL_VER " $KERNEL_VER
106 HEADERS=BR2_TOOLCHAIN_EXTERNAL_HEADERS_$(get_kernel_release $KERNEL_VER)
107 ./buildroot/utils/config --file $O/.config --set-val $HEADERS y
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000108 fi
109 op-build O=$O olddefconfig
110 op-build O=$O
Stewart Smith098d03e2016-03-01 13:59:42 +1100111 r=$?
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000112 if [ ${BUILD_INFO} = 1 ] && [ $r = 0 ]; then
113 op-build O=$O legal-info
114 op-build O=$O graph-build
115 op-build O=$O graph-size
116 op-build O=$O graph-depends
117 fi
118 lsb_release -a > $O/lsb_release
Stewart Smith098d03e2016-03-01 13:59:42 +1100119 if [ $r -ne 0 ]; then
120 exit $r
121 fi
122done
123