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