Home | History | Annotate | Line # | Download | only in unit-tests
archive.mk revision 1.13
      1  1.13    rillig # $NetBSD: archive.mk,v 1.13 2024/04/27 20:23:22 rillig Exp $
      2   1.1    rillig #
      3   1.1    rillig # Very basic demonstration of handling archives, based on the description
      4   1.1    rillig # in PSD.doc/tutorial.ms.
      5   1.7    rillig #
      6   1.7    rillig # This test aims at covering the code, not at being an introduction to
      7  1.11    rillig # archive handling. That's why it deviates from the tutorial style of
      8  1.11    rillig # several other tests.
      9   1.1    rillig 
     10   1.7    rillig ARCHIVE=	libprog.a
     11  1.12  christos FILES=		archive.mk archive-suffix.mk modmisc.mk ternary.mk varmisc.mk
     12   1.1    rillig 
     13   1.1    rillig all:
     14   1.6    rillig .if ${.PARSEDIR:tA} != ${.CURDIR:tA}
     15  1.12  christos 	@cd ${MAKEFILE:H} && cp ${FILES} ${.CURDIR}
     16   1.6    rillig .endif
     17   1.9    rillig # The following targets create and remove files.  The filesystem cache in
     18   1.9    rillig # dir.c would probably not handle this correctly, therefore each of the
     19   1.9    rillig # targets is run in its separate sub-make.
     20  1.11    rillig 	@${MAKE} -f ${MAKEFILE} remove-archive
     21  1.11    rillig 	@${MAKE} -f ${MAKEFILE} create-archive
     22  1.11    rillig 	@${MAKE} -f ${MAKEFILE} list-archive
     23  1.11    rillig 	@${MAKE} -f ${MAKEFILE} list-archive-wildcard
     24  1.11    rillig 	@${MAKE} -f ${MAKEFILE} depend-on-existing-member
     25  1.11    rillig 	@${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member
     26  1.11    rillig 	@${MAKE} -f ${MAKEFILE} remove-archive
     27  1.13    rillig 	@${MAKE} -f ${MAKEFILE} set-up-library
     28  1.13    rillig 	@${MAKE} -f ${MAKEFILE} -dm library 2>&1 \
     29  1.13    rillig 	| sed -n '/^Examining/p' \
     30  1.13    rillig 	| sed 's,\.\.\.modified[^.]*,,'
     31  1.13    rillig 	@${MAKE} -f ${MAKEFILE} tear-down-library
     32  1.13    rillig 
     33   1.1    rillig 
     34   1.9    rillig create-archive: ${ARCHIVE} pre post
     35   1.7    rillig 
     36   1.7    rillig # The indirect references with the $$ cover the code in Arch_ParseArchive
     37   1.7    rillig # that calls Var_Parse.  It's an esoteric scenario since at the point where
     38   1.7    rillig # Arch_ParseArchive is called, the dependency line is already fully expanded.
     39   1.7    rillig #
     40   1.9    rillig ${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
     41  1.10    rillig 	ar cru ${.TARGET} ${.OODATE:O}
     42   1.1    rillig 	ranlib ${.TARGET}
     43   1.1    rillig 
     44   1.9    rillig list-archive: ${ARCHIVE} pre post
     45   1.1    rillig 	ar t ${.ALLSRC}
     46   1.1    rillig 
     47   1.4    rillig # XXX: I had expected that this dependency would select all *.mk files from
     48   1.4    rillig # the archive.  Instead, the globbing is done in the current directory.
     49  1.11    rillig #
     50   1.5    rillig # To prevent an overly long file list, the pattern is restricted to [at]*.mk.
     51   1.9    rillig list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
     52  1.11    rillig 	@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
     53   1.4    rillig 
     54   1.9    rillig depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
     55  1.11    rillig 	@echo $@
     56   1.1    rillig 
     57   1.9    rillig depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
     58  1.11    rillig 	@echo $@
     59   1.1    rillig 
     60   1.9    rillig remove-archive: pre post
     61   1.3    rillig 	rm -f ${ARCHIVE}
     62   1.9    rillig 
     63   1.9    rillig pre: .USEBEFORE
     64  1.10    rillig 	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
     65   1.9    rillig post: .USE
     66   1.9    rillig 	@echo
     67  1.13    rillig 
     68  1.13    rillig 
     69  1.13    rillig set-up-library: .PHONY
     70  1.13    rillig 	@echo "member" > member.txt
     71  1.13    rillig 	@echo "not a library" > libbad.a
     72  1.13    rillig 	@ar cr libgood.a member.txt
     73  1.13    rillig 	@echo "begin library"
     74  1.13    rillig 
     75  1.13    rillig .if make(library)
     76  1.13    rillig .SUFFIXES: .a
     77  1.13    rillig .LIBS: .a
     78  1.13    rillig .endif
     79  1.13    rillig # The two lines for libgood contain the word "library", the two lines for
     80  1.13    rillig # libbad don't.
     81  1.13    rillig #
     82  1.13    rillig # expect: Examining libbad.a...up-to-date.
     83  1.13    rillig # expect: Examining -lbad...up-to-date.
     84  1.13    rillig # expect: Examining libgood.a...library...up-to-date.
     85  1.13    rillig # expect: Examining -lgood...library...up-to-date.
     86  1.13    rillig library: .PHONY libbad.a -lbad libgood.a -lgood
     87  1.13    rillig 	: Making ${.TARGET} from ${.ALLSRC}
     88  1.13    rillig 
     89  1.13    rillig tear-down-library: .PHONY
     90  1.13    rillig 	@echo "end library"
     91  1.13    rillig 	@rm member.txt libbad.a libgood.a
     92