1 # $NetBSD: posix1.mk,v 1.3 2014/08/30 22:21:08 sjg Exp $
3 # Keep the default suffixes from interfering, just in case.
6 all: line-continuations suffix-substitution localvars
8 # we need to clean for repeatable results
11 @
rm -f lib.a
dir/* dummy obj
*
17 # Escaped newlines and leading whitespace from the next line are replaced
18 # with single space, except in commands, where the escape and the newline
19 # are retained, but a single leading tab (if any) from the next line is
22 # ${VAR} = "foo bar baz"
32 @echo
'$${VAR} = "${VAR}"'
33 @echo
'aXbXc' | sed
-e
's/X/\
41 # The only variable modifier accepted by POSIX.
42 # ${VAR:s1=s2}: replace s1, if found, with s2 at end of each word in
43 # ${VAR}. s1 and s2 may contain macro expansions.
44 # Expect: foo baR baz, bar baz, foo bar baz, fooadd baradd bazadd
46 @echo
'${VAR:r=R}, ${VAR:foo=}, ${VAR:not_there=wrong}, ${VAR:=add}'
50 # Local variables: regular forms, D/F forms and suffix substitution.
53 # In the past substitutions did not work with the D/F forms and those
54 # forms were not available for $?. (PR 49085)
60 # $@ = target or archive name $< = implied source
61 # $* = target without suffix $? = sources newer than target
62 # $% = archive member name
65 \$${@}=\"${@}\" \$${<}=\"${<}\"\n\
66 \$${*}=\"${*}\" \$${?}=\"${?}\"\n\
69 # $XD = directory part of X $XF = file part of X
70 # X is one of the local variables.
71 LOCAL_ALTERNATIVES
= \
72 "Directory and filename parts of local variables\n\
73 \$${@D}=\"${@D}\" \$${@F}=\"${@F}\"\n\
74 \$${<D}=\"${<D}\" \$${<F}=\"${<F}\"\n\
75 \$${*D}=\"${*D}\" \$${*F}=\"${*F}\"\n\
76 \$${?D}=\"${?D}\" \$${?F}=\"${?F}\"\n\
77 \$${%%D}=\"${%D}\" \$${%%F}=\"${%F}\"\n\n"
79 # Do all kinds of meaningless substitutions on local variables to see
80 # if they work. Add, remove and replace things.
83 LOCAL_SUBSTITUTIONS
= \
84 "Local variable substitutions\n\
85 \$${@:.o=}=\"${@:.o=}\" \$${<:.c=.C}=\"${<:.c=.C}\"\n\
86 \$${*:=.h}=\"${*:=.h}\" \$${?:.h=.H}=\"${?:.h=.H}\"\n\
87 \$${%%:=}=\"${%:=}\"\n\n"
89 LOCAL_ALTERNATIVE_SUBSTITUTIONS
= \
90 "Target with suffix transformations\n\
91 \$${@D:=append}=\"${@D:=append}\"\n\
92 \$${@F:.o=.O}=\"${@F:.o=.O}\"\n\
94 Implied source with suffix transformations\n\
95 \$${<D:r=rr}=\"${<D:r=rr}\"\n\
96 \$${<F:.c=.C}=\"${<F:.c=.C}\"\n\
98 Suffixless target with suffix transformations\n\
99 \$${*D:.=dot}=\"${*D:.=dot}\"\n\
100 \$${*F:.a=}=\"${*F:.a=}\"\n\
102 Out-of-date dependencies with suffix transformations\n\
103 \$${?D:ir=}=\"${?D:ir=}\"\n\
104 \$${?F:.h=.H}=\"${?F:.h=.H}\"\n\
106 Member with suffix transformations\n\
107 \$${%%D:.=}=\"${%D:.=}\"\n\
108 \$${%%F:\$${VAR2}=\$${VAR}}=\"${%F:${VAR2}=${VAR}}\"\n\n"
112 # The system makefiles make the .c.a rule .PRECIOUS with a special source,
113 # but such a thing is not POSIX compatible. It's also somewhat useless
114 # in a test makefile.
117 @printf
${LOCAL_ALTERNATIVES}
118 @printf
${LOCAL_SUBSTITUTIONS}
119 @printf
${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
120 cc -c
-o
'${%}' '${<}'
121 ar ${ARFLAGS} '${@}' '${%}'
126 @printf
${LOCAL_ALTERNATIVES}
127 @printf
${LOCAL_SUBSTITUTIONS}
128 @printf
${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
129 cc -c
-o
'${@}' '${<}'
131 # Some of these rules are padded with useless extra dependencies just so
132 # that ${?} has more than one file.
134 lib.a
: lib.a
(obj1.o
) lib.a
(obj2.o
) lib.a
(obj3.o
)
137 # Explicit rule where the dependency is an inferred file. The dependency
138 # object's name differs from the member's because there was a bug which
139 # forced a dependency on member even when no such dependency was specified
141 lib.a
(obj1.o
): dir/obj_1.o dummy
143 @printf
${LOCAL_ALTERNATIVES}
144 @printf
${LOCAL_SUBSTITUTIONS}
145 @printf
${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
146 cp
'dir/obj_1.o' '$%'
147 ar ${ARFLAGS} '${@}' '$%'
150 # Excplicit rule where the dependency also has an explicit rule.
151 lib.a
(obj2.o
): obj2.o
152 ar ${ARFLAGS} '${@}' '${%}'
154 # Use .c.a inference with an extra dependency.
155 lib.a
(obj3.o
): obj3.h
dir/dummy
157 # Use .c.o inference with an extra dependency.
158 dir/obj_1.o
: dir/obj_1.h
160 # According to POSIX, $* is only required for inference rules and $<'s
161 # value is unspecified outside of inference rules. Strictly speaking
162 # we shouldn't be expanding them here but who cares. At least we get
163 # to check that the program does nothing stupid (like crash) with them.
164 # The C file is named differently from the object file because there
165 # was a bug which forced dependencies based on inference rules on all
166 # applicable targets (PR 49086).
167 obj2.o
: obj_2.c obj_2.h
dir/obj_1.h
169 @printf
${LOCAL_ALTERNATIVES}
170 @printf
${LOCAL_SUBSTITUTIONS}
171 @printf
${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
172 cc -c
-o
'${@}' 'obj_2.c'
174 # Hey, this is make, we can make our own test data setup! obj1.c
175 # and obj2.c are not used, so they should not get created. They're here
176 # as a bait for a regression into the forced dependencies discussed earlier.
177 obj1.c
dir/obj_1.c obj2.c obj_2.c obj3.c
:
179 printf
'#include "${@F:.c=.h}"\nconst char* ${@F:.c=} = "${@}";\n' \
182 dir/obj_1.h obj_2.h obj3.h dummy
dir/dummy
: