#!/usr/bin/env bash

CC=${CC:-clang}
CFLAGS="-std=c89 -pedantic -Wall -Wextra"

case "$1" in
    asm) $CC $CFLAGS -S test.c -o test.asm ;;
    build) $CC $CFLAGS -g test.c tests/*.c -o test;;
    release)
             FNAME=ylibc_$(grep VERSION y.h | cut -d ' ' -f 3).tar.gz;
             git archive -o "$FNAME" HEAD;
             mv "$FNAME" ../homepage/code/
             sed -i "s/ylibc_[0-9]\.[0-9]\.[0-9]\.tar\.gz/$FNAME/g" ../homepage/index.html
             ;;
    test) ./yak build && MALLOC_OPTIONS="D" ktrace -tu ./test;;
    version) grep Y_VERSION y.h | cut -d ' ' -f 3;;
    map) grep -HEn '^[^ ].*{' y.h ;;
    lint) sed -i 's/ *$//' y.h ;;
    *)
        echo Unknown argument "$1"
        exit 1
        ;;
esac
