NetBSD/usr.bin/make/Makefile

157 lines
4.1 KiB
Makefile
Raw Normal View History

# $NetBSD: Makefile,v 1.123 2022/09/27 17:46:58 rillig Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
1993-03-21 12:45:37 +03:00
PROG= make
SRCS= arch.c
SRCS+= buf.c
SRCS+= compat.c
SRCS+= cond.c
SRCS+= dir.c
SRCS+= for.c
SRCS+= hash.c
SRCS+= job.c
SRCS+= lst.c
SRCS+= main.c
SRCS+= make.c
SRCS+= make_malloc.c
SRCS+= metachar.c
SRCS+= parse.c
SRCS+= str.c
SRCS+= suff.c
SRCS+= targ.c
SRCS+= trace.c
SRCS+= var.c
SRCS+= util.c
WARNS= 6
2006-10-26 00:05:59 +04:00
# Whether to generate a coverage report after running the tests.
USE_COVERAGE?= no # works only with gcc; clang9 fails to link
.if ${USE_COVERAGE} == "yes"
GCOV?= gcov
COPTS+= --coverage -O0 -ggdb
GCOV_PERL= if (/^File '(?:.*\/)?(\S+)'/) {
GCOV_PERL+= $$file = $$1; $$func = "";
GCOV_PERL+= } elsif (/^Function '(\S+)'/) {
GCOV_PERL+= $$func = $$1;
GCOV_PERL+= } elsif (/^Lines executed:(\d+\.\d+)% of (\d+)/ && defined($$file)) {
GCOV_PERL+= my ($$percent, $$lines) = ($$1, $$2);
GCOV_PERL+= my $$uncovered =
GCOV_PERL+= $$percent eq '100.00' ? '0'
GCOV_PERL+= : $$file =~ /\.h$$/ ? '?'
GCOV_PERL+= : `grep -c '\#\#\#\#\#:' < \$$(basename $$file.gcov)`;
GCOV_PERL+= chomp($$uncovered);
GCOV_PERL+= printf("%7.2f %4s/%4d %s%s\n",
GCOV_PERL+= $$percent, $$uncovered, $$lines, $$file, $$func);
GCOV_PERL+= $$file = undef;
GCOV_PERL+= }
LDADD+= --coverage
.endif
CLEANFILES+= *.gcda *.gcno *.gcov
# Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang).
USE_UBSAN?= no
.if ${USE_UBSAN} == "yes"
COPTS+= -fsanitize=undefined
LDADD+= -fsanitize=undefined
.endif
2020-07-25 23:44:50 +03:00
USE_META?= yes
.if ${USE_META:tl} != "no"
2020-07-25 23:44:50 +03:00
SRCS+= meta.c
CPPFLAGS+= -DUSE_META
2020-07-25 23:44:50 +03:00
USE_FILEMON?= ktrace
. if ${USE_FILEMON:tl} != "no"
.PATH: ${.CURDIR}/filemon
2020-07-25 23:44:50 +03:00
SRCS+= filemon_${USE_FILEMON}.c
CPPFLAGS+= -DUSE_FILEMON
CPPFLAGS+= -DUSE_FILEMON_${USE_FILEMON:tu}
. if ${USE_FILEMON} == "dev"
2020-07-25 23:44:50 +03:00
FILEMON_H?= /usr/include/dev/filemon/filemon.h
. if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
2020-07-25 23:44:50 +03:00
COPTS.filemon_dev.c+= \
-DHAVE_FILEMON_H -I${FILEMON_H:H}
. endif
. endif
. endif
.endif
2018-06-10 20:55:11 +03:00
SUBDIR.roff+= PSD.doc
.if make(obj) || make(clean)
2020-07-25 23:44:50 +03:00
SUBDIR+= unit-tests
.endif
LINTFLAGS+= -T # strict bool mode, available since 2021-01-11
LINTFLAGS+= -w # treat warnings as errors
CLEANFILES+= *.o # for filemon objects
COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION}
COPTS.dir.c+= ${GCC_NO_FORMAT_TRUNCATION}
COPTS.job.c+= -Wno-format-nonliteral # custom shell templates
COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION}
COPTS.var.c+= -Wno-format-nonliteral # strftime
2020-07-25 23:44:50 +03:00
CPPFLAGS+= -DMAKE_NATIVE
.if defined(TOOLDIR)
2020-07-25 23:44:50 +03:00
# This is a native NetBSD build, use libutil rather than the local emalloc etc.
CPPFLAGS+= -DUSE_EMALLOC
LDADD+= -lutil
DPADD+= ${LIBUTIL}
2006-08-29 20:54:03 +04:00
.endif
2006-08-26 22:17:41 +04:00
COPTS+= -Wdeclaration-after-statement
# A simple unit-test driver to help catch regressions
TEST_MAKE ?= ${.OBJDIR}/${PROG:T}
test: .MAKE
cd ${.CURDIR}/unit-tests \
&& MAKEFLAGS= ${TEST_MAKE} -r -m / TEST_MAKE=${TEST_MAKE} ${TESTS:DTESTS=${TESTS:Q}} ${.TARGET}
.if ${USE_COVERAGE} == yes
${MAKE} report-coverage
.endif
accept sync-mi: .MAKE
cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
retest:
${.MAKE} -C ${.CURDIR}/unit-tests cleandir
.if ${USE_COVERAGE} == yes
rm -f *.gcov *.gcda
.endif
${.MAKE} test
# Just out of curiosity, during development.
.SUFFIXES: .cpre .casm
.c.cpre:
${COMPILE.c:S,^-c$,-E,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
.c.casm:
${COMPILE.c:S,^-c$,-S,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
2020-12-12 19:06:27 +03:00
test-coverage: .PHONY
@make -s clean cleandir
@env USE_COVERAGE=yes COPTS="-O0 -ggdb" USER_CPPFLAGS="-DCLEANUP" \
sh -c 'make -s all -j8 && make -s test'
@env USE_COVERAGE=yes make report-coverage > coverage.txt
2020-12-12 19:06:27 +03:00
.if ${USE_COVERAGE} == "yes"
report-coverage: .PHONY
@echo 'covered uncovered file'
@${GCOV} ${GCOV_OPTS} *.gcda \
| perl -ne ${GCOV_PERL:Q} \
| sort -nr
@sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
.endif
.include <bsd.prog.mk>
.include <bsd.subdir.mk>
# For -DCLEANUP and similar feature toggles.
CPPFLAGS+= ${USER_CPPFLAGS}
# For overriding -std=gnu99 or similar options.
CFLAGS+= ${USER_CFLAGS}