diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 148 |
1 files changed, 110 insertions, 38 deletions
@@ -1,15 +1,17 @@ -# shellcheck disable=SC2283,SC2068,SC1089 -# ^ cleaner lints this makefile as shell; `NAME = value` is make syntax, -# and $(OBJS)-style make expansions are not shell arrays or a syntax error. +# shellcheck disable=SC2283,SC2046,SC2068,SC1089 +# ^ cleaner lints this makefile as shell: `NAME = value`, `$(CFLAGS)` and a +# recipe that is not a script are make syntax, not shell. .POSIX: .SUFFIXES: .SUFFIXES: .c .o # zash - a small, fast POSIX shell for z/OS UNIX. # -# One flat makefile; nothing here invokes make again. +# One flat makefile; the only make it runs again is `all`'s one-line +# choice of build for the host. # -# make build ./zash (Linux: clang, posix_spawn) +# make build ./zash (Linux: clang, posix_spawn; +# z/OS: the ASCII z/OS build) # make check run the test suite against ./zash # make asan build ./zash-asan, run the suite under ASan + UBSan # make valgrind run the test suite under Valgrind @@ -27,6 +29,7 @@ # make spec typeset formal/zash-spec.pdf with typst # make doc the source reference, Doxygen into doc/ # make other-docs spec and doc: the documentation tools z/OS lacks +# make docs HTML and PDF of README.md and DESIGN.md, in docs/ # # make zos-ascii z/OS build, ASCII program (IBM Open XL C/C++) # make zos-ebcdic z/OS build, EBCDIC program @@ -54,8 +57,11 @@ SANFLAGS = -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=undefined \ -fno-omit-frame-pointer ZCC = ibm-clang -ZAS = as -ZCFLAGS = $(CSTD) $(WARN) -O2 -m64 +# 31-bit: a 64-bit fork() costs 4.2 ms and a 32-bit one 0.10 ms on z/OS, +# and a trivial program starts in 29.5 ms against 1.1 ms. bench/README.md +# has the measurements. Nothing in the sources needs 64 bits, so this is +# the whole fix for the fork-heavy benchmarks. +ZCFLAGS = $(CSTD) $(WARN) -O2 -m32 # _POSIX_C_SOURCE=200809L: z/OS exposes SUSv4 names only through it # (_XOPEN_SOURCE 700 is not accepted). _EXT: IBM extensions (fetch()). @@ -76,7 +82,7 @@ DBGFLAGS = -O0 -g3 -fno-omit-frame-pointer # make syntax, as everywhere else in this file; z/OS make rejects `?=`.) DBX = dbx # dbx needs -g and read/write load; no optimisation or inlining. -ZDBGFLAGS = -O0 -g3 -m64 -fno-omit-frame-pointer +ZDBGFLAGS = -O0 -g3 -m32 -fno-omit-frame-pointer ARGS = PID = DUMP = @@ -100,7 +106,11 @@ OBJS = src/alias.o src/arith.o src/builtin.o src/builtin_ext.o \ src/printf.o src/redir.o src/test.o src/trap.o src/unparse.o \ src/util.o src/var.o src/edit_$(EDIT).o src/sys_$(SYS).o -all: zash +# z/OS builds zash with IBM Open XL (ibm-clang, not clang) and without +# posix_spawn, so plain `make` builds the ASCII z/OS build there. z/OS make +# is POSIX make, with no $(shell) and no conditionals, so the shell picks. +all: + @uname -s | grep OS/390 >/dev/null && exec make zos-ascii; make zash zash: $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) @@ -125,9 +135,9 @@ attach: # z/OS debug build: same sources, -O0 -g3, no inlining. zos-debug: zash-dbg -zash-dbg: $(COMMON) src/sys_zos.c src/zos_csi.o $(HDRS) +zash-dbg: $(COMMON) src/sys_zos.c $(HDRS) $(ZCC) $(ZCPPFLAGS) $(CSTD) $(WARN) $(ZDBGFLAGS) -fzos-le-char-mode=ascii \ - -o $@ $(COMMON) src/sys_zos.c src/zos_csi.o $(LDLIBS) + -o $@ $(COMMON) src/sys_zos.c $(LDLIBS) # make zos-dbx ARGS='-c "echo hi"' # @@ -151,23 +161,13 @@ zos-dump: zash-dbg @if [ -z "$(DUMP)" ]; then echo 'usage: make zos-dump DUMP=file' >&2; exit 2; fi $(DBX) -C $(DUMP) ./zash-dbg -# Map the CSECTs, AMODE/RMODE and entry points of the built program object, -# and of the HLASM routine's object module. amblist reads the control -# statement on stdin and needs a leading blank; the output is long, so it -# goes to a file. -zos-amblist: zos-ascii src/zos_csi.o +# Map the CSECTs, AMODE/RMODE and entry points of the built program object. +# amblist reads the control statement on stdin and needs a leading blank; +# the output is long, so it goes to a file. +zos-amblist: zos-ascii echo ' $(AMBLIST_STMT)' | amblist ./zash > zash.amblist - echo ' LISTOBJ' | amblist src/zos_csi.o > zos_csi.amblist -# HLASM reads its source as EBCDIC records split at X'15'; the file in git -# is ASCII (tagged UTF-8), so convert a copy first. -src/zos_csi.o: src/zos_csi.s - iconv -f UTF-8 -t IBM-1047 src/zos_csi.s > src/zos_csi.ebc.s - chtag -tc IBM-1047 src/zos_csi.ebc.s - $(ZAS) -mgoff -o src/zos_csi.o src/zos_csi.ebc.s - rm -f src/zos_csi.ebc.s - @@ -195,24 +195,37 @@ zash-asan: $(COMMON) src/sys_posix.c $(HDRS) # goes to its own name so the two never overwrite each other: make would # otherwise call a rebuild of the other mode "up to date" and leave the # old one in place. -zos-ascii: $(COMMON) src/sys_zos.c src/zos_csi.o $(HDRS) +zos-ascii: $(COMMON) src/sys_zos.c $(HDRS) $(ZCC) $(ZCPPFLAGS) $(ZCFLAGS) -fzos-le-char-mode=ascii -o zash \ - $(COMMON) src/sys_zos.c src/zos_csi.o $(LDLIBS) + $(COMMON) src/sys_zos.c $(LDLIBS) -zos-ebcdic: $(COMMON) src/sys_zos.c src/zos_csi.o $(HDRS) +zos-ebcdic: $(COMMON) src/sys_zos.c $(HDRS) $(ZCC) $(ZCPPFLAGS) $(ZCFLAGS) -fzos-le-char-mode=ebcdic -o zash-ebcdic \ - $(COMMON) src/sys_zos.c src/zos_csi.o $(LDLIBS) + $(COMMON) src/sys_zos.c $(LDLIBS) + +# /bin/sleep on z/OS takes whole seconds -- "0.3" is an error -- and the +# tests order background jobs with sub-second sleeps. The z/OS test runs +# put a sleep that takes fractions in front of PATH. +ZTOOLS = build/zos-tools -check: zash +$(ZTOOLS)/sleep: tests/tools/zos-sleep.c + @mkdir -p $(ZTOOLS) + $(ZCC) $(ZCPPFLAGS) $(CSTD) -O2 -m32 -Wall -Wextra \ + -fzos-le-char-mode=ascii -o $@ tests/tools/zos-sleep.c + +# On z/OS the `zash` build above wants clang and posix_spawn, so run the z/OS +# build and both its test passes instead. +check: + @uname -s | grep OS/390 >/dev/null && exec make zos-check || $(MAKE) zash sh tests/run.sh ./zash # z/OS has no ASan, but Language Environment can put a check zone after # every heap element and validate the heap on every request, which turns # an overlay into a U4042 abend. Meant for a run on the real system: # make zos-heapcheck -zos-heapcheck: +zos-heapcheck: $(ZTOOLS)/sleep _CEE_RUNOPTS='HEAPZONES(0,ABEND,32,ABEND) HEAPCHK(ON)' \ - sh tests/run.sh ./zash + PATH="$$(pwd)/$(ZTOOLS):$$PATH" sh tests/run.sh ./zash asan: zash-asan ASAN_OPTIONS=detect_leaks=1:abort_on_error=0 sh tests/run.sh ./zash-asan @@ -248,9 +261,9 @@ valgrind: zash # z/OS: behaviour only (no sanitizers or Valgrind there), against the # ./zash that zos-ascii or zos-ebcdic built. -zos-check: zos-ascii zos-ebcdic - sh tests/run.sh ./zash - sh tests/run.sh ./zash-ebcdic zos/ebcdic +zos-check: zos-ascii zos-ebcdic $(ZTOOLS)/sleep + PATH="$$(pwd)/$(ZTOOLS):$$PATH" sh tests/run.sh ./zash + PATH="$$(pwd)/$(ZTOOLS):$$PATH" sh tests/run.sh ./zash-ebcdic zos/ebcdic bench: zash sh bench/run.sh $$(pwd)/zash @@ -280,8 +293,67 @@ coverage: printf "%-24s %7s of %s\n", f, a[2], $$4; f=""}' gcov.log | tr -d "'"; \ tail -n 1 gcov.log +# The source reference. docs/html/ for browsing, and docs/zash-reference.pdf +# as one file to send: Doxygen's LaTeX output built with pdflatex, which needs +# its packages installed (Fedora: texlive-{amsfonts,wasysym,fancyhdr,cmap, +# tocbibind,etoolbox,float,varwidth,adjustbox,alphalph,caption,changepage, +# enumitem,etoc,fancyvrb,geometry,hanging,multirow,natbib,newunicodechar, +# stackengine,tabularray,tocloft,ulem,xltabular,ec,cm-super,metafont, +# collection-fontsrecommended}). Without pdflatex, docs/html is all you get. +# The LaTeX build is quiet unless it fails; its log is docs/latex.log. doc: + @rm -rf docs/html docs/latex docs/zash-reference.pdf doxygen Doxyfile + @if command -v pdflatex >/dev/null 2>&1; then \ + $(MAKE) -C docs/latex > docs/latex.log 2>&1 \ + && cp docs/latex/refman.pdf docs/zash-reference.pdf \ + && echo "docs/zash-reference.pdf"; \ + else \ + echo "doc: pdflatex not found, docs/html only"; \ + fi + +# HTML and PDF of the two documents, in docs/ (which is not committed). +# The PDF comes from the HTML through a headless browser, so no LaTeX +# installation is needed; without one, the HTML is still written. +# The colours are the ones formal/zash-spec.typ uses. +DOCS = README DESIGN +CHROME ?= $(shell command -v google-chrome || command -v chromium || \ + command -v chromium-browser) + +docs: doc + @mkdir -p docs + printf '%s\n' \ + 'body { max-width: 46em; margin: 2em auto; padding: 0 1em;' \ + ' font: 16px/1.55 Helvetica, Arial, sans-serif; color: #1b1f24;' \ + ' -webkit-print-color-adjust: exact; print-color-adjust: exact; }' \ + 'h1 { border-bottom: 2px solid #3fb950; padding-bottom: .2em; }' \ + 'a { color: #1f5fa8; }' \ + 'code { color: #7a3e9d; }' \ + 'pre { background: #f6f8fa; border: 1px solid #d0d7de; padding: .6em;' \ + ' white-space: pre-wrap; }' \ + 'th { background: #eef3fb; }' \ + 'tr:nth-child(even) td { background: #fafbfc; }' \ + 'blockquote { border-left: 4px solid #3fb950; margin-left: 0;' \ + ' padding-left: 1em; color: #57606a; }' \ + 'img { max-width: 100%; }' > docs/style.css + for d in $(DOCS); do \ + awk '/^<p align="center">$$/{print "<p align=\"center\"><img " \ + "src=\"packaging/zash-logo.svg\" alt=\"zash\" width=\"128\"></p>"; \ + skip=1; next} skip && /^<\/p>$$/{skip=0; next} !skip' \ + $$d.md > docs/$$d.md; \ + pandoc -s --embed-resources --resource-path=. \ + --metadata pagetitle="zash $$d" --css docs/style.css \ + -o docs/$$d.html docs/$$d.md || exit 1; \ + rm -f docs/$$d.md; \ + if [ -n "$(CHROME)" ]; then \ + $(CHROME) --headless --disable-gpu --no-sandbox \ + --no-pdf-header-footer --user-data-dir=docs/.chrome \ + --print-to-pdf="$$(pwd)/docs/$$d.pdf" \ + "file://$$(pwd)/docs/$$d.html" >/dev/null 2>&1 || exit 1; \ + else \ + echo "docs: no browser found, docs/$$d.html only"; \ + fi; \ + done # The language specification: formal/zash-spec.typ, typeset by typst. spec: @@ -301,10 +373,10 @@ install: zash clean: rm -f zash zash-asan zash-dbg zash-debug zash-mvslint fuzz-mvsfmt \ src/*.o compile_commands.json - rm -f zash.amblist zos_csi.amblist - rm -rf doc cov + rm -f zash.amblist + rm -rf docs cov $(ZTOOLS) .PHONY: fuzz zos-lint mvs-asan all check asan valgrind bench compdb format tidy \ - doc spec other-docs coverage install clean \ + doc docs spec other-docs coverage install clean \ zos-ascii zos-ebcdic zos-check zos-heapcheck zos-debug zos-dbx \ zos-attach zos-dump zos-amblist |
