1207614Simp# $NetBSD: cmdline.mk,v 1.5 2024/04/23 22:51:28 rillig Exp $ 2207614Simp# 3207614Simp# Tests for command line parsing and related special variables. 4207614Simp 5207614SimpTMPBASE?= ${TMPDIR:U/tmp/uid${.MAKE.UID}} 6207614SimpSUB1= a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45 # just a random UUID 7207614SimpSUB2= 6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5 # just a random UUID 8207614SimpMAKE_CMD= env TMPBASE=${TMPBASE}/${SUB1} ${.MAKE} -f ${MAKEFILE} -r 9207614SimpDIR2= ${TMPBASE}/${SUB2} 10207614SimpDIR12= ${TMPBASE}/${SUB1}/${SUB2} 11207614Simp 12207614Simpall: prepare-dirs 13207614Simpall: makeobjdir-direct makeobjdir-indirect 14207614Simpall: space-and-comment 15207614Simp 16207614Simpprepare-dirs: 17207614Simp @rm -rf ${DIR2} ${DIR12} 18207614Simp @mkdir -p ${DIR2} ${DIR12} 19207614Simp 20207614Simp# The .OBJDIR can be set via the MAKEOBJDIR command line variable. 21207614Simp# It must be a command line variable; an environment variable would not work. 22207614Simpmakeobjdir-direct: 23207614Simp @echo $@: 24207614Simp @${MAKE_CMD} MAKEOBJDIR=${DIR2} show-objdir 25207614Simp 26207614Simp# The .OBJDIR can be set via the MAKEOBJDIR command line variable, 27207614Simp# and expressions based on that variable can contain the usual modifiers. 28207614Simp# Since the .OBJDIR=MAKEOBJDIR assignment happens very early, 29207614Simp# the SUB2 variable in the modifier is not defined yet and is therefore empty. 30207614Simp# The SUB1 in the resulting path comes from the environment variable TMPBASE, 31207614Simp# see MAKE_CMD. 32207614Simpmakeobjdir-indirect: 33207614Simp @echo $@: 34207614Simp @${MAKE_CMD} MAKEOBJDIR='$${TMPBASE}/$${SUB2}' show-objdir 35207614Simp 36207614Simpshow-objdir: 37207614Simp @echo $@: ${.OBJDIR:Q} 38207614Simp 39207614Simp 40207614Simp# Variable assignments in the command line are handled differently from 41207614Simp# variable assignments in makefiles. In the command line, trailing whitespace 42207614Simp# is preserved, and the '#' does not start a comment. This is because the 43207614Simp# low-level parsing from ParseRawLine does not take place. 44207614Simp# 45207614Simp# Preserving '#' and trailing whitespace has the benefit that when passing 46207614Simp# such values to sub-makes via MAKEFLAGS, no special encoding is needed. 47207614Simp# Leading whitespace in the variable value is discarded though, which makes 48207614Simp# the behavior inconsistent. 49207614Simpspace-and-comment: .PHONY 50207614Simp @echo $@: 51207614Simp 52207614Simp @env -i \ 53207614Simp ${MAKE} -r -f /dev/null ' VAR= value # no comment ' -v VAR \ 54207614Simp | sed 's,$$,$$,' 55207614Simp 56207614Simp @env -i MAKEFLAGS="' VAR= value # no comment '" \ 57207614Simp ${MAKE} -r -f /dev/null -v VAR \ 58207614Simp | sed 's,$$,$$,' 59207614Simp