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