Home | History | Annotate | Line # | Download | only in unit-tests
cmdline.mk revision 1.5.2.1
      1  1.5.2.1  perseant # $NetBSD: cmdline.mk,v 1.5.2.1 2025/08/02 05:58:30 perseant Exp $
      2      1.1    rillig #
      3      1.1    rillig # Tests for command line parsing and related special variables.
      4      1.1    rillig 
      5  1.5.2.1  perseant TMPBASE?=	${TMPDIR:U/tmp/uid${.MAKE.UID}}/cmdline
      6      1.1    rillig SUB1=		a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45	# just a random UUID
      7      1.1    rillig SUB2=		6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5	# just a random UUID
      8      1.1    rillig MAKE_CMD=	env TMPBASE=${TMPBASE}/${SUB1} ${.MAKE} -f ${MAKEFILE} -r
      9      1.1    rillig DIR2=		${TMPBASE}/${SUB2}
     10      1.1    rillig DIR12=		${TMPBASE}/${SUB1}/${SUB2}
     11      1.1    rillig 
     12      1.1    rillig all: prepare-dirs
     13      1.1    rillig all: makeobjdir-direct makeobjdir-indirect
     14      1.4    rillig all: space-and-comment
     15  1.5.2.1  perseant all: cleanup
     16      1.1    rillig 
     17      1.1    rillig prepare-dirs:
     18      1.2    rillig 	@rm -rf ${DIR2} ${DIR12}
     19      1.2    rillig 	@mkdir -p ${DIR2} ${DIR12}
     20      1.1    rillig 
     21      1.1    rillig # The .OBJDIR can be set via the MAKEOBJDIR command line variable.
     22      1.1    rillig # It must be a command line variable; an environment variable would not work.
     23      1.1    rillig makeobjdir-direct:
     24      1.1    rillig 	@echo $@:
     25      1.2    rillig 	@${MAKE_CMD} MAKEOBJDIR=${DIR2} show-objdir
     26      1.1    rillig 
     27      1.1    rillig # The .OBJDIR can be set via the MAKEOBJDIR command line variable,
     28      1.5    rillig # and expressions based on that variable can contain the usual modifiers.
     29      1.1    rillig # Since the .OBJDIR=MAKEOBJDIR assignment happens very early,
     30      1.1    rillig # the SUB2 variable in the modifier is not defined yet and is therefore empty.
     31      1.1    rillig # The SUB1 in the resulting path comes from the environment variable TMPBASE,
     32      1.1    rillig # see MAKE_CMD.
     33      1.1    rillig makeobjdir-indirect:
     34      1.1    rillig 	@echo $@:
     35      1.2    rillig 	@${MAKE_CMD} MAKEOBJDIR='$${TMPBASE}/$${SUB2}' show-objdir
     36      1.1    rillig 
     37      1.1    rillig show-objdir:
     38      1.1    rillig 	@echo $@: ${.OBJDIR:Q}
     39      1.4    rillig 
     40      1.4    rillig 
     41      1.4    rillig # Variable assignments in the command line are handled differently from
     42      1.4    rillig # variable assignments in makefiles.  In the command line, trailing whitespace
     43      1.4    rillig # is preserved, and the '#' does not start a comment.  This is because the
     44      1.4    rillig # low-level parsing from ParseRawLine does not take place.
     45      1.4    rillig #
     46      1.4    rillig # Preserving '#' and trailing whitespace has the benefit that when passing
     47      1.4    rillig # such values to sub-makes via MAKEFLAGS, no special encoding is needed.
     48      1.4    rillig # Leading whitespace in the variable value is discarded though, which makes
     49      1.4    rillig # the behavior inconsistent.
     50      1.4    rillig space-and-comment: .PHONY
     51      1.4    rillig 	@echo $@:
     52      1.4    rillig 
     53      1.4    rillig 	@env -i \
     54      1.4    rillig 	    ${MAKE} -r -f /dev/null ' VAR= value # no comment ' -v VAR \
     55      1.4    rillig 	| sed 's,$$,$$,'
     56      1.4    rillig 
     57      1.4    rillig 	@env -i MAKEFLAGS="' VAR= value # no comment '" \
     58      1.4    rillig 	    ${MAKE} -r -f /dev/null -v VAR \
     59      1.4    rillig 	| sed 's,$$,$$,'
     60  1.5.2.1  perseant 
     61  1.5.2.1  perseant cleanup:
     62  1.5.2.1  perseant 	@rm -rf ${TMPBASE}
     63