1 # $NetBSD: Makefile,v 1.85 2020/08/10 18:20:28 rillig Exp $ 2 # @(#)Makefile 5.2 (Berkeley) 12/28/90 3 4 PROG= make 5 SRCS= arch.c 6 SRCS+= buf.c 7 SRCS+= compat.c 8 SRCS+= cond.c 9 SRCS+= dir.c 10 SRCS+= enum.c 11 SRCS+= for.c 12 SRCS+= hash.c 13 SRCS+= job.c 14 SRCS+= lst.c 15 SRCS+= main.c 16 SRCS+= make.c 17 SRCS+= make_malloc.c 18 SRCS+= metachar.c 19 SRCS+= parse.c 20 SRCS+= str.c 21 SRCS+= strlist.c 22 SRCS+= suff.c 23 SRCS+= targ.c 24 SRCS+= trace.c 25 SRCS+= var.c 26 SRCS+= util.c 27 HDRS= buf.h 28 HDRS+= config.h 29 HDRS+= dir.h 30 HDRS+= enum.h 31 HDRS+= hash.h 32 HDRS+= job.h 33 HDRS+= lst.h 34 HDRS+= make.h 35 HDRS+= make_malloc.h 36 HDRS+= meta.h 37 HDRS+= metachar.h 38 HDRS+= nonints.h 39 HDRS+= pathnames.h 40 HDRS+= sprite.h 41 HDRS+= strlist.h 42 HDRS+= trace.h 43 44 # Whether to generate a coverage report after running the tests. 45 USE_COVERAGE?= no # works only with gcc; clang9 fails to link 46 .if ${USE_COVERAGE} == "yes" 47 COPTS+= --coverage -O0 -ggdb 48 LDADD+= --coverage 49 .endif 50 CLEANFILES+= *.gcda *.gcno *.gcov 51 52 # Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang). 53 USE_UBSAN?= no 54 .if ${USE_UBSAN} == "yes" 55 COPTS+= -fsanitize=undefined 56 LDADD+= -fsanitize=undefined 57 .endif 58 59 # Whether to compile with GCC 9 from pkgsrc, during development. 60 USE_GCC9?= no 61 .if ${USE_GCC9} == "yes" 62 # CC is set further down in this file 63 COPTS+= -Wno-attributes # for abs and labs 64 COPTS.arch.c+= -Wno-error=format-truncation 65 COPTS.dir.c+= -Wno-error=format-truncation 66 COPTS.main.c+= -Wno-error=format-truncation 67 COPTS.meta.c+= -Wno-error=format-truncation 68 COPTS.parse.c+= -Wno-error=format-truncation 69 .endif 70 71 USE_META?= yes 72 .if ${USE_META:tl} != "no" 73 74 SRCS+= meta.c 75 CPPFLAGS+= -DUSE_META 76 77 USE_FILEMON?= ktrace 78 . if ${USE_FILEMON:tl} != "no" 79 80 .PATH: ${.CURDIR}/filemon 81 SRCS+= filemon_${USE_FILEMON}.c 82 CPPFLAGS+= -DUSE_FILEMON 83 CPPFLAGS+= -DUSE_FILEMON_${USE_FILEMON:tu} 84 85 . if ${USE_FILEMON} == "dev" 86 FILEMON_H?= /usr/include/dev/filemon/filemon.h 87 . if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h" 88 COPTS.filemon_dev.c+= \ 89 -DHAVE_FILEMON_H -I${FILEMON_H:H} 90 . endif 91 . endif 92 . endif 93 .endif 94 95 SUBDIR.roff+= PSD.doc 96 .if make(obj) || make(clean) 97 SUBDIR+= unit-tests 98 .endif 99 100 ${SRCS:M*.c:.c=.o}: ${HDRS} 101 102 .include <bsd.prog.mk> 103 .include <bsd.subdir.mk> 104 105 CPPFLAGS+= -DMAKE_NATIVE 106 COPTS.var.c+= -Wno-cast-qual 107 COPTS.job.c+= -Wno-format-nonliteral 108 COPTS.parse.c+= -Wno-format-nonliteral 109 COPTS.var.c+= -Wno-format-nonliteral 110 111 .if ${USE_GCC9} == "yes" 112 CC= /usr/pkg/gcc9/bin/gcc 113 .endif 114 115 .if defined(TOOLDIR) 116 # This is a native NetBSD build, use libutil rather than the local emalloc etc. 117 CPPFLAGS+= -DUSE_EMALLOC 118 LDADD+= -lutil 119 DPADD+= ${LIBUTIL} 120 .endif 121 122 COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION} 123 COPTS.dir.c+= ${GCC_NO_FORMAT_TRUNCATION} 124 COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION} 125 COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION} 126 COPTS.parse.c+= ${GCC_NO_FORMAT_TRUNCATION} 127 128 COPTS+= -Wdeclaration-after-statement 129 130 # A simple unit-test driver to help catch regressions 131 test: .MAKE 132 cd ${.CURDIR}/unit-tests \ 133 && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET} 134 .if ${USE_COVERAGE} == yes 135 gcov ${SRCS} 136 sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov 137 .endif 138 139 accept: .MAKE 140 cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET} 141 142 retest: 143 ${.MAKE} -C ${.CURDIR}/unit-tests cleandir 144 .if ${USE_COVERAGE} == yes 145 rm -f *.gcov *.gcda 146 .endif 147 ${.MAKE} test 148