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