#--*- Makefile -*--

# A makefile to generate test profiler statistics

NO_TAINT_CHECK_DIR = tests/no-taint-checks
NYTPROF_DIR = $$(pwd)/nytprof

PERL_SCRIPTS = $(wildcard ${BIN_DIR}/*.pl)

NO_TAINT_CHECK_SCRIPTS = ${PERL_SCRIPTS:${BIN_DIR}/%=${NO_TAINT_CHECK_DIR}/%}

.PHONY: pdisplay

pdisplay:
	@echo ${} | tr " " "\n"

${NO_TAINT_CHECK_DIR}/%.pl: ${BIN_DIR}/%.pl
	perl -pe 's,#!\s*/usr/bin/perl\s+-T.*,#! /usr/bin/perl,' $< > $@
	chmod 755 $@

.PHONY: profiler

profiler: ${NO_TAINT_CHECK_SCRIPTS}
	rm -rf ${NYTPROF_DIR}/*
	PERL5OPT=-d:NYTProf \
	NYTPROF=addpid=1:file=${NYTPROF_DIR}/nytprof.out:forkdepth=0:slowops=0 \
	${MAKE} BIN_DIR=${NO_TAINT_CHECK_DIR} clean tests
	nytprofmerge -out ${NYTPROF_DIR}/nytprof-merged.out \
	                  ${NYTPROF_DIR}/nytprof.out.*
	nytprofhtml --file ${NYTPROF_DIR}/nytprof-merged.out
	${MAKE} cleantemporary

cleantemporary:
	rm -f ${NYTPROF_DIR}/nytprof.out.*
	rm -f ${NYTPROF_DIR}/nytprof-merged.out

distclean: cleantainted
