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 5TMPBASE?= ${TMPDIR:U/tmp/uid${.MAKE.UID}}/cmdline 6SUB1= a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45 # just a random UUID 7SUB2= 6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5 # just a random UUID 8MAKE_CMD= env TMPBASE=${TMPBASE}/${SUB1} ${.MAKE} -f ${MAKEFILE} -r 9DIR2= ${TMPBASE}/${SUB2} 10DIR12= ${TMPBASE}/${SUB1}/${SUB2} 11 12all: prepare-dirs 13all: makeobjdir-direct makeobjdir-indirect 14all: space-and-comment 15all: cleanup 16 17prepare-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. 23makeobjdir-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. 33makeobjdir-indirect: 34 @echo $@: 35 @${MAKE_CMD} MAKEOBJDIR='$${TMPBASE}/$${SUB2}' show-objdir 36 37show-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. 50space-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 61cleanup: 62 @rm -rf ${TMPBASE} 63