#!/bin/sh
# Copyright 2010-2018 FARGOS Development, LLC
# Build named components
# $Id$
subtreePrefix="${SB_SOURCE_SUBTREE}"
targets=""
while test $# -gt 0
do
	case "${1}" in
	-h | -help | --help)
		printf "usage: %s [args] [-j jobs] [--subtree prefix] componentName [...]\n" "${0}" >&2
		printf " --subtree defaults to SB_SOURCE_SUBTREE=%s\n" "${SB_SOURCE_SUBTREE}" >&2
		exit 1
		;;
	-subtree | --subtree)
		subtreePrefix="${2}"
		shift
		;;
	-j)
		args="${args}${args:+ }-j ${2}"
		shift
		;;
	-*)
		args="${args}${args:+ }${1}"
		;;
	*)
		targets="${targets}${targets:+ }${1}"
		;;
	esac
	shift
done

for component in ${targets}
do
	mkdir -p "${STS}${subtreePrefix}/${component}"
	cd "${STS}${subtreePrefix}/${component}"
	sbmake ${args}
done
