diff --git a/src/05_prepare_glibc.sh b/src/05_prepare_glibc.sh deleted file mode 100755 index d82603b8d..000000000 --- a/src/05_prepare_glibc.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -echo "*** PREPARE GLIBC BEGIN ***" - -SRC_DIR=$(pwd) - -# Save the kernel installation directory. -KERNEL_INSTALLED=$(pwd)/work/kernel/kernel_installed - -cd work/glibc - -echo "Preparing glibc. This may take a while..." - -rm -rf glibc_prepared -cp -r glibc_installed glibc_prepared - -cd glibc_prepared - -# Create custom 'usr' area and link it with some of the kernel header directories. -# BusyBox compilation process uses these linked directories. The following -# directories are affected: -# -# usr (glibc) -# | -# +--include (glibc) -# | | -# | +--asm (kernel) -# | | -# | +--asm-generic (kernel) -# | | -# | +--linux (kernel) -# | | -# | +--mtd (kernel) -# | -# +--lib (glibc) - -mkdir -p usr -cd usr - -ln -s ../include include -ln -s ../lib lib - -cd ../include - -ln -s $KERNEL_INSTALLED/include/linux linux -ln -s $KERNEL_INSTALLED/include/asm asm -ln -s $KERNEL_INSTALLED/include/asm-generic asm-generic -ln -s $KERNEL_INSTALLED/include/mtd mtd - -cd $SRC_DIR - -echo "*** PREPARE GLIBC END ***" - diff --git a/src/05_prepare_sysroot.sh b/src/05_prepare_sysroot.sh new file mode 100755 index 000000000..501f1e7ea --- /dev/null +++ b/src/05_prepare_sysroot.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +echo "*** PREPARE SYSROOT BEGIN ***" + +SRC_DIR=$(pwd) + +cd work + +echo "Cleaning existing sysroot. This may take a while..." +rm -rf sysroot +rm -rf sysroot.specs + +echo "Preparing glibc. This may take a while..." +cp -r glibc/glibc_installed sysroot +cd sysroot + +# Create custom 'usr' area and link it with some of the kernel header directories. +# BusyBox compilation process uses these linked directories. The following +# directories are affected: +# +# usr (glibc) +# | +# +--include (glibc) +# | | +# | +--asm (kernel) +# | | +# | +--asm-generic (kernel) +# | | +# | +--linux (kernel) +# | | +# | +--mtd (kernel) +# | +# +--lib (glibc) + +mkdir -p usr + +ln -s ../include usr/include +ln -s ../lib usr/lib + +ln -s ../../kernel/kernel_installed/include/linux include/linux +ln -s ../../kernel/kernel_installed/include/asm include/asm +ln -s ../../kernel/kernel_installed/include/asm-generic include/asm-generic +ln -s ../../kernel/kernel_installed/include/mtd include/mtd + +cd .. + +echo "generating sysroot.specs" +SYSROOT="$PWD/sysroot" + +# gcc has a "internal" path that needs to be added to find the static versions of libgcc_* +GCC_INTERNAL_PATH=$(dirname $(gcc -print-libgcc-file-name)) + +cat << CEOF > sysroot.specs +*link_libgcc: +-L$SYSROOT/lib -L$SYSROOT/lib64 -L$SYSROOT/usr/lib -L$SYSROOT/usr/lib64 -L$SYSROOT/usr/local/lib -L$SYSROOT/usr/local/lib64 -L$GCC_INTERNAL_PATH +CEOF + +cd $SRC_DIR + +echo "*** PREPARE SYSROOT END ***" + diff --git a/src/07_build_busybox.sh b/src/07_build_busybox.sh index 03c3761be..aa9de0197 100755 --- a/src/07_build_busybox.sh +++ b/src/07_build_busybox.sh @@ -13,8 +13,8 @@ NUM_CORES=$(grep ^processor /proc/cpuinfo | wc -l) # Calculate the number of 'make' jobs to be used later. NUM_JOBS=$((NUM_CORES * JOB_FACTOR)) -# Remember the glibc installation area. -GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared +# Remember the sysroot +SYSROOT=$(pwd)/work/sysroot cd work/busybox @@ -53,10 +53,10 @@ fi # This variable holds the full path to the glibc installation area as quoted string. # All back slashes are escaped (/ => \/) in order to keep the 'sed' command stable. -GLIBC_PREPARED_ESCAPED=$(echo \"$GLIBC_PREPARED\" | sed 's/\//\\\//g') +SYSROOT_ESCAPED=$(echo \"$SYSROOT\" | sed 's/\//\\\//g') # Now we tell BusyBox to use the glibc prepared area. -sed -i "s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=$GLIBC_PREPARED_ESCAPED/" .config +sed -i "s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=$SYSROOT_ESCAPED/" .config # Read the 'CFLAGS' property from '.config' CFLAGS="$(grep -i ^CFLAGS .config | cut -f2 -d'=')" diff --git a/src/09_generate_rootfs.sh b/src/09_generate_rootfs.sh index e8485fe97..37c07534a 100755 --- a/src/09_generate_rootfs.sh +++ b/src/09_generate_rootfs.sh @@ -4,8 +4,8 @@ echo "*** GENERATE ROOTFS BEGIN ***" SRC_ROOT=$(pwd) -# Remember the glibc prepared folder. -GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared +# Remember the sysroot +SYSROOT=$(pwd)/work/sysroot # Remember the BysyBox install folder. BUSYBOX_INSTALLED=$(pwd)/work/busybox/busybox_installed @@ -44,22 +44,22 @@ fi BUSYBOX_ARCH=$(file bin/busybox | cut -d' ' -f3) if [ "$BUSYBOX_ARCH" = "64-bit" ] ; then mkdir lib64 - cp $GLIBC_PREPARED/lib/ld-linux* lib64 + cp $SYSROOT/lib/ld-linux* lib64 echo "Dynamic loader is accessed via '/lib64'." else - cp $GLIBC_PREPARED/lib/ld-linux* lib + cp $SYSROOT/lib/ld-linux* lib echo "Dynamic loader is accessed via '/lib'." fi # Copy all necessary 'glibc' libraries to '/lib' BEGIN. # BusyBox has direct dependencies on these libraries. -cp $GLIBC_PREPARED/lib/libm.so.6 lib -cp $GLIBC_PREPARED/lib/libc.so.6 lib +cp $SYSROOT/lib/libm.so.6 lib +cp $SYSROOT/lib/libc.so.6 lib # These libraries are necessary for the DNS resolving. -cp $GLIBC_PREPARED/lib/libresolv.so.2 lib -cp $GLIBC_PREPARED/lib/libnss_dns.so.2 lib +cp $SYSROOT/lib/libresolv.so.2 lib +cp $SYSROOT/lib/libnss_dns.so.2 lib # Copy all necessary 'glibc' libraries to '/lib' END. diff --git a/src/build_minimal_linux_live.sh b/src/build_minimal_linux_live.sh index 82fae6b4b..1d32a3c14 100755 --- a/src/build_minimal_linux_live.sh +++ b/src/build_minimal_linux_live.sh @@ -1,16 +1,6 @@ #!/bin/sh -time sh 00_clean.sh -time sh 01_get_kernel.sh -time sh 02_build_kernel.sh -time sh 03_get_glibc.sh -time sh 04_build_glibc.sh -time sh 05_prepare_glibc.sh -time sh 06_get_busybox.sh -time sh 07_build_busybox.sh -time sh 08_prepare_src.sh -time sh 09_generate_rootfs.sh -time sh 10_pack_rootfs.sh -time sh 11_get_syslinux.sh -time sh 12_generate_iso.sh - +for script in $(ls | grep '^[0-9]*_.*.sh'); do + echo "$script" + time sh "$script" +done diff --git a/src/minimal_overlay/bundles/cf_cli/01_get.sh b/src/minimal_overlay/bundles/cf_cli/01_get.sh index ae47f0360..534e2495c 100755 --- a/src/minimal_overlay/bundles/cf_cli/01_get.sh +++ b/src/minimal_overlay/bundles/cf_cli/01_get.sh @@ -2,10 +2,7 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh # Grab everything after the '=' character. #DOWNLOAD_URL=$(grep -i CLOUD_FOUNDRY_CLI_URL $MAIN_SRC_DIR/.config | cut -f2 -d'=') @@ -32,11 +29,11 @@ fi # Delete folder with previously prepared cloud foundry cli. echo "Removing cloud foundry cli work area. This may take a while..." -rm -rf ../../work/overlay/clofo -mkdir ../../work/overlay/clofo +rm -rf $WORK_DIR/overlay/clofo +mkdir $WORK_DIR/overlay/clofo # Copy cf-cli.tgz to folder 'work/overlay/clofo'. -cp cf-cli.tgz ../../work/overlay/clofo +cp cf-cli.tgz $WORK_DIR/overlay/clofo cd $SRC_DIR diff --git a/src/minimal_overlay/bundles/cf_cli/02_install.sh b/src/minimal_overlay/bundles/cf_cli/02_install.sh index 4a125cace..70314f276 100755 --- a/src/minimal_overlay/bundles/cf_cli/02_install.sh +++ b/src/minimal_overlay/bundles/cf_cli/02_install.sh @@ -2,17 +2,14 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh echo "Removing old cloud foundry artifacts. This may take a while..." -rm -rf $MAIN_SRC_DIR/work/overlay/clofo/clofo_installed -mkdir -p $MAIN_SRC_DIR/work/overlay/clofo/clofo_installed/opt/clofo -mkdir -p $MAIN_SRC_DIR/work/overlay/clofo/clofo_installed/bin +rm -rf $WORK_DIR/overlay/clofo/clofo_installed +mkdir -p $WORK_DIR/overlay/clofo/clofo_installed/opt/clofo +mkdir -p $WORK_DIR/overlay/clofo/clofo_installed/bin -cd $MAIN_SRC_DIR/work/overlay/clofo +cd $WORK_DIR/overlay/clofo cp $MAIN_SRC_DIR/source/overlay/cf-cli.tgz . @@ -20,14 +17,13 @@ tar -xvf cf-cli.tgz rm -f LICENSE NOTICE cf-cli.tgz chmod +rx cf -cp cf $MAIN_SRC_DIR/work/overlay/clofo/clofo_installed/opt/clofo/cf +cp cf $WORK_DIR/overlay/clofo/clofo_installed/opt/clofo/cf -cd $MAIN_SRC_DIR/work/overlay/clofo/clofo_installed +cd $WORK_DIR/overlay/clofo/clofo_installed ln -s ../opt/clofo/cf bin/cf -cp -r $MAIN_SRC_DIR/work/overlay/clofo/clofo_installed/* \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +cp -r $WORK_DIR/overlay/clofo/clofo_installed/* $WORK_DIR/src/minimal_overlay/rootfs echo "cloud foundry cli has been installed." diff --git a/src/minimal_overlay/bundles/dropbear/01_get.sh b/src/minimal_overlay/bundles/dropbear/01_get.sh index 4276c98c2..bcf116a03 100755 --- a/src/minimal_overlay/bundles/dropbear/01_get.sh +++ b/src/minimal_overlay/bundles/dropbear/01_get.sh @@ -2,10 +2,7 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh # Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i DROPBEAR_SOURCE_URL $MAIN_SRC_DIR/.config | cut -f2 -d'=') @@ -33,12 +30,12 @@ fi # Delete folder with previously extracted Dropbear. echo "Removing Dropbear work area. This may take a while..." -rm -rf ../../work/overlay/dropbear -mkdir ../../work/overlay/dropbear +rm -rf $WORK_DIR/overlay/dropbear +mkdir $WORK_DIR/overlay/dropbear # Extract Dropbear to folder 'work/overlay/dropbear'. # Full path will be something like 'work/overlay/dropbear/dropbear-2016.73'. -tar -xvf $ARCHIVE_FILE -C ../../work/overlay/dropbear +tar -xvf $ARCHIVE_FILE -C $WORK_DIR/overlay/dropbear cd $SRC_DIR diff --git a/src/minimal_overlay/bundles/dropbear/02_build.sh b/src/minimal_overlay/bundles/dropbear/02_build.sh index 9fe2db003..bf8469399 100755 --- a/src/minimal_overlay/bundles/dropbear/02_build.sh +++ b/src/minimal_overlay/bundles/dropbear/02_build.sh @@ -2,107 +2,83 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh -# Read the 'JOB_FACTOR' property from '.config' -JOB_FACTOR="$(grep -i ^JOB_FACTOR $MAIN_SRC_DIR/.config | cut -f2 -d'=')" +cd $WORK_DIR/overlay/dropbear -# Read the 'CFLAGS' property from '.config' -CFLAGS="$(grep -i ^CFLAGS $MAIN_SRC_DIR/.config | cut -f2 -d'=')" - -# Find the number of available CPU cores. -NUM_CORES=$(grep ^processor /proc/cpuinfo | wc -l) - -# Calculate the number of 'make' jobs to be used later. -NUM_JOBS=$((NUM_CORES * JOB_FACTOR)) - -if [ ! -d $MAIN_SRC_DIR/work/glibc/glibc_prepared ] ; then - echo "Cannot continue - Dropbear SSH depends on GLIBC. Please buld GLIBC first." - exit 1 -fi - -cd $MAIN_SRC_DIR/work/overlay/dropbear +DESTDIR="$PWD/dropbear_installed" # Change to the Dropbear source directory which ls finds, e.g. 'dropbear-2016.73'. cd $(ls -d dropbear-*) echo "Preparing Dropbear work area. This may take a while..." -make clean -j $NUM_JOBS 2>/dev/null - -rm -rf ../dropbear_installed +make -j $NUM_JOBS clean +rm -rf $DESTDIR echo "Configuring Dropbear..." ./configure \ - --prefix=$MAIN_SRC_DIR/work/overlay/dropbear/dropbear_installed \ + --prefix=/usr \ --disable-zlib \ --disable-loginfunc \ - CFLAGS="$CFLAGS" + CC="$CC" \ + CFLAGS="$CFLAGS" \ + LDFLAGS="$LDFLAGS" echo "Building Dropbear..." make -j $NUM_JOBS echo "Installing Dropbear..." -make install -j $NUM_JOBS +make -j $NUM_JOBS install DESTDIR="$DESTDIR" -mkdir -p ../dropbear_installed/lib +mkdir -p $DESTDIR/lib # Copy all dependent GLIBC libraries. -cp $MAIN_SRC_DIR/work/glibc/glibc_prepared/lib/libnsl.so.1 ../dropbear_installed/lib -cp $MAIN_SRC_DIR/work/glibc/glibc_prepared/lib/libnss_compat.so.2 ../dropbear_installed/lib -cp $MAIN_SRC_DIR/work/glibc/glibc_prepared/lib/libutil.so.1 ../dropbear_installed/lib -cp $MAIN_SRC_DIR/work/glibc/glibc_prepared/lib/libcrypt.so.1 ../dropbear_installed/lib +cp $SYSROOT/lib/libnsl.so.1 $DESTDIR/lib +cp $SYSROOT/lib/libnss_compat.so.2 $DESTDIR/lib +cp $SYSROOT/lib/libutil.so.1 $DESTDIR/lib +cp $SYSROOT/lib/libcrypt.so.1 $DESTDIR/lib -mkdir -p ../dropbear_installed/etc/dropbear +mkdir -p $DESTDIR/etc/dropbear # Create Dropbear SSH configuration BEGIN -# Create RSA key. -../dropbear_installed/bin/dropbearkey \ - -t rsa \ - -f ../dropbear_installed/etc/dropbear/dropbear_rsa_host_key - -# Create DSS key. -../dropbear_installed/bin/dropbearkey \ - -t dss \ - -f ../dropbear_installed/etc/dropbear/dropbear_dss_host_key - -# Create ECDSA key. -../dropbear_installed/bin/dropbearkey \ - -t ecdsa \ - -f ../dropbear_installed/etc/dropbear/dropbear_ecdsa_host_key +for key_type in rsa dss ecdsa; do + echo "generating $key_type host key" + $DESTDIR/usr/bin/dropbearkey \ + -t $key_type \ + -f $DESTDIR/etc/dropbear/dropbear_${key_type}_host_key +done # Create user/group configuration files. -touch ../dropbear_installed/etc/passwd -touch ../dropbear_installed/etc/group +touch $DESTDIR/etc/passwd +touch $DESTDIR/etc/group # Add group 0 for root. echo "root:x:0:" \ - > ../dropbear_installed/etc/group + > $DESTDIR/etc/group # Add user root with password 'toor'. echo "root:AprZpdBUhZXss:0:0:Minimal Root,,,:/root:/bin/sh" \ - > ../dropbear_installed/etc/passwd + > $DESTDIR/etc/passwd # Create home folder for root user. -mkdir -p ../dropbear_installed/root +mkdir -p $DESTDIR/root # Create Dropbear SSH configuration END echo "Reducing Dropbear size..." strip -g \ - ../dropbear_installed/bin/* \ - ../dropbear_installed/sbin/* \ - ../dropbear_installed/lib/* + $DESTDIR/usr/bin/* \ + $DESTDIR/usr/sbin/* \ + $DESTDIR/lib/* -cp -r \ - ../dropbear_installed/etc \ - ../dropbear_installed/bin \ - ../dropbear_installed/sbin \ - ../dropbear_installed/lib \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +ROOTFS=$WORK_DIR/src/minimal_overlay/rootfs + +mkdir -p $ROOTFS/usr +cp -r $DESTDIR/etc $ROOTFS +cp -r $DESTDIR/usr/bin $ROOTFS/usr +cp -r $DESTDIR/usr/sbin $ROOTFS/usr +cp -r $DESTDIR/lib $ROOTFS echo "Dropbear has been installed." diff --git a/src/minimal_overlay/bundles/felix/01_get.sh b/src/minimal_overlay/bundles/felix/01_get.sh index 2f0133189..0a1707b56 100755 --- a/src/minimal_overlay/bundles/felix/01_get.sh +++ b/src/minimal_overlay/bundles/felix/01_get.sh @@ -2,10 +2,7 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh # Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i FELIX_SOURCE_URL $MAIN_SRC_DIR/.config | cut -f2 -d'=') @@ -33,12 +30,12 @@ fi # Delete folder with previously extracted Felix. echo "Removing Apache Felix work area. This may take a while..." -rm -rf ../../work/overlay/felix -mkdir ../../work/overlay/felix +rm -rf $WORK_DIR/overlay/felix +mkdir $WORK_DIR/overlay/felix # Extract Felix to folder 'work/overlay/felix'. # Full path will be something like 'work/overlay/felix/felix-framework-5.4.0'. -tar -xvf $ARCHIVE_FILE -C ../../work/overlay/felix +tar -xvf $ARCHIVE_FILE -C $WORK_DIR/overlay/felix cd $SRC_DIR diff --git a/src/minimal_overlay/bundles/felix/02_install.sh b/src/minimal_overlay/bundles/felix/02_install.sh index 0b90d86bf..a90cdf4ef 100755 --- a/src/minimal_overlay/bundles/felix/02_install.sh +++ b/src/minimal_overlay/bundles/felix/02_install.sh @@ -2,17 +2,14 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh echo "Removing old Apache Felix artifacts. This may take a while..." -rm -rf $MAIN_SRC_DIR/work/overlay/felix/felix_installed -mkdir -p $MAIN_SRC_DIR/work/overlay/felix/felix_installed/opt/felix -mkdir -p $MAIN_SRC_DIR/work/overlay/felix/felix_installed/bin +rm -rf $WORK_DIR/overlay/felix/felix_installed +mkdir -p $WORK_DIR/overlay/felix/felix_installed/opt/felix +mkdir -p $WORK_DIR/overlay/felix/felix_installed/bin -cd $MAIN_SRC_DIR/work/overlay/felix +cd $WORK_DIR/overlay/felix cd $(ls -d felix-*) cat << CEOF > bin/felix-start.sh @@ -25,14 +22,14 @@ CEOF chmod +rx bin/felix-start.sh -cp -r * $MAIN_SRC_DIR/work/overlay/felix/felix_installed/opt/felix +cp -r * $WORK_DIR/overlay/felix/felix_installed/opt/felix -cd $MAIN_SRC_DIR/work/overlay/felix/felix_installed +cd $WORK_DIR/overlay/felix/felix_installed ln -s ../opt/felix/bin/felix-start.sh bin/felix-start -cp -r $MAIN_SRC_DIR/work/overlay/felix/felix_installed/* \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +cp -r $WORK_DIR/overlay/felix/felix_installed/* \ + $WORK_DIR/src/minimal_overlay/rootfs echo "Apache Felix has been installed." diff --git a/src/minimal_overlay/bundles/glibc_full/bundle.sh b/src/minimal_overlay/bundles/glibc_full/bundle.sh index 4d64d1578..3d9010ccc 100755 --- a/src/minimal_overlay/bundles/glibc_full/bundle.sh +++ b/src/minimal_overlay/bundles/glibc_full/bundle.sh @@ -2,26 +2,23 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh -if [ ! -d $MAIN_SRC_DIR/work/glibc/glibc_prepared ] ; then +if [ ! -d $SYSROOT ] ; then echo "Cannot continue - GLIBC is missing. Please buld GLIBC first." exit 1 fi echo "Preparing the overlay glibc folder. This may take a while..." -rm -rf $MAIN_SRC_DIR/work/overlay/glibc -mkdir -p $MAIN_SRC_DIR/work/overlay/glibc/lib +rm -rf $WORK_DIR/overlay/glibc +mkdir -p $WORK_DIR/overlay/glibc/lib -cd $MAIN_SRC_DIR/work/glibc/glibc_prepared/lib +cd $SYSROOT -find . -type l -exec cp {} $MAIN_SRC_DIR/work/overlay/glibc/lib \; +find . -type l -exec cp {} $WORK_DIR/overlay/glibc/lib \; echo "All libraries have been copied." -cd $MAIN_SRC_DIR/work/overlay/glibc/lib +cd $WORK_DIR/overlay/glibc/lib for FILE_DEL in $(ls *.so) do @@ -38,10 +35,8 @@ echo "Duplicate libraries have been replaced with soft links." strip -g * echo "All libraries have been optimized for size." -cp -r $MAIN_SRC_DIR/work/overlay/glibc/lib \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +cp -r $WORK_DIR/overlay/glibc/lib $WORK_DIR/src/minimal_overlay/rootfs echo "All GNU C libraries have been installed." cd $SRC_DIR - diff --git a/src/minimal_overlay/bundles/java/bundle.sh b/src/minimal_overlay/bundles/java/bundle.sh index dcffd407d..887561b79 100755 --- a/src/minimal_overlay/bundles/java/bundle.sh +++ b/src/minimal_overlay/bundles/java/bundle.sh @@ -18,10 +18,7 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh # Read the 'JAVA_ARCHIVE' property from '.config' JAVA_ARCHIVE="$(grep -i ^JAVA_ARCHIVE $MAIN_SRC_DIR/.config | cut -f2 -d'=')" @@ -34,25 +31,25 @@ elif [ ! -f "$JAVA_ARCHIVE" ] ; then exit 1 fi -rm -rf $MAIN_SRC_DIR/work/overlay/java -mkdir -p $MAIN_SRC_DIR/work/overlay/java/opt +rm -rf $WORK_DIR/overlay/java +mkdir -p $WORK_DIR/overlay/java/opt tar -xvf \ $JAVA_ARCHIVE \ - -C $MAIN_SRC_DIR/work/overlay/java/opt + -C $WORK_DIR/overlay/java/opt -cd $MAIN_SRC_DIR/work/overlay/java/opt +cd $WORK_DIR/overlay/java/opt mv $(ls -d *) java -mkdir $MAIN_SRC_DIR/work/overlay/java/bin +mkdir $WORK_DIR/overlay/java/bin for FILE in $(ls java/bin) do ln -s ../opt/java/bin/$FILE ../bin/$FILE done -cp -r $MAIN_SRC_DIR/work/overlay/java/* \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +cp -r $WORK_DIR/overlay/java/* \ + $WORK_DIR/src/minimal_overlay/rootfs echo "Java has been installed." diff --git a/src/minimal_overlay/bundles/links/01_get.sh b/src/minimal_overlay/bundles/links/01_get.sh index e2a9f4da6..f245643c5 100755 --- a/src/minimal_overlay/bundles/links/01_get.sh +++ b/src/minimal_overlay/bundles/links/01_get.sh @@ -2,10 +2,7 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh # Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i LINKS_SOURCE_URL $MAIN_SRC_DIR/.config | cut -f2 -d'=') @@ -33,12 +30,12 @@ fi # Delete folder with previously extracted Links. echo "Removing Links work area. This may take a while..." -rm -rf ../../work/overlay/links -mkdir ../../work/overlay/links +rm -rf $WORK_DIR/overlay/links +mkdir $WORK_DIR/overlay/links # Extract Links to folder 'work/overlay/links'. # Full path will be something like 'work/overlay/links/links-2.12'. -tar -xvf $ARCHIVE_FILE -C ../../work/overlay/links +tar -xvf $ARCHIVE_FILE -C $WORK_DIR/overlay/links cd $SRC_DIR diff --git a/src/minimal_overlay/bundles/links/02_build.sh b/src/minimal_overlay/bundles/links/02_build.sh index 7a23f778f..4d77ce1e4 100755 --- a/src/minimal_overlay/bundles/links/02_build.sh +++ b/src/minimal_overlay/bundles/links/02_build.sh @@ -2,57 +2,41 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh -# Read the 'JOB_FACTOR' property from '.config' -JOB_FACTOR="$(grep -i ^JOB_FACTOR $MAIN_SRC_DIR/.config | cut -f2 -d'=')" +cd $WORK_DIR/overlay/links -# Read the 'CFLAGS' property from '.config' -CFLAGS="$(grep -i ^CFLAGS $MAIN_SRC_DIR/.config | cut -f2 -d'=')" - -# Find the number of available CPU cores. -NUM_CORES=$(grep ^processor /proc/cpuinfo | wc -l) - -# Calculate the number of 'make' jobs to be used later. -NUM_JOBS=$((NUM_CORES * JOB_FACTOR)) - -cd $MAIN_SRC_DIR/work/overlay/links +DESTDIR="$PWD/links_installed" # Change to the Links source directory which ls finds, e.g. 'links-2.12'. cd $(ls -d links-*) echo "Preparing Links work area. This may take a while..." -make clean -j $NUM_JOBS 2>/dev/null +make -j $NUM_JOBS clean -rm -rf ../links_installed +rm -rf $DESTDIR echo "Configuring Links..." -./configure \ - --prefix=../links_installed \ +CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" ./configure \ + --prefix=/usr \ --disable-graphics \ --disable-utf8 \ --without-ipv6 \ - --without-ssl \ - --without-zlib \ - --without-x - -# Set CFLAGS directly in Makefile. -sed -i "s/^CFLAGS = .*/CFLAGS = $CFLAGS/" Makefile + --without-ssl echo "Building Links..." make -j $NUM_JOBS echo "Installing Links..." -make install -j $NUM_JOBS +make -j $NUM_JOBS install DESTDIR=$DESTDIR echo "Reducing Links size..." -strip -g ../links_installed/bin/* 2>/dev/null +strip -g $DESTDIR/usr/bin/* -cp -r ../links_installed/bin \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +ROOTFS="$WORK_DIR/src/minimal_overlay/rootfs" + +mkdir -p "$ROOTFS/usr/bin" +cp -r $DESTDIR/usr/bin/* $ROOTFS/usr/bin/ echo "Links has been installed." diff --git a/src/minimal_overlay/bundles/lua/01_get.sh b/src/minimal_overlay/bundles/lua/01_get.sh index 1891f4c2f..b9182c5d3 100755 --- a/src/minimal_overlay/bundles/lua/01_get.sh +++ b/src/minimal_overlay/bundles/lua/01_get.sh @@ -2,10 +2,7 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh # Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i LUA_SOURCE_URL $MAIN_SRC_DIR/.config | cut -f2 -d'=') @@ -33,11 +30,11 @@ fi # Delete folder with previously extracted Lua. echo "Removing Lua work area. This may take a while..." -rm -rf ../../work/overlay/lua -mkdir ../../work/overlay/lua +rm -rf $WORK_DIR/overlay/lua +mkdir $WORK_DIR/overlay/lua # Extract lua to folder 'work/overlay/lua'. # Full path will be something like 'work/overlay/lua/lua-5.3.4'. -tar -xvf $ARCHIVE_FILE -C ../../work/overlay/lua +tar -xvf $ARCHIVE_FILE -C $WORK_DIR/overlay/lua cd $SRC_DIR diff --git a/src/minimal_overlay/bundles/lua/02_build.sh b/src/minimal_overlay/bundles/lua/02_build.sh index 9169d6a43..088c1b141 100755 --- a/src/minimal_overlay/bundles/lua/02_build.sh +++ b/src/minimal_overlay/bundles/lua/02_build.sh @@ -4,42 +4,32 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh -# Read the 'JOB_FACTOR' property from '.config' -JOB_FACTOR="$(grep -i ^JOB_FACTOR $MAIN_SRC_DIR/.config | cut -f2 -d'=')" +cd $WORK_DIR/overlay/lua -# Read the 'CFLAGS' property from '.config' -CFLAGS="$(grep -i ^CFLAGS $MAIN_SRC_DIR/.config | cut -f2 -d'=')" - -# Find the number of available CPU cores. -NUM_CORES=$(grep ^processor /proc/cpuinfo | wc -l) - -# Calculate the number of 'make' jobs to be used later. -NUM_JOBS=$((NUM_CORES * JOB_FACTOR)) - -cd $MAIN_SRC_DIR/work/overlay/lua +DESTDIR="$PWD/lua_installed" # Change to the Lua source directory which ls finds, e.g. 'lua-5.3.4'. cd $(ls -d lua-*) echo "Preparing Lua work area. This may take a while..." -make clean -j $NUM_JOBS 2>/dev/null -rm -rf ../lua_installed +# we install lua to /usr and not to /usr/local so we need to fix luaconf.h so lua can find modules, etc ... +sed -i 's/#define LUA_ROOT.*/#define LUA_ROOT \"\/usr\/\"/' src/luaconf.h +make -j $NUM_JOBS clean +rm -rf $DESTDIR echo "Building Lua..." -make posix -j $NUM_JOBS CFLAGS="$CFLAGS --sysroot=$MAIN_SRC_DIR/work/glibc/glibc_prepared/" +make -j $NUM_JOBS posix CC="$CC" CFLAGS="$CFLAGS" -make install -j $NUM_JOBS INSTALL_TOP=../../lua_installed/usr +make -j $NUM_JOBS install INSTALL_TOP="$DESTDIR/usr" echo "Reducing Lua size..." -strip -g ../lua_installed/bin/* 2>/dev/null +strip -g $DESTDIR/usr/bin/* 2>/dev/null -mkdir -p $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs/usr/ -cp -r ../lua_installed/usr/* $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs/usr +ROOTFS="$WORK_DIR/src/minimal_overlay/rootfs" +mkdir -p $ROOTFS/usr/ +cp -r $DESTDIR/usr/* $ROOTFS/usr/ echo "Lua has been installed." diff --git a/src/minimal_overlay/bundles/mll_utils/01_prepare.sh b/src/minimal_overlay/bundles/mll_utils/01_prepare.sh index b8aa8d9c9..36b4db352 100755 --- a/src/minimal_overlay/bundles/mll_utils/01_prepare.sh +++ b/src/minimal_overlay/bundles/mll_utils/01_prepare.sh @@ -2,14 +2,11 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh echo "Preparing the Minimal Linux Live utilities folder. This may take a while..." -rm -rf $MAIN_SRC_DIR/work/overlay/mll_utils -mkdir -p $MAIN_SRC_DIR/work/overlay/mll_utils/sbin +rm -rf $WORK_DIR/overlay/mll_utils +mkdir -p $WORK_DIR/overlay/mll_utils/sbin echo "Miminal Linux Live utilities folder has been prepared." diff --git a/src/minimal_overlay/bundles/mll_utils/02_disk_erase.sh b/src/minimal_overlay/bundles/mll_utils/02_disk_erase.sh index 7c4671f4c..46d854c1a 100755 --- a/src/minimal_overlay/bundles/mll_utils/02_disk_erase.sh +++ b/src/minimal_overlay/bundles/mll_utils/02_disk_erase.sh @@ -2,17 +2,14 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh -if [ ! -d "$MAIN_SRC_DIR/work/overlay/mll_utils" ] ; then - echo "The directory $MAIN_SRC_DIR/work/overlay/mll_utils does not exist. Cannot continue." +if [ ! -d "$WORK_DIR/overlay/mll_utils" ] ; then + echo "The directory $WORK_DIR/overlay/mll_utils does not exist. Cannot continue." exit 1 fi -cd $MAIN_SRC_DIR/work/overlay/mll_utils +cd $WORK_DIR/overlay/mll_utils # 'mll-disk-erase' BEGIN diff --git a/src/minimal_overlay/bundles/mll_utils/03_installer.sh b/src/minimal_overlay/bundles/mll_utils/03_installer.sh index 1bb460cae..6a5731574 100755 --- a/src/minimal_overlay/bundles/mll_utils/03_installer.sh +++ b/src/minimal_overlay/bundles/mll_utils/03_installer.sh @@ -2,17 +2,14 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh -if [ ! -d "$MAIN_SRC_DIR/work/overlay/mll_utils" ] ; then - echo "The directory $MAIN_SRC_DIR/work/overlay/mll_utils does not exist. Cannot continue." +if [ ! -d "$WORK_DIR/overlay/mll_utils" ] ; then + echo "The directory $WORK_DIR/overlay/mll_utils does not exist. Cannot continue." exit 1 fi -cd $MAIN_SRC_DIR/work/overlay/mll_utils +cd $WORK_DIR/overlay/mll_utils # 'mll-install' BEGIN @@ -102,30 +99,30 @@ chmod +rx sbin/mll-install # 'mll-install' END -if [ ! -d "$MAIN_SRC_DIR/work/syslinux" ] ; then +if [ ! -d "$WORK_DIR/syslinux" ] ; then echo "The installer depends on Syslinux which is missing. Cannot continue." exit 1 fi; -cd $MAIN_SRC_DIR/work/syslinux +cd $WORK_DIR/syslinux cd $(ls -d syslinux-*) cp bios/extlinux/extlinux \ - $MAIN_SRC_DIR/work/overlay/mll_utils/sbin -mkdir -p $MAIN_SRC_DIR/work/overlay/mll_utils/opt/syslinux + $WORK_DIR/overlay/mll_utils/sbin +mkdir -p $WORK_DIR/overlay/mll_utils/opt/syslinux cp bios/mbr/mbr.bin \ - $MAIN_SRC_DIR/work/overlay/mll_utils/opt/syslinux + $WORK_DIR/overlay/mll_utils/opt/syslinux # Big mama hack - need to find proper workaround!!! # Both syslinux and extlinux are 32-bit executables which require 32-bit libs. # Possible solution 1 - build 32-bit GLIBC on demand. # Possible solution 2 - drop 32-bit MLL and provide 64-bit with multi-arch. -mkdir -p $MAIN_SRC_DIR/work/overlay/mll_utils/lib -mkdir -p $MAIN_SRC_DIR/work/overlay/mll_utils/usr/lib +mkdir -p $WORK_DIR/overlay/mll_utils/lib +mkdir -p $WORK_DIR/overlay/mll_utils/usr/lib cp /lib/ld-linux.so.2 \ - $MAIN_SRC_DIR/work/overlay/mll_utils/lib + $WORK_DIR/overlay/mll_utils/lib cp /lib/i386-linux-gnu/libc.so.6 \ - $MAIN_SRC_DIR/work/overlay/mll_utils/usr/lib + $WORK_DIR/overlay/mll_utils/usr/lib # Big mama hack - end. echo "Minimal Linux Live installer has been generated." diff --git a/src/minimal_overlay/bundles/mll_utils/04_install.sh b/src/minimal_overlay/bundles/mll_utils/04_install.sh index 5610549af..aa4593d30 100755 --- a/src/minimal_overlay/bundles/mll_utils/04_install.sh +++ b/src/minimal_overlay/bundles/mll_utils/04_install.sh @@ -2,19 +2,15 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh -if [ ! -d "$MAIN_SRC_DIR/work/overlay/mll_utils" ] ; then - echo "The directory $MAIN_SRC_DIR/work/overlay/mll_utils does not exist. Cannot continue." +if [ ! -d "$WORK_DIR/overlay/mll_utils" ] ; then + echo "The directory $WORK_DIR/overlay/mll_utils does not exist. Cannot continue." exit 1 fi # Copy all generated files to the source overlay folder. -cp -r $MAIN_SRC_DIR/work/overlay/mll_utils/* \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +cp -r $WORK_DIR/overlay/mll_utils/* $WORK_DIR/src/minimal_overlay/rootfs echo "All MLL utilities have been installed." diff --git a/src/minimal_overlay/bundles/nweb/bundle.sh b/src/minimal_overlay/bundles/nweb/bundle.sh index 837b44a18..40dd54058 100755 --- a/src/minimal_overlay/bundles/nweb/bundle.sh +++ b/src/minimal_overlay/bundles/nweb/bundle.sh @@ -1,25 +1,22 @@ #!/bin/sh + SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR - -# Read the 'CFLAGS' property from '.config' -CFLAGS="$(grep -i ^CFLAGS $MAIN_SRC_DIR/.config | cut -f2 -d'=')" +. ../../common.sh echo "removing previous work area" -rm -rf $MAIN_SRC_DIR/work/overlay/nweb -mkdir -p $MAIN_SRC_DIR/work/overlay/nweb -cd $MAIN_SRC_DIR/work/overlay/nweb +rm -rf $WORK_DIR/overlay/nweb +mkdir -p $WORK_DIR/overlay/nweb +cd $WORK_DIR/overlay/nweb set -x + # nweb -gcc $CFLAGS --sysroot=$MAIN_SRC_DIR/work/glibc/glibc_prepared/ $SRC_DIR/nweb23.c -o nweb +$CC $CFLAGS $LDFLAGS $SRC_DIR/nweb23.c -o nweb # client -#cc $CFLAGS $SRC_DIR/client.c -o client +#$CC $CFLAGS $LDFLAGS $SRC_DIR/client.c -o client + set +x echo "nweb has been build." diff --git a/src/minimal_overlay/bundles/static_get/01_get.sh b/src/minimal_overlay/bundles/static_get/01_get.sh index 4bad67ea3..ad1425db8 100755 --- a/src/minimal_overlay/bundles/static_get/01_get.sh +++ b/src/minimal_overlay/bundles/static_get/01_get.sh @@ -2,10 +2,7 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh # Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i STATIC_GET_SOURCE_URL $MAIN_SRC_DIR/.config | cut -f2 -d'=') @@ -30,11 +27,11 @@ fi # Delete folder with previously prepared static-get. echo "Removing static-get work area. This may take a while..." -rm -rf ../../work/overlay/staget -mkdir ../../work/overlay/staget +rm -rf $WORK_DIR/overlay/staget +mkdir $WORK_DIR/overlay/staget # Copy static-get to folder 'work/overlay/staget'. -cp static-get.sh ../../work/overlay/staget +cp static-get.sh $WORK_DIR/overlay/staget cd $SRC_DIR diff --git a/src/minimal_overlay/bundles/static_get/02_install.sh b/src/minimal_overlay/bundles/static_get/02_install.sh index 611a73ec5..59316a1f4 100755 --- a/src/minimal_overlay/bundles/static_get/02_install.sh +++ b/src/minimal_overlay/bundles/static_get/02_install.sh @@ -2,31 +2,28 @@ SRC_DIR=$(pwd) -# Find the main source directory -cd ../../.. -MAIN_SRC_DIR=$(pwd) -cd $SRC_DIR +. ../../common.sh echo "Removing old static-get artifacts. This may take a while..." -rm -rf $MAIN_SRC_DIR/work/overlay/staget/staget_installed -mkdir -p $MAIN_SRC_DIR/work/overlay/staget/staget_installed/opt/staget -mkdir -p $MAIN_SRC_DIR/work/overlay/staget/staget_installed/bin +rm -rf $WORK_DIR/overlay/staget/staget_installed +mkdir -p $WORK_DIR/overlay/staget/staget_installed/opt/staget +mkdir -p $WORK_DIR/overlay/staget/staget_installed/bin -cd $MAIN_SRC_DIR/work/overlay/staget +cd $WORK_DIR/overlay/staget cp $MAIN_SRC_DIR/source/overlay/static-get.sh . chmod +rx static-get.sh -cp static-get.sh $MAIN_SRC_DIR/work/overlay/staget/staget_installed/opt/staget +cp static-get.sh $WORK_DIR/overlay/staget/staget_installed/opt/staget -cd $MAIN_SRC_DIR/work/overlay/staget/staget_installed +cd $WORK_DIR/overlay/staget/staget_installed ln -s ../opt/staget/static-get.sh bin/static-get ln -s ../opt/staget/static-get.sh bin/mll-get -cp -r $MAIN_SRC_DIR/work/overlay/staget/staget_installed/* \ - $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs +cp -r $WORK_DIR/overlay/staget/staget_installed/* \ + $WORK_DIR/src/minimal_overlay/rootfs echo "static-get has been installed." diff --git a/src/minimal_overlay/common.sh b/src/minimal_overlay/common.sh new file mode 100755 index 000000000..9bda67606 --- /dev/null +++ b/src/minimal_overlay/common.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# 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=$(pwd) +export CONFIG="$MAIN_SRC_DIR/.config" +export SYSROOT="$WORK_DIR/sysroot" +export SYSROOT_SPECS="$WORK_DIR/sysroot.specs" + +# 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 +export NUM_CORES="$(grep ^processor /proc/cpuinfo | wc -l)" + +# Calculate the number of make "jobs" +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" + +# sysroot flags for the compiler + +#-Wl,-nostdlib is required to make ld / gcc ignore the host's /usr/lib and /lib +ld_flags="-Wl,-nostdlib $(grep -- \"-L\" $SYSROOT_SPECS)" +#-static-libgcc is neeeded since we don't have the gcc-libs in our sysroot +gcc_flags="-specs=$SYSROOT_SPECS -static-libgcc" + +# $ld_flags is passed 2 times because sometimes bundles ignore one of the variables +export CC="${CC-gcc} $gcc_flags $ld_flags" +export CFLAGS="$CFLAGS" +export LDFLAGS="$LDFLAGS $ld_flags"