#!/bin/bash
# BEGIN_ICS_COPYRIGHT8 ****************************************
#
# Copyright (c) 2015-2020, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * 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.
# * Neither the name of Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
#
# END_ICS_COPYRIGHT8 ****************************************
##
## runmake
## -----------
## Perform a full build
## This is used by the weeklybuild script to provide product specific
## build operations for product's whose build is more complex
## than simply a "make stage prepfiles"
## When this is invoked, the current directory will be the TL_DIR for a
## full checkout of the product to be built
##
## Usage:
## runmake [-B 'build_config'] [-n]
## or
## runmake -r [-B 'build_config'] [-iCR] [-n]
##
## Arguments:
## -B build_config release type to build, (debug/release). default is release
## -r rerun the build in place without doing a new checkout/tag
## -i allow incremental builds by building in-place before package rpm
## -R skip building rpm, just leave in-place files
## -C don't clobber prior to the rerun
## -n No build. Useful for checking build machine
##
## In addition, the following environment variables are expected to be set:
## RELEASE_TAG, BRANCH_TAG, BUILD_TARGET, PRODUCT, RELEASE_HOME, BUILD_CONFIG
## The target command is expected to have already been run to set up the
## environment for the specified target
##
## re-run can be used for 2 situations:
## 1. re-run a failed build to correct incorrect weeklybuild arguments
## or other non-source code related problems (out of disk space)
## 2. re-run a build for a different BUILD_TARGET_OS_VERSION while using the same
## source code image/tag
## If the source code needs to be corrected, a full weeklybuild should be run
## after the correction such that the code is properly tagged.
##
## For developer builds (such as via dobuildall), the following combinations
## of the -r, -i, -C and -R options are useful
## -r - existing typical mode for developer builds
## - clobbers any existing built files
## - creates a src.rpm
## - builds in rpmbuild tree
## - creates a resulting binary rpm
## -r -C - behaves same as -r above except skips the clobber
## -r -i [-C] - incremental build mode for developer builds
## - clobbers any existing built files (unless -C specified)
## - builds code in place in source tree
## - src rpm contains pre-built code
## - rpmbuild ends up using pre-built code, creates binary rpm
## After this build, the developer may do incremental sub-tree builds
## using . setenv and then running make in the subtree
## -r -i [-C] -R - incremental build mode for developer builds with no rpms
## - same as -r -i [-C] except no rpms are created
## none of these options - typical production build
## - expects a fresh un-built checkout of code tree
## - creates a src.rpm
## - builds in rpmbuild tree
## - creates a resulting binary rpm
##
## Recommended developer sequence of builds when debugging new code
## -r -i -C -R - performs the fastest full build possible, generates no rpms
## It is recommended to omit the -C option on 1st build so the tree
## is clobbered to be sure you start fresh.
## iterate on this and code changes until the basic build works
## and syntax errors and warnings are all resolved
## For unit tests only needing a few binaries, they can also be
## directly tested.
## after initial attempt, if compile errors are limited to a subtree:
## create a new bash shell, use . setenv and then
## iterate on make in the subtree and code changes until compiles
## -r -i -C - performs a build to generate rpms
## install the rpms and continue testing
## if focused on a few executables:
## create a new bash shell, use . setenv and then
## iterate on make in the subtree and code changes and test of
## the individual binary until works properly
## -r - perform a full build and generate rpms
## install the rpms, confirm clean build, proper install and function
##
## Since weeklybuild and target commands always set BUILD_CONFIG, this
## script ignores BUILD_CONFIG. As such the BuildOptions file
## or the -B argument completely control BUILD_CONFIG for this product.
. $ICSBIN/funcs.sh
# A given release will be targeted for a specific version of ofed
# however we allow build.config to override if needed
#export OFED_STACK_PREFIX=${OFED_STACK_PREFIX:-/usr/ofed-1.5.2}
export OFED_STACK_PREFIX=${OFED_STACK_PREFIX:-/usr}
# typically exported by build.config
export BUILD_WITH_STACK=${BUILD_WITH_STACK:-OPENIB}
Usage()
{
# include "ERROR" in message so weeklybuild catches it in error log
echo "ERROR: runmake failed" >&2
echo "Usage: runmake [-B 'build_config'] [-n]" >&2
echo " OR" >&2
echo " runmake -r [-B 'build_config'] [-iCR] [-n]" >&2
exit 2
}
build_config=
rerun=n
Cflag=n
nflag=n
inplace=n
rpm=y
while getopts B:riRCn param
do
case $param in
r)
rerun=y;;
B)
build_config="$OPTARG";;
i)
inplace=y;;
R)
rpm=n;;
C)
Cflag=y;;
n)
nflag=y;;
?)
Usage
esac
done
shift $(($OPTIND -1))
if [ $# != 0 ]
then
Usage
fi
if [ -z "$RELEASE_TAG" ]
then
export RELEASE_TAG=`patch_engineer_version|cut -d"." -f1`
echo "Defaulting RELEASE_TAG to $RELEASE_TAG"
# engineers will always forget this flag, since clobber is fast
# default to a rerun which will clobber first unless -C specified
rerun=y
fi
resetct
resetbsp
target $BUILD_TARGET
# the kernel rev is not important. We simply use the kernel rev
# of the running kernel. While BUILD_TARGET_OS_VERSION is needed by Makerules
# it will have no impact on what is actually built
export BUILD_TARGET_OS_VERSION=${BUILD_TARGET_OS_VERSION:-`uname -r`}
setver $BUILD_TARGET_OS_VENDOR $BUILD_TARGET_OS_VERSION
export PROJ_FILE_DIR=Esm
echo "Using PROJ_FILE_DIR=$PROJ_FILE_DIR"
if [ -z "$build_config" ]
then
# default to release build
export BUILD_CONFIG=release
elif [ "$build_config" != debug -a "$build_config" != release ]
then
Usage
else
export BUILD_CONFIG="$build_config"
fi
if [ ! -d $OFED_STACK_PREFIX ]
then
echo "$0: ERROR: OFED stack not found: $OFED_STACK_PREFIX" >&2
exit 1
fi
echo "---------------------------------------"
# Import OPA Build feature settings.
export OPA_FEATURE_SET=${OPA_FEATURE_SET:-$(cat $TL_DIR/$PROJ_FILE_DIR/DEFAULT_OPA_FEATURE_SET)}
FEATURE_SETTINGS_FILE=opa_feature_settings.${PRODUCT}.$BUILD_CONFIG
$TL_DIR/OpaBuildFeatureToggles/opa_build_import_feature_settings.sh
if [ -e ./$FEATURE_SETTINGS_FILE ]; then
. ./$FEATURE_SETTINGS_FILE
else
echo "$0: ERROR: OPA BUILD - $FEATURE_SETTINGS_FILE not found" >&2
exit 1
fi
showenv
echo "---------------------------------------"
# To run thew klocwork scans using klocwork_analyze script, it requires OPA_FEATURE_SET and BUILD_TARGET_OS_ID
# Copying the required variables to $TL_DIR/$PRODUCT_DIRNAME/klocwork.env
if [ "$KW_ENABLE" = "yes" ]; then
echo "export OPA_FEATURE_SET=${OPA_FEATURE_SET}" >> $TL_DIR/$PRODUCT_DIRNAME/klocwork.env
echo "export BUILD_TARGET_OS_ID=${BUILD_TARGET_OS_ID}" >> $TL_DIR/$PRODUCT_DIRNAME/klocwork.env
fi
echo "build for: $BUILD_TARGET"
echo "Stack to build for: $BUILD_WITH_STACK ($OFED_STACK_PREFIX)"
if [ "$nflag" = "y" ]
then
exit 0
fi
if [ "$BUILD_TARGET_OS" = "VXWORKS" ]
then
echo "ERROR: Wrong runmake file"
exit 1
fi
MODULEVERSION=`$TL_DIR/MakeTools/format_releasetag.sh $RELEASE_TAG`
RPMVERSION=`$TL_DIR/MakeTools/format_releasetag.sh -f rpm $RELEASE_TAG`
RPM_VER=`echo $RPMVERSION|cut -d"-" -f1`
RPM_REL=`echo $RPMVERSION-999|cut -d"-" -f2`
export MKRPM_VER=$RPM_VER
export MKRPM_REL=$RPM_REL`rpm --eval %{?dist}`
# even if building rpms, clobber to cleanup any previous in-place builds
# so they don't end up inside the src.rpm when not wanted
# clean up from prior build when rebuilding
if [ "$rerun" = y -a "$Cflag" != y ]
then
# force full rebuild
# Clobber is really only necessary if we have ever built inplace
# but to be safe we always clobber just in case an aborted inplace
# build has previously occurred.
#if [ -e $TL_DIR/builtinplace.$PRODUCT.$BUILD_CONFIG \
# -o -e $TL_DIR/builtinclude.$PRODUCT.$BUILD_CONFIG \
# -o -e $TL_DIR/builtlibs.$PRODUCT.$BUILD_CONFIG \
# -o -e $TL_DIR/builtbin.$PRODUCT.$BUILD_CONFIG ]
#then
export REMOVE_DEPENDS=yes
make clobber clobber_stage clobber_release
(cd $TL_DIR/CommonInstall; make clobber_pl_files)
rm -f $TL_DIR/builtinplace.$PRODUCT.$BUILD_CONFIG
#fi
fi
rm -rf $TL_DIR/$PROJ_FILE_DIR/packaged_files $TL_DIR/$PROJ_FILE_DIR/dist_files $TL_DIR/Fd/buildFeatureDefs
# make sure buildFeatureDefs is in place for the build
make -f Makefile.linux $TL_DIR/Fd/buildFeatureDefs || exit 1
# make sure opafm_src.xml is in place for the build
(cd ib/src/linux/startup;make opafm_src.xml) || exit 1
# make sure files from BaseFiles are in place
while read comp fn
do
if ! echo $comp | grep HFM > /dev/null
then
continue
fi
dir=$(dirname $fn)
bn=$(basename $fn)
(cd $TL_DIR/$dir;make $bn) || exit 1
done < $TL_DIR/Fd/BaseFiles
# make sure CommonInstall files are in place
#(cd $TL_DIR/CommonInstall; make clobber_pl_files fm_files)
args=
if [ "$inplace" = y ]
then
# Do not use unifdef for inplace build
export USE_UNIFDEF="no"
echo > $TL_DIR/builtinplace.$PRODUCT.$BUILD_CONFIG
./rpm_runmake -r -C -B $BUILD_CONFIG
args="-r -C" # we pre-built, so skip clobber in rpmbuild
fi
if [ "$rpm" = y ]
then
USE_UNIFDEF=${USE_UNIFDEF:-"yes"}
set -x
# Pass env variables to rpmbuild. In integration build,
# most of the rpmbuild environment variables remains the same except
# a few (like TL_DIR). However, when the SRPM is built on another
# different machine, the environment variables may be totally
# different. In that case, we may want to pass (hardcode) some
# environment variables.
echo "# Adjust the environment variables if necessary" > build.env
echo "export PRODUCT=${PRODUCT}" >> build.env
echo "export RELEASE_TAG=${RELEASE_TAG}" >> build.env
echo "export BUILD_CONFIG=\${BUILD_CONFIG:-\"${BUILD_CONFIG}\"}" >> build.env
echo "export BUILD_WITH_STACK=${BUILD_WITH_STACK}" >> build.env
echo "export LDENVFS=${LDENVFS}" >> build.env
FILES_TO_TAR=
# if in-place build left builtbin, builtinclude and builtlibs, pick them up
# to accelerate incremental builds
for i in builtbin builtinclude builtlibs builtinplace
do
if [ -e $TL_DIR/$i.$PRODUCT.$BUILD_CONFIG ]
then
FILES_TO_TAR="$FILES_TO_TAR $i.$PRODUCT.$BUILD_CONFIG"
fi
done
FILES_TO_TAR="$FILES_TO_TAR -T tar_inc_srcs_all"
if [ "$BUILD_PLATFORM_OS_VENDOR" != "ubuntu" ]
then
RPMDIR="$TL_DIR/rpmbuild"
mkdir -p $RPMDIR/{BUILD,SPECS,BUILDROOT,SOURCES,RPMS,SRPMS}
# Update the spec file
cp opa-fm.spec.base opa-fm.spec
sed -i "s/__RPM_VERSION/${RPM_VER}/g" opa-fm.spec
sed -i "s/__RPM_RELEASE/${RPM_REL}%{?dist}/g" opa-fm.spec
# update distro dependencies
./update_opa-fm_spec.sh
mv opa-fm.spec $RPMDIR/SPECS/
# Create source tar ball. Update licenses if needed.
$TL_DIR/MakeTools/make_src_tar.sh \
"${RELEASE_TYPE}" \
"${TL_DIR}" \
"$USE_UNIFDEF" \
"$RPMDIR/SOURCES/opa-fm.tar.gz" \
"$FILES_TO_TAR" \
" -X tar_exc_pattern " \
"--transform=s,$PROJ_FILE_DIR/debian,debian," \
|| exit 1
(
export BUILD_ARGS="$args"
cd $RPMDIR
rpmbuild -ba --define "_topdir $RPMDIR" SPECS/opa-fm.spec
) || exit 1
else
RPMDIR="$TL_DIR/debbuild"
RPMVER=${RPM_VER}-${RPM_REL}
mkdir -p $RPMDIR/{build,dists}
OPAFM_SOURCE_TARBALL="$RPMDIR/dists/opa-fm.tar.gz"
# Create source tar ball. Update licenses if needed.
$TL_DIR/MakeTools/make_src_tar.sh \
"${RELEASE_TYPE}" \
"${TL_DIR}" \
"$USE_UNIFDEF" \
"$OPAFM_SOURCE_TARBALL" \
"$FILES_TO_TAR" \
" -X tar_exc_pattern " \
" --transform=s,$PROJ_FILE_DIR/debian,debian," \
|| exit 1
(
OPAFM_DIR="$RPMDIR/build/opa-fm-$RPM_VER"
mkdir -p "$OPAFM_DIR"
cd "$OPAFM_DIR"
tar xzf "$OPAFM_SOURCE_TARBALL"
# Prepate manifest from template
mv debian/changelog.in debian/changelog
# Annotate changelog file to get proper version
debchange --newversion=$RPMVER "Bump up version to $RPMVER"
# Pass build variables into package build environment
export BUILD_ARGS="$args"
dpkg-buildpackage -us -uc
) || exit 1
fi
make final_package
echo "$TL_DIR/$PROJ_FILE_DIR/$FEATURE_SETTINGS_FILE" >> packaged_files
fi
exit 0