1 1.4 rillig # $NetBSD: deptgt-posix.mk,v 1.4 2022/05/07 21:24:52 rillig Exp $ 2 1.1 rillig # 3 1.1 rillig # Tests for the special target '.POSIX', which enables POSIX mode. 4 1.1 rillig # 5 1.3 rillig # As of 2022-04-18, when parsing the dependency line '.POSIX', the variable 6 1.3 rillig # '%POSIX' is defined and <posix.mk> is included, if it exists. Other than 7 1.3 rillig # that, POSIX support is still incomplete, the exact set of supported features 8 1.3 rillig # needs to be cross-checked with the POSIX specification. 9 1.1 rillig # 10 1.3 rillig # At the point of '.POSIX:', <sys.mk> has been loaded already, unless the 11 1.3 rillig # option '-r' was given. This means that an implementation of <posix.mk> must 12 1.3 rillig # work both with and without the system rules from <sys.mk> being in effect. 13 1.3 rillig # 14 1.3 rillig # Implementation note: this test needs to run isolated from the usual tests 15 1.3 rillig # directory to prevent unit-tests/posix.mk from interfering with the posix.mk 16 1.4 rillig # from the system directory that this test uses; since at least 1997, the 17 1.4 rillig # directive '.include <file>' has been looking in the current directory first 18 1.4 rillig # before searching the file in the system search path, as described in 19 1.4 rillig # https://gnats.netbsd.org/15163. 20 1.1 rillig # 21 1.1 rillig # See also: 22 1.1 rillig # https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html 23 1.1 rillig 24 1.2 sjg TESTTMP= ${TMPDIR:U/tmp}/make.test.deptgt-posix 25 1.2 sjg SYSDIR= ${TESTTMP}/sysdir 26 1.2 sjg MAIN_MK= ${TESTTMP}/main.mk 27 1.2 sjg INCLUDED_MK= ${TESTTMP}/included.mk 28 1.1 rillig 29 1.1 rillig all: .PHONY 30 1.1 rillig .SILENT: 31 1.1 rillig 32 1.1 rillig set-up-sysdir: .USEBEFORE 33 1.1 rillig mkdir -p ${SYSDIR} 34 1.1 rillig printf '%s\n' > ${SYSDIR}/sys.mk \ 35 1.1 rillig 'CC=sys-cc' \ 36 1.1 rillig 'SEEN_SYS_MK=yes' 37 1.1 rillig printf '%s\n' > ${SYSDIR}/posix.mk \ 38 1.1 rillig 'CC=posix-cc' 39 1.1 rillig 40 1.1 rillig check-is-posix: .USE 41 1.1 rillig printf '%s\n' >> ${MAIN_MK} \ 42 1.1 rillig '.if $${CC} != "posix-cc"' \ 43 1.1 rillig '. error' \ 44 1.1 rillig '.endif' \ 45 1.1 rillig '.if $${%POSIX} != "1003.2"' \ 46 1.1 rillig '. error' \ 47 1.1 rillig '.endif' \ 48 1.1 rillig 'all: .PHONY' 49 1.1 rillig 50 1.1 rillig check-not-posix: .USE 51 1.1 rillig printf '%s\n' >> ${MAIN_MK} \ 52 1.1 rillig '.if $${CC} != "sys-cc"' \ 53 1.1 rillig '. error' \ 54 1.1 rillig '.endif' \ 55 1.1 rillig '.if defined(%POSIX)' \ 56 1.1 rillig '. error' \ 57 1.1 rillig '.endif' \ 58 1.1 rillig 'all: .PHONY' 59 1.1 rillig 60 1.1 rillig check-not-seen-sys-mk: .USE 61 1.1 rillig printf '%s\n' >> ${MAIN_MK} \ 62 1.1 rillig '.if defined(SEEN_SYS_MK)' \ 63 1.1 rillig '. error' \ 64 1.1 rillig '.endif' 65 1.1 rillig 66 1.1 rillig run: .USE 67 1.2 sjg (cd "${TESTTMP}" && MAKEFLAGS=${MAKEFLAGS.${.TARGET}:Q} ${MAKE} \ 68 1.1 rillig -m "${SYSDIR}" -f ${MAIN_MK:T}) 69 1.2 sjg rm -rf ${TESTTMP} 70 1.1 rillig 71 1.1 rillig # If the main makefile has a '.for' loop as its first non-comment line, a 72 1.1 rillig # strict reading of POSIX 2018 makes the makefile non-conforming. 73 1.1 rillig all: after-for 74 1.1 rillig after-for: .PHONY set-up-sysdir check-not-posix run 75 1.1 rillig printf '%s\n' > ${MAIN_MK} \ 76 1.1 rillig '# comment' \ 77 1.1 rillig '' \ 78 1.1 rillig '.for i in once' \ 79 1.1 rillig '.POSIX:' \ 80 1.1 rillig '.endfor' 81 1.1 rillig 82 1.1 rillig # If the main makefile has an '.if' conditional as its first non-comment line, 83 1.1 rillig # a strict reading of POSIX 2018 makes the makefile non-conforming. 84 1.1 rillig all: after-if 85 1.1 rillig after-if: .PHONY set-up-sysdir check-not-posix run 86 1.1 rillig printf '%s\n' > ${MAIN_MK} \ 87 1.1 rillig '# comment' \ 88 1.1 rillig '' \ 89 1.1 rillig '.if 1' \ 90 1.1 rillig '.POSIX:' \ 91 1.1 rillig '.endif' 92 1.1 rillig 93 1.1 rillig # If the main makefile first includes another makefile and that included 94 1.1 rillig # makefile tries to switch to POSIX mode, that's too late. 95 1.1 rillig all: in-included-file 96 1.1 rillig in-included-file: .PHONY set-up-sysdir check-not-posix run 97 1.1 rillig printf 'include included.mk\n' > ${MAIN_MK} 98 1.1 rillig printf '.POSIX:\n' > ${INCLUDED_MK} 99 1.1 rillig 100 1.1 rillig # If the main makefile switches to POSIX mode in its very first line, before 101 1.1 rillig # and comment lines or empty lines, that works. 102 1.1 rillig all: in-first-line 103 1.1 rillig in-first-line: .PHONY set-up-sysdir check-is-posix run 104 1.1 rillig printf '%s\n' > ${MAIN_MK} \ 105 1.1 rillig '.POSIX:' 106 1.1 rillig 107 1.1 rillig # The only allowed lines before switching to POSIX mode are comment lines. 108 1.3 rillig # POSIX defines comment lines as "blank lines, empty lines, and lines with 109 1.3 rillig # <number-sign> ('#') as the first character". 110 1.1 rillig all: after-comment-lines 111 1.1 rillig after-comment-lines: .PHONY set-up-sysdir check-is-posix run 112 1.1 rillig printf '%s\n' > ${MAIN_MK} \ 113 1.1 rillig '# comment' \ 114 1.1 rillig '' \ 115 1.1 rillig '.POSIX:' 116 1.1 rillig 117 1.1 rillig # Running make with the option '-r' skips the builtin rules from <sys.mk>. 118 1.1 rillig # In that mode, '.POSIX:' just loads <posix.mk>, which works as well. 119 1.1 rillig MAKEFLAGS.no-builtins= -r 120 1.1 rillig all: no-builtins 121 1.1 rillig no-builtins: .PHONY set-up-sysdir check-is-posix check-not-seen-sys-mk run 122 1.1 rillig printf '%s\n' > ${MAIN_MK} \ 123 1.1 rillig '.POSIX:' 124