####################################################
# ------------------------------------------------------------------------
# Minimalistic Makefile
# ------------------------------------------------------------------------
####################################################

SHELL = /bin/sh

CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)

# bandwidth file to use for the simulation. Has effect when the bandwidth distribution algorithm is Jansen
BW_FILE := 2021-12-16-16-41-15-bandwidth-lower

# file, containing circuit building times to evaluate
CB_FILE := onionperf-buildtimes-2021-12-13-2021-12-19.csv

# algorithm for bandwidth distribution. Anything other than "komlo" will default to the Jansen algorithm
BW_ALGO := jansen

export CURRENT_UID
export CURRENT_GID
export BW_FILE
export CB_FILE
export BW_ALGO

all: clean build run

attach:
	docker-compose exec -u walkingo walking_onions screen -rd

build:
	mkdir -p docker/datasets
	cp -av Dockerfile.in docker/Dockerfile
	cp -av wo_docker_start.in docker/wo_docker_start
	chmod 755 docker/wo_docker_start
	cp -av *.py docker/
	cp -av analysis/*.py docker/
	cp -av datasets/* docker/datasets/
	echo "deflogin off" > docker/.screenrc
	docker-compose build

clean:
	docker-compose down || true
	rm -rf docker

debug: clean build run
	docker-compose exec -u walkingo walking_onions bash

docs:
	python3 -m pydoc -p 8080 -b simulator

plots: clean build run
	docker-compose exec -u walkingo walking_onions /bin/bash -c "cd logdir && ../parselogs.py *.log"
	docker-compose exec -u walkingo walking_onions /bin/bash -c "cd logdir && ../plotdats.py"
	docker-compose exec -u walkingo walking_onions /bin/bash -c "cd logdir && ../plotonionperf.py"
	docker-compose exec -u walkingo walking_onions /bin/bash -c "./plotbandwidth.py logdir"
	docker-compose exec -u walkingo walking_onions /bin/bash -c "./plotdist.py logdir"

run:
	mkdir -p logdir
ifeq (,$(wildcard logdir/run_sims))
	cp run_sims.in logdir/run_sims
	chmod 755 logdir/run_sims
endif
	docker-compose up -d

uml:
	pyreverse -o svg -p simulator .