deptgt-posix.mk revision 1.3 1 1.3 rillig # $NetBSD: deptgt-posix.mk,v 1.3 2022/05/07 12:40:40 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.3 rillig # from the system directory that this test uses.
17 1.1 rillig #
18 1.1 rillig # See also:
19 1.1 rillig # https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
20 1.1 rillig
21 1.2 sjg TESTTMP= ${TMPDIR:U/tmp}/make.test.deptgt-posix
22 1.2 sjg SYSDIR= ${TESTTMP}/sysdir
23 1.2 sjg MAIN_MK= ${TESTTMP}/main.mk
24 1.2 sjg INCLUDED_MK= ${TESTTMP}/included.mk
25 1.1 rillig
26 1.1 rillig all: .PHONY
27 1.1 rillig .SILENT:
28 1.1 rillig
29 1.1 rillig set-up-sysdir: .USEBEFORE
30 1.1 rillig mkdir -p ${SYSDIR}
31 1.1 rillig printf '%s\n' > ${SYSDIR}/sys.mk \
32 1.1 rillig 'CC=sys-cc' \
33 1.1 rillig 'SEEN_SYS_MK=yes'
34 1.1 rillig printf '%s\n' > ${SYSDIR}/posix.mk \
35 1.1 rillig 'CC=posix-cc'
36 1.1 rillig
37 1.1 rillig check-is-posix: .USE
38 1.1 rillig printf '%s\n' >> ${MAIN_MK} \
39 1.1 rillig '.if $${CC} != "posix-cc"' \
40 1.1 rillig '. error' \
41 1.1 rillig '.endif' \
42 1.1 rillig '.if $${%POSIX} != "1003.2"' \
43 1.1 rillig '. error' \
44 1.1 rillig '.endif' \
45 1.1 rillig 'all: .PHONY'
46 1.1 rillig
47 1.1 rillig check-not-posix: .USE
48 1.1 rillig printf '%s\n' >> ${MAIN_MK} \
49 1.1 rillig '.if $${CC} != "sys-cc"' \
50 1.1 rillig '. error' \
51 1.1 rillig '.endif' \
52 1.1 rillig '.if defined(%POSIX)' \
53 1.1 rillig '. error' \
54 1.1 rillig '.endif' \
55 1.1 rillig 'all: .PHONY'
56 1.1 rillig
57 1.1 rillig check-not-seen-sys-mk: .USE
58 1.1 rillig printf '%s\n' >> ${MAIN_MK} \
59 1.1 rillig '.if defined(SEEN_SYS_MK)' \
60 1.1 rillig '. error' \
61 1.1 rillig '.endif'
62 1.1 rillig
63 1.1 rillig run: .USE
64 1.2 sjg (cd "${TESTTMP}" && MAKEFLAGS=${MAKEFLAGS.${.TARGET}:Q} ${MAKE} \
65 1.1 rillig -m "${SYSDIR}" -f ${MAIN_MK:T})
66 1.2 sjg rm -rf ${TESTTMP}
67 1.1 rillig
68 1.1 rillig # If the main makefile has a '.for' loop as its first non-comment line, a
69 1.1 rillig # strict reading of POSIX 2018 makes the makefile non-conforming.
70 1.1 rillig all: after-for
71 1.1 rillig after-for: .PHONY set-up-sysdir check-not-posix run
72 1.1 rillig printf '%s\n' > ${MAIN_MK} \
73 1.1 rillig '# comment' \
74 1.1 rillig '' \
75 1.1 rillig '.for i in once' \
76 1.1 rillig '.POSIX:' \
77 1.1 rillig '.endfor'
78 1.1 rillig
79 1.1 rillig # If the main makefile has an '.if' conditional as its first non-comment line,
80 1.1 rillig # a strict reading of POSIX 2018 makes the makefile non-conforming.
81 1.1 rillig all: after-if
82 1.1 rillig after-if: .PHONY set-up-sysdir check-not-posix run
83 1.1 rillig printf '%s\n' > ${MAIN_MK} \
84 1.1 rillig '# comment' \
85 1.1 rillig '' \
86 1.1 rillig '.if 1' \
87 1.1 rillig '.POSIX:' \
88 1.1 rillig '.endif'
89 1.1 rillig
90 1.1 rillig # If the main makefile first includes another makefile and that included
91 1.1 rillig # makefile tries to switch to POSIX mode, that's too late.
92 1.1 rillig all: in-included-file
93 1.1 rillig in-included-file: .PHONY set-up-sysdir check-not-posix run
94 1.1 rillig printf 'include included.mk\n' > ${MAIN_MK}
95 1.1 rillig printf '.POSIX:\n' > ${INCLUDED_MK}
96 1.1 rillig
97 1.1 rillig # If the main makefile switches to POSIX mode in its very first line, before
98 1.1 rillig # and comment lines or empty lines, that works.
99 1.1 rillig all: in-first-line
100 1.1 rillig in-first-line: .PHONY set-up-sysdir check-is-posix run
101 1.1 rillig printf '%s\n' > ${MAIN_MK} \
102 1.1 rillig '.POSIX:'
103 1.1 rillig
104 1.1 rillig # The only allowed lines before switching to POSIX mode are comment lines.
105 1.3 rillig # POSIX defines comment lines as "blank lines, empty lines, and lines with
106 1.3 rillig # <number-sign> ('#') as the first character".
107 1.1 rillig all: after-comment-lines
108 1.1 rillig after-comment-lines: .PHONY set-up-sysdir check-is-posix run
109 1.1 rillig printf '%s\n' > ${MAIN_MK} \
110 1.1 rillig '# comment' \
111 1.1 rillig '' \
112 1.1 rillig '.POSIX:'
113 1.1 rillig
114 1.1 rillig # Running make with the option '-r' skips the builtin rules from <sys.mk>.
115 1.1 rillig # In that mode, '.POSIX:' just loads <posix.mk>, which works as well.
116 1.1 rillig MAKEFLAGS.no-builtins= -r
117 1.1 rillig all: no-builtins
118 1.1 rillig no-builtins: .PHONY set-up-sysdir check-is-posix check-not-seen-sys-mk run
119 1.1 rillig printf '%s\n' > ${MAIN_MK} \
120 1.1 rillig '.POSIX:'
121