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