##############################################################################
# Copyright (c) 2000-2018 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
#
# Contributors:
#   Balasko, Jeno
#   Szabados, Kristof
#   Szabo, Bence Janos
#
##############################################################################
TOPDIR := ../../
include   $(TOPDIR)/Makefile.regression

#FILES := oi.ttcn oi_before1.cfg oi_before2.cfg oi_before3.cfg oi_before4.cfg oi_after1.cfg oi_after2.cfg   oi1_before1.cfg  oi1_after1.cfg oi1_after2.cfg oi1_after3.cfg oi2.cfg oi22.cfg oi23.cfg oi_last1.cfg oi_last2.cfg oi_last3.cfg oi_after_list1.cfg oi_after_list2.cfg oi2_nomacro.cfg oi_include_interference.cfg oi_subfolder1.cfg
FILES := oi.ttcn 
RUNNABLE := oi

CFGS := oi_before1.cfg oi_before2.cfg oi_before3.cfg oi_before4.cfg oi_after1.cfg oi_after2.cfg oi_last1.cfg oi_last2.cfg oi_last3.cfg oi_after_list1.cfg oi_after_list2.cfg oi_include_interference.cfg oi_subfolder1.cfg  oi_before5.cfg  oi_include_mix.cfg

DIR_SINGLE := dir_single_mode
DIR_PARALLEL := dir_parallel_mode
GENERATED_DIRS := $(DIR_SINGLE) $(DIR_PARALLEL) 

COVERAGE_FLAG := 
ifeq ($(COVERAGE), yes)
  COVERAGE_FLAG += -C
endif

ifdef DYN
ifeq ($(PLATFORM), WIN32)
  export PATH:=$(PATH):$(TTCN3_DIR)/lib:$(ABS_SRC)/$(DIR_SINGLE):$(ABS_SRC)/$(DIR_PARALLEL):
else
  export LD_LIBRARY_PATH:=$(LD_LIBRARY_PATH):$(ABS_SRC)/$(DIR_SINGLE):$(ABS_SRC)/$(DIR_PARALLEL):
endif 
endif

MAKE_PROG := $(MAKE)

# List of fake targets:
.PHONY: all clean run run_single run_parallel runall

all: $(GENERATED_DIRS)

dir_single_mode:
	mkdir $@
	cd $@ && for file in $(FILES); do ln -s ../$$file || exit; done
	cd $@ && $(TTCN3_DIR)/bin/ttcn3_makefilegen $(COVERAGE_FLAG) $(SPLIT_FLAG) $(RT2_FLAG) -s ./* && $(MAKE_PROG)
	
dir_parallel_mode:
	mkdir $@
	cd $@ && for file in $(FILES); do ln -s ../$$file || exit; done
	cd $@ && $(TTCN3_DIR)/bin/ttcn3_makefilegen $(COVERAGE_FLAG) $(SPLIT_FLAG) $(RT2_FLAG) ./* && $(MAKE_PROG)

run: clean run_single run_parallel

#run: $(GENERATED_DIRS)
#	cd $(DIR_SINGLE) && ./$(RUNNABLE) $(CFG) 
#	cd $(DIR_PARALLEL) && for C in $(CFGS); do $(TTCN3_DIR)/bin/ttcn3_start $(RUNNABLE) $$(C) || exit; done

# To run all tests, possibly in parallel
run_single: $(DIR_SINGLE) 
	cd $(DIR_SINGLE) && for C in $(CFGS); do ./$(RUNNABLE) ../$$C || exit; done
        
run_parallel: $(DIR_PARALLEL) 
	cd $(DIR_PARALLEL) && for C in $(CFGS); do $(TTCN3_DIR)/bin/ttcn3_start $(RUNNABLE) ../$$C || exit; done

runall: run_single run_parallel 

clean distclean:
	rm -rf $(GENERATED_DIRS)

