xref: /freebsd/contrib/bmake/unit-tests/archive.mk (revision 96474d2a3fa895fb9636183403fc8ca7ccf60216)
1# $NetBSD: archive.mk,v 1.5 2020/08/23 17:51:24 rillig Exp $
2#
3# Very basic demonstration of handling archives, based on the description
4# in PSD.doc/tutorial.ms.
5
6ARCHIVE=	libprog.${EXT.a}
7FILES=		archive.${EXT.mk} modmisc.${EXT.mk} varmisc.mk
8
9EXT.a=		a
10EXT.mk=		mk
11
12MAKE_CMD=	${.MAKE} -f ${MAKEFILE}
13RUN?=		@set -eu;
14
15all:
16	${RUN} ${MAKE_CMD} remove-archive
17	${RUN} ${MAKE_CMD} create-archive
18	${RUN} ${MAKE_CMD} list-archive
19	${RUN} ${MAKE_CMD} list-archive-wildcard
20	${RUN} ${MAKE_CMD} depend-on-existing-member
21	${RUN} ${MAKE_CMD} depend-on-nonexistent-member
22	${RUN} ${MAKE_CMD} remove-archive
23
24create-archive: ${ARCHIVE}
25${ARCHIVE}: ${ARCHIVE}(${FILES})
26	ar cru ${.TARGET} ${.OODATE}
27	ranlib ${.TARGET}
28
29list-archive: ${ARCHIVE}
30	ar t ${.ALLSRC}
31
32# XXX: I had expected that this dependency would select all *.mk files from
33# the archive.  Instead, the globbing is done in the current directory.
34# To prevent an overly long file list, the pattern is restricted to [at]*.mk.
35list-archive-wildcard: ${ARCHIVE}([at]*.mk)
36	${RUN} printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
37
38depend-on-existing-member: ${ARCHIVE}(archive.mk)
39	${RUN} echo $@
40
41depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk)
42	${RUN} echo $@
43
44remove-archive:
45	rm -f ${ARCHIVE}
46