1 1.1 rillig # $NetBSD: cmdline-redirect-stdin.mk,v 1.1 2021/02/01 20:31:41 rillig Exp $ 2 1.1 rillig # 3 1.1 rillig # Demonstrate that the '!=' assignment operator can read individual lines 4 1.1 rillig # from make's stdin. 5 1.1 rillig # 6 1.1 rillig # This edge case is an implementation detail that has no practical 7 1.1 rillig # application. 8 1.1 rillig 9 1.1 rillig all: .PHONY 10 1.1 rillig @printf '%s\n' "first line" "second line" \ 11 1.1 rillig | ${MAKE} -f ${MAKEFILE} read-lines 12 1.1 rillig 13 1.1 rillig .if make(read-lines) 14 1.1 rillig line1!= read line; echo "$$line" 15 1.1 rillig line2!= read line; echo "$$line" 16 1.1 rillig 17 1.1 rillig .if ${line1} != "first line" 18 1.1 rillig . error line1="${line1}" 19 1.1 rillig 20 1.1 rillig .elif ${line2} == "" 21 1.1 rillig # If this branch is ever reached, the shell from the assignment to line1 22 1.1 rillig # probably buffers its input. Most shells use unbuffered stdin, and this 23 1.1 rillig # is actually specified by POSIX, which says that "The read utility shall 24 1.1 rillig # read a single line from standard input". This is the reason why the shell 25 1.1 rillig # reads its input byte by byte, which makes it terribly slow for practical 26 1.1 rillig # applications. 27 1.1 rillig . error The shell's read command does not read a single line. 28 1.1 rillig 29 1.1 rillig .elif ${line2} != "second line" 30 1.1 rillig . error line2="${line2}" 31 1.1 rillig .endif 32 1.1 rillig 33 1.1 rillig read-lines: .PHONY 34 1.1 rillig .endif 35