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