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. 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_gcc: .PHONY 78 @echo ${HAVE_GCC} 79 80print_machine: .PHONY 81 @echo ${MACHINE} 82 83print_machine_arch: .PHONY 84 @echo ${MACHINE_ARCH} 85 86print_machine_cpu: .PHONY 87 @echo ${MACHINE_CPU} 88 89print_object_fmt: .PHONY 90 @echo ${OBJECT_FMT} 91 92print_toolchain_missing: .PHONY 93 @echo "${TOOLCHAIN_MISSING}" 94 95print_mkvars \ 96print_set_lists_base print_set_lists_x print_set_lists_ext \ 97list_set_lists_base list_set_lists_x list_set_lists_ext \ 98list_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 129METALOG_REMOVE_DUPLICATES= \ 130 ${TOOL_AWK} '{ a[$$1] = $$0; } END { for (f in a) print a[f]; }' 131 132.if ${MKUNPRIVED} == "no" 133METALOG.unpriv= 134sanitise_METALOG: .PHONY 135 @true 136clean_METALOG: .PHONY 137 @true 138.else # MKUNPRIVED 139METALOG.unpriv= -M ${METALOG}.sanitised 140sanitise_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}) 155clean_METALOG: .PHONY 156 rm -f ${METALOG} ${METALOG}.* 157.else # MKUPDATE 158clean_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. 175makeflist: .PHONY .PRECIOUS check_DESTDIR 176 ${SETSCMD} ./makeflist ${MAKEFLIST_FLAGS} 177 178checkflist: .PRECIOUS .PHONY check_DESTDIR sanitise_METALOG 179 ${SETSCMD} ${.CURDIR}/checkflist \ 180 ${MAKEFLIST_FLAGS} ${CHECKFLIST_FLAGS} ${METALOG.unpriv} 181 182checkflist-x11: .PHONY check_DESTDIR 183 ${SETSCMD} ./checkflist -x ${CHECKFLIST_FLAGS} 184 185checkflist-extsrc: .PHONY check_DESTDIR 186 ${SETSCMD} ./checkflist -y ${CHECKFLIST_FLAGS} 187 188.if defined(DESTDIR) && ${DESTDIR} != "" 189checkflist_if_DESTDIR: checkflist 190.else 191checkflist_if_DESTDIR: 192.endif 193 194# 195# SET BUILDING TARGETS 196# 197 198TARDIR= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 199SOURCETARDIR= ${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# 208MAKETARS_SERIAL?= NO 209.if empty(MAKETARS_SERIAL:M[Yy][Ee][Ss]) 210_MAKETARS_WAIT= # empty 211.else 212_MAKETARS_WAIT= .WAIT 213.endif 214 215maketars: .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 221maketarsetup: .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 231makesetfiles: .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} 238do-${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 247makesrctars: .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 255makesums: .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} 262do-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 272installsets: .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? 282SLOPPY_FLIST?= NO 283.if !empty(SLOPPY_FLIST:M[Yy][Ee][Ss]) 284CHECKFLIST_FLAGS+= -e -m 285REGPKG.sloppy= -m 286.endif 287 288.if ${MAKEVERBOSE} == 0 289REGPKG.verbose?= -q 290.elif ${MAKEVERBOSE} == 1 291REGPKG.verbose?= 292.else # MAKEVERBOSE >= 2 293REGPKG.verbose?= -v 294.endif 295REGPKG.force?= # -f, or empty 296REGPKG.cache?= -c # -c, or empty 297REGPKG.update:= ${MKUPDATE:tl:Nno:C/..*/-u/} 298SYSPKGSETS?= all 299makesyspkgs: .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 309makesyspkgsums: .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? 315makedeps: .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# 325sortlists: .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 350syspkgs: .PHONY makesyspkgs .WAIT makesyspkgsums 351 @true 352 353sets: .PHONY maketars .WAIT makesums 354 @true 355 356sourcesets: .PHONY makesrctars 357 @true 358 359.include <bsd.files.mk> 360