diff --git a/src/minimal_overlay/bundles/coreutils/01_get.sh b/src/minimal_overlay/bundles/coreutils/01_get.sh index 779eab667..06e0b57b3 100755 --- a/src/minimal_overlay/bundles/coreutils/01_get.sh +++ b/src/minimal_overlay/bundles/coreutils/01_get.sh @@ -4,35 +4,16 @@ set -e . ../../common.sh -# Read the common configuration properties. +# Read the 'coreutils' download URL from '.config'. DOWNLOAD_URL=`read_property COREUTILS_SOURCE_URL` -USE_LOCAL_SOURCE=`read_property USE_LOCAL_SOURCE` # Grab everything after the last '/' character. ARCHIVE_FILE=${DOWNLOAD_URL##*/} -if [ "$USE_LOCAL_SOURCE" = "true" -a ! -f $MAIN_SRC_DIR/source/overlay/$ARCHIVE_FILE ] ; then - echo "Source bundle $MAIN_SRC_DIR/source/overlay/$ARCHIVE_FILE is missing and will be downloaded." - USE_LOCAL_SOURCE="false" -fi +# Download 'coreutils' source archive in the 'source/overlay' directory. +download_source $DOWNLOAD_URL $OVERLAY_SOURCE_DIR/$ARCHIVE_FILE -cd $MAIN_SRC_DIR/source/overlay - -if [ ! "$USE_LOCAL_SOURCE" = "true" ] ; then - # Downloading coreutils source bundle file. The '-c' option allows the download to resume. - echo "Downloading coreutils source bundle from $DOWNLOAD_URL" - wget -c $DOWNLOAD_URL -else - echo "Using local coreutils source bundle $MAIN_SRC_DIR/source/overlay/$ARCHIVE_FILE" -fi - -# Delete folder with previously extracted coreutils. -echo "Removing coreutils work area. This may take a while." -rm -rf $WORK_DIR/overlay/$BUNDLE_NAME -mkdir $WORK_DIR/overlay/$BUNDLE_NAME - -# Extract coreutils to folder 'work/overlay/coreutils'. -# Full path will be something like 'work/overlay/coreutils/coreutils-8.28'. -tar -xvf $ARCHIVE_FILE -C $WORK_DIR/overlay/$BUNDLE_NAME +# Extract all 'coreutils' sources in the 'work/overlay/coreutils' directory. +extract_source $OVERLAY_SOURCE_DIR/$ARCHIVE_FILE coreutils cd $SRC_DIR diff --git a/src/minimal_overlay/bundles/coreutils/02_build.sh b/src/minimal_overlay/bundles/coreutils/02_build.sh index 0bb145815..49d610be3 100755 --- a/src/minimal_overlay/bundles/coreutils/02_build.sh +++ b/src/minimal_overlay/bundles/coreutils/02_build.sh @@ -4,17 +4,12 @@ set -e . ../../common.sh -cd $WORK_DIR/overlay/$BUNDLE_NAME +cd $OVERLAY_WORK_DIR/$BUNDLE_NAME # Change to the coreutils source directory which ls finds, e.g. 'coreutils-8.28'. cd $(ls -d coreutils-*) -if [ -f Makefile ] ; then - echo "Preparing '$BUNDLE_NAME' work area. This may take a while." - make -j $NUM_JOBS clean -else - echo "The clean phase for '$BUNDLE_NAME' has been skipped." -fi +make_clean rm -rf $DEST_DIR @@ -23,20 +18,15 @@ CFLAGS="$CFLAGS" ./configure \ --prefix=/usr echo "Building '$BUNDLE_NAME'." -make -j $NUM_JOBS +make_target echo "Installing '$BUNDLE_NAME'." -make -j $NUM_JOBS install DESTDIR=$DEST_DIR +make_target install DESTDIR=$DEST_DIR echo "Reducing '$BUNDLE_NAME' size." -set +e -strip -g $DEST_DIR/usr/bin/* -set -e +reduce_size $DEST_DIR/usr/bin -# With '--remove-destination' all possibly existing soft links in -# '$OVERLAY_ROOTFS' will be overwritten correctly. -cp -r --remove-destination $DEST_DIR/* \ - $OVERLAY_ROOTFS +install_to_overlay echo "Bundle '$BUNDLE_NAME' has been installed." diff --git a/src/minimal_overlay/common.sh b/src/minimal_overlay/common.sh index 4b58470f0..d11fa2e12 100755 --- a/src/minimal_overlay/common.sh +++ b/src/minimal_overlay/common.sh @@ -2,12 +2,15 @@ set -e -# common code used by all bundles -# should be included at the top of every *.sh file of each bundle +# Common code used by all bundles. Should be included at the +# top of every *.sh file of each bundle. -export MAIN_SRC_DIR=`realpath --no-symlinks $PWD/../../../` -export WORK_DIR=$MAIN_SRC_DIR/work export SRC_DIR=`realpath --no-symlinks $PWD` +export MAIN_SRC_DIR=`realpath --no-symlinks $SRC_DIR/../../../` +export WORK_DIR=$MAIN_SRC_DIR/work +export SOURCE_DIR=$MAIN_SRC_DIR/source +export OVERLAY_WORK_DIR=$WORK_DIR/overlay +export OVERLAY_SOURCE_DIR=$SOURCE_DIR/overlay export OVERLAY_ROOTFS=$WORK_DIR/overlay_rootfs export BUNDLE_NAME=`basename $SRC_DIR` export DEST_DIR=$WORK_DIR/overlay/$BUNDLE_NAME/${BUNDLE_NAME}_installed @@ -33,33 +36,116 @@ read_property() ( if [ ! "$prop_name" = "" ] ; then # Search in the main '.config' file. - prop_value=`grep -i ^${prop_name}= $CONFIG | cut -f2- -d'=' | xargs` + prop_value="`grep -i ^${prop_name}= $CONFIG | cut -f2- -d'=' | xargs`" if [ -f $SRC_DIR/.config ] ; then # Search in the local '.config' file. - prop_value_local=`grep -i ^${prop_name}= $SRC_DIR/.config | cut -f2- -d'=' | xargs` + prop_value_local="`grep -i ^${prop_name}= $SRC_DIR/.config | cut -f2- -d'=' | xargs`" if [ ! "$prop_value_local" = "" ] ; then # Override the original value with the local value. - prop_value=$prop_value_local + prop_value="$prop_value_local" fi fi fi - echo $prop_value + echo "$prop_value" ) -# Read the 'JOB_FACTOR' property from $CONFIG -export JOB_FACTOR="$(grep -i ^JOB_FACTOR $CONFIG | cut -f2 -d'=')" - -# Read the 'CFLAGS' property from $CONFIG -export CFLAGS="$(grep -i ^CFLAGS $CONFIG | cut -f2 -d'=')" - -# Find the number of available CPU cores +# Read commonly used configuration properties. +export JOB_FACTOR="`read_property JOB_FACTOR`" +export CFLAGS="`read_property CFLAGS`" export NUM_CORES="$(grep ^processor /proc/cpuinfo | wc -l)" # Calculate the number of make "jobs" -export NUM_JOBS=$((NUM_CORES * JOB_FACTOR)) +export NUM_JOBS="$((NUM_CORES * JOB_FACTOR))" # Ideally we would export MAKE at this point with -j etc to allow programs to just run $(MAKE) and not worry about extra flags that need to be passed -# export MAKE="${MAKE-make} -j $NUM_JOBS" +# export MAKE="${MAKE-make} -j $NUM_JOBS" + +download_source() ( + url=$1 # Download from this URL. + file=$2 # Save the resource in this file. + + local=`read_property USE_LOCAL_SOURCE` + + if [ "$local" = "true" -a ! -f $file ] ; then + echo "Source file '$file' is missing and will be downloaded." + local=false + fi + + if [ ! "$local" = "true" ] ; then + echo "Downloading overlay source file from '$url'." + echo "Saving overlay source file in '$file'". + wget -O $file -c $url + else + echo "Using local overlay source file '$file'." + fi +) + +extract_source() ( + file=$1 + name=$2 + + # Delete folder with previously extracted source. + echo "Removing overlay work area for '$name'. This may take a while." + rm -rf $OVERLAY_WORK_DIR/$name + mkdir -p $OVERLAY_WORK_DIR/$name + + # Extract source to folder 'work/overlay/$source'. + tar -xvf $file -C $OVERLAY_WORK_DIR/$name +) + +make_target() ( + make -j $NUM_JOBS "$@" +) + +make_clean() ( + target=$1 + + if [ "$target" = "" ] ; then + target=clean + fi + + if [ -f Makefile ] ; then + echo "Preparing '$BUNDLE_NAME' work area. This may take a while." + make_target $target + else + echo "The clean phase for '$BUNDLE_NAME' has been skipped." + fi +) + +reduce_size() ( + while [ ! "$1" = "" ] ; do + if [ -d $1 ] ; then + for file in $1/* ; do + reduce_size $file + done + elif [ -f $1 ] ; then + set +e + strip -g $1 + set -e + fi + + shift + done +) + +install_to_overlay() ( + # With '--remove-destination' all possibly existing soft links in + # '$OVERLAY_ROOTFS' will be overwritten correctly. + + if [ "$#" = "2" ] ; then + cp -r --remove-destination \ + $DEST_DIR/$1 \ + $OVERLAY_ROOTFS/$2 + elif [ "$#" = "1" ] ; then + cp -r --remove-destination \ + $DEST_DIR/$1 \ + $OVERLAY_ROOTFS + elif [ "$#" = "0" ] ; then + cp -r --remove-destination \ + $DEST_DIR/* \ + $OVERLAY_ROOTFS + fi +)