build script for x86_64
authorRalph Ronnquist <rrq@rrq.au>
Mon, 13 Jan 2025 03:10:20 +0000 (14:10 +1100)
committerRalph Ronnquist <rrq@rrq.au>
Mon, 13 Jan 2025 03:10:20 +0000 (14:10 +1100)
build.sh [new file with mode: 0755]

diff --git a/build.sh b/build.sh
new file mode 100755 (executable)
index 0000000..e122be4
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+HERE="$(pwd)"
+
+includes() {
+    cd "${1%/*}"
+    for F in $(awk "-F'" '$1 ~ /include / {print $2}' "${1##*/}") ; do
+       F="${F//\\//}"
+       realpath --relative-to="$HERE" "$F"
+    done
+}
+
+prepare() {
+    echo $1
+    for F in $(includes $1) ; do
+       F="${F#fasm/}"
+       BF="build/${F#source/}"
+       [ -e "$BF" ] && continue
+       [ -e "$F" ] || F="fasm/${F/linux/Linux}"
+       [ -e "$F" ] || exit 1
+       mkdir -p "${BF%/*}"
+       cp "$F" "$BF"
+       prepare "$F"
+    done
+}
+
+SRC="source/linux/x64/fasmarm.asm"
+BLD="build/${SRC#source/}"
+BIN="$(basename "$SRC" .asm)"
+
+set -e
+if [ -d build ] ; then
+    read -p "Type y for removing the old build tree" X
+    if [ "$X" = y ] ; then
+       rm -r build
+    fi
+fi
+prepare "$SRC"
+cp "$SRC" "$BLD"
+fasm -m 50000 "$BLD" "$BIN"
+chmod a+x "$BIN"
+