xref: /freebsd/contrib/bmake/unit-tests/archive.mk (revision b0c40a00)
1*b0c40a00SSimon J. Gerraty# $NetBSD: archive.mk,v 1.12 2021/04/09 14:42:00 christos Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Very basic demonstration of handling archives, based on the description
42c3632d1SSimon J. Gerraty# in PSD.doc/tutorial.ms.
5956e45f6SSimon J. Gerraty#
6956e45f6SSimon J. Gerraty# This test aims at covering the code, not at being an introduction to
7e2eeea75SSimon J. Gerraty# archive handling. That's why it deviates from the tutorial style of
8e2eeea75SSimon J. Gerraty# several other tests.
92c3632d1SSimon J. Gerraty
10956e45f6SSimon J. GerratyARCHIVE=	libprog.a
11*b0c40a00SSimon J. GerratyFILES=		archive.mk archive-suffix.mk modmisc.mk ternary.mk varmisc.mk
122c3632d1SSimon J. Gerraty
132c3632d1SSimon J. Gerratyall:
14956e45f6SSimon J. Gerraty.if ${.PARSEDIR:tA} != ${.CURDIR:tA}
15*b0c40a00SSimon J. Gerraty	@cd ${MAKEFILE:H} && cp ${FILES} ${.CURDIR}
16956e45f6SSimon J. Gerraty.endif
17956e45f6SSimon J. Gerraty# The following targets create and remove files.  The filesystem cache in
18956e45f6SSimon J. Gerraty# dir.c would probably not handle this correctly, therefore each of the
19956e45f6SSimon J. Gerraty# targets is run in its separate sub-make.
20e2eeea75SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} remove-archive
21e2eeea75SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} create-archive
22e2eeea75SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} list-archive
23e2eeea75SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} list-archive-wildcard
24e2eeea75SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} depend-on-existing-member
25e2eeea75SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member
26e2eeea75SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} remove-archive
272c3632d1SSimon J. Gerraty
28956e45f6SSimon J. Gerratycreate-archive: ${ARCHIVE} pre post
29956e45f6SSimon J. Gerraty
30956e45f6SSimon J. Gerraty# The indirect references with the $$ cover the code in Arch_ParseArchive
31956e45f6SSimon J. Gerraty# that calls Var_Parse.  It's an esoteric scenario since at the point where
32956e45f6SSimon J. Gerraty# Arch_ParseArchive is called, the dependency line is already fully expanded.
33956e45f6SSimon J. Gerraty#
34956e45f6SSimon J. Gerraty${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
35956e45f6SSimon J. Gerraty	ar cru ${.TARGET} ${.OODATE:O}
362c3632d1SSimon J. Gerraty	ranlib ${.TARGET}
372c3632d1SSimon J. Gerraty
38956e45f6SSimon J. Gerratylist-archive: ${ARCHIVE} pre post
392c3632d1SSimon J. Gerraty	ar t ${.ALLSRC}
402c3632d1SSimon J. Gerraty
412c3632d1SSimon J. Gerraty# XXX: I had expected that this dependency would select all *.mk files from
422c3632d1SSimon J. Gerraty# the archive.  Instead, the globbing is done in the current directory.
43e2eeea75SSimon J. Gerraty#
442c3632d1SSimon J. Gerraty# To prevent an overly long file list, the pattern is restricted to [at]*.mk.
45956e45f6SSimon J. Gerratylist-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
46e2eeea75SSimon J. Gerraty	@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
472c3632d1SSimon J. Gerraty
48956e45f6SSimon J. Gerratydepend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
49e2eeea75SSimon J. Gerraty	@echo $@
502c3632d1SSimon J. Gerraty
51956e45f6SSimon J. Gerratydepend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
52e2eeea75SSimon J. Gerraty	@echo $@
532c3632d1SSimon J. Gerraty
54956e45f6SSimon J. Gerratyremove-archive: pre post
552c3632d1SSimon J. Gerraty	rm -f ${ARCHIVE}
56956e45f6SSimon J. Gerraty
57956e45f6SSimon J. Gerratypre: .USEBEFORE
58956e45f6SSimon J. Gerraty	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
59956e45f6SSimon J. Gerratypost: .USE
60956e45f6SSimon J. Gerraty	@echo
61