1# $NetBSD: var-op-shell.mk,v 1.6 2022/01/10 20:32:29 rillig Exp $ 2# 3# Tests for the != variable assignment operator, which runs its right-hand 4# side through the shell. 5 6# The variable OUTPUT gets the output from running the shell command. 7OUTPUT!= echo "success"'ful' 8.if ${OUTPUT} != "successful" 9. error 10.endif 11 12# Since 2014-08-20, the output of the shell command may be empty. 13# 14# On 1996-05-29, when the '!=' assignment operator and Cmd_Exec were added, 15# an empty output produced the error message "Couldn't read shell's output 16# for \"%s\"". 17# 18# The error message is still in Cmd_Exec but reserved for technical errors. 19# It may be possible to trigger the error message by killing the shell after 20# reading part of its output. 21OUTPUT!= true 22.if ${OUTPUT} != "" 23. error 24.endif 25 26# The output of a shell command that failed is processed nevertheless. 27# Unlike the other places that run external commands (expression modifier 28# '::!=', expression modifier ':!...!'), a failed command generates only a 29# warning, not an "error". These "errors" are ignored in default mode, for 30# compatibility, but not in lint mode (-dL). 31OUTPUT!= echo "failed"; false 32.if ${OUTPUT} != "failed" 33. error 34.endif 35 36# A command with empty output may fail as well. 37OUTPUT!= false 38.if ${OUTPUT} != "" 39. error 40.endif 41 42# In the output of the command, each newline is replaced with a space. 43# Except for the very last one, which is discarded. 44OUTPUT!= echo "line 1"; echo "line 2" 45.if ${OUTPUT} != "line 1 line 2" 46. error 47.endif 48 49# A failing command in the middle results in the exit status 0, which in the 50# end means that the whole sequence of commands succeeded. 51OUTPUT!= echo "before"; false; echo "after" 52.if ${OUTPUT} != "before after" 53. error 54.endif 55 56# This should result in a warning about "exited on a signal". 57# This used to be kill -14 (SIGALRM), but that stopped working on 58# Darwin18 after recent update. 59OUTPUT!= kill $$$$ 60.if ${OUTPUT} != "" 61. error 62.endif 63 64# A nonexistent command produces a non-zero exit status. 65OUTPUT!= /bin/no/such/command 66.if ${OUTPUT} != "" 67. error 68.endif 69 70# The output from the shell's stderr is not captured, it just passes through. 71OUTPUT!= echo "stdout"; echo "stderr" 1>&2 72.if ${OUTPUT} != "stdout" 73. error 74.endif 75 76# The 8 dollar signs end up as 4 dollar signs when expanded. The shell sees 77# the command "echo '$$$$'". The 4 dollar signs are stored in OUTPUT, and 78# when that variable is expanded, they expand to 2 dollar signs. 79OUTPUT!= echo '$$$$$$$$' 80.if ${OUTPUT} != "\$\$" 81. error 82.endif 83 84 85# As a debugging aid, log the exact command that is run via the shell. 86.MAKEFLAGS: -dv 87OUTPUT!= echo '$$$$$$$$' 88.MAKEFLAGS: -d0 89 90all: 91