.PHONY: builder init deps all

DEPS=utsusemi-deps
BASE_PKGS = mxml cycler kiwisolver python2-matplotlib manyo
DOCKER_IMAGE ?= builder
CONTAINER ?= builder

all: deps manyo utsusemi037 utsusemi4

deps: nexus matplotlib python2-matplotlib

builder:
	# Dockerイメージのビルド
	docker build -t $(DOCKER_IMAGE) $(CURDIR)/docker

init: builder
	# Dockerコンテナの起動を確認して、起動していなければ起動する
	if [ -z "$(shell docker ps -f name=$(CONTAINER) -q)" ]; then\
		docker run --rm -tid -v $(CURDIR):/tmp/src --name $(CONTAINER) $(DOCKER_IMAGE);\
	fi

$(BASE_PKGS): init
	$(MAKE) -C $(DEPS)-$@

nexus: mxml
	$(MAKE) -C $(DEPS)-nexus

matplotlib: cycler kiwisolver
	$(MAKE) -C $(DEPS)-matplotlib

utsusemi037:
	$(MAKE) -C utsusemi 0.3.7

utsusemi4:
	$(MAKE) -C utsusemi 4.0.0

clean:
	for n in $(BASE_PKGS) nexus matplotlib; do\
		$(MAKE) -C $(DEPS)-$$n clean;\
	done
	$(MAKE) -C utsusemi clean

