#!/bin/bash

. buildsys/functions

ProcessArgs $*
Assert LoadConfigs
Assert SetupLogDir
Assert SetupResFile

if [ "$BUILD_DIST" != "yes" ]
then
   echo "BUILD_DIST=SKIPPED" >> $RESFILE
   exit 0
fi

cd ../../..

SetState BuildingDistribution
ArchiveLogs

if [ "$DEP" != "none" ]
then
   OSPL_HOME=$DEPWORKDIR
   export OSPL_HOME
fi

SPLICE_PLATFORM=$SETUP_TYPE
export SPLICE_PLATFORM
. ./configure -full
if [ "$CONFIGURATION" != "OK" ]
then
   echo  "ERROR: configuration - dcps_build_dist"
   exit 1
fi

echo "BUILD_DIST=RUNNING" >> $RESFILE
ArchiveLogs

cd install ||
{
    echo "ERROR: could not cd to install dir - dcps_build_dist";
    exit 2;
}

# Write a list of features enabled to a features file then store to the
# logs section on the scoreboard. Hides any INCLUDE_*=no before writing.
env | grep 'INCLUDE_' | grep -v 'no' | xargs -I % echo % > $LOGDIR/features.txt
cp $LOGDIR/features.txt $OSPL_HOME/etc/features.txt

# Copy list of possible ospli/osplo features done as part of the dcps_build.
if [ -f $OSPL_HOME/all_features.txt ]
then
   cp $OSPL_HOME/all_features.txt $LOGDIR/all_features.txt
fi

#Make a full distro and an eval, then an lgpl
make all_distros

exit 0
