#!/usr/bin/make -f

#
# \brief  Tool for preparing and updating ports
# \author Martin Stein
# \date   2016-02-03
#

ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif

export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..)

include $(GENODE_DIR)/tool/ports/mk/common.inc

usage:
	@echo
	@echo "Tool for preparing and updating ports"
	@echo
	@echo "usage:"
	@echo
	@echo "  $(notdir $(MAKEFILE_LIST)) [-j<n>] <ports>"
	@echo
	@echo "  -j<n>     prepare <n> ports in parallel at a max, default is 1"
	@echo
	@echo "  <ports>   whitespace-separated list of ports"
	@echo

TARGETS = $(sort $(MAKECMDGOALS))

.PHONY: $(TARGETS)

#
# Protect the GENODE_DIR Git repository by creating an
# empty Git repository in CONTRIB_DIR. This is to catch
# Git tools called by port recipes from falling through
# the parent directories of PORT_DIR and affecting other
# Git repositories.
#
$(PORT_DIR): $(CONTRIB_DIR)/.git/HEAD
$(CONTRIB_DIR)/.git/HEAD:
	@$(VERBOSE)mkdir -p $(CONTRIB_DIR)
	@$(VERBOSE)git init --quiet $(CONTRIB_DIR)

$(TARGETS): $(CONTRIB_DIR)/.git/HEAD
	@$(MAKE) -f $(GENODE_DIR)/tool/ports/mk/prepare_single_port.mk $@
