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