archive.mk revision 1.7 1 # $NetBSD: archive.mk,v 1.7 2020/09/05 06:20:51 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
10 ARCHIVE= libprog.a
11 FILES= archive.mk modmisc.mk varmisc.mk
12
13 MAKE_CMD= ${.MAKE} -f ${MAKEFILE}
14 RUN?= @set -eu;
15
16 all:
17 .if ${.PARSEDIR:tA} != ${.CURDIR:tA}
18 @cd ${MAKEFILE:H} && cp ${FILES} t*.mk ${.CURDIR}
19 .endif
20 # The following targets are run in sub-makes to ensure that they get the
21 # current state of the filesystem right, since they creating and removing
22 # files.
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
31 create-archive: ${ARCHIVE}
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})
38 ar cru ${.TARGET} ${.OODATE}
39 ranlib ${.TARGET}
40
41 list-archive: ${ARCHIVE}
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.
47 list-archive-wildcard: ${ARCHIVE}([at]*.mk)
48 ${RUN} printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
49
50 depend-on-existing-member: ${ARCHIVE}(archive.mk)
51 ${RUN} echo $@
52
53 depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk)
54 ${RUN} echo $@
55
56 remove-archive:
57 rm -f ${ARCHIVE}
58