# Makefile at top of application tree
TOP = .
include $(TOP)/configure/CONFIG

# Directories to build, any order
DIRS += configure
DIRS += $(wildcard *Sup)
DIRS += $(wildcard *App)
DIRS += $(wildcard *Top)
DIRS += $(wildcard iocBoot)

# The build order is controlled by these dependency rules:

# All dirs except configure depend on configure
$(foreach dir, $(filter-out configure, $(DIRS)), \
    $(eval $(dir)_DEPEND_DIRS += configure))

# Any *App dirs depend on all *Sup dirs
$(foreach dir, $(filter %App, $(DIRS)), \
    $(eval $(dir)_DEPEND_DIRS += $(filter %Sup, $(DIRS))))

# Any *Top dirs depend on all *Sup and *App dirs
$(foreach dir, $(filter %Top, $(DIRS)), \
    $(eval $(dir)_DEPEND_DIRS += $(filter %Sup %App, $(DIRS))))

# iocBoot depends on all *App dirs
iocBoot_DEPEND_DIRS += $(filter %App,$(DIRS))

# Add any additional dependency rules here:

include $(TOP)/configure/RULES_TOP

UNINSTALL_DIRS += $(wildcard $(INSTALL_LOCATION)/python*)

# Docker rules
DOCKER_EPICS_VERSION ?= 7.0.7
DOCKER_IMAGES = epics_marmon_env marmon

.PHONY: docker
docker: $(DOCKER_IMAGES)

%: Dockerfile.%
	docker build \
		-t lbnl-atg/$*:$(DOCKER_EPICS_VERSION) \
		-t lbnl-atg/$*:latest \
		--build-arg EPICS_VERSION=$(DOCKER_EPICS_VERSION) \
		--build-arg BUILD_VERSION=0.0.1 \
		--build-arg BUILD_DATE=$(shell date +\"%Y-%m-%dT%H:%M:%S%z\") \
		-f $< \
		.
