######################## -*- Mode: Makefile-Automake -*- ######################
##
## Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
##
## The contents of this file are covered under the licence agreement in the
## file "LICENCE" distributed with Cforall.
##
## Makefile.am --
##
## Author           : Peter A. Buhr
## Created On       : Sun May 31 09:08:15 2015
## Last Modified By : Peter A. Buhr
## Last Modified On : Mon Jan 25 22:31:42 2016
## Update Count     : 25
###############################################################################

# applies to both programs
CFLAGS =
AM_CFLAGS = -g -Wall -Wno-unused-function -O2
CC = @CFA_BINDIR@/@CFA_NAME@
TOOLSDIR = ${abs_top_srcdir}/tools/
REPEAT   = ${TOOLSDIR}repeat
STATS    = ${TOOLSDIR}stat.py
repeats  = 30
skipcompile = no
TIME_FORMAT = "%E"
PRINT_FORMAT = %20s: #Comments needed for spacing

.NOTPARALLEL:

noinst_PROGRAMS =

all : ctxswitch$(EXEEXT) mutex$(EXEEXT) signal$(EXEEXT) waitfor$(EXEEXT) creation$(EXEEXT)

%.run : %$(EXEEXT) ${REPEAT}
	@rm -f .result.log
	@echo "------------------------------------------------------"
	@echo $<
	@${REPEAT} ${repeats} ./a.out | tee -a .result.log
	@${STATS} .result.log
	@echo "------------------------------------------------------"
	@rm -f a.out .result.log

%.runquiet :
	@+make $(basename $@) CFLAGS="-w"
	@taskset -c 1 ./a.out
	@rm -f a.out

%.make :
	@printf "${PRINT_FORMAT}" $(basename $(subst compile-,,$@))
	@+/usr/bin/time -f ${TIME_FORMAT} make $(basename $@) 2>&1

${REPEAT} :
	@+make -C ${TOOLSDIR} repeat

## =========================================================================================================

jenkins$(EXEEXT):
	@echo "{"
	@echo -e '\t"githash": "'${githash}'",'
	@echo -e '\t"arch": "'   ${arch}   '",'
@DOifskipcompile@
	@echo -e '\t"compile": {'
	@+make compile TIME_FORMAT='%e,' PRINT_FORMAT='\t\t\"%s\" :'
	@echo -e '\t\t"dummy" : {}'
	@echo -e '\t},'
@DOendif@
	@echo -e '\t"ctxswitch": {'
	@echo -en '\t\t"coroutine":'
	@+make ctxswitch-cfa_coroutine.runquiet
	@echo -en '\t\t,"thread":'
	@+make ctxswitch-cfa_thread.runquiet
	@echo -e '\t},'
	@echo -e '\t"mutex": ['
	@echo -en '\t\t'
	@+make mutex-cfa1.runquiet
	@echo -en '\t\t,'
	@+make mutex-cfa2.runquiet
	@echo -e '\t],'
	@echo -e '\t"scheduling": ['
	@echo -en '\t\t'
	@+make signal-cfa1.runquiet
	@echo -en '\t\t,'
	@+make signal-cfa2.runquiet
	@echo -en '\t\t,'
	@+make waitfor-cfa1.runquiet
	@echo -en '\t\t,'
	@+make waitfor-cfa2.runquiet
	@echo -e '\n\t],'
	@echo -e '\t"epoch": ' $(shell date +%s)
	@echo "}"

## =========================================================================================================
ctxswitch$(EXEEXT): \
	ctxswitch-pthread.run		\
	ctxswitch-cfa_coroutine.run	\
	ctxswitch-cfa_thread.run	\
	ctxswitch-upp_coroutine.run	\
	ctxswitch-upp_thread.run	\
	ctxswitch-goroutine.run		\
	ctxswitch-java_thread.run

ctxswitch-cfa_coroutine$(EXEEXT):
	@${CC}        ctxswitch/cfa_cor.c   -DBENCH_N=50000000  -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

ctxswitch-cfa_thread$(EXEEXT):
	@${CC}        ctxswitch/cfa_thrd.c  -DBENCH_N=50000000  -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

ctxswitch-upp_coroutine$(EXEEXT):
	@u++          ctxswitch/upp_cor.cc  -DBENCH_N=50000000  -I. -nodebug -lrt -quiet             ${AM_CFLAGS} ${CFLAGS} ${ccflags}

ctxswitch-upp_thread$(EXEEXT):
	@u++          ctxswitch/upp_thrd.cc -DBENCH_N=50000000  -I. -nodebug -lrt -quiet             ${AM_CFLAGS} ${CFLAGS} ${ccflags}

ctxswitch-pthread$(EXEEXT):
	@@BACKEND_CC@ ctxswitch/pthreads.c  -DBENCH_N=50000000  -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}

ctxswitch-goroutine$(EXEEXT):
	@go build -o a.out ctxswitch/goroutine.go

ctxswitch-java_thread$(EXEEXT):
	@javac ctxswitch/JavaThread.java
	@echo "#!/bin/sh" > a.out
	@echo "cd ctxswitch && java JavaThread" >> a.out
	@chmod a+x a.out

## =========================================================================================================
mutex$(EXEEXT) :\
	mutex-function.run	\
	mutex-fetch_add.run	\
	mutex-pthread_lock.run	\
	mutex-upp.run		\
	mutex-cfa1.run		\
	mutex-cfa2.run		\
	mutex-cfa4.run		\
	mutex-java_thread.run

mutex-function$(EXEEXT):
	@@BACKEND_CC@ mutex/function.c    -DBENCH_N=500000000   -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}

mutex-fetch_add$(EXEEXT):
	@@BACKEND_CC@ mutex/fetch_add.c   -DBENCH_N=500000000   -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}

mutex-pthread_lock$(EXEEXT):
	@@BACKEND_CC@ mutex/pthreads.c    -DBENCH_N=50000000    -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}

mutex-upp$(EXEEXT):
	@u++          mutex/upp.cc        -DBENCH_N=50000000    -I. -nodebug -lrt -quiet             ${AM_CFLAGS} ${CFLAGS} ${ccflags}

mutex-cfa1$(EXEEXT):
	@${CC}        mutex/cfa1.c        -DBENCH_N=5000000     -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

mutex-cfa2$(EXEEXT):
	@${CC}        mutex/cfa2.c        -DBENCH_N=5000000     -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

mutex-cfa4$(EXEEXT):
	@${CC}        mutex/cfa4.c        -DBENCH_N=5000000     -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

mutex-java_thread$(EXEEXT):
	@javac mutex/JavaThread.java
	@echo "#!/bin/sh" > a.out
	@echo "cd mutex && java JavaThread" >> a.out
	@chmod a+x a.out

## =========================================================================================================
signal$(EXEEXT) :\
	signal-pthread_cond.run \
	signal-upp.run		\
	signal-cfa1.run		\
	signal-cfa2.run		\
	signal-cfa4.run		\
	signal-java_thread.run

signal-pthread_cond$(EXEEXT):
	@@BACKEND_CC@ schedint/pthreads.c -DBENCH_N=500000      -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}

signal-upp$(EXEEXT):
	@u++          schedint/upp.cc     -DBENCH_N=5000000     -I. -nodebug -lrt -quiet             ${AM_CFLAGS} ${CFLAGS} ${ccflags}

signal-cfa1$(EXEEXT):
	@${CC}        schedint/cfa1.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

signal-cfa2$(EXEEXT):
	@${CC}        schedint/cfa2.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

signal-cfa4$(EXEEXT):
	@${CC}        schedint/cfa4.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

signal-java_thread$(EXEEXT):
	@javac schedint/JavaThread.java
	@echo "#!/bin/sh" > a.out
	@echo "cd schedint && java JavaThread" >> a.out
	@chmod a+x a.out


## =========================================================================================================
waitfor$(EXEEXT) :\
	waitfor-upp.run		\
	waitfor-cfa1.run		\
	waitfor-cfa2.run		\
	waitfor-cfa4.run

waitfor-upp$(EXEEXT):
	@u++          schedext/upp.cc     -DBENCH_N=5000000     -I. -nodebug -lrt -quiet             ${AM_CFLAGS} ${CFLAGS} ${ccflags}

waitfor-cfa1$(EXEEXT):
	@${CC}        schedext/cfa1.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

waitfor-cfa2$(EXEEXT):
	@${CC}        schedext/cfa2.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

waitfor-cfa4$(EXEEXT):
	@${CC}        schedext/cfa4.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

## =========================================================================================================
creation$(EXEEXT) :\
	creation-pthread.run			\
	creation-cfa_coroutine.run		\
	creation-cfa_coroutine_eager.run	\
	creation-cfa_thread.run			\
	creation-upp_coroutine.run		\
	creation-upp_thread.run			\
	creation-goroutine.run			\
	creation-java_thread.run

creation-cfa_coroutine$(EXEEXT):
	@${CC}        creation/cfa_cor.c   -DBENCH_N=10000000   -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

creation-cfa_coroutine_eager$(EXEEXT):
	@${CC}        creation/cfa_cor.c   -DBENCH_N=10000000   -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} -DEAGER

creation-cfa_thread$(EXEEXT):
	@${CC}        creation/cfa_thrd.c  -DBENCH_N=10000000   -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

creation-upp_coroutine$(EXEEXT):
	@u++          creation/upp_cor.cc  -DBENCH_N=50000000   -I. -nodebug -lrt -quiet             ${AM_CFLAGS} ${CFLAGS} ${ccflags}

creation-upp_thread$(EXEEXT):
	@u++          creation/upp_thrd.cc -DBENCH_N=50000000   -I. -nodebug -lrt -quiet             ${AM_CFLAGS} ${CFLAGS} ${ccflags}

creation-pthread$(EXEEXT):
	@@BACKEND_CC@ creation/pthreads.c  -DBENCH_N=250000     -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}

creation-goroutine$(EXEEXT):
	@go build -o a.out creation/goroutine.go

creation-java_thread$(EXEEXT):
	@javac creation/JavaThread.java
	@echo "#!/bin/sh" > a.out
	@echo "cd creation && java JavaThread" >> a.out
	@chmod a+x a.out

## =========================================================================================================

compile$(EXEEXT) :\
	compile-array.make	\
	compile-attributes.make	\
	compile-empty.make  	\
	compile-expression.make	\
	compile-io.make		\
	compile-monitor.make	\
	compile-operators.make	\
	compile-typeof.make


compile-array$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/array.c				@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-attributes$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/attributes.c			@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-empty$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w compile/empty.c				@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-expression$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/expression.c			@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-io$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/io1.c				@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-monitor$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/concurrent/monitor.c	@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-operators$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/operators.c			@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-thread$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/concurrent/thread.c		@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

compile-typeof$(EXEEXT):
	@${CC} -quiet -fsyntax-only -w ../tests/typeof.c			@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}

