os

An operating system
git clone https://erai.gay/code/os/
Log | Files | Refs | README | LICENSE

commit a8bd1e3f226509e1bcb8a0a2af6b4e37882b0690
parent cf69454fe5d34d92e4e4987efe0fa70c2974e999
Author: erai <erai@omiltem.net>
Date:   Sat, 16 Mar 2024 11:39:47 -0400

Update bootstrap script

Diffstat:
M.gitignore | 2++
Mbootstrap.sh | 32+++++++++++++++++++++++++-------
2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -3,3 +3,5 @@ cc1 cc2 genlex gencc +lex3.c +parse3.c diff --git a/bootstrap.sh b/bootstrap.sh @@ -2,22 +2,40 @@ set -ue +uptodate() { + target=$1 + shift + if ! [ -x "${target}" ]; then + return 1 + fi + while [ $# -gt 0 ]; do + if ! [ -f "$1" ] || [ "$1" -nt "${target}" ]; then + return 1 + fi + shift + done + return 0 +} + # Environmental variables used to compile the bootstrap : ${CC:=gcc} : ${CFLAGS:=-Wall -Wextra -Wno-unused -pedantic -std=c99} +LIBS="bufio.c lib.c alloc.c syscall.c" +SOURCES="cc1.c type.c parse1.c lex1.c as.c ${LIBS}" +GENLEX_SOURCES="genlex.c ${LIBS}" # First compile the bootstrap -${CC} ${CFLAGS} -o cc0 ./cc0.c || exit 1 +uptodate cc0 cc0.c || ${CC} ${CFLAGS} ./cc0.c -o cc0 || { rm -f cc0; echo "bootstrap failed" >&2; exit 1; } # Then use the bootstrap to compile the compiler -timeout 1 sh -c './cc0 cc1.c -o cc1' || { echo "cc0 failed"; exit 1; } -chmod +x cc1 +uptodate cc1 ${SOURCES} || ./cc0 ${SOURCES} -o cc1 || { rm -f cc1; echo "cc0 failed" >&2; exit 1; } # Then compile the compiler with itself -timeout 1 sh -c './cc1 cc1.c -o cc2' || { echo "cc1 failed"; exit 1; } -chmod +x cc2 +uptodate cc2 cc1 ${SOURCES} && false || ./cc1 ${SOURCES} -o cc2 || { rm -f cc2; echo "cc1 failed" >&2; exit 1; } # And check our work -diff <(xxd cc1) <(xxd cc2) +diff <(xxd cc1) <(xxd cc2) || : cmp cc1 cc2 || { echo "output mismatch"; exit 1; } -exit 0 + +uptodate genlex cc1 ${GENLEX_SOURCES} || ./cc1 ${GENLEX_SOURCES} -o genlex || { rm -f genlex; echo "cc1 failed" >&2; exit 1; } +uptodate lex3.c genlex cc3.l || ./genlex < cc3.l > lex3.c || { rm -f lex3.c; echo "genlex failed" >&2; exit 1; }