@@ -69,9 +69,10 @@ m4=${m4:-$_m4} has nasm && asm=nasm has yasm && asm=yasm # prefer yasm export gen=${gen:-gen} -library=${libkind:-static} # {static|shared|both} +library=${library:-static} # {static|shared|both} +export verbose=${verbose:-quiet} # {no|quiet|loud} doc=${doc:-yes} export doc_html=${doc_html:-yes} export doc_pdf=${doc_pdf:-yes} @@ -134,22 +135,78 @@ macro_compile_env="$macro_compile_env -Datom_target_bits=$bits" fi -comp_mac() { $m4 $macro_compile_env -I "$gen" $3 "$1" > "$2"; } -comp_asm() { $asm "-f$bin_fmt" -i "$gen" $1 -o "$2"; } +if test "$COLORTERM" != ""; then + announce() { + test "$verbose" = "silent" && return + color="$1" cmd="$2"; shift 2; + printf " → [38;5;$color;1m$cmd" + for a in "$@"; do + if test ${a:0:1} = "-"; then + printf " $a"; + else + printf " $a"; + fi + done + echo + } +else + announce() { shift; echo " --> " $@; } +fi + +# the following function is called to report a command invocation +# the person compiling the library. the first argument should be +# an ansi format string; this is used to color-code the tool being +# launched and thus should be different for each one. +report() { announce $@; shift; $@; } +comp_mac() { + local src=$1 + local output=$2 + local flags=$3 + if test -e "$output"; then + if test ! "$output" -ot "$src"; then + return + fi + fi + $m4 $macro_compile_env -I "$gen" $flags "$src" > "$output" + announce 207 $m4 $macro_compile_env -I "$gen" $flags "$src" \> "$output" + # yes, this is incredibly stupid. if you know a better way, feel + # free to submit a fix. the problem is there's no way to pass > + # to report in such a way that it'll do the right thing, and if + # you just write > it redirects *report's* output, instead of + # m4's. piece of shit that it is, m4 doesn't have any way to emit + # output into a fille - stdout only apparently. tl;dr i hate bash. +} +comp_asm() { + local src=$1 + local output=$2 + local flags=$3 + if test -e "$output"; then + if test ! "$output" -ot "$src"; then + return + fi + fi + report 198 $asm $flags "-f$bin_fmt" -i "$gen" "$src" -o "$output"; +} comp_co() { comp_c $1 $2 "-c -fPIC"; } comp_c(){ - src=$1 - output=$2 - flags=$3 - $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output" + local src=$1 + local output=$2 + local flags=$3 + if test -e "$output"; then + if test ! "$output" -ot "$src"; then + return + fi + fi + # only rebuild the file if the source file is newer + report 213 $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output" } scan() { find "$1" -name "$2"; } say "commencing libk build $build at $(timestamp)" -set -x +# set -x # get type data mkdir -p $gen $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize @@ -200,9 +257,9 @@ for mod in ${modules[@]}; do for doc in $(scan $mod '*.md'); do base="$(basename $doc)" stem="${base%%.md}" - global/build-manpage.sh "$doc" + report 177 global/build-manpage.sh "$doc" done done fi @@ -248,16 +305,16 @@ # configured to be built if test $build_static_library == yes; then for obj in ${fn_objects[@]} ${rt_objects[@]} ${data_objects[@]}; do - ar rc $out/libk.a $obj + report 120 ar rc $out/libk.a $obj done - ranlib $out/libk.a + report 105 ranlib $out/libk.a fi if test $build_shared_library == yes; then - ld -r ${rt_objects[@]} -o $out/boot.o - ld -shared ${fn_objects[@]} -o $out/libk.so + report 216 ld -r ${rt_objects[@]} -o $out/boot.o + report 216 ld -shared ${fn_objects[@]} -o $out/libk.so fi # fifth pass: compile the executable tools # against the libraries created in pass 5