tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: etc/motd not updated



On Fri, 19 Oct 2012, Joerg Sonnenberger wrote:
> On Fri, Oct 19, 2012 at 10:32:48AM +0200, Alan Barrett wrote:
> > DESTDIR/etc/motd is created from different source files depending on
> > pattern matching against ${DISTRIBVER} in etc/Makefile.  If
> > DISTRIBVER changes, then the rules change, but nothing notices that
> > the installed file might need to change.
> 
> A simpler idea would be to depend on sys/param.h?

I generalised that idea.  The appended patch adds a "params" file in
the top-level obj directory, containing all the setting that might
affect the build, defines the variable _NETBSD_VERSION_DEPENDENT in
<bsd.own.mk>, and uses ${_NETBSD_VERSION_DEPENDENT} as a dependency for
a few files that must be re-generated when the NetBSD version changes,
and that should possibly be re-generated when certain build settings are
changed.

Here's the documentation from share/mk/bsd.README, followed by the
patch.

[[[
_NETBSD_VERSION_DEPENDENT
                A list of files which contain information about
                the version of the NetBSD being built.  This is
                defined only if the current directory appears
                to be inside a NetBSD source tree.  The list of
                files includes ${NETBSDSRCDIR}/sys/sys/param.h
                (which contains the kernel version number),
                ${NETBSDSRCDIR}/sys/conf/newvers.sh and
                ${NETBSDSRCDIR}/sys/conf/osrelease.sh (which
                interpret the information in sys/sys/param.h), and
                ${_SRC_TOP_OBJ_}/params (which is an optional file,
                created by "make build" in ${_SRC_TOP_}/Makefile,
                containing all the variables that may influence the
                build).

                Targets that depend on the NetBSD version, or on
                variables defined at build time, can declare a
                dependency on ${_NETBSD_VERSION_DEPENDENT}, like this:

                        version.c: ${_NETBSD_VERSION_DEPENDENT}
                                commands to create version.c
]]]

--apb (Alan Barrett)


diff --git a/Makefile b/Makefile
index f632dd6673..ce8f6447da 100644
--- a/Makefile
+++ b/Makefile
@@ -87,6 +87,8 @@
 #   do-top-obj:      creates the top level object directory.
 #   do-tools-obj:    creates object directories for the host toolchain.
 #   do-tools:        builds host toolchain.
+#   params:          record the values of variables that might affect the
+#                    build.
 #   obj:             creates object directories.
 #   do-distrib-dirs: creates the distribution directories.
 #   includes:        installs include files.
@@ -222,6 +224,7 @@ BUILDTARGETS+=      do-tools-obj
 .endif
 BUILDTARGETS+= do-tools
 .endif # USETOOLS              # }
+BUILDTARGETS+= params
 .if ${MKOBJDIRS} != "no"
 BUILDTARGETS+= obj
 .endif
@@ -252,6 +255,25 @@ includes-lib:      .PHONY includes-include includes-sys
 includes-gnu:  .PHONY includes-lib
 
 #
+# Record the values of variables that might affect the build.
+# If no values have changed, avoid updating the timestamp
+# of the params file.
+#
+# This is referenced by _NETBSD_VERSION_DEPENDENT in <bsd.own.mk>.
+#
+
+params: .EXEC
+       ${_MKMSG_CREATE} params
+       @(${MAKEDIRTARGET:S/^@//} etc params) >${.TARGET}.new
+       @if cmp -s ${.TARGET}.new ${.TARGET} > /dev/null 2>&1; then \
+               : "params is unchanged" ; \
+               rm ${.TARGET}.new ; \
+       else \
+               : "params has changed or is new" ; \
+               mv ${.TARGET}.new ${.TARGET} ; \
+       fi
+
+#
 # Build the system and install into DESTDIR.
 #
 
@@ -508,5 +530,5 @@ dependall-distrib depend-distrib all-distrib: .PHONY
 #
 # Display current make(1) parameters
 #
-params: .PHONY .MAKE
+show-params: .PHONY .MAKE
        ${MAKEDIRTARGET} etc params
diff --git a/etc/Makefile b/etc/Makefile
index 0c3bc19aab..d8a2f678eb 100644
--- a/etc/Makefile
+++ b/etc/Makefile
@@ -114,21 +114,8 @@ BIN1+=     etc.${MACHINE}/ttyaction
 .endif
 
 # -rw-rw-r--
-.if !empty(DISTRIBVER:M*.99.*)
-BIN2+= motd.current
-FILESNAME_motd.current=        motd
-.elif !empty(DISTRIBVER:M*BETA*)
-BIN2+= motd.beta
-FILESNAME_motd.beta=   motd
-.elif !empty(DISTRIBVER:M*RC*)
-BIN2+= motd.rc
-FILESNAME_motd.rc=     motd
-.elif !empty(DISTRIBVER:M*STABLE*)
-BIN2+= motd.stable
-FILESNAME_motd.stable= motd
-.else
 BIN2+= motd
-.endif
+FILESBUILD_motd=       YES
 
 # -rw-------
 BIN3+= hosts.equiv
@@ -172,6 +159,24 @@ distribution: .PHONY .MAKE check_DESTDIR distrib-dirs
 .endif # !DISTRIBUTION_DONE
 
 
+# motd is copied from a different ${MOTD_SOURCE} depending on DISTRIBVER
+#
+.if !empty(DISTRIBVER:M*.99.*)
+MOTD_SOURCE=   motd.current
+.elif !empty(DISTRIBVER:M*BETA*)
+MOTD_SOURCE=   motd.beta
+.elif !empty(DISTRIBVER:M*RC*)
+MOTD_SOURCE=   motd.rc
+.elif !empty(DISTRIBVER:M*STABLE*)
+MOTD_SOURCE=   motd.stable
+.else
+MOTD_SOURCE=   motd.default
+.endif
+CLEANFILES+= motd
+motd: ${.CURDIR}/${MOTD_SOURCE} ${_NETBSD_VERSION_DEPENDENT}
+       ${_MKTARGET_CREATE}
+       ${HOST_INSTALL_FILE} ${.CURDIR}/${MOTD_SOURCE} ${.TARGET}
+
 CLEANFILES+=   MAKEDEV
 MAKEDEV: ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.tmpl \
     ${.CURDIR}/etc.${MACHINE}/MAKEDEV.conf
@@ -182,7 +187,7 @@ MAKEDEV: ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.tmpl \
            > ${.TARGET}
 
 RELEASEVARS=   BSDOBJDIR BSDSRCDIR BUILDID \
-               DESTDIR EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
+               DESTDIR DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
                INSTALLWORLDDIR \
                KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
                MACHINE MACHINE_ARCH MAKE MAKECONF MAKEFLAGS \
diff --git a/etc/motd b/etc/motd
deleted file mode 100644
index 35f8066c71..0000000000
--- a/etc/motd
+++ /dev/null
@@ -1,4 +0,0 @@
-NetBSD ?.? (UNKNOWN)
-
-Welcome to NetBSD!
-
diff --git a/etc/motd.default b/etc/motd.default
new file mode 100644
index 0000000000..35f8066c71
--- /dev/null
+++ b/etc/motd.default
@@ -0,0 +1,4 @@
+NetBSD ?.? (UNKNOWN)
+
+Welcome to NetBSD!
+
diff --git a/share/mk/bsd.README b/share/mk/bsd.README
index a1fc683d20..73e6643ff3 100644
--- a/share/mk/bsd.README
+++ b/share/mk/bsd.README
@@ -499,6 +499,28 @@ _SRC_TOP_  Top of the system source tree, as determined by 
<bsd.own.mk>
                is "internal" to <bsd.own.mk>, although its value is only
                determined once and then propagated to all sub-makes.
 
+_NETBSD_VERSION_DEPENDENT
+               A list of files which contain information about
+               the version of the NetBSD being built.  This is
+               defined only if the current directory appears
+               to be inside a NetBSD source tree.  The list of
+               files includes ${NETBSDSRCDIR}/sys/sys/param.h
+               (which contains the kernel version number),
+               ${NETBSDSRCDIR}/sys/conf/newvers.sh and
+               ${NETBSDSRCDIR}/sys/conf/osrelease.sh (which
+               interpret the information in sys/sys/param.h), and
+               ${_SRC_TOP_OBJ_}/params (which is an optional file,
+               created by "make build" in ${_SRC_TOP_}/Makefile,
+               containing all the variables that may influence the
+               build).
+
+               Targets that depend on the NetBSD version, or on
+               variables defined at build time, can declare a
+               dependency on ${_NETBSD_VERSION_DEPENDENT}, like this:
+
+                       version.c: ${_NETBSD_VERSION_DEPENDENT}
+                               commands to create version.c
+
 BSDSRCDIR      The real path to the system sources, so that 'make obj'
                will work correctly.  [/usr/src]
 
diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
index 230401afe6..6048c15f5a 100644
--- a/share/mk/bsd.own.mk
+++ b/share/mk/bsd.own.mk
@@ -107,8 +107,11 @@ _SRC_TOP_!= cd "${.CURDIR}"; while :; do \
 .endif                                 # }
 
 #
-# If _SRC_TOP_ != "", we're within the NetBSD source tree, so set
-# defaults for NETBSDSRCDIR and _SRC_TOP_OBJ_.
+# If _SRC_TOP_ != "", we're within the NetBSD source tree.
+# * Set defaults for NETBSDSRCDIR and _SRC_TOP_OBJ_.
+# * Define _NETBSD_VERSION_DEPENDENT.  Targets that depend on the
+#   NetBSD version, or on variables defined at build time, can
+#   declare a dependency on ${_NETBSD_VERSION_DEPENDENT}.
 #
 .if (${_SRC_TOP_} != "")               # {
 
@@ -119,6 +122,12 @@ _SRC_TOP_OBJ_!=            cd "${_SRC_TOP_}" && 
${PRINTOBJDIR}
 .MAKEOVERRIDES+=       _SRC_TOP_OBJ_
 .endif
 
+_NETBSD_VERSION_DEPENDENT=     ${_SRC_TOP_OBJ_}/params
+_NETBSD_VERSION_DEPENDENT+=    ${NETBSDSRCDIR}/sys/sys/param.h
+_NETBSD_VERSION_DEPENDENT+=    ${NETBSDSRCDIR}/sys/conf/newvers.sh
+_NETBSD_VERSION_DEPENDENT+=    ${NETBSDSRCDIR}/sys/conf/osrelease.sh
+${_SRC_TOP_OBJ_}/params: .NOTMAIN .OPTIONAL # created by top level "make build"
+
 .endif # _SRC_TOP_ != ""               # }
 
 
diff --git a/sys/arch/next68k/stand/boot/Makefile 
b/sys/arch/next68k/stand/boot/Makefile
index f61d7eb2a2..185770d602 100644
--- a/sys/arch/next68k/stand/boot/Makefile
+++ b/sys/arch/next68k/stand/boot/Makefile
@@ -77,10 +77,10 @@ srt0.o: ${.CURDIR}/srt0.s
        ${CC} -m68040 -x assembler-with-cpp ${INCLUDES} ${DEFS} -c 
${.CURDIR}/srt0.s
 
 .PHONY: build.c
-build.c:
+build.c: ${_NETBSD_VERSION_DEPENDENT}
        ${HOST_SH} ${.CURDIR}/newvers.sh
 
-vers.c: version
+vers.c: version ${_NETBSD_VERSION_DEPENDENT}
        ${HOST_SH} ${S}/conf/newvers_stand.sh ${.CURDIR}/version "next68k"
 
 #installboot: ${.CURDIR}/installboot.sh
diff --git a/sys/conf/Makefile.kern.inc b/sys/conf/Makefile.kern.inc
index 598824164e..f18a97f9f3 100644
--- a/sys/conf/Makefile.kern.inc
+++ b/sys/conf/Makefile.kern.inc
@@ -338,7 +338,8 @@ _NVFLAGS=${NVFLAGS}
 
 .if !target(vers.o)
 newvers: vers.o
-vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh 
$S/conf/osrelease.sh
+vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh \
+               $S/conf/osrelease.sh ${_NETBSD_VERSION_DEPENDENT}
        ${_MKMSG_CREATE} vers.c
        ${HOST_SH} $S/conf/newvers.sh ${_NVFLAGS}
        ${_MKTARGET_COMPILE}
diff --git a/sys/rump/librump/rumpkern/Makefile.rumpkern 
b/sys/rump/librump/rumpkern/Makefile.rumpkern
index fa19e3aa5a..4b7909818b 100644
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern
@@ -36,7 +36,8 @@ _NVFLAGS=-r
 _NVFLAGS=
 .endif
 
-vers.c: ${RUMPTOP}/../conf/newvers.sh ${RUMPTOP}/../conf/osrelease.sh 
${RUMPTOP}/../sys/param.h
+vers.c: ${RUMPTOP}/../conf/newvers.sh ${RUMPTOP}/../conf/osrelease.sh \
+               ${RUMPTOP}/../sys/param.h ${_NETBSD_VERSION_DEPENDENT}
        ${_MKMSG_CREATE} vers.c
        ${HOST_SH} ${RUMPTOP}/../conf/newvers.sh -i RUMP-ROAST -n ${_NVFLAGS}
 SRCS+=         vers.c
diff --git a/usr.sbin/crash/Makefile b/usr.sbin/crash/Makefile
index 4bea6a6e98..c3e49a148a 100644
--- a/usr.sbin/crash/Makefile
+++ b/usr.sbin/crash/Makefile
@@ -79,7 +79,7 @@ COPTS.db_output.c += -Wno-format-nonliteral
 
 # vers.c
 SRCS+= vers.c
-vers.c:        ${S}/conf/newvers.sh
+vers.c:        ${S}/conf/newvers.sh ${_NETBSD_VERSION_DEPENDENT}
        ${HOST_SH} ${S}/conf/newvers.sh -r -n
 CLEANFILES+=   vers.c version
 


Home | Main Index | Thread Index | Old Index