.DEFAULT_GOAL := all
FLAGS := --privileged

UNAME := $(shell uname)
ifeq ($(UNAME),Linux)
	FLAGS += -e DISPLAY=$$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix
endif
ifeq ($(UNAME),Darwin)
	FLAGS += -e DISPLAY=docker.for.mac.localhost:0
endif

all:
	docker network create nwA --subnet=10.0.0.0/24
	docker network create nwB --subnet=10.1.0.0/24
	docker network create nwC --subnet=10.2.0.0/24
	$(MAKE) create NAME=client NW=nwA IMG=ieng:3
	$(MAKE) create NAME=routerA NW=nwB IMG=ieng:3
	$(MAKE) create NAME=routerB NW=nwC IMG=ieng:3
	$(MAKE) create NAME=serverA NW=nwC IMG=ieng:4
	$(MAKE) create NAME=serverB NW=nwC IMG=ieng:5
	$(MAKE) create NAME=serverC NW=nwC IMG=ieng:6

create:
	docker run -itd --name ${NAME} --hostname=${NAME} $(FLAGS) --net=${NW} ${IMG} /bin/bash

clean:
	-docker rm client routerA routerB serverA serverB serverC --force
	-docker network rm nwA nwB nwC
