aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/archive.mk
blob: 2cd43a99e9adf66155e1e6dabc6c42b09882a314 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# $NetBSD: archive.mk,v 1.12 2021/04/09 14:42:00 christos Exp $
#
# Very basic demonstration of handling archives, based on the description
# in PSD.doc/tutorial.ms.
#
# This test aims at covering the code, not at being an introduction to
# archive handling. That's why it deviates from the tutorial style of
# several other tests.

ARCHIVE=	libprog.a
FILES=		archive.mk archive-suffix.mk modmisc.mk ternary.mk varmisc.mk

all:
.if ${.PARSEDIR:tA} != ${.CURDIR:tA}
	@cd ${MAKEFILE:H} && cp ${FILES} ${.CURDIR}
.endif
# The following targets create and remove files.  The filesystem cache in
# dir.c would probably not handle this correctly, therefore each of the
# targets is run in its separate sub-make.
	@${MAKE} -f ${MAKEFILE} remove-archive
	@${MAKE} -f ${MAKEFILE} create-archive
	@${MAKE} -f ${MAKEFILE} list-archive
	@${MAKE} -f ${MAKEFILE} list-archive-wildcard
	@${MAKE} -f ${MAKEFILE} depend-on-existing-member
	@${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member
	@${MAKE} -f ${MAKEFILE} remove-archive

create-archive: ${ARCHIVE} pre post

# The indirect references with the $$ cover the code in Arch_ParseArchive
# that calls Var_Parse.  It's an esoteric scenario since at the point where
# Arch_ParseArchive is called, the dependency line is already fully expanded.
#
${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
	ar cru ${.TARGET} ${.OODATE:O}
	ranlib ${.TARGET}

list-archive: ${ARCHIVE} pre post
	ar t ${.ALLSRC}

# XXX: I had expected that this dependency would select all *.mk files from
# the archive.  Instead, the globbing is done in the current directory.
#
# To prevent an overly long file list, the pattern is restricted to [at]*.mk.
list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
	@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}

depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
	@echo $@

depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
	@echo $@

remove-archive: pre post
	rm -f ${ARCHIVE}

pre: .USEBEFORE
	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
post: .USE
	@echo