1 # $NetBSD: archive.mk,v 1.10 2020/10/09 06:44:42 rillig Exp $
3 # Very basic demonstration of handling archives, based on the description
4 # in PSD.doc/tutorial.ms.
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
11 FILES= archive.mk modmisc.mk varmisc.mk
13 MAKE_CMD= ${.MAKE} -f ${MAKEFILE}
17 .if ${.PARSEDIR:tA} != ${.CURDIR:tA}
18 @cd ${MAKEFILE:H} && cp ${FILES} [at]*.mk ${.CURDIR}
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
31 create-archive: ${ARCHIVE} pre post
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.
37 ${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
38 ar cru ${.TARGET} ${.OODATE:O}
41 list-archive: ${ARCHIVE} pre post
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.
47 list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
48 ${RUN} printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
50 depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
53 depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
56 remove-archive: pre post
60 @echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}