Skip to content

Commit

Permalink
Teach system-image.sh to handle its own dependencies, rebuilding kern…
Browse files Browse the repository at this point in the history
…el and

repackaging cpio/squashfs as appropraite, and _not_ doing so when unneeded.
  • Loading branch information
landley committed Nov 22, 2015
1 parent e5e6a20 commit 2393d39
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
24 changes: 10 additions & 14 deletions build.sh 100755 → 100644
Expand Up @@ -81,6 +81,7 @@ zap()
done
}

# If $AFTER set, skip stages until we match $AFTER to implement $2="start here"
do_stage()
{
STAGE="$1"
Expand All @@ -95,10 +96,12 @@ do_stage()
}

# The first two stages (download.sh and host-tools.sh) are architecture
# independent. In order to allow multiple builds in parallel, re-running
# independent. In order to allow multiple builds in parallel, re-running
# them after they've already completed must be a safe NOP.

# Download source code.
# Download source code. If tarballs already there, verify sha1sums and
# delete/redownload if they don't match (to handle interrupted partial
# download).

do_stage download

Expand All @@ -116,7 +119,7 @@ if [ -z "$MY_CROSS_PATH" ] && not_already simple-cross-compiler
then
# If we need to build cross compiler, assume root filesystem is stale.

zap root-filesystem cross-compiler native-compiler system-image
zap root-filesystem cross-compiler native-compiler

do_stage simple-cross-compiler "$ARCH"
fi
Expand All @@ -128,7 +131,7 @@ fi
if [ -z "$MY_CROSS_PATH" ] && [ ! -z "$CROSS_COMPILER_HOST" ] &&
not_already cross-compiler
then
zap root-filesystem native-compiler system-image
zap root-filesystem native-compiler

# Build the host compiler if necessary

Expand All @@ -149,9 +152,6 @@ fi

if not_already root-filesystem
then
zap system-image
[ "$SYSIMAGE_TYPE" == rootfs ] && zap system-image

do_stage root-filesystem "$ARCH"
fi

Expand All @@ -163,14 +163,10 @@ fi
if [ -z "$MY_CROSS_PATH" ] && ! grep -q ELF2FLT sources/targets/"$ARCH" &&
not_already native-compiler
then
zap system-image

do_stage native-compiler "$ARCH"
fi

# Package it all up into something qemu can boot.
# Package it all up into something qemu can boot. Like host-tools.sh,
# this is always called and handles its own dependencies internally.

if not_already system-image
then
do_stage system-image "$ARCH"
fi
do_stage system-image "$ARCH"
2 changes: 1 addition & 1 deletion sources/functions.sh
Expand Up @@ -73,7 +73,7 @@ load_target()

STAGE_DIR="$BUILD/${STAGE_NAME}-${ARCH_NAME}"

blank_tempdir "$STAGE_DIR"
[ -z "$KEEP_STAGEDIR" ] && blank_tempdir "$STAGE_DIR"
NO_CLEANUP=${NO_CLEANUP/temp//} blank_tempdir "$WORK"

export PATH="$(cc_path "$ARCH")$PATH"
Expand Down
48 changes: 38 additions & 10 deletions system-image.sh
@@ -1,14 +1,31 @@
#!/bin/bash

# Combine a filesystem image and kernel with emulator launch scripts.

# Package a root filesystem directory into a filesystem image file
# Combine filesystem images, kernel, and emulator launch scripts
# into something you can boot and run.

source sources/include.sh || exit 1

# Parse sources/targets/$1
# We do our own dependency checking (like host-tool.sh) so don't delete stage
# dir when parsing sources/targets/$1

KEEP_STAGEDIR=1 load_target "$1"

# Is $1 newer than cross compiler and all listed prerequisites ($2...)?

load_target "$1"
is_newer()
{
X="$1"
shift
[ ! -e "$X" ] && return 0
[ "$(which "${CC_PREFIX}cc")" -nt "$X" ] && return 0
while [ ! -z "$1" ]
do
[ ! -z "$(find "$X" -newer "$X" 2>/dev/null)" ] && return 0
shift
done

return 1
}

# Provide qemu's common command line options between architectures.

Expand Down Expand Up @@ -65,17 +82,27 @@ done

# Package root-filesystem into cpio file for initramfs

SYSIMAGE_TYPE=cpio image_filesystem "$BUILD/root-filesystem-$ARCH" \
"$STAGE_DIR/rootfs" &&
if [ -d "$BUILD/native-compiler-$ARCH" ]
if is_newer "$STAGE_DIR/rootfs.cpio.gz" "$BUILD/root-filesystem-$ARCH"
then
SYSIMAGE_TYPE=cpio image_filesystem "$BUILD/root-filesystem-$ARCH" \
"$STAGE_DIR/temp" &&
mv -f "$STAGE_DIR"/{temp,rootfs}.cpio.gz || dienow
[ "$SYSIMAGE_TYPE" == rootfs ] && rm -f "$STAGE_DIR/linux"
fi

# Package native-compiler into squashfs for /dev/hda mount

if is_newer "$STAGE_DIR/toolchain.sqf" "$BUILD/native-compiler-$ARCH"
then
SYSIMAGE_TYPE=squashfs image_filesystem "$BUILD/native-compiler-$ARCH" \
"$STAGE_DIR/toolchain" || dienow
"$STAGE_DIR/temp" &&
mv -f "$STAGE_DIR"/{temp,toolchain}.sqf || dienow
fi

# Build linux kernel for the target

if [ -z "$NO_CLEANUP" ] || [ ! -e "$STAGE_DIR/linux" ]
if is_newer "$STAGE_DIR/linux" "$BUILD/root-filesystem-$ARCH" \
$(package_cache linux)
then
setupfor linux
getconfig linux > mini.conf
Expand All @@ -88,6 +115,7 @@ then
cp "$KERNEL_PATH" "$STAGE_DIR/linux"
cleanup
fi

# Tar it up.

ARCH="$ARCH_NAME" create_stage_tarball
Expand Down

0 comments on commit 2393d39

Please sign in to comment.