xref: /freebsd/contrib/bmake/unit-tests/cmdline.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1*6a7405f5SSimon J. Gerraty# $NetBSD: cmdline.mk,v 1.7 2024/08/29 17:56:37 sjg Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for command line parsing and related special variables.
42c3632d1SSimon J. Gerraty
5*6a7405f5SSimon J. GerratyTMPBASE?=	${TMPDIR:U/tmp/uid${.MAKE.UID}}/cmdline
62c3632d1SSimon J. GerratySUB1=		a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45	# just a random UUID
72c3632d1SSimon J. GerratySUB2=		6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5	# just a random UUID
82c3632d1SSimon J. GerratyMAKE_CMD=	env TMPBASE=${TMPBASE}/${SUB1} ${.MAKE} -f ${MAKEFILE} -r
92c3632d1SSimon J. GerratyDIR2=		${TMPBASE}/${SUB2}
102c3632d1SSimon J. GerratyDIR12=		${TMPBASE}/${SUB1}/${SUB2}
112c3632d1SSimon J. Gerraty
122c3632d1SSimon J. Gerratyall: prepare-dirs
132c3632d1SSimon J. Gerratyall: makeobjdir-direct makeobjdir-indirect
14954401e6SSimon J. Gerratyall: space-and-comment
15*6a7405f5SSimon J. Gerratyall: cleanup
162c3632d1SSimon J. Gerraty
172c3632d1SSimon J. Gerratyprepare-dirs:
18e2eeea75SSimon J. Gerraty	@rm -rf ${DIR2} ${DIR12}
19e2eeea75SSimon J. Gerraty	@mkdir -p ${DIR2} ${DIR12}
202c3632d1SSimon J. Gerraty
212c3632d1SSimon J. Gerraty# The .OBJDIR can be set via the MAKEOBJDIR command line variable.
222c3632d1SSimon J. Gerraty# It must be a command line variable; an environment variable would not work.
232c3632d1SSimon J. Gerratymakeobjdir-direct:
242c3632d1SSimon J. Gerraty	@echo $@:
25e2eeea75SSimon J. Gerraty	@${MAKE_CMD} MAKEOBJDIR=${DIR2} show-objdir
262c3632d1SSimon J. Gerraty
272c3632d1SSimon J. Gerraty# The .OBJDIR can be set via the MAKEOBJDIR command line variable,
28548bfc56SSimon J. Gerraty# and expressions based on that variable can contain the usual modifiers.
292c3632d1SSimon J. Gerraty# Since the .OBJDIR=MAKEOBJDIR assignment happens very early,
302c3632d1SSimon J. Gerraty# the SUB2 variable in the modifier is not defined yet and is therefore empty.
312c3632d1SSimon J. Gerraty# The SUB1 in the resulting path comes from the environment variable TMPBASE,
322c3632d1SSimon J. Gerraty# see MAKE_CMD.
332c3632d1SSimon J. Gerratymakeobjdir-indirect:
342c3632d1SSimon J. Gerraty	@echo $@:
35e2eeea75SSimon J. Gerraty	@${MAKE_CMD} MAKEOBJDIR='$${TMPBASE}/$${SUB2}' show-objdir
362c3632d1SSimon J. Gerraty
372c3632d1SSimon J. Gerratyshow-objdir:
382c3632d1SSimon J. Gerraty	@echo $@: ${.OBJDIR:Q}
39954401e6SSimon J. Gerraty
40954401e6SSimon J. Gerraty
41954401e6SSimon J. Gerraty# Variable assignments in the command line are handled differently from
42954401e6SSimon J. Gerraty# variable assignments in makefiles.  In the command line, trailing whitespace
43954401e6SSimon J. Gerraty# is preserved, and the '#' does not start a comment.  This is because the
44954401e6SSimon J. Gerraty# low-level parsing from ParseRawLine does not take place.
45954401e6SSimon J. Gerraty#
46954401e6SSimon J. Gerraty# Preserving '#' and trailing whitespace has the benefit that when passing
47954401e6SSimon J. Gerraty# such values to sub-makes via MAKEFLAGS, no special encoding is needed.
48954401e6SSimon J. Gerraty# Leading whitespace in the variable value is discarded though, which makes
49954401e6SSimon J. Gerraty# the behavior inconsistent.
50954401e6SSimon J. Gerratyspace-and-comment: .PHONY
51954401e6SSimon J. Gerraty	@echo $@:
52954401e6SSimon J. Gerraty
53954401e6SSimon J. Gerraty	@env -i \
54954401e6SSimon J. Gerraty	    ${MAKE} -r -f /dev/null ' VAR= value # no comment ' -v VAR \
55954401e6SSimon J. Gerraty	| sed 's,$$,$$,'
56954401e6SSimon J. Gerraty
57954401e6SSimon J. Gerraty	@env -i MAKEFLAGS="' VAR= value # no comment '" \
58954401e6SSimon J. Gerraty	    ${MAKE} -r -f /dev/null -v VAR \
59954401e6SSimon J. Gerraty	| sed 's,$$,$$,'
60*6a7405f5SSimon J. Gerraty
61*6a7405f5SSimon J. Gerratycleanup:
62*6a7405f5SSimon J. Gerraty	@rm -rf ${TMPBASE}
63