# Compile and install the example custom metrics plugin along with the partial report.

# Path to the metrics plugin directory. The metric plugin API
# header files should be in the 'include/' subdirectory to this.
FORGE_METRIC_PLUGIN_DIR=../..

CC=gcc
CFLAGS=-fPIC -I$(FORGE_METRIC_PLUGIN_DIR)/include
LFLAGS=
DEFAULTCONFIGDIR=~/.allinea

CONFIGDIR = $(DEFAULTCONFIGDIR)
ifdef ALLINEA_CONFIG_DIR
    CONFIGDIR = $(ALLINEA_CONFIG_DIR)
endif
ifdef FORGE_CONFIG_DIR
    CONFIGDIR = $(FORGE_CONFIG_DIR)
endif

MAPCONFIGDIR = $(CONFIGDIR)/map/metrics
PERFCONFIGDIR = $(CONFIGDIR)/perf-report/reports

.PHONY: all
all: libcustom1.so libbackfill1.so
	@echo "Use 'make install' to install the metric to $(MAPCONFIGDIR) and the partial report to $(PERFCONFIGDIR) for testing."

libcustom1.so: custom1.c
	$(CC) $(CFLAGS) -shared -o $@ $< $(LFLAGS)

libbackfill1.so: backfill1.c
	$(CC) $(CFLAGS) -shared -o $@ $< $(LFLAGS)

.PHONY: install-metric
install-metric: libcustom1.so custom1.xml libbackfill1.so backfill1.xml
	cp $^ $(MAPCONFIGDIR)

.PHONY: install-partial
install-partial: report.xml
	cp $^ $(PERFCONFIGDIR)

$(CONFIGDIR)/%:
	mkdir -p $@

.PHONY: install
install: $(MAPCONFIGDIR) $(PERFCONFIGDIR) install-metric install-partial

.PHONY: clean
clean:
	-rm *.so
