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