#!gmake
#
# Copyright (c) 2009-2010 Aconex.  All Rights Reserved.
# Copyright (c) 1997-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

ifdef PCP_CONF
include $(PCP_CONF)
else
include $(PCP_DIR)/etc/pcp.conf
endif
PATH	= $(shell . $(PCP_DIR)/etc/pcp.env; echo $$PATH)
include $(PCP_INC_DIR)/builddefs

STDPMID		= $(PCP_VAR_DIR)/pmns/stdpmid

# strip -I and -L options
#
TMP             := $(CFLAGS:-I%=)
CFLAGS          = $(TMP)
PCP_LIBS	=

ifneq "$(PCP_INC_DIR)" "/usr/include/pcp"
# for cc add -I<run-time-include-dir> (need /.. at the end so
# #include <pcp/foo.h> works) when $(PCP_INC_DIR) may not be on
# the default cpp include search path.
CFLAGS		+= -I$(PCP_INC_DIR)/..
endif
ifneq "$(PCP_LIB_DIR)" "/usr/lib"
# for ld add -L<run-time-lib-dir> and include -rpath when
# $(PCP_LIB_DIR) may not be on the default ld search path.
#
ifeq "$(PCP_PLATFORM)" "darwin"
PCP_LIBS	+= -L$(PCP_LIB_DIR) -Wl,-rpath $(PCP_LIB_DIR)
else
PCP_LIBS	+= -L$(PCP_LIB_DIR) -Wl,-rpath=$(PCP_LIB_DIR)
endif
endif

CFILES		= broken_pmda.c
CFILES_TARGETS	= $(CFILES)

TARGETS = $(subst broken_pmda,,$(basename $(CFILES_TARGETS))) \
	broken_pmda_2_0 broken_v2.dir broken_pmda_2_1 broken_pmda_2_2 \
	broken_pmda_2_3 broken_pmda_2_4 broken_pmda_2_5 

LLDLIBS = -lpcp $(LIB_FOR_MATH) $(LIB_FOR_DLOPEN) $(LIB_FOR_PTHREADS)

LDIRT	= *.log help.pag help.dir $(subst .c,.o,$(CFILES)) \
	broken_pmda_*.c real_broken_pmns broken_v?.dir broken_v?.pag \
	$(TARGETS)

default default_pcp setup: $(TARGETS)

include $(PCP_INC_DIR)/buildrules

install install_pcp:

broken_v2.dir:	broken_help real_broken_pmns
	rm -f broken_v2.pag broken_v2.dir
	newhelp -n real_broken_pmns -v 2 -o broken_v2 broken_help

real_broken_pmns:	domain.h broken_pmns
	cat domain.h >real_broken_pmns
	echo >>real_broken_pmns
	echo 'root {' >>real_broken_pmns
	echo '  broken' >>real_broken_pmns
	echo '}' >>real_broken_pmns
	echo >>real_broken_pmns
	cat broken_pmns >>real_broken_pmns

broken_pmda_2_0: broken_pmda.c domain.h
	rm -f $@ $@.c
	ln -s broken_pmda.c $@.c
	$(CCF) $(CDEFS) -DVERSION_2 -o $@ $@.c $(LDLIBS) -lpcp_pmda

broken_pmda_2_1: broken_pmda.c domain.h
	rm -f $@ $@.c
	ln -s broken_pmda.c $@.c
	$(CCF) $(CDEFS) -DVERSION_2 -DBUG_1 -o $@ $@.c $(LDLIBS) -lpcp_pmda

broken_pmda_2_2: broken_pmda.c domain.h
	rm -f $@ $@.c
	ln -s broken_pmda.c $@.c
	$(CCF) $(CDEFS) -DVERSION_2 -DBUG_2 -o $@ $@.c $(LDLIBS) -lpcp_pmda

broken_pmda_2_3: broken_pmda.c domain.h
	rm -f $@ $@.c
	ln -s broken_pmda.c $@.c
	$(CCF) $(CDEFS) -DVERSION_2 -DBUG_3 -o $@ $@.c $(LDLIBS) -lpcp_pmda

broken_pmda_2_4: broken_pmda.c domain.h
	rm -f $@ $@.c
	ln -s broken_pmda.c $@.c
	$(CCF) $(CDEFS) -DVERSION_2 -DBUG_4 -o $@ $@.c $(LDLIBS) -lpcp_pmda

broken_pmda_2_5: broken_pmda.c domain.h
	rm -f $@ $@.c
	ln -s broken_pmda.c $@.c
	$(CCF) $(CDEFS) -DVERSION_2 -DBUG_5 -o $@ $@.c $(LDLIBS) -lpcp_pmda
