# Configurable variables, will use the following defaults if not set from command line
# Note: Ideally you explicately pass the paths to the dependencies like so:
# make bundles DEPS="-B ee-gripper", but in case you omit this the default is
# to print dependency errors only as warnings
SOURCE_DIR ?= bundles
BUILD_DIR  ?= build
DEPS       ?= --ignore-dependencies

# File handling variables
SRCS    := $(shell find $(SOURCE_DIR) -type f -name 'manifest.json' | sed -r 's|/[^/]+$$||' | sed -r 's|^$(SOURCE_DIR)/||' | sort | uniq)
BUNDLES := $(wildcard $(BUILD_DIR)/*.bundle)

all: bundles

.PHONY: bundles
bundles:
	mkdir -p $(BUILD_DIR)
	for bundle in $(SRCS); do \
		make -s bundle-$$bundle; \
	done

.PHONY: install
install: $(BUNDLES)
	for bundle in $(BUNDLES); do \
		ride bundle install $$bundle; \
	done

bundle-%:
	ride bundle compile $(SOURCE_DIR)/$(@:bundle-%=%) -o $(BUILD_DIR)/$(@:bundle-%=%).bundle $(DEPS)

install-%: bundle-%
	ride bundle install $(BUILD_DIR)/$(@:install-%=%).bundle

.PHONY: clean
clean:
	rm -rf $(BUILD_DIR)
