1 # $NetBSD: Makefile,v 1.78 2020/08/01 21:48:17 rillig Exp $ 2 # @(#)Makefile 5.2 (Berkeley) 12/28/90 3 4 PROG= make 5 SRCS= arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c lst.c main.c 6 SRCS+= make.c make_malloc.c metachar.c parse.c 7 SRCS+= str.c strlist.c suff.c targ.c trace.c var.c util.c 8 9 USE_COVERAGE?= no # works only with gcc; clang9 fails to link 10 .if ${USE_COVERAGE} == "yes" 11 COPTS+= --coverage -O0 -ggdb 12 LDADD+= --coverage 13 CLEANFILES+= ${SRCS:.c=.gcda} ${SRCS:.c=.gcno} ${SRCS:=.gcov} 14 .endif 15 16 USE_UBSAN?= no 17 .if ${USE_UBSAN} == "yes" 18 COPTS+= -fsanitize=undefined 19 LDADD+= -fsanitize=undefined 20 .endif 21 22 USE_META?= yes 23 .if ${USE_META:tl} != "no" 24 25 SRCS+= meta.c 26 CPPFLAGS+= -DUSE_META 27 28 USE_FILEMON?= ktrace 29 . if ${USE_FILEMON:tl} != "no" 30 31 .PATH: ${.CURDIR}/filemon 32 SRCS+= filemon_${USE_FILEMON}.c 33 CPPFLAGS+= -DUSE_FILEMON 34 CPPFLAGS+= -DUSE_FILEMON_${USE_FILEMON:tu} 35 36 . if ${USE_FILEMON} == "dev" 37 FILEMON_H?= /usr/include/dev/filemon/filemon.h 38 . if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h" 39 COPTS.filemon_dev.c+= \ 40 -DHAVE_FILEMON_H -I${FILEMON_H:H} 41 . endif 42 . endif 43 . endif 44 .endif 45 46 SUBDIR.roff+= PSD.doc 47 .if make(obj) || make(clean) 48 SUBDIR+= unit-tests 49 .endif 50 51 ${SRCS:M*.c:.c=.o}: buf.h config.h dir.h hash.h job.h lst.h make.h make_malloc.h 52 ${SRCS:M*.c:.c=.o}: meta.h metachar.h nonints.h pathnames.h sprite.h strlist.h trace.h 53 54 .include <bsd.prog.mk> 55 .include <bsd.subdir.mk> 56 57 CPPFLAGS+= -DMAKE_NATIVE 58 COPTS.var.c+= -Wno-cast-qual 59 COPTS.job.c+= -Wno-format-nonliteral 60 COPTS.parse.c+= -Wno-format-nonliteral 61 COPTS.var.c+= -Wno-format-nonliteral 62 63 .if defined(TOOLDIR) 64 # This is a native NetBSD build, use libutil rather than the local emalloc etc. 65 CPPFLAGS+= -DUSE_EMALLOC 66 LDADD+= -lutil 67 DPADD+= ${LIBUTIL} 68 .endif 69 70 COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION} 71 COPTS.dir.c+= ${GCC_NO_FORMAT_TRUNCATION} 72 COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION} 73 COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION} 74 COPTS.parse.c+= ${GCC_NO_FORMAT_TRUNCATION} 75 76 # A simple unit-test driver to help catch regressions 77 test: .MAKE 78 cd ${.CURDIR}/unit-tests \ 79 && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET} 80 .if ${USE_COVERAGE} == yes 81 gcov ${SRCS} 82 sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov 83 .endif 84 85 accept: .MAKE 86 cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET} 87 88 retest: 89 ${.MAKE} -C ${.CURDIR}/unit-tests cleandir 90 .if ${USE_COVERAGE} == yes 91 rm -f *.gcov *.gcda 92 .endif 93 ${.MAKE} test 94