#######################################################################
# Copyright (C) 2021-2022 Nicolas Feral and Alain Giorgetti           #
# FEMTO-ST institute                                                  #
#######################################################################

#######################################################################
#  This software is distributed under the terms of the GNU Lesser     #
#  General Public License version 2.1                                 #
#######################################################################

# This file provides targets to install and use a virtual machine
# (a 'container' in docker terminology) with Why3 and Cubicle.

.PHONY: build ctr ctrmac start

build: Dockerfile
	docker pull registry.gitlab.inria.fr/why3/why3:1.4.0
	docker tag registry.gitlab.inria.fr/why3/why3:1.4.0 why3
	docker build --tag why3_cubicle_sv:latest .

# For Unix and Linux. Warning: sometimes 'make ctr' does not work. Then run 'bash ./ctr.sh' directly!
ctr:
	# Uncomment next line if the container already exists
	# docker container rm why3_cubicle_SV_ctr
	bash ./ctr.sh

# For MacOS. Warning: sometimes 'make ctrmac' does not work. Then run 'bash ./ctrmac.sh' directly!
ctrmac:
	# Uncomment next line if the container already exists
	# docker container rm why3_cubicle_SV_ctr
	bash ./ctrmac.sh

# For more safety xhost is opened only to the container hostname, retrieved by
# the command
# docker inspect --format='{{ .Config.Hostname }}.
start:
	@-xhost +local:`docker inspect --format='{{ .Config.Hostname }}' why3_cubicle_SV_ctr` >> /dev/null
	docker start --attach --interactive why3_cubicle_SV_ctr

