]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/archive.mk
Merge bmake-20201117
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / archive.mk
1 # $NetBSD: archive.mk,v 1.11 2020/11/15 14:07:53 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 deviates from the tutorial style of
8 # several other tests.
9
10 ARCHIVE=        libprog.a
11 FILES=          archive.mk modmisc.mk varmisc.mk
12
13 all:
14 .if ${.PARSEDIR:tA} != ${.CURDIR:tA}
15         @cd ${MAKEFILE:H} && cp ${FILES} [at]*.mk ${.CURDIR}
16 .endif
17 # The following targets create and remove files.  The filesystem cache in
18 # dir.c would probably not handle this correctly, therefore each of the
19 # targets is run in its separate sub-make.
20         @${MAKE} -f ${MAKEFILE} remove-archive
21         @${MAKE} -f ${MAKEFILE} create-archive
22         @${MAKE} -f ${MAKEFILE} list-archive
23         @${MAKE} -f ${MAKEFILE} list-archive-wildcard
24         @${MAKE} -f ${MAKEFILE} depend-on-existing-member
25         @${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member
26         @${MAKE} -f ${MAKEFILE} remove-archive
27
28 create-archive: ${ARCHIVE} pre post
29
30 # The indirect references with the $$ cover the code in Arch_ParseArchive
31 # that calls Var_Parse.  It's an esoteric scenario since at the point where
32 # Arch_ParseArchive is called, the dependency line is already fully expanded.
33 #
34 ${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
35         ar cru ${.TARGET} ${.OODATE:O}
36         ranlib ${.TARGET}
37
38 list-archive: ${ARCHIVE} pre post
39         ar t ${.ALLSRC}
40
41 # XXX: I had expected that this dependency would select all *.mk files from
42 # the archive.  Instead, the globbing is done in the current directory.
43 #
44 # To prevent an overly long file list, the pattern is restricted to [at]*.mk.
45 list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
46         @printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
47
48 depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
49         @echo $@
50
51 depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
52         @echo $@
53
54 remove-archive: pre post
55         rm -f ${ARCHIVE}
56
57 pre: .USEBEFORE
58         @echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
59 post: .USE
60         @echo