diff options
author | davidovski <david@davidovski.xyz> | 2022-06-27 01:14:42 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2022-06-27 01:14:42 +0100 |
commit | 7bba6cd7612293796e905885f9ed3072877798ab (patch) | |
tree | dd01942dbdd474a4df62ecf74479f5e78d83f1c8 | |
parent | 79fb6f41104cd0d88891598ddfc3c30d1bb0352d (diff) |
added shmk, building all with shmk
-rwxr-xr-x | Makefile | 77 | ||||
-rwxr-xr-x | build.shmk | 22 | ||||
-rwxr-xr-x | shmk.shmk | 9 | ||||
-rw-r--r-- | src/lib/colors.h (renamed from src/colors.h) | 0 | ||||
-rw-r--r-- | src/lib/colors.list (renamed from src/colors.list) | 0 | ||||
-rw-r--r-- | src/lib/colors.sh (renamed from src/colors.sh) | 0 | ||||
-rw-r--r-- | src/lib/generate_colors.sh (renamed from src/generate_colors.sh) | 0 | ||||
-rw-r--r-- | src/lib/glyphs.sh (renamed from src/glyphs.sh) | 0 | ||||
-rw-r--r-- | src/lib/xilib.sh (renamed from src/xilib.sh) | 0 | ||||
-rw-r--r-- | src/lib/xitui.sh (renamed from src/xitui.sh) | 0 | ||||
-rwxr-xr-x | src/tools/default-jvm.sh (renamed from src/default-jvm.sh) | 3 | ||||
-rw-r--r-- | src/tools/xichroot.sh (renamed from src/xichroot.sh) | 0 | ||||
-rw-r--r-- | src/util/hbar.c (renamed from src/hbar.c) | 0 | ||||
-rw-r--r-- | src/util/parseconf.sh (renamed from src/parseconf.sh) | 0 | ||||
-rwxr-xr-x | src/util/shmk.sh | 200 | ||||
-rw-r--r-- | src/util/shtests.sh (renamed from src/shtests.sh) | 3 |
16 files changed, 248 insertions, 66 deletions
@@ -1,73 +1,22 @@ -FLAGS= - DESTDIR= PREFIX=/usr - -DIST=dist - .DEFAULT_GOAL := build -install: build install-hbar install-colors install-parseconf install-shtests install-glyphs install-xitui install-xilib -check: check-parseconf -build: make-dist hbar shtests parseconf colors - -make-dist: - mkdir -p ${DIST} - -install-headers: src/*.h - install -Dm644 src/*.h ${DESTDIR}${PREFIX}/include - -install-shtests: shtests - install -Dm755 ${DIST}/shtests ${DESTDIR}${PREFIX}/bin/shtests - -install-parseconf: parseconf - install -Dm755 ${DIST}/parseconf ${DESTDIR}${PREFIX}/bin/parseconf - -install-hbar: hbar - install -Dm755 ${DIST}/hbar ${DESTDIR}${PREFIX}/bin - -install-colors: src/colors.list - install -Dm755 ${DIST}/colors.sh ${DESTDIR}${PREFIX}/lib/colors.sh - install -Dm755 ${DIST}/colors.h ${DESTDIR}${PREFIX}/include/colors.h - -install-glyphs: src/glyphs.sh - install -Dm755 src/glyphs.sh ${DESTDIR}${PREFIX}/lib +export PATH := .:$(PATH) -install-xitui: src/xitui.sh - install -Dm755 src/xitui.sh ${DESTDIR}${PREFIX}/lib +shmk0: + @echo shmk stage0 + @install -m755 src/util/shmk.sh shmk -install-xilib: src/xilib.sh - install -Dm755 src/xilib.sh ${DESTDIR}${PREFIX}/lib +bootstrap: shmk0 + @echo shmk stage1 + @./shmk.shmk build + @install -m755 dist/shmk shmk -check-parseconf: shtests parseconf test/parseconf.sh - ${DIST}/shtests ./test/parseconf.sh - - -hbar: colors src/hbar.c - ${CC} -I${DIST} src/hbar.c -o ${DIST}/hbar ${FLAGS} - -shtests: src/shtests.sh - install -Dm755 src/shtests.sh ${DIST}/shtests - -parseconf: src/parseconf.sh - install -Dm755 src/parseconf.sh ${DIST}/parseconf - -colors: src/colors.list - cp src/colors.sh ${DIST} - cp src/colors.h ${DIST} +build: bootstrap + @echo all xiutils + @./build.shmk clean: - rm -r ${DIST} - - -# xichroot -# -install-chroot: src/xichroot.sh - install -Dm755 src/xichroot.sh ${DESTDIR}${PREFIX}/bin/xichroot - - -# default-jvm -# -install-default-jvm: src/default-jvm.sh - install -Dm755 src/default-jvm.sh ${DESTDIR}${PREFIX}/bin/default-jvm - + @rm -r dist + @rm -r shmk diff --git a/build.shmk b/build.shmk new file mode 100755 index 0000000..2ce463d --- /dev/null +++ b/build.shmk @@ -0,0 +1,22 @@ +#!/usr/bin/env shmk + +CC=gcc + +LIBS="src/lib/*.sh" + +PROGS=" +hbar +src/util/shmk.sh +src/util/shtests.sh +src/util/parseconf.sh +src/tools/xichroot.sh +src/tools/default-jvm.sh +" + +prog_hbar () { + ${CC} -I${DIST} -o ${DIST}/hbar src/util/hbar.c +} + +check_shtests () { + ${DIST}/shtests test/parseconf.sh +} diff --git a/shmk.shmk b/shmk.shmk new file mode 100755 index 0000000..c6a3e8c --- /dev/null +++ b/shmk.shmk @@ -0,0 +1,9 @@ +#!/bin/env shmk + +LIBS=" +src/lib/colors.sh +" + +PROGS=" +src/util/shmk.sh +" diff --git a/src/colors.h b/src/lib/colors.h index e7bc26d..e7bc26d 100644 --- a/src/colors.h +++ b/src/lib/colors.h diff --git a/src/colors.list b/src/lib/colors.list index 0829a63..0829a63 100644 --- a/src/colors.list +++ b/src/lib/colors.list diff --git a/src/colors.sh b/src/lib/colors.sh index 8e5de11..8e5de11 100644 --- a/src/colors.sh +++ b/src/lib/colors.sh diff --git a/src/generate_colors.sh b/src/lib/generate_colors.sh index 6e01d58..6e01d58 100644 --- a/src/generate_colors.sh +++ b/src/lib/generate_colors.sh diff --git a/src/glyphs.sh b/src/lib/glyphs.sh index b4ecccd..b4ecccd 100644 --- a/src/glyphs.sh +++ b/src/lib/glyphs.sh diff --git a/src/xilib.sh b/src/lib/xilib.sh index 57dd10c..57dd10c 100644 --- a/src/xilib.sh +++ b/src/lib/xilib.sh diff --git a/src/xitui.sh b/src/lib/xitui.sh index dcfaf02..dcfaf02 100644 --- a/src/xitui.sh +++ b/src/lib/xitui.sh diff --git a/src/default-jvm.sh b/src/tools/default-jvm.sh index 96f4f68..56c427c 100755 --- a/src/default-jvm.sh +++ b/src/tools/default-jvm.sh @@ -39,6 +39,9 @@ link () { "-l"|"--list") ls -1 $JVM_DIR ;; + "-h"|"--help") + usage + ;; *) link $1 \ || link $JVM_DIR/$1 \ diff --git a/src/xichroot.sh b/src/tools/xichroot.sh index 7136e25..7136e25 100644 --- a/src/xichroot.sh +++ b/src/tools/xichroot.sh diff --git a/src/hbar.c b/src/util/hbar.c index 59cf888..59cf888 100644 --- a/src/hbar.c +++ b/src/util/hbar.c diff --git a/src/parseconf.sh b/src/util/parseconf.sh index d215a99..d215a99 100644 --- a/src/parseconf.sh +++ b/src/util/parseconf.sh diff --git a/src/util/shmk.sh b/src/util/shmk.sh new file mode 100755 index 0000000..0174857 --- /dev/null +++ b/src/util/shmk.sh @@ -0,0 +1,200 @@ +#!/bin/sh +# +# A tool to build a single executable from a collection of shell scripts + +#include colors + +usage () { + cat << EOF +${BLUE}Available Options: + +EOF +} + +find_file () { + for p in $search_path; do + for f in $p/$1.sh $p/$1; do + $verbose \ + && printf "${LIGHT_BLACK}checking: $f\n" 1>&2 + + [ -f "$f" ] && { + echo "$f" + return 0 + } + done + done + return 1 +} + +parse_lines () { + while IFS= read -r line; do + case "$line" in + "#include "*) + cat $(find_file ${line#\#include}) | parse_lines + ;; + "#>"*) + eval ${line#'#>'} + ;; + "#!"*) + printf "%s\n" "$line" + ;; + "#"*);; + *) + printf "%s\n" "$line" + ;; + esac + done +} + +build_shmk () { + [ -f "$1" ] || return 1 + [ ! -z "$2" ] && output="$2" + [ -z "$output" ] && output=$(basename $1) + output=${output%.*} + + $clean && { + rm -f $output + exit + } + + $verbose && echo "building $1 to $output" + + [ ! -d "${output%/*}" ] && mkdir -p "${output%/*}" + + cat $1 \ + | parse_lines > ${output} && + [ ! -z ${entry_function} ] && echo "$entry_function" >> ${output} + chmod +x ${output} +} + +interpret_shmk () { + . $1 + local cmdlist="" + + DIST="./dist" + PROGS="$PROGS $(sed -rn "s/^prog_(.*)\s*\(\)\s*\{/\1/p" $1)" + LIBS="$LIBS $(sed -rn "s/^lib_(.*)\s*\(\)\s*\{/\1/p" $1)" + CHECKS="$CHECKS $(sed -rn "s/^check_(.*)\s*\(\)\s*\{/\1/p" $1)" + + shift + [ -z "$1" ] && set -- clean build check install + while [ ! -z "$1" ]; do + case "$1" in + install) + for prog in $PROGS; do + prog=$(basename $prog) + prog="${prog%.*}" + cmdlist="$cmdlist + install -Dm755 $DIST/$prog ${DESTDIR}/${PREFIX}/bin/$prog #Install program $prog" + done + for lib in $LIBS; do + lib=$(basename $lib) + lib="${lib%.*}" + cmdlist="$cmdlist + install -Dm755 $DIST/$lib ${DESTDIR}/${PREFIX}/lib/$lib #Install library $lib" + done + ;; + clean) + [ -d "$DIST" ] && cmdlist="$cmdlist + rm -r $DIST #Clean" + ;; + check) + for check in $CHECKS; do + command -v check_$check > /dev/null 2>&1 && cmdlist="$cmdlist + check_$check #Check $check" + done + ;; + *) # build all programs + search_path="$DIST $search_path" + + for lib in $LIBS; do + name=$(basename $lib) + build_cmd=lib_$lib + command -v $build_cmd > /dev/null 2>&1 || { + build_cmd="build_shmk $lib $DIST/$name" + } + cmdlist="$cmdlist + $build_cmd #Build library $name" + done + + for prog in $PROGS; do + name=$(basename $prog) + build_cmd=prog_$prog + command -v $build_cmd > /dev/null 2>&1 || { + build_cmd="build_shmk $prog $DIST/$name" + } + cmdlist="$cmdlist + $build_cmd #Build program $name" + done + + # build all libs + ;; + esac + shift + done + + local out len i + $verbose && out=/dev/stdout || out=/dev/null + len=$(($(echo "$cmdlist" | wc -l)-1)) + i=-1 + echo "$cmdlist" | while read -r cmd; do + i=$((i+1)) + printf "${LIGHT_BLACK}[${LIGHT_BLUE}%s${LIGHT_BLACK}/${LIGHT_BLUE}%s${LIGHT_BLACK}] ${LIGHT_WHITE}%s${RESET}\n" "$i" "$len" "${cmd#*#}" + ${cmd%#*} 2>&1 > $out || { + printf "${RED}Error $?\n" + exit 1 + } + done +} + +search_path=". +/usr/lib +/usr/local/lib +/usr/share/shmk +" + +verbose=false +clean=false + +while getopts ":e:I:o:chv" opt; do + case "${opt}" in + e) + entry_function="$OPTARG" + ;; + o) + output="$OPTARG" + ;; + c) + clean=true + ;; + I) + search_path="$search_path + $OPTARG" + ;; + v) + verbose=true + ;; + h) + usage && exit 0 + ;; + esac +done + +shift $((OPTIND-1)) + +[ -z $1 ] && { + exit 1 +} + +echo "$0 $*" +[ -f "$1" ] && shebang="$(head -1 $1)" +case "$shebang" in + "#!"*"shmk"*) + interpret_shmk $@ + ;; + *) + build_shmk $@ + ;; +esac + + diff --git a/src/shtests.sh b/src/util/shtests.sh index a899f3c..69da232 100644 --- a/src/shtests.sh +++ b/src/util/shtests.sh @@ -9,8 +9,7 @@ # shtests [FILE] # -[ -f /usr/lib/colors.sh ] && . /usr/lib/colors.sh -[ -f colors.sh ] && . colors.sh +#include colors PASS="${BLUE}[ ${GREEN}PASS${BLUE} ]${RESET}" FAIL="${BLUE}[ ${RED}FAIL${BLUE} ]${RESET}" |