#!/usr/bin/env bash
# Copyright (c) 2017-2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Output a Make fragment that builds the dars in the _fixtures/src directory.

root_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../.. >/dev/null 2>&1 && pwd )"
cd $root_dir

dar_dirs=$(find _fixtures/src -mindepth 1 -maxdepth 1 | sort)
dars=$(for dar_dir in $dar_dirs; do echo -n " $dar_dir/.daml/dist/$(basename $dar_dir)-1.0.0.dar"; done)

echo ".PHONY: dars"
echo "dars:$dars"
for dar_dir in $dar_dirs; do
    echo 
    echo $dar_dir/.daml/dist/$(basename $dar_dir)-1.0.0.dar: $dar_dir/daml.yaml $(find $dar_dir -name *.daml -type f)
    echo -e "\tcd \$(<D) && daml build"
done
