#
# Copyright (c) 2012-2015 Red Hat.
# Copyright (c) 2009 Aconex.  All Rights Reserved.
# Copyright (c) 1997-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

#DBG    = -DPCP_DEBUG -DDEBUG -DMALLOC_AUDIT -g
DBG     = -DPCP_DEBUG -DDEBUG -g

DEBUG   = $(DBG)

HAVE_64	= $(shell test `uname -m | sed -e 's/.*64/64/g'` = "64" && echo 1 || echo 0)

SRCARCH	= mirage.0 moomba.client.0 \
	babylon.percpu.0 babylon.percpu_v2.0 \
	omen.client.0 bozo.client.0 bozo.client_v2.0 \
	late.0 ok-bigbin.0 ok-mv-bigbin.0 ok-truncbin.0 \
	babylon.pmview.0 babylon.pmview_v2.0 ok-foo.0 ok-mv-foo.0 \
	bug.0 bug_v2.0 ace.0 ace_v2.0 bigace.0 bigace_v2.0 \
	951127.23.01.0 951127.23.01_v2.0 960624.08.17.0 960624.08.17_v2.0 \
	rattle.0 mark-bug.0 arch_a.0 arch_b.0 \
	err_v1.0 changeinst.0 19970807.09.54.0 19970807.09.59.0 \
	binning.0 wrap.0 573184.0 xbug1.0 pcpcmd.0 markmerge.0 \
	sample-secs.0 gmt-boring.0 kenj-pc-1.0 kenj-pc-2.0 \
	reduce-1.0 reduce-2.0 kenj-pc-diskstat.0 snort-disks.0 \
	vldb-disks.0 moomba.pmkstat.0 fcsw_indom.0 \
	uwrap.0 20041125.0 ac15.0 conn20070309.0 logsummary-bug.0 \
	tzchange-10-a.0 tzchange-10-b.0 tzchange-11-a.0 tzchange-11-b.0 \
	tzchange-12-a.0 tzchange-12-b.0 sample_expr.0 \
	mirage-1.0 mirage-2.0 eventrec-old.0 eventrec.0 \
	540117-short.0 541380.0 541380_v2.0 573184.0 20101004-trunc.0 \
	bozo.client_v2.meta.bad.1 bozo.client_v2.meta.bad.2 \
	rewrite.0 proc.0 section-a.0 section-b.0 section-c.0 section-d.0 \
	interpmark.0 all-irix-6.5.25.0 all-sles9-sp1.0 naslog.0 \
	multi-vm00.0 multi-vm01.0 multi-vm02.0 multi-vm03.0 pmatop-log.0 \
	new_mysql.0 new_snmp.0 old_xfs.0 node_archive.0 count-mark.0 \
	pyapi.0 pcp-free.0 pcp-uptime.0 pcp-numastat-1-node.0 numa.0 \
	bug1057.0

SRCARCHPART = ok-noti-bigbin.0 pmatop-log.folio \
	20130706.0.bz2 20130706.index 20130706.meta

MKARCH	= foo.0 mv-foo.0 noti-foo.0 bar.0 mv-bar.0 noti-bar.0 \
	bigbin.0 mv-bigbin.0 noti-bigbin.0 truncbin.0 null.0 \
	interp.0 mv-interp.0 noti-interp.0 noti-ok-foo.0 gap.0 gap2.0 \
	dodgey-some.0 dodgey-all.0 dodgey-mixed.0 reduce-gap.0

CFILES = disk_test.c exercise.c context_test.c chkoptfetch.c \
	xval.c xxx.c chkopenlog.c chkconnect.c t_fetch.c \
	hp-mib.c agenttimeout.c chkctx2.c pmcdgone.c chkhelp.c \
	scale.c chktrim.c store.c torture_api.c logcontrol.c xlog.c \
	hex2nbo.c chknumval.c xarch.c eofarch.c defctx.c chkacc1.c chkacc2.c \
	chkacc3.c storepast.c pmdashutdown.c exertz.c badpmcdpmid.c \
	permfetch.c archinst.c pmlcmacro.c whichtimezone.c eol.c \
	interp0.c interp1.c interp2.c interp3.c interp4.c \
	pcp_lite_crash.c compare.c mkfiles.c nameall.c nullinst.c \
	storepdu.c fetchpdu.c badloglabel.c interp_bug2.c interp_bug.c \
	xmktime.c descreqX2.c recon.c torture_indom.c \
	fetchrate.c stripmark.c pmnsinarchives.c \
	endian.c chk_memleak.c chk_metric_types.c mark-bug.c \
	pmnsunload.c parsemetricspec.c parseinterval.c \
	pducheck.c pducrash.c pdu-server.c \
	pmprintf.c pmsocks_objstyle.c numberstr.c \
	read-bf.c write-bf.c slow_af.c indom.c tztest.c \
	multifetch.c pmconvscale.c torture-eol.c \
	crashpmcd.c dumb_pmda.c torture_cache.c wrap_int.c \
	matchInstanceName.c torture_pmns.c \
	mmv_genstats.c mmv_instances.c mmv_poke.c mmv_noinit.c mmv_nostats.c \
	record.c record-setarg.c clientid.c killparent.c grind_ctx.c \
	pmdacache.c check_import.c unpack.c hrunpack.c aggrstore.c atomstr.c \
	grind_conv.c getconfig.c err.c torture_logmeta.c keycache.c \
	keycache2.c pmdaqueue.c drain-server.c template.c anon-sa.c \
	username.c rtimetest.c getcontexthost.c badpmda.c chkputlogresult.c \
	churnctx.c badUnitsStr_r.c units-parse.c rootclient.c \
	lookupnametest.c getversion.c

ifeq ($(shell test -f ../localconfig && echo 1), 1)
include ../localconfig
else
ifeq ($(shell cd ..; ( $(MAKE) localconfig >/dev/null && echo 1 )), 1)
include ../localconfig
else
$(error Cannot make qa/localconfig)
endif
endif

ifeq ($(shell test $(PCP_VER) -ge 3600 && echo 1), 1)
CFILES += multithread0.c multithread1.c multithread2.c multithread3.c \
	multithread4.c multithread5.c multithread6.c multithread7.c \
	multithread8.c multithread9.c \
	exerlock.c
else
MYFILES += multithread0.c multithread1.c multithread2.c multithread3.c \
	multithread4.c multithread5.c multithread6.c multithread7.c \
	multithread8.c multithread9.c \
	exerlock.c
LDIRT += multithread0 multithread1 multithread2 multithread3 \
	multithread4 multithread5 multithread6 multithread7 \
	multithread8 multithread9 \
	exerlock
endif

ifeq ($(shell test $(PCP_VER) -ge 3700 && echo 1), 1)
CFILES += hashwalk.c
else
MYFILES += hashwalk.c
LDIRT += hashwalk
endif

ifeq ($(shell test $(PCP_VER) -ge 3800 && echo 1), 1)
CFILES += parsehostattrs.c parsehostspec.c check_import_name.c
else
MYFILES += parsehostattrs.c parsehostspec.c check_import_name.c
LDIRT += parsehostattrs parsehostspec check_import_name
endif

ifeq ($(shell test $(PCP_VER) -ge 3802 && echo 1), 1)
CFILES += chkacc4.c
else
MYFILES += chkacc4.c
LDIRT += chkacc4
endif

ifeq ($(shell test $(PCP_VER) -ge 3901 && echo 1), 1)
CFILES += getoptions.c
else
MYFILES += getoptions.c
LDIRT += getoptions
endif

ifeq ($(shell test $(PCP_VER) -ge 3811 && echo 1), 1)
CONFIG_INTERP = config2.interp
else
CONFIG_INTERP = config1.interp
endif

ifeq ($(shell test -f /usr/include/pcp/fault.h && echo 1), 1)
# only make these ones if the fault injection version of libpcp
# appears to have been installed (assumes PCP >= 3.5), and then
# only for the setup target (so not in the build)
#
XTRATARGETS += check_fault_injection exercise_fault
endif
MYFILES += check_fault_injection.c exercise_fault.c
LDIRT += check_fault_injection exercise_fault

POSIXFILES = \
	ipc.c proc_test.c context_fd_leak.c arch_maxfd.c torture_trace.c \
	779246.c 

TRACEFILES = \
	obs.c tstate.c tabort.c 

PERLFILES = \
	batch_import.perl check_import.perl import_limit_test.perl
# not installed:
PLFILES = $(shell echo $(PERLFILES) | sed -e 's/\.perl/.pl/g')

ifeq "$(HAVE_PYTHON)" "true"
PYTHONFILES = \
	test_pcp.python test_pmcc.python \
	test_pmi.python check_import.python \
	test_mmv.python test_webapi.python \
	test_pcp_options.python test_pcp_getopts.python \
	test_pcp_time.python test_pmnswalk.python \
	pmapi_exceptions.python
# not installed:
PYFILES = $(shell echo $(PYTHONFILES) | sed -e 's/\.python/.py/g')
else
PYTHONFILES =
PYFILES =
endif

ifneq "$(TARGET_OS)" "mingw"
CFILES += $(POSIXFILES) $(TRACEFILES)
else
MYFILES += $(POSIXFILES) $(TRACEFILES)
endif

MYFILES += $(SRCARCH) \
	$(patsubst %.0,%.meta,$(SRCARCH)) $(patsubst %.0,%.index,$(SRCARCH)) \
	ok-mv-bigbin.[1-9] ok-mv-foo.[12] \
	$(SRCARCHPART) \
	ok-noti-bigbin.meta err_v1.dump \
	bigace.pmns \
	config.bar config.bigbin config.dodgey-all config.dodgey-mixed \
	config.dodgey-some config.foo config1.interp config2.interp \
	kenj-pc-2.config reduce.config uwrap.config wrap.config \
	root_irix root_pmns tiny.pmns sgi.bf versiondefs \
	simple.csv simple.ods simple-resave.csv simple-resave.xlsx \
	simple.sxc simple.xls simple.xlsx \
	iostat iostat-c iostat-d iostat-d-k iostat-d-m iostat-p-ALL \
	iostat-t iostat-t.ISO iostat-x iostat-z iostat-z-p-ALL \
	iostat-t-x-bud \
	pthread_barrier.h pv.c qa_test.c qa_timezone.c \
	sa-sysstat-9.0.4 sa-sysstat-9.0.6 sa-sysstat-9.0.6.1 \
	sa-sysstat-10.0.1 sa-sysstat-10.0.5 sa-sysstat-10.2.0 \
	sa-sysstat-9.0.4_rh6.5 \
	permslist \
	qa_shmctl.c

MYSCRIPTS = grind-tools ipcs_clear make.dodgey mkarch-all \
	mkeventrec mkinterpmark mkmirage mkproc mkrewrite mksample_expr \
	mksa-sysstat mktzchange show-args mkbig1 fixhosts mkpermslist \
	memcachestats.pl

PSCRIPTS = $(PERLFILES) $(PYTHONFILES)

CFILES_TARGETS = $(CFILES)

TARGETS = $(subst broken_pmda,,$(basename $(CFILES_TARGETS))) \
	chkctx2_lite template \
	fetchrate_lite pv

ifeq "$(TARGET_OS)" "linux"
TARGETS += qa_shmctl.$(DSOSUFFIX)
endif

ifeq ($(HAVE_64), 1)
TARGETS	+= pv64
endif

LCFLAGS = -DHAVE_TRACE
LLDLIBS	= $(LDFLAGS) $(PCPLIB)

ifneq ($(NVIDIAQALIB),)
LIBTARGET = true
MYCFILES += nvidia-ml.c
LCFLAGS += $(NVIDIACFLAGS)
TARGETS += $(NVIDIAQALIB)
endif

# libpcp_trace is ready
TRACELIB	= $(LLDLIBS) -lpcp_trace

# all archives, except the ones checked into the source tree,
# then add executables beyond $(TARGETS)
#
LDIRT	+= *.log domain.h help.pag help.dir \
	foo.0 foo.index foo.meta \
	mv-foo.[0-9] mv-foo.index mv-foo.meta \
	noti-foo.0 noti-foo.meta \
	bar.0 bar.index bar.meta \
	big[0-2].[0-2] big[0-2].index big[0-2].meta \
	mv-bar.[0-9] mv-bar.index mv-bar.meta \
	noti-bar.0 noti-bar.meta \
	bigbin.0 bigbin.index bigbin.meta \
	mv-bigbin.[0-9] mv-bigbin.index mv-bigbin.meta \
	noti-bigbin.0 noti-bigbin.meta \
	truncbin.0 truncbin.index truncbin.meta \
	null.0 null.index null.meta \
	interp.0 interp.index interp.meta \
	mv-interp.[0-9] mv-interp.index mv-interp.meta \
	noti-interp.0 noti-interp.meta \
	noti-ok-foo.0 noti-ok-foo.meta \
	gap.0 gap.index gap.meta \
	gap2.0 gap2.index gap2.meta \
	dodgey-some.0 dodgey-some.index dodgey-some.meta \
	dodgey-all.0 dodgey-all.index dodgey-all.meta \
	dodgey-mixed.0 dodgey-mixed.index dodgey-mixed.meta \
	reduce-gap.0 reduce-gap.index reduce-gap.meta \
	chkctx2_lite.c fetchrate_lite.c \
	localconfig.h gmon.out \
	$(TARGETS)

.ORDER:	torture_api \
	chkctx2 fetchrate

default default_pcp: \
	$(CFILES_TARGETS) $(TARGETS) \
	$(SRCARCH) $(SRCARCHPART) \
	$(PLFILES) $(PYFILES) \
	ipcs_clear

setup: default $(MKARCH) $(XTRATARGETS)

$(TARGETS):

include $(BUILDRULES)

# remove just the binaries, not the archives
#
clean-exec:
	rm -f $(TARGETS)
	rm -f $(OBJECTS)
	rm -f pv64

# remake just the archives, not the binaries
#
clean-arch:
	rm -f $(MKARCH) $(subst 0,meta,$(MKARCH)) $(subst 0,index,$(MKARCH))

OBJECTS = $(shell echo $(CFILES) | sed -e 's/\.c/.o/g')

# make just the archives, not the binaries
#
arch:	$(SRCARCH) $(SRCARCHPART) $(MKARCH)

# --- do NOT need libpcp
#

pause:	pause.c
	$(CCF) $(CDEFS) -o pause pause.c

errmap: errmap.c
	$(CCF) $(CDEFS) -o errmap errmap.c

cpuload:	cpuload.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ cpuload.c

load_o2000:	load_o2000.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ load_o2000.c

chain:	chain.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ chain.c

syscall:	syscall.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ syscall.c

getpagesize:	getpagesize.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ getpagesize.c

rdwr:	rdwr.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ rdwr.c

spawn:	spawn.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ spawn.c

diowr:	diowr.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ diowr.c

endian:	endian.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ endian.c

pmlcmacro:	pmlcmacro.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ pmlcmacro.c

sys5_ipc:	sys5_ipc.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ sys5_ipc.c

stripmark: stripmark.c
	$(CCF) $(CDEFS) -o $@ stripmark.c

anon-sa: anon-sa.c
	$(CCF) $(CDEFS) -o $@ anon-sa.c

# --- need libpcp
#

template:	template.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ template.c $(LDLIBS)

exercise:	exercise.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ exercise.c  $(LDLIBS)

chkacc1:	chkacc1.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ chkacc1.c $(LDLIBS)

chkacc2:	chkacc2.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ chkacc2.c $(LDLIBS)

chkacc3:	chkacc3.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ chkacc3.c $(LDLIBS)

ipc:	ipc.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ ipc.c  $(LDLIBS)

chk_memleak:	chk_memleak.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ chk_memleak.c $(LDLIBS)

chknumval:	chknumval.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ chknumval.c  $(LDLIBS)

logcontrol:	logcontrol.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ logcontrol.c  $(LDLIBS)

numberstr: numberstr.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ numberstr.c $(LDLIBS)

pmcdgone:	pmcdgone.c localconfig.h
	rm -f $@
	$(CCF) $(CDEFS) -o $@ pmcdgone.c  $(LDLIBS)

slow_af:	slow_af.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ slow_af.c  $(LDLIBS)

mmv_poke:	mmv_poke.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ mmv_poke.c $(LDLIBS)

# --- need libpcp but also PM_CONTEXT_LOCAL
#

fetchrate_lite:	fetchrate_lite.c
	rm -f $@
	$(CCF) $(CDEFS) -DLITE=1 -o $@ fetchrate_lite.c $(LDLIBS)

fetchrate_lite.c:	fetchrate.c
	rm -f $@
	ln -s fetchrate.c fetchrate_lite.c

chkctx2_lite:	chkctx2_lite.c
	rm -f $@
	$(CCF) $(CDEFS) -DLITE=1 -o $@ chkctx2_lite.c $(LDLIBS)

chkctx2_lite.c:	chkctx2.c
	rm -f $@
	ln -s chkctx2.c chkctx2_lite.c

hp-mib: hp-mib.c
	rm -f $@
	$(CCF) $(CDEFS) -DLITE=1 -o $@ hp-mib.c $(LDLIBS)

pcp_lite_crash: pcp_lite_crash.c
	rm -f $@
	$(CCF) $(CDEFS) -DLITE=1 -o $@ pcp_lite_crash.c $(LDLIBS)

store: store.c
	rm -f $@
	$(CCF) $(CDEFS) -DLITE=1 -o $@ store.c $(LDLIBS)

# --- need libpcp_pmda
#

domain.h:	$(PCP_VAR_DIR)/pmns/stdpmid
	rm -f $@
	echo "/*" >domain.h
	echo " * built from $(PCP_VAR_DIR)/pmns/stdpmid on `date`" >>domain.h
	echo " */" >>domain.h
	sed -n -e 's/[ 	]*$$//' -e '/define[ 	]BROKEN[ 	]/s/.*[ 	]/#define BROKEN /p' $(PCP_VAR_DIR)/pmns/stdpmid >>domain.h
	sed -n -e 's/[ 	]*$$//' -e '/define[ 	]DYNAMIC[ 	]/s/.*[ 	]/#define DYNAMIC /p' $(PCP_VAR_DIR)/pmns/stdpmid >>domain.h

pmdashutdown:	pmdashutdown.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

dumb_pmda: dumb_pmda.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

pmdacache: pmdacache.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

pmdaqueue: pmdaqueue.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

rootclient: rootclient.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

atomstr: atomstr.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

keycache: keycache.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

keycache2: keycache2.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

badpmda: badpmda.c
	$(CCF) $(LCDEFS) $(LCOPTS) -o $@ $@.c $(LDLIBS) -lpcp_pmda

# --- need libpcp_gui
#

record:	record.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_gui

record-setarg: record-setarg.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_gui

# --- need libpcp_mmv
#
mmv_genstats:	mmv_genstats.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_mmv

mmv_instances:	mmv_instances.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_mmv

mmv_noinit:	mmv_noinit.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_mmv

mmv_nostats:	mmv_nostats.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_mmv

pducheck:	pducheck.o 
	rm -f $@
	$(CCF) $(CDEFS) -o $@ pducheck.o  $(TRACELIB) $(LDLIBS) -lpcp_pmda

pducrash:	pducrash.o 
	rm -f $@
	$(CCF) $(CDEFS) -o $@ pducrash.o  $(TRACELIB) $(LDLIBS)

pdu-server:	pdu-server.o
	rm -f $@
	$(CCF) $(CDEFS) -o $@ pdu-server.o  $(TRACELIB) $(LIBSOL) $(LDLIBS)

torture_cache:	torture_cache.o 
	rm -f $@
	$(CCF) $(CDEFS) -o $@ torture_cache.o $(LDLIBS) -lpcp_pmda

obs:	obs.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ obs.c $(TRACELIB) 

torture_trace:	torture_trace.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ torture_trace.c $(LIB_FOR_PTHREADS) $(TRACELIB) 

tstate:	tstate.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ tstate.c $(TRACELIB) 

tabort:	tabort.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ tabort.c $(TRACELIB) 

# --- need libpcp_import
#

check_import:	check_import.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_import

check_import_name:	check_import_name.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LDLIBS) -lpcp_import

# --- need libpcp_fault
#

check_fault_injection: check_fault_injection.c
	rm -f $@
	$(CCF) $(CDEFS) -DPM_FAULT_INJECTION=1 -o $@ $@.c -lpcp_fault -lpcp -lpcp_pmda

exercise_fault: exercise_fault.c
	rm -f $@
	$(CCF) $(CDEFS) -DPM_FAULT_INJECTION=1 -o $@ $@.c -lpcp_fault -lpcp -lpcp_pmda

# --- need lib for pthreads
#

multithread0:	multithread0.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread1:	multithread1.c
	rm -f $@
ifeq "$(TARGET_OS)" "darwin"
	@# see comments in multithread1.c to explain this crock
	$(CCF) $(CDEFS) -Ddarwin_hack=1 -o $@ $@.c $(LIB_FOR_PTHREADS) -framework CoreFoundation $(LDLIBS)
else
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)
endif

multithread2:	multithread2.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread3:	multithread3.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread4:	multithread4.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread5:	multithread5.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread6:	multithread6.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread7:	multithread7.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread8:	multithread8.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

multithread9:	multithread9.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

exerlock:	exerlock.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ $@.c $(LIB_FOR_PTHREADS) $(LDLIBS)

# --- binary format dependencies
#

ifeq ($(HAVE_64), 1)
pv64: pv.c
	$(CCF) $(CDEFS) -o $@ pv.c $(LDLIBS)
endif

# -- archives
#

foo.0:	config.foo
	rm -f foo.index foo.meta foo.0
	pmlogger -c config.foo -s 8 foo

mv-foo.0:	config.foo
	rm -f mv-foo.index mv-foo.meta mv-foo.?
	pmlogger -c config.foo -s 8 -v 3 mv-foo

noti-foo.0:	foo.0
	cp foo.0 noti-foo.0
	cp foo.meta noti-foo.meta

noti-ok-foo.0:	ok-foo.0
	cp ok-foo.0 noti-ok-foo.0
	cp ok-foo.meta noti-ok-foo.meta

bar.0:	config.bar
	rm -f bar.index bar.meta bar.0
	pmlogger -c config.bar -s 70 bar

mv-bar.0:	config.bar
	rm -f mv-bar.index mv-bar.meta mv-bar.?
	pmlogger -c config.bar -s 70 -v 20 mv-bar

noti-bar.0:	bar.0
	cp bar.0 noti-bar.0
	cp bar.meta noti-bar.meta

mirage.0:
	rm -f mirage.index mirage.meta mirage.0
	pmlogger -c config.mirage -s 20 mirage

dodgey-some.0:	make.dodgey config.dodgey-some
	./make.dodgey some 50

dodgey-all.0:	make.dodgey config.dodgey-all
	./make.dodgey all 50

dodgey-mixed.0:	make.dodgey config.dodgey-mixed
	./make.dodgey mixed 150

bigbin.0:	config.bigbin
	rm -f bigbin.index bigbin.meta bigbin.0
	sync
	sleep 3
	pmlogger -c config.bigbin -s 1000 bigbin

mv-bigbin.0:	config.bigbin
	rm -f mv-bigbin.index mv-bigbin.meta mv-bigbin.?
	sync
	sleep 3
	pmlogger -c config.bigbin -s 1000 -v 101 mv-bigbin

noti-bigbin.0:	bigbin.0
	cp bigbin.0 noti-bigbin.0
	cp bigbin.meta noti-bigbin.meta

interp.0:	$(CONFIG_INTERP)
	rm -f interp.index interp.meta interp.0
	pmlogger -c $(CONFIG_INTERP) -s 30 interp

mv-interp.0:	$(CONFIG_INTERP)
	rm -f mv-interp.index mv-interp.meta mv-interp.?
	pmlogger -c $(CONFIG_INTERP) -s 30 -v 10 mv-interp

noti-interp.0:	interp.0
	cp interp.0 noti-interp.0
	cp interp.meta noti-interp.meta

truncbin.0:	bigbin.0
	rm -f truncbin.index truncbin.meta truncbin.0
	ln bigbin.meta truncbin.meta
	ln bigbin.index truncbin.index
	dd ibs=1024 count=200 if=bigbin.0 of=truncbin.0

# just the label record
null.0:	foo.0
	rm -f null.index null.meta null.0
	ln foo.meta null.meta
	ln foo.index null.index
	dd ibs=132 count=1 if=foo.0 of=null.0

# 4 secs, 3 sec gap, 4 secs, 3 sec gap, 4 secs
# and indom changes ... checked in, this is the recipe that was
# used
#
changeinst.0:
	rm -rf tmp
	mkdir tmp
	echo 'log mandatory on once { hinv.ncpu }' >tmp/A.config
	echo 'log mandatory on 1sec {' >>tmp/A.config
	echo '  sample.seconds,hinv.ncpu,sample.bin["bin-100","bin-200","bin-400"]' >>tmp/A.config
	echo '  sample.drift' >>tmp/A.config
	echo '  irix.network.interface.total.packets["lo0","ec0"]' >>tmp/A.config
	echo '}' >>tmp/A.config
	echo 'log mandatory on once { sample.bin["bin-500"] }' >tmp/B.config
	echo 'log mandatory on 1sec {' >>tmp/B.config
	echo '  sample.seconds,sample.milliseconds,sample.bin["bin-100","bin-300","bin-400"]' >>tmp/B.config
	echo '}' >>tmp/B.config
	echo 'log mandatory on once { hinv.ncpu }' >tmp/C.config
	echo 'log mandatory on 1sec {' >>tmp/C.config
	echo '  sample.drift' >>tmp/C.config
	echo '  sample.seconds,sample.bin["bin-200","bin-300","bin-400","bin-500"]' >>tmp/C.config
	echo '  irix.network.interface.total.packets["ec2","lo0"]' >>tmp/C.config
	echo '}' >>tmp/C.config
	pmlogger -s 5 -c tmp/A.config tmp/A
	sleep 3
	pmlogger -s 5 -c tmp/B.config tmp/B
	sleep 3
	pmlogger -s 5 -c tmp/C.config tmp/C
	rm -f changeinst.index changeinst.meta changeinst.0
	pmlogextract tmp/A tmp/B tmp/C changeinst
	rm -rf tmp

# gap: 10 sec data, 5 sec gap, 10 sec data
# gap2: 10 sec data, 5 sec gap, 10 sec data, 5 sec gap, 10 sec data
# sample.bin instances change across gaps
#
gap.0 gap2.0:
	rm -rf tmp
	mkdir tmp
	echo 'log mandatory on 1sec { pmcd.pdu_in,pmcd.numagents,hinv.ncpu,sample.bin["bin-100","bin-200","bin-400"] }' >tmp/A.config
	echo 'log mandatory on 1sec { pmcd.pdu_in,pmcd.numagents,hinv.ncpu,sample.bin["bin-100","bin-300","bin-400"] }' >tmp/B.config
	echo 'log mandatory on 1sec { pmcd.pdu_in,pmcd.numagents,hinv.ncpu,sample.bin["bin-100","bin-400"] }' >tmp/C.config
	pmlogger -s 10 -c tmp/A.config tmp/A
	sleep 5
	pmlogger -s 10 -c tmp/B.config tmp/B
	sleep 5
	pmlogger -s 10 -c tmp/C.config tmp/C
	rm -f gap.index gap.meta gap.0
	pmlogextract tmp/A tmp/B gap
	rm -f gap2.index gap2.meta gap2.0
	pmlogextract tmp/A tmp/B tmp/C gap2
	rm -rf tmp

reduce-gap.0:	reduce-1.0 reduce-2.0
	rm -f reduce-gap.*
	pmlogextract reduce-1 reduce-2 reduce-gap

torture_indom: torture_indom.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ torture_indom.c $(LDLIBS)

torture_pmns: torture_pmns.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ torture_pmns.c $(LDLIBS)

units-parse: units-parse.c
	rm -f $@
	$(CCF) $(CDEFS) -o $@ units-parse.c $(LDLIBS)

# --- miscellaneous
#
qa_timezone.$(DSOSUFFIX):	qa_timezone.o
	$(LD) -shared -o $@ -nostdlib $<

qa_shmctl.$(DSOSUFFIX):	 qa_shmctl.c
	$(CC) -fPIC -c qa_shmctl.c
	$(LD) -shared -o $@ -nostdlib qa_shmctl.o
	@rm -f qa_shmctl.o

ifneq ($(NVIDIAQALIB),)
$(NVIDIAQALIB):	nvidia-ml.o
	$(CC) $(LDFLAGS) $(_SHAREDOPTS) -o $@ $<
endif

arch_maxfd.o:	localconfig.h
scale.o:	localconfig.h

bozo:
	@echo TARGETS=$(TARGETS)
