@@ -1,12 +1,7 @@ #!/usr/bin/env bash -export out=${out:-out} +export to=${to:-out} . global/common.sh -noimpl() { - say "$1 is not currently implemented on your system. an exciting chance for you to contribute, no?" - exit 1 -} -timestamp() { date "+%H:%M:%S %A"; } if test "$os$arch$bits" = ""; then say "set the following environment variables to the appropriate atoms describing your system. for help determining the appropriate atoms, see libk.md" say ' - $os={lin|fbsd|hai|osx…}' @@ -68,8 +63,10 @@ has m4 && _m4=m4 m4=${m4:-$_m4} has nasm && asm=nasm has yasm && asm=yasm # prefer yasm +export cc +export m4 export gen=${gen:-gen} library=${library:-static} # {static|shared|both} export verbose=${verbose:-quiet} # {no|quiet|loud} @@ -111,31 +108,8 @@ if test "$bits" != ""; then macro_compile_env="$macro_compile_env -Datom_target_bits=$bits" fi -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 @@ -143,10 +117,10 @@ 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" + $m4 $macro_compile_env -I "$gen" $flags "$src" > "$output" + announce $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 @@ -161,9 +135,9 @@ if test ! "$output" -ot "$src"; then return fi fi - report 198 $asm $flags "-f$bin_fmt" -i "$gen" "$src" -o "$output"; + report $asm $flags "-f$bin_fmt" -i "$gen" "$src" -o "$output"; } comp_co() { comp_c $1 $2 "-c -fPIC"; } comp_c(){ local src=$1 @@ -174,13 +148,11 @@ 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" + report $cc $src $3 -std=c11 -isystem "$to" -isystem "$gen" -isystem "arch/" -nostdlib "-L$to" "-o$output" } -scan() { find "$1" -name "$2"; } - say "commencing libk build $build at $(timestamp)" # set -x # get type data @@ -218,26 +190,26 @@ cat $p_headers_errno $gen/error_names.tbl | cpp -P >$gen/error_numbers.tbl awk -f arch/errtbl.awk <$gen/error_numbers.tbl >$gen/error_table.h # generate symbol tables for error handling functions -mkdir -p "$out/k" -awk -f global/gen-conds.awk $out/k/internal.egroup.h +mkdir -p "$to/k" +awk -f global/gen-conds.awk $to/k/internal.egroup.h awk -f global/gen-ident.awk $gen/internal.ident.c -comp_co $gen/internal.ident.c $out/internal.ident.o +comp_co $gen/internal.ident.c $to/internal.ident.o # first pass: copy all headers into place, # including ones we need to generate for mod in ${modules[@]}; do for h in $(scan $mod '*.h'); do base=$(basename $h) - cp "$h" "$out/k/$base" + cp "$h" "$to/k/$base" done for h in $(scan $mod '*.h.m'); do base=$(basename $h) dest=${base%%.m} - comp_mac "$h" "$out/k/$dest" + comp_mac "$h" "$to/k/$dest" done done # second pass: generate manpage, html, and pdf @@ -248,46 +220,46 @@ for mod in ${modules[@]}; do for doc in $(scan $mod '*.md'); do base="$(basename $doc)" stem="${base%%.md}" - report 177 global/build-manpage.sh "$doc" + report global/build-manpage.sh "$doc" done done fi # third pass: compile sources and save the -# resulting object files to $out, tracking +# resulting object files to $to, tracking # which is a runtime or function unit. exe's # will not be compiled until a later pass fn_objects=() rt_objects=() -data_objects=( $out/internal.ident.o ) +data_objects=( $to/internal.ident.o ) for mod in ${modules[@]}; do for fn in $(scan $mod '*.fn.c'); do base="$(basename $fn)" - dest="$out/$mod.${base%%.c}.o" + dest="$to/$mod.${base%%.c}.o" comp_co "$fn" "$dest" fn_objects+=("$dest") done for rt in $(scan $mod '*.rt.c'); do base="$(basename $rt)" - dest="$out/$mod.${base%%.c}.o" + dest="$to/$mod.${base%%.c}.o" comp_co "$rt" "$dest" rt_objects+=("$dest") done for fn in $(scan $mod "*.fn.$target.s"); do base="$(basename $fn)" - dest="$out/$mod.${base%%.s}.o" + dest="$to/$mod.${base%%.s}.o" comp_asm "$fn" "$dest" fn_objects+=("$dest") done for rt in $(scan $mod "*.rt.$target.s"); do base="$(basename $rt)" - dest="$out/$mod.${base%%.s}.o" + dest="$to/$mod.${base%%.s}.o" comp_asm "$rt" "$dest" rt_objects+=("$dest") done done @@ -296,16 +268,16 @@ # configured to be built if test $build_static_library == yes; then for obj in ${fn_objects[@]} ${rt_objects[@]} ${data_objects[@]}; do - report 120 ar rc $out/libk.a $obj + report ar rc $to/libk.a $obj done - report 105 ranlib $out/libk.a + report ranlib $to/libk.a fi if test $build_shared_library == yes; then - report 216 ld -r ${rt_objects[@]} -o $out/boot.o - report 216 ld -shared ${fn_objects[@]} -o $out/libk.so + report ld -r ${rt_objects[@]} -o $to/boot.o + report ld -shared ${fn_objects[@]} -o $to/libk.so fi # fifth pass: compile the executable tools # against the libraries created in pass 5 @@ -312,11 +284,11 @@ for mod in ${modules[@]}; do for exe in $(scan $mod '*.exe.c'); do base="$(basename $exe)" - dest="$out/$mod.${base%%.exe.c}" + dest="$to/$mod.${base%%.exe.c}" if test $build_shared_library == yes; then - comp_c "$out/boot.o $exe" "$dest" -lk + comp_c "$to/boot.o $exe" "$dest" -lk else comp_c "$exe" "$dest" -lk fi done