From bd14c6ef69b9924de1bc34ef56c5a06ffa02eb92 Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 12 Oct 2013 17:31:21 +0000 Subject: [PATCH] MFC r255775 r255796 r255807 r255930 r255929 r255957: Create a separate script to generate osreldate.h rather than sourcing newvers.sh into a temporary subshell with inline make rules. Fixes PR 160646. Allow the path to the system source directory to be passed in to newvers.sh. Pass it in from include/Makefile. If it isn't passed in, fall back to the old logic of using dirname $0. Fixes PR 174422. PR: 160646 174422 git-svn-id: svn://svn.freebsd.org/base/stable/9@256386 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- include/Makefile | 25 ++++++++++---------- include/mk-osreldate.sh | 52 +++++++++++++++++++++++++++++++++++++++++ sys/conf/newvers.sh | 5 +++- 3 files changed, 68 insertions(+), 14 deletions(-) create mode 100755 include/mk-osreldate.sh diff --git a/include/Makefile b/include/Makefile index c92a2da65..9932fd53a 100644 --- a/include/Makefile +++ b/include/Makefile @@ -99,19 +99,18 @@ SHARED?= copies 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 \" cannot be used in the kernel, use \"" >> osreldate.h; \ - echo "#else" >> osreldate.h; \ - echo "#undef __FreeBSD_version" >> osreldate.h; \ - echo "#define __FreeBSD_version $$RELDATE" >> osreldate.h; \ - echo "#endif" >> osreldate.h +SYSDIR= ${.CURDIR}/../sys +NEWVERS_SH= ${SYSDIR}/conf/newvers.sh +PARAM_H= ${SYSDIR}/sys/param.h +MK_OSRELDATE_SH= ${.CURDIR}/mk-osreldate.sh + +osreldate.h vers.c: ${NEWVERS_SH} ${PARAM_H} ${MK_OSRELDATE_SH} + env ECHO="${ECHO}" \ + MAKE="${MAKE}" \ + NEWVERS_SH=${NEWVERS_SH} \ + PARAM_H=${PARAM_H} \ + SYSDIR=${SYSDIR} \ + sh ${MK_OSRELDATE_SH} .for i in ${LHDRS} INCSLINKS+= sys/$i ${INCLUDEDIR}/$i diff --git a/include/mk-osreldate.sh b/include/mk-osreldate.sh new file mode 100755 index 000000000..239a66159 --- /dev/null +++ b/include/mk-osreldate.sh @@ -0,0 +1,52 @@ +#!/bin/sh - +# Copyright (c) 2013 Garrett Cooper +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +set -e + +CURDIR=$(pwd) +ECHO=${ECHO:=echo} + +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}" +set +e +. "${NEWVERS_SH:=$CURDIR/../sys/conf/newvers.sh}" || exit 1 +set -e +cat > $tmpfile < cannot be used in the kernel, use " +#else +#undef __FreeBSD_version +#define __FreeBSD_version $RELDATE +#endif +EOF +chmod 644 $tmpfile +mv $tmpfile osreldate.h diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh index 401b0540f..42f0358cd 100644 --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -38,7 +38,10 @@ if [ "X${BRANCH_OVERRIDE}" != "X" ]; then fi RELEASE="${REVISION}-${BRANCH}" VERSION="${TYPE} ${RELEASE}" -SYSDIR=$(dirname $0)/.. + +if [ "X${SYSDIR}" = "X" ]; then + SYSDIR=$(dirname $0)/.. +fi if [ "X${PARAMFILE}" != "X" ]; then RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \ -- 2.45.0