summaryrefslogtreecommitdiffhomepage
path: root/Makefile
blob: ff2f2bf622246dbb2e6274ae2fe715bf3ced854f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# shellcheck disable=SC2283,SC2046,SC2068,SC1089
# ^ our linter reads this as shell: `NAME = value` and `$(CFLAGS)` are make.
.POSIX:
.SUFFIXES:
.SUFFIXES: .c .o

# ztop - what z/OS has where, for a systems programmer over ssh.
#
#   make            build ./ztop (z/OS)
#   make check      run it against storage, system and jobs
#   make test       parser, library and system helpers, on any host
#   make tidy       clang-tidy over the portable sources
#   make demo       tui/demo, the library on its own
#   make clean      remove what the targets above write
#
# z/OS only for ./ztop: VSMLIST, the PSA and the ASVT do not exist
# elsewhere, so `make` on another host says so and stops.  This tree is
# kept on Linux as a backup and for the portable tests.
#
# The build is POSIX make, the make z/OS ships: no :=, no ?=, no ifeq,
# no $(shell), no pattern rules.  One more z/OS make trait: a recipe line
# holding a pipeline *and* a || spins it, so the pipeline is
# parenthesised.

CC       = ibm-clang
CSTD     = -std=c23
WARN     = -Wall -Wextra -Wshadow -Wpedantic
CFLAGS   = $(CSTD) $(WARN) -O2 -m32 -D_XOPEN_SOURCE=500 \
           -D_POSIX_C_SOURCE=200112L
CPPFLAGS = -Itui
# AC(1) selects XPLINK.  Quoted: the z/OS shell reads `(` in an
# unquoted word as a syntax error.
LDFLAGS  = -Wl,'-bAC(1)'

# The .S suffix sends the stub through clang's preprocessor; -P drops
# the line markers HLASM would read as statements, and -fno-integrated-as
# hands the result to HLASM.  That path writes its own tagged temporary,
# so the checked-out ASCII source needs no chtag first.
ASFLAGS  = -fno-integrated-as -Xpreprocessor -P

# The library is compiled into the program rather than linked as an
# archive: one binary, and the same sources build on Linux for the tests.
SRC = src/ztop.c src/vsm.c src/sys.c src/uss.c src/mdb.c src/zmcs.c tui/tui.c
OBJ = src/zvslist.o src/zmcs.o
HDR = src/vsm.h src/sys.h src/uss.h src/mdb.h tui/tui.h

# The portable half: no z/OS services, no terminal.
TESTCC    = cc
TESTFLAGS = -std=c23 -g -O1 -Wall -Wextra -Wshadow -Wpedantic \
            -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200112L

# Language Environment sees every heap request the program makes.  Its
# storage report is therefore the leak test a z/OS user can run: if the
# gets and the frees differ by the end of the enclave, something was
# allocated and never freed.  HEAPCHK(ON) additionally walks the heap at
# every call, so a double free or an overlay abends instead of hiding.

# The working tree arrives tagged ISO8859-1 from .gitattributes, so this is
# only for a tree that predates that file or a file written by hand.  The
# tag matters because make, sh, awk and the compiler read these files
# through the EBCDIC converter and see ASCII, not EBCDIC.
tag:
	@-chtag -t -c ISO8859-1 Makefile README.md DESIGN.md tests/*.sh tests/*.py
	@-chtag -t -c ISO8859-1 src/*.c src/*.h src/*.S src/*.s tui/*.c tui/*.h
	@-chtag -t -c ISO8859-1 tui/Makefile tui/test_tui.c tui/demo.c

all:
	@uname -s | grep OS/390 > /dev/null || \
	    { echo "ztop builds only on z/OS; this tree is a backup copy"; exit 1; }
	$(MAKE) ztop

ztop: $(SRC) $(OBJ) $(HDR)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(SRC) $(OBJ)

src/zvslist.o: src/zvslist.S
	$(CC) $(CFLAGS) $(ASFLAGS) -c -o $@ src/zvslist.S

# zmcs.s is plain assembler on purpose: the .S path puts the source
# through clang's preprocessor, and that squeezes the runs of blanks
# which hold a continuation character in column 72.  A macro call that
# needs more than one line cannot survive it, and this stub has no
# #ifdef to justify the preprocessor anyway.
src/zmcs.o: src/zmcs.s
	$(CC) $(CFLAGS) -fno-integrated-as -c -o $@ src/zmcs.s

check: ztop
	./ztop
	./ztop -a sqa
	./ztop -a pvt
	./ztop -j

test: tests/test_vsm.c tests/test_sys.c tests/test_mdb.c src/vsm.c src/sys.c \
    src/mdb.c tui/test_tui.c tui/tui.c
	$(TESTCC) $(TESTFLAGS) -o tests/test_vsm tests/test_vsm.c src/vsm.c
	./tests/test_vsm
	$(TESTCC) $(TESTFLAGS) -Isrc -o tests/test_sys tests/test_sys.c src/sys.c
	./tests/test_sys
	$(TESTCC) $(TESTFLAGS) -Isrc -o tests/test_mdb tests/test_mdb.c src/mdb.c
	./tests/test_mdb
	$(TESTCC) $(TESTFLAGS) -Itui -o tui/test_tui tui/test_tui.c tui/tui.c
	./tui/test_tui
	@sh tests/leakcheck.sh --selftest

demo: tui/demo.c tui/tui.c
	$(TESTCC) $(TESTFLAGS) -Itui -o tui/demo tui/demo.c tui/tui.c

# ztop.c needs the z/OS headers, so the tidy pass covers everything else:
# the parser, the system helpers, the library and their tests.
tidy:
	clang-tidy src/vsm.c src/sys.c src/uss.c src/mdb.c src/zmcs.c \
	    tui/tui.c tests/test_vsm.c tests/test_sys.c tests/test_mdb.c \
	    tui/test_tui.c tui/demo.c -- \
	    $(TESTFLAGS) -Isrc -Itui

leakcheck: ztop
	@sh tests/leakcheck.sh ./ztop

# The console needs APF: extattr marks this file, and the library it sits
# in still has to be in the APF list.  Then the user needs READ on
# MVS.MCSOPER.ZTOP, and ztop is started with -c.
auth:
	extattr +ap ./ztop
	ls -E ./ztop

clean:
	rm -f ztop $(OBJ) tests/test_vsm tests/test_sys tui/test_tui tui/demo