Makefile revision 1.102 1 # $NetBSD: Makefile,v 1.102 2016/05/25 00:07:20 christos Exp $
2
3 # Experimental RCS METALOG versioning
4 # (Needs host's rcs(1) commands)
5 #
6 # TODO:
7 # - In 'build.sh distribution', print diff to previous
8 #RCSMETALOG=1
9
10 # The `all' target must appear before bsd.own.mk is pulled in.
11 all:
12 @echo "Please understand what you are doing, first."
13 @false
14
15 .include <bsd.own.mk>
16 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
17
18 COMPRESS_PROGRAM=${TOOL_GZIP}
19 GZIP_FLAGS= ${GZIP_N_FLAG}
20
21 SETSENV= DESTDIR=${DESTDIR:Q} \
22 MACHINE=${MACHINE:Q} \
23 MACHINE_ARCH=${MACHINE_ARCH:Q} \
24 AWK=${TOOL_AWK:Q} \
25 CKSUM=${TOOL_CKSUM:Q} \
26 DB=${TOOL_DB:Q} \
27 EGREP=${TOOL_GREP:Q}\ -E \
28 HOST_SH=${HOST_SH:Q} \
29 MAKE=${MAKE:Q} \
30 MKTEMP=${TOOL_MKTEMP:Q} \
31 MTREE=${TOOL_MTREE:Q} \
32 PAX=${TOOL_PAX:Q} \
33 COMPRESS_PROGRAM=${COMPRESS_PROGRAM:Q} \
34 GZIP=${GZIP_FLAGS:Q} \
35 PKG_CREATE=${TOOL_PKG_CREATE:Q} \
36 SED=${TOOL_SED:Q} \
37 TSORT=${TSORT:Q}
38 SETSCMD= cd ${.CURDIR} && \
39 ${SETSENV} \
40 ${HOST_SH}
41
42 MAKETARS_FLAGS=
43 .if ${MKREPRO_TIMESTAMP:Uno} != "no"
44 MAKETARS_FLAGS+= -T "${MKREPRO_TIMESTAMP}"
45 .endif
46 .if ${MKX11} != "no"
47 MAKESRCTARS_X11_FLAGS= -x ${X11SRCDIR}
48 .endif
49 .if ${MKEXTSRC} != "no"
50 MAKESRCTARS_EXTSRC_FLAGS= -y ${EXTSRCSRCDIR}
51 .endif
52 .if ${MKX11} != "no"
53 MAKEFLIST_X11_FLAGS= ,x
54 .endif
55 .if ${MKEXTSRC} != "no"
56 MAKEFLIST_EXTSRC_FLAGS= ,ext
57 .endif
58 MAKEFLIST_FLAGS= -L base${MAKEFLIST_X11_FLAGS}${MAKEFLIST_EXTSRC_FLAGS}
59 MAKESRCTARS_FLAGS= -N ${NETBSDSRCDIR}/etc
60
61 .if ${MAKEVERBOSE} < 2
62 MAKETARS_FLAGS+= -q
63 MAKESRCTARS_FLAGS+= -q
64 .endif
65
66 .if !defined(MAKETARSETS)
67 MAKETARSETS!= ${SETSCMD} ./makeflist -l ${MAKEFLIST_FLAGS}
68 .endif
69
70 print_have_gcc: .PHONY
71 @echo ${HAVE_GCC}
72
73 print_machine: .PHONY
74 @echo ${MACHINE}
75
76 print_machine_arch: .PHONY
77 @echo ${MACHINE_ARCH}
78
79 print_machine_cpu: .PHONY
80 @echo ${MACHINE_CPU}
81
82 print_object_fmt: .PHONY
83 @echo ${OBJECT_FMT}
84
85 print_toolchain_missing: .PHONY
86 @echo "${TOOLCHAIN_MISSING}"
87
88 print_mkvars \
89 print_set_lists_base print_set_lists_x print_set_lists_ext \
90 list_set_lists_base list_set_lists_x list_set_lists_ext \
91 list_set_files_base list_set_files_x list_set_files_ext \
92 : .PHONY
93 @${SETSENV}; rundir="${.CURDIR}"; . ./sets.subr; ${.TARGET}
94
95 #
96 # METALOG MANIPULATION TARGETS
97 #
98 # METALOG is the name of a metadata log file, and is set in <bsd.own.mk>
99 # if MKUNPRIVED is not "no".
100 #
101 # METALOG.unpriv is a command line option passed to various scripts;
102 # it is either blank or "-M ${METALOG}.sanitised", depending on the
103 # MKUNPRIVED flag.
104 #
105 # The sanitise_METALOG target creates METALOG.sanitised from METALOG,
106 # without modifying METALOG itself. This is used near the end of
107 # a build, after build products have been installed in DESTDIR
108 # and corresponding lines have been added to METALOG, but before
109 # METALOG.sanitised is used in the creation of sets in RELEASEDIR.
110 # For update builds, METALOG.sanitised has duplicates merged (keeping
111 # only the last of multiple entries for the same item), but for clean
112 # builds it's an error if a file or directory name appears twice.
113 # METALOG.sanitised is always sorted and has timestamps removed.
114 #
115 # The clean_METALOG target either deletes METALOG, or replaces METALOG with
116 # a sanitised version of itself, depending on the MKUPDATE flag, and
117 # deletes old METALOG.* files. This is intended to be used at the start
118 # of a build, to ensure that repeated MKUPDATE builds do not cause
119 # unbounded growth of METALOG.
120 #
121
122 METALOG_REMOVE_DUPLICATES= \
123 ${TOOL_AWK} '{ a[$$1] = $$0; } END { for (f in a) print a[f]; }'
124
125 .if ${MKUNPRIVED} == "no"
126 METALOG.unpriv=
127 sanitise_METALOG: .PHONY
128 @true
129 clean_METALOG: .PHONY
130 @true
131 .else # MKUNPRIVED
132 METALOG.unpriv= -M ${METALOG}.sanitised
133 sanitise_METALOG: .PHONY ${METALOG}.sanitised
134 ${METALOG}.sanitised: ${METALOG}
135 <${METALOG} \
136 ${${MKUPDATE} != "no" :? ${METALOG_REMOVE_DUPLICATES} | :} \
137 sort | ${TOOL_MTREE} -CSM -k all -R time -N ${NETBSDSRCDIR}/etc \
138 >${METALOG}.new
139 mv ${METALOG}.new ${METALOG}.sanitised
140 .if defined(RCSMETALOG)
141 . ./metalog.subr; \
142 xrcs_descr="build distribution METALOG"; \
143 xrcs_msg="$$(date)"; \
144 xrcs_cur=${METALOG}.sanitised; \
145 xrcs update
146 .endif
147 .if ${MKUPDATE} == "no" || !exists(${METALOG})
148 clean_METALOG: .PHONY
149 rm -f ${METALOG} ${METALOG}.*
150 .else # MKUPDATE
151 clean_METALOG: .PHONY ${METALOG}.sanitised
152 mv ${METALOG}.sanitised ${METALOG}
153 .if defined(RCSMETALOG)
154 [ -f ${METALOG}.sanitised,v ] && mv ${METALOG}.sanitised,v ${METALOG},v
155 .endif
156 rm -f ${METALOG}.*
157 .if defined(RCSMETALOG)
158 [ -f ${METALOG},v ] && mv ${METALOG},v ${METALOG}.sanitised,v
159 .endif
160 .endif # MKUPDATE
161 .endif # MKUNPRIVED
162
163 #
164 # FILE LIST TARGETS
165 #
166
167 # This target has debugging value only, really.
168 makeflist: .PHONY .PRECIOUS check_DESTDIR
169 ${SETSCMD} ./makeflist ${MAKEFLIST_FLAGS}
170
171 checkflist: .PRECIOUS .PHONY check_DESTDIR sanitise_METALOG
172 ${SETSCMD} ${.CURDIR}/checkflist \
173 ${MAKEFLIST_FLAGS} ${CHECKFLIST_FLAGS} ${METALOG.unpriv}
174
175 checkflist-x11: .PHONY check_DESTDIR
176 ${SETSCMD} ./checkflist -x ${CHECKFLIST_FLAGS}
177
178 checkflist-extsrc: .PHONY check_DESTDIR
179 ${SETSCMD} ./checkflist -y ${CHECKFLIST_FLAGS}
180
181 .if defined(DESTDIR) && ${DESTDIR} != ""
182 checkflist_if_DESTDIR: checkflist
183 .else
184 checkflist_if_DESTDIR:
185 .endif
186
187 #
188 # SET BUILDING TARGETS
189 #
190
191 TARDIR= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
192 SOURCETARDIR= ${RELEASEDIR}/source/sets
193
194 # If MAKETARS_SERIAL is set to "YES" or "yes", then the tar sets will be
195 # made in series, even if make's "-j" flag requests multiple parallel
196 # jobs. This is useful on systems that exhibit poor performance when
197 # running multiple parallel disk-intensive operations. The default is
198 # MAKETARS_SERIAL=NO, which will obey the "-j" flag passed to the make
199 # command.
200 #
201 MAKETARS_SERIAL?= NO
202 .if empty(MAKETARS_SERIAL:M[Yy][Ee][Ss])
203 _MAKETARS_WAIT= # empty
204 .else
205 _MAKETARS_WAIT= .WAIT
206 .endif
207
208 maketars: .PRECIOUS .PHONY check_DESTDIR check_RELEASEDIR \
209 sanitise_METALOG checkflist_if_DESTDIR .WAIT \
210 maketarsetup .WAIT \
211 ${MAKETARSETS:@.TARS.@${_MAKETARS_WAIT} do-${.TARS.}@}
212 @true
213
214 maketarsetup: .EXEC
215 .if defined(DESTDIR) && ${DESTDIR} != ""
216 ${_MKMSG} "execute checkflist"
217 cd ${.CURDIR}; ${MAKE} checkflist
218 .endif
219 mkdir -p ${TARDIR}
220 for i in MD5 SHA512; do \
221 rm -f ${TARDIR}/$$i ${TARDIR}/$$i.tmp; \
222 done
223
224 makesetfiles: .PHONY sanitise_METALOG
225 ${_MKMSG_CREATE} "set lists"
226 ${SETSCMD} ./maketars -S -d ${DESTDIR:S,^$,/,} ${MAKETARS_FLAGS} \
227 ${METALOG.unpriv} \
228 -N ${NETBSDSRCDIR}/etc ${MAKEFLIST_FLAGS} -t ${TARDIR}
229
230 .for tar in ${MAKETARSETS}
231 do-${tar}: .PHONY sanitise_METALOG
232 ${_MKMSG_CREATE} "${tar}.tgz"
233 ${SETSCMD} ./maketars -d ${DESTDIR:S,^$,/,} ${MAKETARS_FLAGS} \
234 ${METALOG.unpriv} \
235 -N ${NETBSDSRCDIR}/etc -t ${TARDIR} ${tar} \
236 || { rm -f ${TARDIR}/${tar}.tgz; false; }
237 .endfor
238
239
240 makesrctars: .PRECIOUS .PHONY check_RELEASEDIR
241 ${_MKMSG_CREATE} "source tar files"
242 mkdir -p ${SOURCETARDIR}
243 ${SETSCMD} ./makesrctars ${MAKESRCTARS_FLAGS} \
244 ${MAKESRCTARS_X11_FLAGS} ${MAKESRCTARS_EXTSRC_FLAGS} \
245 ${NETBSDSRCDIR} ${SOURCETARDIR}
246
247
248 makesums: .PRECIOUS .PHONY check_RELEASEDIR .WAIT \
249 ${MAKETARSETS:@.TARS.@do-sum-${.TARS.}@}
250 for i in MD5 SHA512; do \
251 mv ${TARDIR}/$$i.tmp ${TARDIR}/$$i; \
252 done
253
254 .for tar in ${MAKETARSETS}
255 do-sum-${tar}: .PHONY do-${tar}
256 ${_MKMSG_CREATE} "${tar} checksums"
257 ${MAKESUMS} -t ${TARDIR} ${tar}.tgz
258 for i in MD5 SHA512; do \
259 ${TOOL_CAT} ${TARDIR}/$$i >> ${TARDIR}/$$i.tmp; \
260 done
261 .endfor
262 .ORDER: ${MAKETARSETS:@.TARS.@do-sum-${.TARS.}@}
263
264
265 installsets: .PHONY check_DESTDIR sanitise_METALOG
266 .if !defined(INSTALLDIR)
267 @echo "setenv INSTALLDIR before doing that!"
268 @false
269 .endif
270 ${SETSCMD} ./maketars -d ${DESTDIR:S,^$,/,} ${MAKETARS_FLAGS} \
271 ${METALOG.unpriv} -N ${NETBSDSRCDIR}/etc \
272 ${MAKEFLIST_FLAGS} -i ${INSTALLDIR} ${INSTALLSETS}
273
274 # Should we ignore errors like extra or missing files in the flists?
275 SLOPPY_FLIST?= NO
276 .if !empty(SLOPPY_FLIST:M[Yy][Ee][Ss])
277 CHECKFLIST_FLAGS+= -e -m
278 REGPKG.sloppy= -m
279 .endif
280
281 .if ${MAKEVERBOSE} == 0
282 REGPKG.verbose?= -q
283 .elif ${MAKEVERBOSE} == 1
284 REGPKG.verbose?=
285 .else # MAKEVERBOSE >= 2
286 REGPKG.verbose?= -v
287 .endif
288 REGPKG.force?= # -f, or empty
289 REGPKG.cache?= -c # -c, or empty
290 REGPKG.update:= ${MKUPDATE:tl:Nno:C/..*/-u/}
291 SYSPKGSETS?= all
292 makesyspkgs: .PHONY check_DESTDIR check_RELEASEDIR \
293 sanitise_METALOG checkflist_if_DESTDIR
294 mkdir -p ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
295 ${SETSCMD} ${.CURDIR}/regpkgset \
296 ${REGPKG.verbose} ${REGPKG.force} ${REGPKG.sloppy} \
297 ${REGPKG.cache} ${REGPKG.update} \
298 -d ${DESTDIR:S,^$,/,} ${METALOG.unpriv} \
299 -N ${NETBSDSRCDIR}/etc \
300 -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs ${SYSPKGSETS}
301
302 makesyspkgsums: .PHONY check_RELEASEDIR
303 ${MAKESUMS} -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
304
305 # Update the "deps" file.
306 # XXX: Why is "deps" checked in to the source tree, instead of
307 # just being created as necessary?
308 makedeps: .PHONY
309 ${SETSCMD} ./syspkgdeps all >${.CURDIR}/deps
310
311 # Sort the lists files.
312 #
313 # The tricky stuff with awk and sort -k options is to ensure that the
314 # heading remains undisturbed, and on non-heading lines anything before
315 # the first "." is ignored, so that "./dir/file" and "#./dir/file" are
316 # sorted together.
317 #
318 sortlists: .PHONY
319 find ${.CURDIR}/lists \! \( -name CVS -prune \) \! -name .#\* \
320 -type f -print \
321 | while read f ; do \
322 ${_MKSHMSG} "sorting $${f#${.CURDIR}/}" ; \
323 awk 'BEGIN { inheader = 1 } \
324 /^#*\.\// { inheader = 0 } \
325 // { tag = (inheader ? NR : 999999); \
326 print tag "." $$0 }' \
327 <"$$f" \
328 | sort -t . -k 1n,2 -k 3 \
329 | cut -d . -f 2- \
330 | cat -s >"$$f".tmp; \
331 if cmp "$$f" "$$f".tmp >/dev/null; then \
332 : "$$f is unchanged" ; \
333 rm "$$f".tmp ; \
334 else \
335 mv "$$f".tmp "$$f" ; \
336 fi ; \
337 done
338
339 #
340 # MAIN ENTRY POINTS
341 #
342
343 syspkgs: .PHONY makesyspkgs .WAIT makesyspkgsums
344 @true
345
346 sets: .PHONY maketars .WAIT makesums
347 @true
348
349 sourcesets: .PHONY makesrctars
350 @true
351
352 .include <bsd.files.mk>
353