#!/bin/bash

function do_subdirs
{
	local subdirs="zafl"
	local my_cwd=$PWD

	for subdir in $subdirs
	do
		cd $subdir
		if [[ -x ./get-packages.sh ]]; then
			./get-packages.sh "$@"
		fi
	done
}

function main()
{

	local here_dir=$(pwd)
	local grpc_packs="build-essential autoconf libtool pkg-config"

	do_subdirs "$@"


	sudo apt install -y $grpc_packs


	cd $here_dir/third-party/grpc
	if [[ ! -x third_party/protobuf/src/protoc ]] && [[ ! -x /usr/local/bin/protoc ]] ; then
		if [[ ! -f Makefile ]]; then
			cmake .
		fi
		make -j 3

		cd $here_dir/third-party/grpc/third_party/protobuf
		pwd
		sudo make install

		cd $here_dir/third-party/grpc
		pwd
		sudo make install
	fi

	cd $here_dir

}

main "$@"
