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