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