#!/bin/bash

source ./set_version

if [ -e build_version_override ] ; then
  #
  # If build_version_override exists, the build is being made from a
  # host software source package. We'll get the HOST_SW_VERSION_STRING value
  # from it, then append "-manual" to indicate that this is a manual build
  # from a source package.
  #
  # Software built from this source package will now have a version
  # number that identifies it has been locally built, and which
  # source package it came from.
  #
  export HOST_SW_VERSION_STRING="${HOST_SW_VERSION_STRING}-manual"
else
  # Generate the version header for the user space application
  COMMON_SCRIPT_DIR=../../../common/scripts
  COMMON_BASE_DIR=../../../common/linux

  # Check for optional argument that specifies the path of python to use
  PYTHON=python
  if [ $# -gt 0 ] ; then
    PYTHON=$1
    echo "Using parameter 1 ($PYTHON) as path to python"
  fi

  if ! $PYTHON $COMMON_SCRIPT_DIR/generate_version_header.py $COMMON_SCRIPT_DIR/tera_version.h.in $COMMON_BASE_DIR/inc/tera_version.h 1; then
    echo "Failed to generate tera_version.h"
    exit 1
  fi
fi

echo "Building Daemon"
pushd ../daemon
make clean
make REVISION=$HOST_SW_VERSION_STRING PUSH_TOPO=$PUSH_TOPO
popd

echo "Building Host SW"
make clean
make CONFIG=Release REVISION=$HOST_SW_VERSION_STRING PUSH_TOPO=$PUSH_TOPO

echo "Done"

