#!/bin/bash
#
# This script is to be executed at the top of a project area
# with the proper release setup via cm_setup.sh.
#
# It will figure out which submodules have changed in the last
# commit, update them and then build them all together against
# the release.
#
show=0
since="HEAD~"
while [ $# -gt 0 ]
do
    case $1 in
        --show)
            show=1
            shift
            ;;
        --since=*)
            since=${1#--since=}
            shift
            ;;
        *)
            break
            ;;
    esac
done

[ -f CMakeLists.txt ] || { echo "No CMakeLists.txt: you should run this in a project area"; exit 1; }
pkgs=$(git diff --submodule ${since} | grep '^Submodule '| cut -d' ' -f2 | tr '\n' ' ')
[ ${show} -eq 1 ] && { echo ${pkgs}; exit 0; }
[ -z "${pkgs}" ] && exit 0
prepare_patches --no-rpms ${pkgs}

