diff --git a/build.sh b/build.sh index ec6a7f2..28b1a18 100644 --- a/build.sh +++ b/build.sh @@ -46,6 +46,90 @@ success() { printf "${GREEN}==> SUCCESS:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" } +# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- + +# ----------------------------------------------------------------------------- +# build +# ----------------------------------------------------------------------------- + + +# ----------------------------------------------------------------------------- +# tools +# ----------------------------------------------------------------------------- + +build_tools() { + msg "Builing tools" + plain "tools dir: %s" "${TOOLS_DIR}" + + make tools +} + +# ----------------------------------------------------------------------------- +# doctor - check os dependancies +# ----------------------------------------------------------------------------- +check_tool() { + local tool=$1; shift + + printf "checking for %s " "${tool}" + + tool_path="$(which "${tool}" 2> /dev/null)" + if [ "x${tool_path}" = "x" ]; then + printf "${BOLD}${RED}NO${ALL_OFF}\n" + false; + else + printf "${GREEN}${tool_path}${ALL_OFF}\n" + true; + fi +} + +doctor() { + local err=0 + + check_tool fasm || ((err++)) + check_tool gcc || ((err++)) + check_tool bmake || ((err++)) + check_tool sha256sum || ((err++)) + check_tool python3 || ((err++)) + + if [ $err -gt 0 ]; then error "Some tools are missing"; fi +} + +# ----------------------------------------------------------------------------- +# usage & version +# ----------------------------------------------------------------------------- + +usage() { + local status=$1 + + if [ ${status} -eq 0 ]; then + cat <&2 + fi + + exit ${status} +} + +version() { + VERSION_MAJOR="$(grep VERSION_MAJOR kernel/const.inc | cut -d' ' -f 3)" + VERSION_MINOR="$(grep VERSION_MINOR kernel/const.inc | cut -d' ' -f 3)" + + printf "%s (StupidOS) %d.%d\n" "${prgname}" ${VERSION_MAJOR} ${VERSION_MINOR} + + exit 0 +} + # ----------------------------------------------------------------------------- # entry # ----------------------------------------------------------------------------- @@ -81,8 +165,34 @@ BUILD_DIR="${topdir}/.build" TOOLS_DIR="${topdir}/.tools" TOOLS_PREFIX="stpd-" -if [ $# -eq 0 ]; then - printf "Try '%s -h' for more information.\n" "${prgname}" >&2 - exit 1 +export PATH="$PATH:$TOOLS_DIR" + +if [ ! -f Makefile ] || [ ! -f LICENSE ]; then + error "Run this script at StupidOS root" fi +if [ $# -eq 0 ]; then + usage 1 +fi + +while [ $# -gt 0 ]; do + op=$1; shift + + case "${op}" in + help | --help | -h) + usage 0 + ;; + --version | -V) + version + ;; + doctor) + doctor + ;; + tools) + build_tools + ;; + *) + usage 1 + ;; + esac +done diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..add8f2b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pytest==8.0.1 +qemu.qmp==0.0.3