1*956e45f6SSimon J. Gerraty# $NetBSD: archive.mk,v 1.10 2020/10/09 06:44:42 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. 5*956e45f6SSimon J. Gerraty# 6*956e45f6SSimon J. Gerraty# This test aims at covering the code, not at being an introduction to 7*956e45f6SSimon J. Gerraty# archive handling. That's why it is more complicated and detailed than 8*956e45f6SSimon J. Gerraty# strictly necessary. 92c3632d1SSimon J. Gerraty 10*956e45f6SSimon J. GerratyARCHIVE= libprog.a 11*956e45f6SSimon J. GerratyFILES= archive.mk modmisc.mk varmisc.mk 122c3632d1SSimon J. Gerraty 132c3632d1SSimon J. GerratyMAKE_CMD= ${.MAKE} -f ${MAKEFILE} 142c3632d1SSimon J. GerratyRUN?= @set -eu; 152c3632d1SSimon J. Gerraty 162c3632d1SSimon J. Gerratyall: 17*956e45f6SSimon J. Gerraty.if ${.PARSEDIR:tA} != ${.CURDIR:tA} 18*956e45f6SSimon J. Gerraty @cd ${MAKEFILE:H} && cp ${FILES} [at]*.mk ${.CURDIR} 19*956e45f6SSimon J. Gerraty.endif 20*956e45f6SSimon J. Gerraty# The following targets create and remove files. The filesystem cache in 21*956e45f6SSimon J. Gerraty# dir.c would probably not handle this correctly, therefore each of the 22*956e45f6SSimon J. Gerraty# targets is run in its separate sub-make. 232c3632d1SSimon J. Gerraty ${RUN} ${MAKE_CMD} remove-archive 242c3632d1SSimon J. Gerraty ${RUN} ${MAKE_CMD} create-archive 252c3632d1SSimon J. Gerraty ${RUN} ${MAKE_CMD} list-archive 262c3632d1SSimon J. Gerraty ${RUN} ${MAKE_CMD} list-archive-wildcard 272c3632d1SSimon J. Gerraty ${RUN} ${MAKE_CMD} depend-on-existing-member 282c3632d1SSimon J. Gerraty ${RUN} ${MAKE_CMD} depend-on-nonexistent-member 292c3632d1SSimon J. Gerraty ${RUN} ${MAKE_CMD} remove-archive 302c3632d1SSimon J. Gerraty 31*956e45f6SSimon J. Gerratycreate-archive: ${ARCHIVE} pre post 32*956e45f6SSimon J. Gerraty 33*956e45f6SSimon J. Gerraty# The indirect references with the $$ cover the code in Arch_ParseArchive 34*956e45f6SSimon J. Gerraty# that calls Var_Parse. It's an esoteric scenario since at the point where 35*956e45f6SSimon J. Gerraty# Arch_ParseArchive is called, the dependency line is already fully expanded. 36*956e45f6SSimon J. Gerraty# 37*956e45f6SSimon J. Gerraty${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post 38*956e45f6SSimon J. Gerraty ar cru ${.TARGET} ${.OODATE:O} 392c3632d1SSimon J. Gerraty ranlib ${.TARGET} 402c3632d1SSimon J. Gerraty 41*956e45f6SSimon J. Gerratylist-archive: ${ARCHIVE} pre post 422c3632d1SSimon J. Gerraty ar t ${.ALLSRC} 432c3632d1SSimon J. Gerraty 442c3632d1SSimon J. Gerraty# XXX: I had expected that this dependency would select all *.mk files from 452c3632d1SSimon J. Gerraty# the archive. Instead, the globbing is done in the current directory. 462c3632d1SSimon J. Gerraty# To prevent an overly long file list, the pattern is restricted to [at]*.mk. 47*956e45f6SSimon J. Gerratylist-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post 482c3632d1SSimon J. Gerraty ${RUN} printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@} 492c3632d1SSimon J. Gerraty 50*956e45f6SSimon J. Gerratydepend-on-existing-member: ${ARCHIVE}(archive.mk) pre post 512c3632d1SSimon J. Gerraty ${RUN} echo $@ 522c3632d1SSimon J. Gerraty 53*956e45f6SSimon J. Gerratydepend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post 542c3632d1SSimon J. Gerraty ${RUN} echo $@ 552c3632d1SSimon J. Gerraty 56*956e45f6SSimon J. Gerratyremove-archive: pre post 572c3632d1SSimon J. Gerraty rm -f ${ARCHIVE} 58*956e45f6SSimon J. Gerraty 59*956e45f6SSimon J. Gerratypre: .USEBEFORE 60*956e45f6SSimon J. Gerraty @echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O} 61*956e45f6SSimon J. Gerratypost: .USE 62*956e45f6SSimon J. Gerraty @echo 63