+
+[ -f "$BASEDIR/include/toplevel.mk" ] || \
+ die "Error: Could not find buildsystem base directory"
+[ -f "$BASEDIR/.config" ] || \
+ die "The buildsystem is not configured. Please run make menuconfig."
+cd "$BASEDIR" || die "Failed to enter base directory"
+
+mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
+ "$BIN_DIR" "$LOG_DIR"
+
+bootstrap_deptest_make()
+{
+ local target="$1"
+ shift
+ local logfile="bootstrap-deptest-$(echo "$target" | tr / -).log"
+ echo "deptest-make $target"
+ deptest_make "$target" "$logfile" "$@" || \
+ die "make $target failed, please check $logfile"
+}
+
+bootstrap_native_make()
+{
+ local target="$1"
+ shift
+ local logfile="bootstrap-native-$(echo "$target" | tr / -).log"
+ echo "make $target"
+ make -j$nrjobs "$target" \
+ V=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
+ die "make $target failed, please check $logfile"
+}
+
+[ -d "$STAGING_DIR_HOST_TMPL" ] || {
+ echo "Bootstrapping build environment..."
+ rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
+ mkdir -p "$STAGING_DIR" "$STAGING_DIR_HOST" \
+ "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
+ bootstrap_native_make tools/install
+ bootstrap_native_make toolchain/install
+ bootstrap_deptest_make tools/install
+ bootstrap_deptest_make target/linux/install
+ cp -al "$STAGING_DIR_HOST" "$STAGING_DIR_HOST_TMPL"
+ rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST"
+ echo "Build environment OK."
+}
+
+if [ -z "$packages" ]; then
+ # iterate over all packages
+ for pkg in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
+ test_package "$pkg"
+ done
+else
+ # only check the specified packages
+ for pkg in $packages; do
+ test_package "$pkg"
+ done
+fi