Makefile revision 1.100
1#	$NetBSD: Makefile,v 1.100 2023/07/21 15:00:32 lukem Exp $
2
3.include <bsd.own.mk>
4
5PROG=		lint1
6SRCS=		cgram.y \
7		ckbool.c ckctype.c ckgetopt.c debug.c \
8		decl.c emit.c emit1.c err.c func.c init.c inittyp.c lex.c \
9		main1.c mem.c mem1.c oper.c scan.l tree.c tyname.c
10
11MAN=		lint.7
12YHEADER=
13#DBG=		-g
14#CPPFLAGS+=	-DYYDEBUG=1
15#YFLAGS+=	-v
16#LFLAGS+=	-d
17
18CWARNFLAGS.clang+=	-Wno-error=implicit-int-float-conversion
19LOBJS.${PROG}+=		${SRCS:M*.y:.y=.ln}
20LOBJS.${PROG}+=		${SRCS:M*.l:.l=.ln}
21LINTFLAGS.cgram.c+=	-X 351		# 'extern' declaration in .c file
22LINTFLAGS.scan.c+=	-X 107,126,330,331,332,333	# strict bool mode
23LINTFLAGS.scan.c+=	-X 192,214	# due to suppressed bool errors
24LINTFLAGS.scan.c+=	-X 307		# static variable unused
25LINTFLAGS.scan.c+=	-X 351		# 'extern' declaration in .c file
26
27CPPFLAGS+=	-DIS_LINT1
28CPPFLAGS+=	-I${.CURDIR} -I${.OBJDIR}
29CPPFLAGS+=	${DEBUG:D-DDEBUG -DYYDEBUG}
30CPPFLAGS+=	${DEBUG_MEM:D-DDEBUG_MEM}
31
32COPTS.err.c+=	${${ACTIVE_CC} == "clang":? -Wno-format-nonliteral :}
33
34BINDIR=		/usr/libexec
35
36CLEANFILES+=	${MAN} ${MAN}.date
37
38.if ${USETOOLS} == "yes"
39LINT1=		${TOOLDIR}/libexec/${MACHINE_GNU_PLATFORM}-lint1
40.endif
41LINT1?=		./${PROG}
42
43${MAN}.date:	err.c
44	${_MKTARGET_CREATE}
45	${TOOL_SED} -E \
46	    -e 's,.*(....)/([0-9]{2})/0?([0-9]+).*,\2 \3\, \1,' \
47	    -e 's,^01,January,' \
48	    -e 's,^02,February,' \
49	    -e 's,^03,March,' \
50	    -e 's,^04,April,' \
51	    -e 's,^05,May,' \
52	    -e 's,^06,June,' \
53	    -e 's,^07,July,' \
54	    -e 's,^08,August,' \
55	    -e 's,^09,September,' \
56	    -e 's,^10,October,' \
57	    -e 's,^11,November,' \
58	    -e 's,^12,December,' \
59	    -e 1q \
60	    ${.ALLSRC} > ${.TARGET}
61
62# Extra -UYYDEBUG for lint's strict bool mode, since cgram.c contains 'int
63# yydebug; if (yydebug)'.
64cgram.ln: cgram.c
65	${LINT} ${LINTFLAGS} ${LINTFLAGS.${.IMPSRC}} \
66	    ${CPPFLAGS:C/-([IDUW]) */-\1/Wg:M-[IDUW]*} \
67	    -i -UYYDEBUG ${.IMPSRC}
68
69${MAN}:		makeman err.c Makefile ${MAN}.date
70	${_MKTARGET_CREATE}
71	SED=${TOOL_SED:Q} ${HOST_SH} ${.ALLSRC:M*makeman} \
72	    "$$(cat ${.ALLSRC:M*.date})" ${.ALLSRC:M*err.c} \
73	    >${.TARGET}
74
75LDADD+=		-lm
76.ifndef HOSTPROG
77DPADD+=		${LIBM}
78
79LDADD+=		-ll
80DPADD+=		${LIBL}
81.endif
82
83err-msgs.h: err.c
84	${_MKTARGET_CREATE}
85	sp='[[:space:]]*'; \
86	from="^$$sp\(\"[^\"].*\"\)\,$$sp/\*$$sp\(Q*[0-9][0-9]*\)$$sp\*/\$$"; \
87	${TOOL_SED} -n -e "s,$$from,#define MSG_\2 \1,p" < ${.ALLSRC:M*err.c} > ${.TARGET}.tmp
88	mv -f ${.TARGET}.tmp ${.TARGET}
89
90CLEANFILES+=	err-msgs.h
91DPSRCS+=	err-msgs.h
92CPPFLAGS+=	-I.
93
94externs1.h: err-msgs.h
95${SRCS:Nerr.c}: err-msgs.h
96
97add-test: .PHONY
98	@set -eu; \
99	test=${NAME:Q}; \
100	[ "$$test" ] || { \
101		echo "usage: ${MAKE} add-test NAME=<name>"; \
102		exit; \
103	}; \
104	\
105	cd '../../../tests/usr.bin/xlint/lint1'; \
106	if [ -f "$$test.c" ]; then \
107		echo "error: test $$test already exists in $$PWD."; \
108		exit 1; \
109	fi; \
110	\
111	echo "=> Adding test $$test"; \
112	printf '%s\n' \
113		'/*	$$''NetBSD$$	*/' \
114		"# 3 \"$$test.c\"" \
115		'' \
116		'/*' \
117		' * TODO: Explain the purpose of the test.' \
118		' */' \
119		'' \
120		'/* lint1-extra-flags: -Z */' \
121		'/* lint1-flags: -Z */' \
122		'/* lint1-only-if: schar uchar ilp32 lp64 int long */' \
123		'/* lint1-skip-if: ldbl64 ldbl96 ldbl128 */' \
124		'' \
125		'// TODO: Add some code that passes.' \
126		'// TODO: Add some code that fails.' \
127	> "$$test.c"; \
128	cvs add "$$test.c"; \
129	${MAKE} sync-mi
130
131.include <bsd.prog.mk>
132