#****h* ACCC/Makefile
# NAME
#  Makefile
# DESCRIPTION
#  Makefile to generate the data for ACCC (Adaptive Cruise Control of Constant dynamics) benchmark
#
# USAGE
#  make
#
#******
DIMENSIONS = 5 10 15
MODELS=$(DIMENSIONS:%=./models/ACCC_%.dot)
LENGTH = 10 $(shell seq 25 25 100) $(shell seq 200 100 1000)
REPEATS = $(shell seq 1 30)
LOGS = $(foreach length,$(LENGTH),$(foreach repeat,$(REPEATS),./logs/ACCC_5-$(length)-$(repeat).txt)) $(foreach repeat,$(REPEATS),$(foreach dimension, $(DIMENSIONS), ./logs/ACCC_$(dimension)-10-$(repeat).txt))

all: ACCC.zip

ACCC.zip: $(MODELS) $(LOGS)
	zip $@ $^

ARCH-COMP-master-2019-HBMC-BACH-Motorcade.zip:
	wget "https://gitlab.com/goranf/ARCH-COMP/-/archive/master/ARCH-COMP-master.zip?path=2019%2FHBMC%2FBACH%2FMotorcade" -O ARCH-COMP-master-2019-HBMC-BACH-Motorcade.zip

motorcar_%.xml: ARCH-COMP-master-2019-HBMC-BACH-Motorcade.zip
	unzip $< ARCH-COMP-master-2019-HBMC-BACH-Motorcade/2019/HBMC/BACH/Motorcade/$@
	mv ARCH-COMP-master-2019-HBMC-BACH-Motorcade/2019/HBMC/BACH/Motorcade/$@ $@
	rmdir ARCH-COMP-master-2019-HBMC-BACH-Motorcade/2019/HBMC/BACH/Motorcade/
	rmdir ARCH-COMP-master-2019-HBMC-BACH-Motorcade/2019/HBMC/BACH/
	rmdir ARCH-COMP-master-2019-HBMC-BACH-Motorcade/2019/HBMC/
	rmdir ARCH-COMP-master-2019-HBMC-BACH-Motorcade/2019/
	rmdir ARCH-COMP-master-2019-HBMC-BACH-Motorcade

define GENLOG

./logs/%-$(1)-$(2).txt: ./models/%.dot ../../build/hamoni-sim
	mkdir -p ./logs
	../../build/hamoni-sim -f $$< -l $(1) > $$@

endef

$(foreach length, $(LENGTH), $(foreach repeat, $(REPEATS), $(eval $(call GENLOG,$(length),$(repeat)))))

./models/ACCC_%.dot: motorcar_%.xml
	mkdir -p ./models
	saxon -xsl:hamoni.xsl $< | sed 's/x_1\([^0-9]\)/x0\1/g;s/x_2/x1/g;s/x_3/x2/g;s/x_4/x3/g;s/x_5/x4/g;s/x_6/x5/g;s/x_7/x6/g;s/x_8/x7/g;s/x_9/x8/g;s/x_10/x9/g;s/x_11/x10/g;s/x_12/x11/g;s/x_13/x12/g;s/x_14/x13/g;s/x_15/x14/g;s/==\([0-9]*\)\./ * 10 == \1/g' > $@

clean:
	$(RM) -r logs models ARCH-COMP-master-2019-HBMC-BACH-Motorcade.zip
