c/src/Makefile: Split a `CFLAGS` line
[sunny256-utils.git] / Lib / std / c / src / Makefile
blob949a50db10bd5b0b2f8f5f6c649b77f67d4ea6b0
1 # Makefile for STDexecDTS.c
2 # File ID: STDuuidDTS
3 # Author: Øyvind A. Holm <sunny@sunbase.org>
5 PREFIX = /usr/local
7 EXEC = STDexecDTS
9 CC = cc
10 LD = cc
12 CFLAGS =
13 CFLAGS += $$(test -n "$(GCOV)" && echo -n "-fprofile-arcs -ftest-coverage")
14 CFLAGS += $$(test -n "$(PROF)" && echo -n "-pg")
15 CFLAGS += -O0
16 CFLAGS += -Wall
17 CFLAGS += -Werror
18 CFLAGS += -Wextra
19 CFLAGS += -c
20 CFLAGS += -g
22 LDFLAGS =
23 LDFLAGS += $$(test -n "$(PROF)" && echo -n "-pg")
25 LIBS =
26 LIBS += $$(test -n "$(GCOV)" && echo "-lgcov --coverage")
28 OBJS =
29 OBJS += STDexecDTS.o
30 OBJS += selftest.o
32 CFILES =
33 CFILES += STDexecDTS.c
34 CFILES += selftest.c
36 HFILES =
37 HFILES += STDexecDTS.h
39 DEPS = version.h $(HFILES) Makefile
40 GNCOV_STR = $$(test -n "$(GNCOV)" && echo "-g")
41 TESTABLE_LINES = $$(grep -E '^ +\#\#\#\#\#:' *.c.gcov \
42 | grep -vF '/* gncov */' | wc -l)
44 .PHONY: all
45 all: $(EXEC)
47 $(EXEC): $(OBJS)
48 $(LD) -o $(EXEC) $(LDFLAGS) $(OBJS) $(LIBS)
50 version.h: Gen-version $(CFILES) $(HFILES) Makefile
51 ./Gen-version
53 STDexecDTS.o: STDexecDTS.c $(DEPS)
54 $(CC) $(CFLAGS) STDexecDTS.c
56 selftest.o: selftest.c $(DEPS)
57 $(CC) $(CFLAGS) selftest.c
59 .PHONY: clean
60 clean:
61 rm -f $(EXEC) $(OBJS)
62 rm -f *.gcda *.gcno *.gcov
63 rm -f gmon.out gmon.sum
64 rm -f version.h
65 cd t && $(MAKE) clean
67 .PHONY: edit
68 edit: tags
69 $(EDITOR) $$(git ls-files)
70 rm tags
72 .PHONY: gcov
73 gcov:
74 $(MAKE) clean test GCOV=1
75 gcov $(CFILES)
76 @echo $$(grep -E '^ +#####:' *.c.gcov | wc -l) untested lines >&2
77 @echo $$(grep -E '^ +#####:' *.c.gcov | grep -F '/* gncov */' \
78 | wc -l) gncov lines >&2
79 @echo $(TESTABLE_LINES) testable lines >&2
81 .PHONY: gcov-cmt
82 gcov-cmt: gcov
83 gcov-cmt $(GNCOV_STR) $(CFILES)
85 .PHONY: gcov-cmt-clean
86 gcov-cmt-clean:
87 gcov-cmt -d $(CFILES)
89 .PHONY: gdb
90 gdb: $(EXEC)
91 gdb -x gdbrc $$(cat gdbopts 2>/dev/null) $(EXEC)
93 .PHONY: install
94 install: $(PREFIX)/bin/$(EXEC)
96 $(PREFIX)/bin/$(EXEC): $(EXEC)
97 mkdir -p $(PREFIX)/bin
98 install $(EXEC) $(PREFIX)/bin/$(EXEC)
100 tags: $(CFILES) $(HFILES)
101 ctags $(CFILES) $(HFILES)
103 .PHONY: test
104 test: $(EXEC)
105 cd t && $(MAKE) test
107 .PHONY: testall
108 testall:
109 $(MAKE) testcomb WHAT=test
111 .PHONY: testcomb
112 testcomb:
113 $(MAKE) clean $(WHAT) NDEBUG=1
114 $(MAKE) clean $(WHAT) UNUSED=1
115 $(MAKE) clean $(WHAT) NDEBUG=1 UNUSED=1
116 $(MAKE) clean $(WHAT)
118 .PHONY: testsrc
119 testsrc:
120 @echo Check files for long lines >&2
121 @for f in $(CFILES) $(HFILES) Gen-version Makefile; do \
122 [ -f "$$f" ] && expand "$$f" | sed 's/ $$//;' \
123 | grep -q -E '.{80}' && echo "$$f"; \
124 done | grep . && exit 1 || true
126 .PHONY: tlok
127 tlok:
128 @$(MAKE) -s gcov 2>.make-tlok.tmp >&2; res=$$?; \
129 if test $$res -eq 0; then \
130 printf '%u:%u\n' \
131 "$(TESTABLE_LINES)" \
132 "$$(grep ^1\\.\\. .make-tlok.tmp \
133 | perl -pe 's/^1\.\.(\d+).*/$$1/;')"; \
134 else \
135 grep "Looks like you failed" <.make-tlok.tmp \
136 | perl -p \
137 -e 's/.*failed (\d+) tests? of (\d+).*/$$1\/$$2 FAIL/;'; \
138 fi; \
139 rm .make-tlok.tmp
141 .PHONY: uninstall
142 uninstall:
143 rm -f $(PREFIX)/bin/$(EXEC)
145 .PHONY: valgrind
146 valgrind:
147 cd t && $(MAKE) valgrind
149 .PHONY: valgrindall
150 valgrindall:
151 $(MAKE) testcomb WHAT=valgrind