misc/160646: [patch] rework build of osreldate.h to not depend on include/Makefile

Garrett Cooper gcooper at ixsystems.com
Sat Sep 10 23:50:10 UTC 2011

>Number:         160646
>Category:       misc
>Synopsis:       [patch] rework build of osreldate.h to not depend on include/Makefile
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 10 23:50:06 UTC 2011
>Originator:     Garrett Cooper
>Release:        9.0-BETA2
iXsystems, Inc.
FreeBSD bayonetta.local 9.0-BETA2 FreeBSD 9.0-BETA2 #0 r225457M: Fri Sep  9 00:19:17 PDT 2011     gcooper at bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA  amd64
osreldate.h depends on include/Makefile as the recipe for generating osreldate.h is included in include/Makefile. This makes sense if the blurb of text changes in the Makefile, but not if a developer makes another modification to the Makefile (say, add a header). This will break make installworld if someone modifies include/Makefile after the fact; the freenas build, which uses nanobsd currently does this as a hammer solution with the src and ports patches that are in the tree as it uses csup for pulling sources (it could be improved, but regardless..).

The attached patch adds a script which takes care of generating the osreldate.h header in an atomic manner (the current include/Makefile snippet could build a bad osreldate.h header file if one of the echo calls fails).

An example of one of these failures can be found here:

- http://lists.freebsd.org/pipermail/freebsd-questions/2007-August/154719.html
make buildworld
touch -am include/Makefile
make installworld
1. Apply patch.
2. Make osreldate.h:
    - cd include; make osreldate.h
3. Verify that the above reproduction cases no longer trigger the failure.

If you apply this patch to your sourcebase each time like the freenas build system, you will need to touch mk-osreldate.sh like so to avoid retriggering the problem discussed above:

touch -am -t 200001010000 include/mk-osreldate.sh

This is only temporary though, because one the change is rolled into FreeBSD this hack is no longer required.

Patch attached with submission follows:

Index: include/Makefile
--- include/Makefile	(revision 225457)
+++ include/Makefile	(working copy)
@@ -95,20 +95,17 @@
 INCS+=	osreldate.h
-osreldate.h: ${.CURDIR}/../sys/conf/newvers.sh ${.CURDIR}/../sys/sys/param.h \
-    ${.CURDIR}/Makefile
-	@${ECHO} creating osreldate.h from newvers.sh
-	@MAKE=${MAKE}; \
-	PARAMFILE=${.CURDIR}/../sys/sys/param.h; \
-	. ${.CURDIR}/../sys/conf/newvers.sh; \
-	echo "$$COPYRIGHT" > osreldate.h; \
-	echo "#ifdef _KERNEL" >> osreldate.h; \
-	echo "#error \"<osreldate.h> cannot be used in the kernel, use <sys/param.h>\"" >> osreldate.h; \
-	echo "#else" >> osreldate.h; \
-	echo "#undef __FreeBSD_version" >> osreldate.h; \
-	echo "#define __FreeBSD_version $$RELDATE" >> osreldate.h; \
-	echo "#endif" >> osreldate.h
+NEWVERS_SH=		${.CURDIR}/../sys/conf/newvers.sh
+PARAM_H=		${.CURDIR}/../sys/sys/param.h
+MK_OSRELDATE_SH=	${.CURDIR}/mk-osreldate.sh
+osreldate.h: ${NEWVERS_SH} ${PARAM_H} ${MK_OSRELDATE_SH}
+	env ECHO="${ECHO}" \
+	    MAKE="${MAKE}" \
+	    PARAM_H=${PARAM_H} \
 .for i in ${LHDRS}
Index: include/mk-osreldate.sh
--- include/mk-osreldate.sh	(revision 0)
+++ include/mk-osreldate.sh	(revision 0)
@@ -0,0 +1,24 @@
+set -e
+tmpfile=$(mktemp osreldate.XXXXXXXX)
+trap "rm -f $tmpfile" EXIT
+${ECHO} creating osreldate.h from newvers.sh
+export PARAMFILE="${PARAM_H:=$CURDIR/../sys/sys/param.h}"
+. "${NEWVERS_SH:=$CURDIR/../sys/conf/newvers.sh}"
+cat > $tmpfile <<EOF
+#ifdef _KERNEL
+#error "<osreldate.h> cannot be used in the kernel, use <sys/param.h>"
+#undef __FreeBSD_version
+#define __FreeBSD_version $RELDATE
+mv $tmpfile osreldate.h

Property changes on: include/mk-osreldate.sh
Added: svn:executable
   + *


More information about the freebsd-bugs mailing list