Makefile revision 1.114
1# $NetBSD: Makefile,v 1.114 2021/04/11 11:41:27 rillig Exp $ 2# @(#)Makefile 5.2 (Berkeley) 12/28/90 3 4PROG= make 5SRCS= arch.c 6SRCS+= buf.c 7SRCS+= compat.c 8SRCS+= cond.c 9SRCS+= dir.c 10SRCS+= enum.c 11SRCS+= for.c 12SRCS+= hash.c 13SRCS+= job.c 14SRCS+= lst.c 15SRCS+= main.c 16SRCS+= make.c 17SRCS+= make_malloc.c 18SRCS+= metachar.c 19SRCS+= parse.c 20SRCS+= str.c 21SRCS+= suff.c 22SRCS+= targ.c 23SRCS+= trace.c 24SRCS+= var.c 25SRCS+= util.c 26 27# Whether to generate a coverage report after running the tests. 28USE_COVERAGE?= no # works only with gcc; clang9 fails to link 29.if ${USE_COVERAGE} == "yes" 30GCOV?= gcov 31COPTS+= --coverage -O0 -ggdb 32GCOV_PERL= if (/^File '(?:.*\/)?(\S+)'/) { 33GCOV_PERL+= $$file = $$1; $$func = ""; 34GCOV_PERL+= } elsif (/^Function '(\S+)'/) { 35GCOV_PERL+= $$func = $$1; 36GCOV_PERL+= } elsif (/^Lines executed:(\d+\.\d+)% of (\d+)/ && defined($$file)) { 37GCOV_PERL+= my ($$percent, $$lines) = ($$1, $$2); 38GCOV_PERL+= my $$uncovered = `grep -c '\#\#\#\#\#:' < \$$(basename $$file.gcov)`; 39GCOV_PERL+= printf("%7.2f %4d/%4d %s%s\n", 40GCOV_PERL+= $$percent, $$uncovered, $$lines, $$file, $$func); 41GCOV_PERL+= $$file = undef; 42GCOV_PERL+= } 43LDADD+= --coverage 44.endif 45CLEANFILES+= *.gcda *.gcno *.gcov 46 47# Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang). 48USE_UBSAN?= no 49.if ${USE_UBSAN} == "yes" 50COPTS+= -fsanitize=undefined 51LDADD+= -fsanitize=undefined 52.endif 53 54# Whether to compile with GCC 10 from pkgsrc, during development. 55USE_GCC10?= no 56.if ${USE_GCC10} == "yes" 57# CC is set further down in this file 58COPTS+= -Wno-attributes # for abs and labs 59COPTS.arch.c+= -Wno-error=format-truncation 60COPTS.dir.c+= -Wno-error=format-truncation 61COPTS.main.c+= -Wno-error=format-truncation 62COPTS.meta.c+= -Wno-error=format-truncation 63.endif 64 65# Whether to compile with GCC 9 from pkgsrc, during development. 66USE_GCC9?= no 67.if ${USE_GCC9} == "yes" 68# CC is set further down in this file 69COPTS+= -Wno-attributes # for abs and labs 70COPTS.arch.c+= -Wno-error=format-truncation 71COPTS.dir.c+= -Wno-error=format-truncation 72COPTS.main.c+= -Wno-error=format-truncation 73COPTS.meta.c+= -Wno-error=format-truncation 74.endif 75 76# Whether to compile with GCC 8 from pkgsrc, during development. 77USE_GCC8?= no 78.if ${USE_GCC8} == "yes" 79# CC is set further down in this file 80COPTS+= -Wno-attributes # for abs and labs 81COPTS.arch.c+= -Wno-error=format-truncation 82COPTS.dir.c+= -Wno-error=format-truncation 83COPTS.main.c+= -Wno-error=format-truncation 84COPTS.meta.c+= -Wno-error=format-truncation 85.endif 86 87USE_META?= yes 88.if ${USE_META:tl} != "no" 89 90SRCS+= meta.c 91CPPFLAGS+= -DUSE_META 92 93USE_FILEMON?= ktrace 94. if ${USE_FILEMON:tl} != "no" 95 96.PATH: ${.CURDIR}/filemon 97SRCS+= filemon_${USE_FILEMON}.c 98CPPFLAGS+= -DUSE_FILEMON 99CPPFLAGS+= -DUSE_FILEMON_${USE_FILEMON:tu} 100 101. if ${USE_FILEMON} == "dev" 102FILEMON_H?= /usr/include/dev/filemon/filemon.h 103. if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h" 104COPTS.filemon_dev.c+= \ 105 -DHAVE_FILEMON_H -I${FILEMON_H:H} 106. endif 107. endif 108. endif 109.endif 110 111SUBDIR.roff+= PSD.doc 112.if make(obj) || make(clean) 113SUBDIR+= unit-tests 114.endif 115 116LINTFLAGS+= -T # strict bool mode, available since 2021-01-11 117CLEANFILES+= *.o # for filemon objects 118 119COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION} 120COPTS.dir.c+= ${GCC_NO_FORMAT_TRUNCATION} 121COPTS.job.c+= -Wno-format-nonliteral 122COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION} 123COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION} 124COPTS.parse.c+= -Wno-format-nonliteral 125COPTS.var.c+= -Wno-format-nonliteral 126 127CPPFLAGS+= -DMAKE_NATIVE 128 129.if ${USE_GCC10} == "yes" 130GCC10BASE?= /usr/pkg/gcc10 131LATE_CC= ${GCC10BASE}/bin/gcc 132GCOV= ${GCC10BASE}/bin/gcov 133.endif 134 135.if ${USE_GCC9} == "yes" 136GCC9BASE?= /usr/pkg/gcc9 137LATE_CC= ${GCC9BASE}/bin/gcc 138GCOV= ${GCC9BASE}/bin/gcov 139.endif 140 141.if ${USE_GCC8} == "yes" 142GCC8BASE?= /usr/pkg/gcc8 143LATE_CC= ${GCC8BASE}/bin/gcc 144GCOV= ${GCC8BASE}/bin/gcov 145.endif 146 147.if defined(TOOLDIR) 148# This is a native NetBSD build, use libutil rather than the local emalloc etc. 149CPPFLAGS+= -DUSE_EMALLOC 150LDADD+= -lutil 151DPADD+= ${LIBUTIL} 152.endif 153 154COPTS+= -Wdeclaration-after-statement 155 156# A simple unit-test driver to help catch regressions 157TEST_MAKE ?= ${.OBJDIR}/${PROG:T} 158test: .MAKE 159 cd ${.CURDIR}/unit-tests \ 160 && MAKEFLAGS= ${TEST_MAKE} -r -m / TEST_MAKE=${TEST_MAKE} ${TESTS:DTESTS=${TESTS:Q}} ${.TARGET} 161.if ${USE_COVERAGE} == yes 162 ${MAKE} report-coverage 163.endif 164 165accept sync-mi: .MAKE 166 cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET} 167 168retest: 169 ${.MAKE} -C ${.CURDIR}/unit-tests cleandir 170.if ${USE_COVERAGE} == yes 171 rm -f *.gcov *.gcda 172.endif 173 ${.MAKE} test 174 175# Just out of curiosity, during development. 176.SUFFIXES: .cpre .casm 177.c.cpre: 178 ${COMPILE.c:S,^-c$,-E,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET} 179.c.casm: 180 ${COMPILE.c:S,^-c$,-S,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET} 181 182test-coverage: .PHONY 183 @make -s clean cleandir 184 @env USE_COVERAGE=yes COPTS="-O0 -ggdb" USER_CPPFLAGS="-DCLEANUP" \ 185 sh -c 'make -s all -j8 && make -s test' 186 187report-coverage: .PHONY 188 @echo 'covered uncovered file' 189 @${GCOV} ${GCOV_OPTS} *.gcda 2>&1 \ 190 | perl -ne ${GCOV_PERL:Q} \ 191 | sort -nr 192 @sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov 193 194.include <bsd.prog.mk> 195.include <bsd.subdir.mk> 196 197# For -DCLEANUP and similar feature toggles. 198CPPFLAGS+= ${USER_CPPFLAGS} 199# For overriding -std=gnu99 or similar options. 200CFLAGS+= ${USER_CFLAGS} 201.if defined(LATE_CC) 202CC= ${LATE_CC} 203.endif 204