Home | History | Annotate | Line # | Download | only in unit-tests
archive.mk revision 1.13.2.1
      1  1.13.2.1  perseant # $NetBSD: archive.mk,v 1.13.2.1 2025/08/02 05:58:30 perseant 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.13.2.1  perseant 	@${MAKE} -f ${MAKEFILE} list-archive-undef-archive || echo "exit $$?"
     25  1.13.2.1  perseant 	@echo
     26  1.13.2.1  perseant 	@${MAKE} -f ${MAKEFILE} list-archive-undef-member || echo "exit $$?"
     27  1.13.2.1  perseant 	@echo
     28      1.11    rillig 	@${MAKE} -f ${MAKEFILE} depend-on-existing-member
     29      1.11    rillig 	@${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member
     30      1.11    rillig 	@${MAKE} -f ${MAKEFILE} remove-archive
     31      1.13    rillig 	@${MAKE} -f ${MAKEFILE} set-up-library
     32      1.13    rillig 	@${MAKE} -f ${MAKEFILE} -dm library 2>&1 \
     33      1.13    rillig 	| sed -n '/^Examining/p' \
     34      1.13    rillig 	| sed 's,\.\.\.modified[^.]*,,'
     35      1.13    rillig 	@${MAKE} -f ${MAKEFILE} tear-down-library
     36      1.13    rillig 
     37       1.1    rillig 
     38       1.9    rillig create-archive: ${ARCHIVE} pre post
     39       1.7    rillig 
     40       1.7    rillig # The indirect references with the $$ cover the code in Arch_ParseArchive
     41       1.7    rillig # that calls Var_Parse.  It's an esoteric scenario since at the point where
     42       1.7    rillig # Arch_ParseArchive is called, the dependency line is already fully expanded.
     43       1.7    rillig #
     44       1.9    rillig ${ARCHIVE}: $${:Ulibprog.a}(archive.mk modmisc.mk $${:Uvarmisc.mk}) pre post
     45      1.10    rillig 	ar cru ${.TARGET} ${.OODATE:O}
     46       1.1    rillig 	ranlib ${.TARGET}
     47       1.1    rillig 
     48       1.9    rillig list-archive: ${ARCHIVE} pre post
     49       1.1    rillig 	ar t ${.ALLSRC}
     50       1.1    rillig 
     51       1.4    rillig # XXX: I had expected that this dependency would select all *.mk files from
     52       1.4    rillig # the archive.  Instead, the globbing is done in the current directory.
     53      1.11    rillig #
     54       1.5    rillig # To prevent an overly long file list, the pattern is restricted to [at]*.mk.
     55       1.9    rillig list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
     56      1.11    rillig 	@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
     57       1.4    rillig 
     58  1.13.2.1  perseant .if make(list-archive-undef-archive)
     59  1.13.2.1  perseant # TODO: Be more specific: mention that the variable "UNDEF" is not defined.
     60  1.13.2.1  perseant # expect+1: Error in source archive spec "libprog.a${UNDEF}(archive.mk) pre post"
     61  1.13.2.1  perseant list-archive-undef-archive: ${ARCHIVE}$${UNDEF}(archive.mk) pre post
     62  1.13.2.1  perseant 	@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
     63  1.13.2.1  perseant .endif
     64  1.13.2.1  perseant 
     65  1.13.2.1  perseant .if make(list-archive-undef-member)
     66  1.13.2.1  perseant # TODO: Be more specific: mention that the variable "UNDEF" is not defined.
     67  1.13.2.1  perseant # expect+1: Error in source archive spec "libprog.a"
     68  1.13.2.1  perseant list-archive-undef-member: ${ARCHIVE}(archive$${UNDEF}.mk) pre post
     69  1.13.2.1  perseant 	@printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
     70  1.13.2.1  perseant .endif
     71  1.13.2.1  perseant 
     72       1.9    rillig depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
     73      1.11    rillig 	@echo $@
     74       1.1    rillig 
     75       1.9    rillig depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
     76      1.11    rillig 	@echo $@
     77       1.1    rillig 
     78       1.9    rillig remove-archive: pre post
     79       1.3    rillig 	rm -f ${ARCHIVE}
     80       1.9    rillig 
     81       1.9    rillig pre: .USEBEFORE
     82      1.10    rillig 	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
     83       1.9    rillig post: .USE
     84       1.9    rillig 	@echo
     85      1.13    rillig 
     86      1.13    rillig 
     87      1.13    rillig set-up-library: .PHONY
     88      1.13    rillig 	@echo "member" > member.txt
     89      1.13    rillig 	@echo "not a library" > libbad.a
     90      1.13    rillig 	@ar cr libgood.a member.txt
     91      1.13    rillig 	@echo "begin library"
     92      1.13    rillig 
     93      1.13    rillig .if make(library)
     94      1.13    rillig .SUFFIXES: .a
     95      1.13    rillig .LIBS: .a
     96      1.13    rillig .endif
     97      1.13    rillig # The two lines for libgood contain the word "library", the two lines for
     98      1.13    rillig # libbad don't.
     99      1.13    rillig #
    100      1.13    rillig # expect: Examining libbad.a...up-to-date.
    101      1.13    rillig # expect: Examining -lbad...up-to-date.
    102      1.13    rillig # expect: Examining libgood.a...library...up-to-date.
    103      1.13    rillig # expect: Examining -lgood...library...up-to-date.
    104      1.13    rillig library: .PHONY libbad.a -lbad libgood.a -lgood
    105      1.13    rillig 	: Making ${.TARGET} from ${.ALLSRC}
    106      1.13    rillig 
    107      1.13    rillig tear-down-library: .PHONY
    108      1.13    rillig 	@echo "end library"
    109      1.13    rillig 	@rm member.txt libbad.a libgood.a
    110