xref: /freebsd/contrib/bmake/unit-tests/archive.mk (revision 36d6566e5985030fd2f1100bd9c1387bbe0bd290)
1# $NetBSD: archive.mk,v 1.10 2020/10/09 06:44:42 rillig Exp $
2#
3# Very basic demonstration of handling archives, based on the description
4# in PSD.doc/tutorial.ms.
5#
6# This test aims at covering the code, not at being an introduction to
7# archive handling. That's why it is more complicated and detailed than
8# strictly necessary.
9
10ARCHIVE=	libprog.a
11FILES=		archive.mk modmisc.mk varmisc.mk
12
13MAKE_CMD=	${.MAKE} -f ${MAKEFILE}
14RUN?=		@set -eu;
15
16all:
17.if ${.PARSEDIR:tA} != ${.CURDIR:tA}
18	@cd ${MAKEFILE:H} && cp ${FILES} [at]*.mk ${.CURDIR}
19.endif
20# The following targets create and remove files.  The filesystem cache in
21# dir.c would probably not handle this correctly, therefore each of the
22# targets is run in its separate sub-make.
23	${RUN} ${MAKE_CMD} remove-archive
24	${RUN} ${MAKE_CMD} create-archive
25	${RUN} ${MAKE_CMD} list-archive
26	${RUN} ${MAKE_CMD} list-archive-wildcard
27	${RUN} ${MAKE_CMD} depend-on-existing-member
28	${RUN} ${MAKE_CMD} depend-on-nonexistent-member
29	${RUN} ${MAKE_CMD} remove-archive
30
31create-archive: ${ARCHIVE} pre post
32
33# The indirect references with the $$ cover the code in Arch_ParseArchive
34# that calls Var_Parse.  It's an esoteric scenario since at the point where
35# Arch_ParseArchive is called, the dependency line is already fully expanded.
36#
37${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
38	ar cru ${.TARGET} ${.OODATE:O}
39	ranlib ${.TARGET}
40
41list-archive: ${ARCHIVE} pre post
42	ar t ${.ALLSRC}
43
44# XXX: I had expected that this dependency would select all *.mk files from
45# the archive.  Instead, the globbing is done in the current directory.
46# To prevent an overly long file list, the pattern is restricted to [at]*.mk.
47list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
48	${RUN} printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
49
50depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
51	${RUN} echo $@
52
53depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
54	${RUN} echo $@
55
56remove-archive: pre post
57	rm -f ${ARCHIVE}
58
59pre: .USEBEFORE
60	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
61post: .USE
62	@echo
63