1# $NetBSD: archive.mk,v 1.12 2021/04/09 14:42:00 christos Exp $ 2# 3# Very basic demonstration of handling archives, based on the description 4# in PSD.doc/tutorial.ms. 5# 6# This test aims at covering the code, not at being an introduction to 7# archive handling. That's why it deviates from the tutorial style of 8# several other tests. 9 10ARCHIVE= libprog.a 11FILES= archive.mk archive-suffix.mk modmisc.mk ternary.mk varmisc.mk 12 13all: 14.if ${.PARSEDIR:tA} != ${.CURDIR:tA} 15 @cd ${MAKEFILE:H} && cp ${FILES} ${.CURDIR} 16.endif 17# The following targets create and remove files. The filesystem cache in 18# dir.c would probably not handle this correctly, therefore each of the 19# targets is run in its separate sub-make. 20 @${MAKE} -f ${MAKEFILE} remove-archive 21 @${MAKE} -f ${MAKEFILE} create-archive 22 @${MAKE} -f ${MAKEFILE} list-archive 23 @${MAKE} -f ${MAKEFILE} list-archive-wildcard 24 @${MAKE} -f ${MAKEFILE} depend-on-existing-member 25 @${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member 26 @${MAKE} -f ${MAKEFILE} remove-archive 27 28create-archive: ${ARCHIVE} pre post 29 30# The indirect references with the $$ cover the code in Arch_ParseArchive 31# that calls Var_Parse. It's an esoteric scenario since at the point where 32# Arch_ParseArchive is called, the dependency line is already fully expanded. 33# 34${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post 35 ar cru ${.TARGET} ${.OODATE:O} 36 ranlib ${.TARGET} 37 38list-archive: ${ARCHIVE} pre post 39 ar t ${.ALLSRC} 40 41# XXX: I had expected that this dependency would select all *.mk files from 42# the archive. Instead, the globbing is done in the current directory. 43# 44# To prevent an overly long file list, the pattern is restricted to [at]*.mk. 45list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post 46 @printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@} 47 48depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post 49 @echo $@ 50 51depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post 52 @echo $@ 53 54remove-archive: pre post 55 rm -f ${ARCHIVE} 56 57pre: .USEBEFORE 58 @echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O} 59post: .USE 60 @echo 61