Differences From
Artifact [a37c2dbfb1]:
66 66 has gcc && _cc=gcc # prefer gcc
67 67 cc=${cc:-$_cc}
68 68 has m4 && _m4=m4
69 69 m4=${m4:-$_m4}
70 70 has nasm && asm=nasm
71 71 has yasm && asm=yasm # prefer yasm
72 72 export gen=${gen:-gen}
73 -library=${libkind:-static} # {static|shared|both}
73 +library=${library:-static} # {static|shared|both}
74 +export verbose=${verbose:-quiet} # {no|quiet|loud}
74 75
75 76 doc=${doc:-yes}
76 77 export doc_html=${doc_html:-yes}
77 78 export doc_pdf=${doc_pdf:-yes}
78 79 export doc_man=${doc_man:-yes}
79 80
80 81 case $library in
................................................................................
131 132 macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix"
132 133
133 134 if test "$bits" != ""; then
134 135 macro_compile_env="$macro_compile_env -Datom_target_bits=$bits"
135 136 fi
136 137
137 138
138 -comp_mac() { $m4 $macro_compile_env -I "$gen" $3 "$1" > "$2"; }
139 -comp_asm() { $asm "-f$bin_fmt" -i "$gen" $1 -o "$2"; }
139 +if test "$COLORTERM" != ""; then
140 + announce() {
141 + test "$verbose" = "silent" && return
142 + color="$1" cmd="$2"; shift 2;
143 + printf " [1;95m→ [38;5;$color;1m$cmd[m"
144 + for a in "$@"; do
145 + if test ${a:0:1} = "-"; then
146 + printf " [91;3m$a[m";
147 + else
148 + printf " [94;4m$a[m";
149 + fi
150 + done
151 + echo
152 + }
153 +else
154 + announce() { shift; echo " --> " $@; }
155 +fi
156 +
157 +# the following function is called to report a command invocation
158 +# the person compiling the library. the first argument should be
159 +# an ansi format string; this is used to color-code the tool being
160 +# launched and thus should be different for each one.
161 +report() { announce $@; shift; $@; }
162 +comp_mac() {
163 + local src=$1
164 + local output=$2
165 + local flags=$3
166 + if test -e "$output"; then
167 + if test ! "$output" -ot "$src"; then
168 + return
169 + fi
170 + fi
171 + $m4 $macro_compile_env -I "$gen" $flags "$src" > "$output"
172 + announce 207 $m4 $macro_compile_env -I "$gen" $flags "$src" \> "$output"
173 + # yes, this is incredibly stupid. if you know a better way, feel
174 + # free to submit a fix. the problem is there's no way to pass >
175 + # to report in such a way that it'll do the right thing, and if
176 + # you just write > it redirects *report's* output, instead of
177 + # m4's. piece of shit that it is, m4 doesn't have any way to emit
178 + # output into a fille - stdout only apparently. tl;dr i hate bash.
179 +}
180 +comp_asm() {
181 + local src=$1
182 + local output=$2
183 + local flags=$3
184 + if test -e "$output"; then
185 + if test ! "$output" -ot "$src"; then
186 + return
187 + fi
188 + fi
189 + report 198 $asm $flags "-f$bin_fmt" -i "$gen" "$src" -o "$output";
190 +}
140 191 comp_co() { comp_c $1 $2 "-c -fPIC"; }
141 192 comp_c(){
142 - src=$1
143 - output=$2
144 - flags=$3
145 - $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output"
193 + local src=$1
194 + local output=$2
195 + local flags=$3
196 + if test -e "$output"; then
197 + if test ! "$output" -ot "$src"; then
198 + return
199 + fi
200 + fi
201 + # only rebuild the file if the source file is newer
202 + report 213 $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output"
146 203 }
147 204
148 205 scan() { find "$1" -name "$2"; }
149 206
150 207 say "commencing libk build $build at $(timestamp)"
151 -set -x
208 +# set -x
152 209
153 210 # get type data
154 211 mkdir -p $gen
155 212 $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize
156 213 $gen/typesize > gen/typesize.m
157 214
158 215 # generate syscall tables
................................................................................
197 254
198 255 if test "$doc" = "yes"; then
199 256 global/build-manpage.sh libk.md
200 257 for mod in ${modules[@]}; do
201 258 for doc in $(scan $mod '*.md'); do
202 259 base="$(basename $doc)"
203 260 stem="${base%%.md}"
204 - global/build-manpage.sh "$doc"
261 + report 177 global/build-manpage.sh "$doc"
205 262 done
206 263 done
207 264 fi
208 265
209 266 # third pass: compile sources and save the
210 267 # resulting object files to $out, tracking
211 268 # which is a runtime or function unit. exe's
................................................................................
245 302 done
246 303
247 304 # fourth pass: link the libraries that are
248 305 # configured to be built
249 306
250 307 if test $build_static_library == yes; then
251 308 for obj in ${fn_objects[@]} ${rt_objects[@]} ${data_objects[@]}; do
252 - ar rc $out/libk.a $obj
309 + report 120 ar rc $out/libk.a $obj
253 310 done
254 - ranlib $out/libk.a
311 + report 105 ranlib $out/libk.a
255 312 fi
256 313
257 314 if test $build_shared_library == yes; then
258 - ld -r ${rt_objects[@]} -o $out/boot.o
259 - ld -shared ${fn_objects[@]} -o $out/libk.so
315 + report 216 ld -r ${rt_objects[@]} -o $out/boot.o
316 + report 216 ld -shared ${fn_objects[@]} -o $out/libk.so
260 317 fi
261 318
262 319 # fifth pass: compile the executable tools
263 320 # against the libraries created in pass 5
264 321
265 322 for mod in ${modules[@]}; do
266 323 for exe in $(scan $mod '*.exe.c'); do