xref: /freebsd/contrib/bmake/unit-tests/archive.mk (revision 548bfc56)
1*548bfc56SSimon J. Gerraty# $NetBSD: archive.mk,v 1.13 2024/04/27 20:23:22 rillig 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
11b0c40a00SSimon 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}
15b0c40a00SSimon 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
27*548bfc56SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} set-up-library
28*548bfc56SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} -dm library 2>&1 \
29*548bfc56SSimon J. Gerraty	| sed -n '/^Examining/p' \
30*548bfc56SSimon J. Gerraty	| sed 's,\.\.\.modified[^.]*,,'
31*548bfc56SSimon J. Gerraty	@${MAKE} -f ${MAKEFILE} tear-down-library
32*548bfc56SSimon J. Gerraty
332c3632d1SSimon J. Gerraty
34956e45f6SSimon J. Gerratycreate-archive: ${ARCHIVE} pre post
35956e45f6SSimon J. Gerraty
36956e45f6SSimon J. Gerraty# The indirect references with the $$ cover the code in Arch_ParseArchive
37956e45f6SSimon J. Gerraty# that calls Var_Parse.  It's an esoteric scenario since at the point where
38956e45f6SSimon J. Gerraty# Arch_ParseArchive is called, the dependency line is already fully expanded.
39956e45f6SSimon J. Gerraty#
40956e45f6SSimon J. Gerraty${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
41956e45f6SSimon J. Gerraty	ar cru ${.TARGET} ${.OODATE:O}
422c3632d1SSimon J. Gerraty	ranlib ${.TARGET}
432c3632d1SSimon J. Gerraty
44956e45f6SSimon J. Gerratylist-archive: ${ARCHIVE} pre post
452c3632d1SSimon J. Gerraty	ar t ${.ALLSRC}
462c3632d1SSimon J. Gerraty
472c3632d1SSimon J. Gerraty# XXX: I had expected that this dependency would select all *.mk files from
482c3632d1SSimon J. Gerraty# the archive.  Instead, the globbing is done in the current directory.
49e2eeea75SSimon J. Gerraty#
502c3632d1SSimon J. Gerraty# To prevent an overly long file list, the pattern is restricted to [at]*.mk.
51956e45f6SSimon J. Gerratylist-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
52e2eeea75SSimon J. Gerraty	@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
532c3632d1SSimon J. Gerraty
54956e45f6SSimon J. Gerratydepend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
55e2eeea75SSimon J. Gerraty	@echo $@
562c3632d1SSimon J. Gerraty
57956e45f6SSimon J. Gerratydepend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
58e2eeea75SSimon J. Gerraty	@echo $@
592c3632d1SSimon J. Gerraty
60956e45f6SSimon J. Gerratyremove-archive: pre post
612c3632d1SSimon J. Gerraty	rm -f ${ARCHIVE}
62956e45f6SSimon J. Gerraty
63956e45f6SSimon J. Gerratypre: .USEBEFORE
64956e45f6SSimon J. Gerraty	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
65956e45f6SSimon J. Gerratypost: .USE
66956e45f6SSimon J. Gerraty	@echo
67*548bfc56SSimon J. Gerraty
68*548bfc56SSimon J. Gerraty
69*548bfc56SSimon J. Gerratyset-up-library: .PHONY
70*548bfc56SSimon J. Gerraty	@echo "member" > member.txt
71*548bfc56SSimon J. Gerraty	@echo "not a library" > libbad.a
72*548bfc56SSimon J. Gerraty	@ar cr libgood.a member.txt
73*548bfc56SSimon J. Gerraty	@echo "begin library"
74*548bfc56SSimon J. Gerraty
75*548bfc56SSimon J. Gerraty.if make(library)
76*548bfc56SSimon J. Gerraty.SUFFIXES: .a
77*548bfc56SSimon J. Gerraty.LIBS: .a
78*548bfc56SSimon J. Gerraty.endif
79*548bfc56SSimon J. Gerraty# The two lines for libgood contain the word "library", the two lines for
80*548bfc56SSimon J. Gerraty# libbad don't.
81*548bfc56SSimon J. Gerraty#
82*548bfc56SSimon J. Gerraty# expect: Examining libbad.a...up-to-date.
83*548bfc56SSimon J. Gerraty# expect: Examining -lbad...up-to-date.
84*548bfc56SSimon J. Gerraty# expect: Examining libgood.a...library...up-to-date.
85*548bfc56SSimon J. Gerraty# expect: Examining -lgood...library...up-to-date.
86*548bfc56SSimon J. Gerratylibrary: .PHONY libbad.a -lbad libgood.a -lgood
87*548bfc56SSimon J. Gerraty	: Making ${.TARGET} from ${.ALLSRC}
88*548bfc56SSimon J. Gerraty
89*548bfc56SSimon J. Gerratytear-down-library: .PHONY
90*548bfc56SSimon J. Gerraty	@echo "end library"
91*548bfc56SSimon J. Gerraty	@rm member.txt libbad.a libgood.a
92