Home | History | Annotate | Line # | Download | only in unit-tests
archive.mk revision 1.9
      1 # $NetBSD: archive.mk,v 1.9 2020/10/08 18:37:26 rillig 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 is more complicated and detailed than
      8 # strictly necessary.
      9 
     10 ARCHIVE=	libprog.a
     11 FILES=		archive.mk modmisc.mk varmisc.mk
     12 
     13 MAKE_CMD=	${.MAKE} -f ${MAKEFILE}
     14 RUN?=		@set -eu;
     15 
     16 all:
     17 .if ${.PARSEDIR:tA} != ${.CURDIR:tA}
     18 	@cd ${MAKEFILE:H} && cp ${FILES} [at]*.mk ${.CURDIR}
     19 .endif
     20 # The following targets create and remove files.  The filesystem cache in
     21 # dir.c would probably not handle this correctly, therefore each of the
     22 # targets is run in its separate sub-make.
     23 	${RUN} ${MAKE_CMD} remove-archive
     24 	${RUN} ${MAKE_CMD} create-archive
     25 	${RUN} ${MAKE_CMD} list-archive
     26 	${RUN} ${MAKE_CMD} list-archive-wildcard
     27 	${RUN} ${MAKE_CMD} depend-on-existing-member
     28 	${RUN} ${MAKE_CMD} depend-on-nonexistent-member
     29 	${RUN} ${MAKE_CMD} remove-archive
     30 
     31 create-archive: ${ARCHIVE} pre post
     32 
     33 # The indirect references with the $$ cover the code in Arch_ParseArchive
     34 # that calls Var_Parse.  It's an esoteric scenario since at the point where
     35 # Arch_ParseArchive is called, the dependency line is already fully expanded.
     36 #
     37 ${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
     38 	ar cru ${.TARGET} ${.OODATE}
     39 	ranlib ${.TARGET}
     40 
     41 list-archive: ${ARCHIVE} pre post
     42 	ar t ${.ALLSRC}
     43 
     44 # XXX: I had expected that this dependency would select all *.mk files from
     45 # the archive.  Instead, the globbing is done in the current directory.
     46 # To prevent an overly long file list, the pattern is restricted to [at]*.mk.
     47 list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
     48 	${RUN} printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
     49 
     50 depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
     51 	${RUN} echo $@
     52 
     53 depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
     54 	${RUN} echo $@
     55 
     56 remove-archive: pre post
     57 	rm -f ${ARCHIVE}
     58 
     59 pre: .USEBEFORE
     60 	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE}
     61 post: .USE
     62 	@echo
     63