xref: /freebsd/tools/build/test-includes/Makefile (revision d80ab37f9883cb981c9b359d50bbfe8f0d6f2884)
1#
2# A number of header files in sys/* have, going back to 7th Edition Unix in
3# 1979, reqiured other files (like sys/types.h) to compile. Likewise the 4BSD
4# networking code has had prerequisites. However, going back to around the turn
5# of the century, other systems have made them be independently includable
6# (wide-spread header include protection post-dates 7th edition Unix by maybe 4
7# or 5 years judging from netnews sources). Start down the path of making them
8# all independently includable by creating this test that fails buildworld when
9# they are not.
10#
11# The _foo.h files are excluded as they are internal-only headers and/or have
12# special requirements. Since the purpose of this is to allow autoconfig
13# programs to detect FreeBSD has different headers, omitting internal
14# headers cuts down on the noise w/o causing problems for the goal.
15#
16LIB=	test-includes
17INTERNALLIB=	This is a compile-only test
18MAN=
19HDRS!=	(cd ${SRCTOP}/sys; ls sys/[!_]*.h | sort ; ls net*/[!_]*.h | sort)
20NO_PIC=	yes
21
22# Some files have to be clean for extra defines too...
23CFLAGS.event.c=	-D_WANT_KEVENT32 -D_WANT_FREEBSD11_KEVENT
24
25# We currently support C89 and newer compilers. Catch the odd little fussy
26# details like __inline that the header files must follow to support C89.
27CFLAGS+=-ansi
28
29# Make sure we're pulling in headers from the src tree.
30CFLAGS+=-I${SRCTOP}/sys
31
32.include "badfiles.inc"
33
34.for h c in ${HDRS:@x@$x ${x:S,/,_,g:R}.c@}
35.if !${BADHDRS:M${h}}
36SRCS+= $c
37CLEANFILES+=$c
38$c:
39	echo "#include <$h>" > ${.TARGET}
40.endif
41.endfor
42
43test-includes: lib${LIB}.a .PHONY
44
45#
46# Target to make the current known bad list. In general, this list should only
47# ever shrink and never grow.
48#
49.PHONY:	badfiles.inc
50badfiles.inc:
51	@(cd ${SRCTOP}/sys;							\
52	echo "# DO NOT EDIT-- this file is automatically @""generated.";	\
53	echo "BADHDRS= \\";							\
54	for i in ${HDRS}; do						\
55		echo "#include <$$i>" |						\
56			${CC} ${CFLAGS} -xc - -c -o /dev/null 2> /dev/null ||	\
57			echo "	$$i \\";					\
58	done;									\
59	echo) > ${.CURDIR}/badfiles.inc
60
61.include <bsd.lib.mk>
62