cosmo: avoid ugly variable expansions with an ugly script

This commit is contained in:
Connor Olding 2022-10-09 14:19:20 -07:00
parent fb551d7220
commit ca186e01f9

View File

@ -50,58 +50,71 @@ RUN : \
# apply patches from dash to unbourne shell \
&& /usr/bin/busybox patch -p1 -i unbourne-backports.patch \
# make calling make a little shorter (don't put this in distrib!) \
&& ln -s build/bootstrap/make.com make \
&& printf '%s\n' >makeit '#!/usr/bin/env sh' \
"build/bootstrap/make.com -j2 MODE='$mode'"' "$@"' \
# make accessing some common paths a littler shorter (don't put this in distrib!) \
&& printf '%s\n' >expand '#!/usr/bin/env sh' \
"o='o/$mode' once=false" \
'for f; do g="${f#?//}"; case "$f" in' \
'(a//*) f="$o/ape/$g";;' \
'(b//*) f="$o/tool/build/$g";;' \
'(e//*) f="$o/examples/$g";;' \
'(o//*) f="$o/$g";;' \
'(t//*) f="$o/third_party/$g";;' \
'(T//*) f="third_party/$g";;' \
'esac; $once && set -- "$@" "$f" || set -- "$f"; once=true; done' \
'"$@"' \
# don't forget to do this \
&& chmod +x makeit expand \
;
# finally start building
RUN --mount=type=tmpfs,target=/tmp : \
&& . ./env && o="o/$mode" a="$o/ape" b="$o/tool/build" t="$o/third_party" e="$o/examples" \
&& ./make -j2 MODE="$mode" \
"$a/ape-copy-self.o" "$a/ape-no-modify-self.o" "$a/ape.elf" \
"$a/ape.lds" "$a/ape.macho" "$a/ape.o" \
"$a/public/ape.lds" "$o/cosmopolitan.a" "$o/libc/crt/crt.o" \
"o/cosmopolitan.h" \
&& ./expand ./makeit \
a//ape-copy-self.o a//ape-no-modify-self.o a//ape.elf \
a//ape.lds a//ape.macho a//ape.o \
a//public/ape.lds o//cosmopolitan.a o//libc/crt/crt.o \
o/cosmopolitan.h \
# build some extra tools for other containers to stem off of: \
&& rebuild() { ./make -j2 MODE="$mode" "$@" && cp -t build/bootstrap "$@" ;} \
&& rebuild() { ./expand ./makeit "$@" && ./expand cp -t build/bootstrap "$@" ;} \
&& rebuild \
"$t/make/make.com" "$b/ar.com" "$b/cocmd.com" \
"$b/compile.com" "$b/cp.com" "$b/echo.com" \
"$b/fixupobj.com" "$b/gzip.com" "$b/mkdeps.com" \
"$b/mkdir.com" "$b/package.com" "$b/pwd.com" \
"$b/rm.com" "$b/touch.com" "$b/unbundle.com" \
"$b/zipobj.com" \
t//make/make.com b//ar.com b//cocmd.com \
b//compile.com b//cp.com b//echo.com \
b//fixupobj.com b//gzip.com b//mkdeps.com \
b//mkdir.com b//package.com b//pwd.com \
b//rm.com b//touch.com b//unbundle.com \
b//zipobj.com \
# these are essential too! \
&& ./make -j2 MODE="$mode" "$@" \
"$e/unbourne.com" "$t/awk/awk.com" "$t/sed/sed.com" \
"$t/unzip/unzip.com" "$t/zip/zip.com" "$b/assimilate.com" \
&& ./expand ./makeit \
e//unbourne.com t//awk/awk.com t//sed/sed.com \
t//unzip/unzip.com t//zip/zip.com b//assimilate.com \
;
# install the basics (no executable binaries besides ape.elf)
RUN : \
&& . ./env && o="o/$mode" a="$o/ape" b="$o/tool/build" t="$o/third_party" e="$o/examples" \
&& . ./env \
&& mkdir dist "dist/$flavor" "dist/$flavor/public" \
&& echo /dist >>.gitignore \
&& cp -t "dist/$flavor" \
"$a/ape-copy-self.o" "$a/ape-no-modify-self.o" "$a/ape.elf" \
"$a/ape.lds" "$a/ape.macho" "$a/ape.o" \
"$o/cosmopolitan.a" "$o/libc/crt/crt.o" "o/cosmopolitan.h" \
&& cp -t "dist/$flavor/public" "$a/public/ape.lds" \
&& ./expand cp -t "dist/$flavor" \
a//ape-copy-self.o a//ape-no-modify-self.o a//ape.elf \
a//ape.lds a//ape.macho a//ape.o \
o//cosmopolitan.a o//libc/crt/crt.o o/cosmopolitan.h \
&& cp -t "dist/$flavor/public" "o/$mode/ape/public/ape.lds" \
\
&& install -m0755 "dist/$flavor/ape.elf" /usr/bin/ape \
&& find libc -name '*.h' >headers.txt \
&& t=third_party ln=linenoise \
&& tar zcf "dist/headers.tar.gz" -T "headers.txt" \
"ape/config.h" "libc/integral" "$t/gdtoa/gdtoa.h" \
"$t/getopt/getopt.h" "$t/$ln/$ln.h" "$t/musl/crypt.h" \
"$t/musl/fnmatch.h" "$t/musl/passwd.h" "$t/regex/regex.h" \
"$t/zlib/zconf.h" "$t/zlib/zlib.h" \
&& ./expand tar zcf dist/headers.tar.gz -T headers.txt \
ape/config.h libc/integral T//gdtoa/gdtoa.h \
T//getopt/getopt.h T//linenoise/linenoise.h T//musl/crypt.h \
T//musl/fnmatch.h T//musl/passwd.h T//regex/regex.h \
T//zlib/zconf.h T//zlib/zlib.h \
;
# install the rest
FROM builder AS distrib
COPY --chmod=0755 --from=localhost/notwa-util /nu/dedupe /usr/bin/
RUN --mount=type=tmpfs,target=/tmp : \
&& . ./env && o="o/$mode" a="$o/ape" b="$o/tool/build" t="$o/third_party" e="$o/examples" \
&& . ./env \
&& find o -name '*.sym' -delete \
&& dedupe o/third_party/gcc /distrib/gcc/ \
bin/x86_64-linux-musl-gcc \
@ -111,15 +124,15 @@ RUN --mount=type=tmpfs,target=/tmp : \
&& mkdir /tmp/bin \
# discover .com files by uncommenting this command: \
#&& find o -name '*.com' ! -type d -exec printf '%s\n' cp -t /tmp/bin {} + | sort && exit 1 \
&& cp -t /tmp/bin \
"$e/unbourne.com" "$t/awk/awk.com" "$t/make/make.com" \
"$t/sed/sed.com" "$t/unzip/unzip.com" "$t/zip/zip.com" \
"$b/ar.com" "$b/assimilate.com" "$b/cocmd.com" \
"$b/compile.com" "$b/cp.com" "$b/echo.com" \
"$b/fixupobj.com" "$b/gzip.com" "$b/mkdeps.com" \
"$b/mkdir.com" "$b/package.com" "$b/pwd.com" \
"$b/rm.com" "$b/rollup.com" "$b/symtab.com" \
"$b/touch.com" "$b/unbundle.com" "$b/zipobj.com" \
&& ./expand cp -t /tmp/bin \
e//unbourne.com t//awk/awk.com t//make/make.com \
t//sed/sed.com t//unzip/unzip.com t//zip/zip.com \
b//ar.com b//assimilate.com b//cocmd.com \
b//compile.com b//cp.com b//echo.com \
b//fixupobj.com b//gzip.com b//mkdeps.com \
b//mkdir.com b//package.com b//pwd.com \
b//rm.com b//rollup.com b//symtab.com \
b//touch.com b//unbundle.com b//zipobj.com \
&& dedupe /tmp/bin /distrib/bin/ \
#&& ln -s "../dist/$flavor/ape.elf" /distrib/bin/ape \
&& cp "dist/$flavor/ape.elf" /distrib/bin/ape \