1# $NetBSD: cond1.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $
2
3# TODO: Convert these tests into tutorial form.
4# TODO: Split these tests by topic.
5# TODO: Use better variable names and expression values that actually express
6# the intended behavior.  uname(1) has nothing to do with conditions.
7
8# hard code these!
9TEST_UNAME_S= NetBSD
10TEST_UNAME_M= sparc
11TEST_MACHINE= i386
12
13.if ${TEST_UNAME_S}
14Ok=var,
15.endif
16.if ("${TEST_UNAME_S}")
17Ok+=(\"var\"),
18.endif
19.if (${TEST_UNAME_M} != ${TEST_MACHINE})
20Ok+=(var != var),
21.endif
22.if ${TEST_UNAME_M} != ${TEST_MACHINE}
23Ok+= var != var,
24.endif
25.if !((${TEST_UNAME_M} != ${TEST_MACHINE}) && defined(X))
26Ok+= !((var != var) && defined(name)),
27.endif
28# from bsd.obj.mk
29MKOBJ?=no
30.if ${MKOBJ} == "no"
31o= no
32Ok+= var == "quoted",
33.else
34.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
35.if defined(notMAKEOBJDIRPREFIX)
36o=${MAKEOBJDIRPREFIX}${__curdir}
37.else
38o= ${MAKEOBJDIR}
39.endif
40.endif
41o= o
42.endif
43
44# repeat the above to check we get the same result
45.if ${MKOBJ} == "no"
46o2= no
47.else
48.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
49.if defined(notMAKEOBJDIRPREFIX)
50o2=${MAKEOBJDIRPREFIX}${__curdir}
51.else
52o2= ${MAKEOBJDIR}
53.endif
54.endif
55o2= o
56.endif
57
58PRIMES=2 3 5 7 11
59NUMBERS=1 2 3 4 5
60
61n=2
62.if ${PRIMES:M$n} == ""
63X=not
64.else
65X=
66.endif
67
68.if ${MACHINE_ARCH} == no-such
69A=one
70.else
71.if ${MACHINE_ARCH} == not-this
72.if ${MACHINE_ARCH} == something-else
73A=unlikely
74.else
75A=no
76.endif
77.endif
78A=other
79# We expect an extra else warning - we're not skipping here
80.else
81A=this should be an error
82.endif
83
84.if $X != ""
85.if $X == not
86B=one
87.else
88B=other
89# We expect an extra else warning - we are skipping here
90.else
91B=this should be an error
92.endif
93.else
94B=unknown
95.endif
96
97.if "quoted" == quoted
98C=clever
99.else
100C=dim
101.endif
102
103.if defined(nosuch) && ${nosuch:Mx} != ""
104# this should not happen
105.info nosuch is x
106.endif
107
108all:
109	@echo "$n is $X prime"
110	@echo "A='$A' B='$B' C='$C' o='$o,${o2}'"
111	@echo "Passed:${.newline} ${Ok:S/,/${.newline}/}"
112	@echo "${NUMBERS:@n@$n is ${("${PRIMES:M$n}" == ""):?not:} prime${.newline}@}"
113	@echo "${"${DoNotQuoteHere:U0}" > 0:?OK:No}"
114	@echo "${${NoSuchNumber:U42} > 0:?OK:No}"
115