better build script!

This commit is contained in:
nora 2022-01-02 15:10:35 +01:00
parent 9cf4469be6
commit ad531e2811
3 changed files with 95 additions and 25 deletions

View file

@ -1,8 +1,14 @@
QUIET="false"
CLEAN="false"
assemble () {
FILE="$1"
PROGRAM_NAME="$2"
echo "Assembling $PROGRAM_NAME"
if [ "$QUIET" = "false" ]; then
echo "Assembling $PROGRAM_NAME"
fi
nasm -g -F dwarf -f elf64 "$FILE" -o "./target/$PROGRAM_NAME.o" || return
}
@ -23,27 +29,58 @@ build () {
assemble "$FILE" "$PROGRAM_NAME"
echo "Linking $PROGRAM_NAME"
if [ "$QUIET" = "false" ]; then
echo "Linking $PROGRAM_NAME"
fi
ld.lld "./target/$PROGRAM_NAME.o" "./target/common.o" -o "./target/$PROGRAM_NAME"
}
if [ "$1" = "--clean" ]; then
clean () {
if [ -d ./target ]; then
rm -r target
exit
fi
}
for ARG in "$@" ; do
case $ARG in
"--clean")
CLEAN="true"
;;
"--quiet" | "-q")
QUIET="true"
;;
"--help")
cat << EOF
self-made shitty build script
Run to build all programs into the ./target directory
Options:
--quiet, -q | Don't output information
--clean | Clean all build artifacts
EOF
exit
;;
esac
done
if [ "$CLEAN" = "true" ]; then
clean
exit
fi
if [ ! -d ./target ]; then
mkdir ./target
fi
assemble "src/common.asm" "common"
if [ "$#" -eq 0 ]; then
for FILE in ./src/*.asm ; do
build "$FILE"
done
else
build "src/$1.asm"
fi
for FILE in ./src/*.asm ; do
build "$FILE"
done