2021-06-25 18:16:24 +00:00
|
|
|
# $NetBSD: archive.mk,v 1.12 2021/04/09 14:42:00 christos Exp $
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
|
|
|
# Very basic demonstration of handling archives, based on the description
|
|
|
|
# in PSD.doc/tutorial.ms.
|
2020-11-07 19:39:21 +00:00
|
|
|
#
|
|
|
|
# This test aims at covering the code, not at being an introduction to
|
2020-11-20 03:54:37 +00:00
|
|
|
# archive handling. That's why it deviates from the tutorial style of
|
|
|
|
# several other tests.
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
ARCHIVE= libprog.a
|
2021-06-25 18:16:24 +00:00
|
|
|
FILES= archive.mk archive-suffix.mk modmisc.mk ternary.mk varmisc.mk
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
all:
|
2020-11-07 19:39:21 +00:00
|
|
|
.if ${.PARSEDIR:tA} != ${.CURDIR:tA}
|
2021-06-25 18:16:24 +00:00
|
|
|
@cd ${MAKEFILE:H} && cp ${FILES} ${.CURDIR}
|
2020-11-07 19:39:21 +00:00
|
|
|
.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.
|
2020-11-20 03:54:37 +00:00
|
|
|
@${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
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
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}
|
2020-09-05 16:11:04 +00:00
|
|
|
ranlib ${.TARGET}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
list-archive: ${ARCHIVE} pre post
|
2020-09-05 16:11:04 +00:00
|
|
|
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.
|
2020-11-20 03:54:37 +00:00
|
|
|
#
|
2020-09-05 16:11:04 +00:00
|
|
|
# To prevent an overly long file list, the pattern is restricted to [at]*.mk.
|
2020-11-07 19:39:21 +00:00
|
|
|
list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
|
2020-11-20 03:54:37 +00:00
|
|
|
@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
|
2020-11-20 03:54:37 +00:00
|
|
|
@echo $@
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
|
2020-11-20 03:54:37 +00:00
|
|
|
@echo $@
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
remove-archive: pre post
|
2020-09-05 16:11:04 +00:00
|
|
|
rm -f ${ARCHIVE}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
pre: .USEBEFORE
|
|
|
|
@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
|
|
|
|
post: .USE
|
|
|
|
@echo
|