### Change the variable below, so they match your system ###


#Compiler
CC?=g++

#Path where to install ocpip package
INSTALLPATH?=/usr/local/ocpip

#Path to your systemc installation
SYSTEMC?=/usr/local/SystemC/

#Path to your TLM2 installation
TLM2?=/usr/local/SystemC/TLM-2009-07-15
TLM2_UTILS?=$(TLM2)/include/tlm/tlm_utils

#Path to SCV if available (required by some examples but not mandatory for the kit).
SCV?=/usr/local/SystemC/SCV

#Special flags you wanna pass to the compiler, e.g. -DNDEBUG or something along that line
EXTRAFLAGS?=

#the target architecture of your system
#  the default value tries to guess it from your systemc installation
#  if that fails, set it manually
TARGET_ARCH ?= $(subst $(SYSTEMC)/lib-,,$(wildcard $(SYSTEMC)/lib-*))


#### DO NOT MODIFY BELOW THIS LINE !#####

VERSION=$(shell cat ../recent_version.txt)
SRC_EXT=cpp
SOURCES=$(wildcard ./src/ocpip_dev/*.$(SRC_EXT))
OBJECTS=$(SOURCES:%.$(SRC_EXT)=%.o)
DIR=$(shell pwd)

TPPS=$(subst ocpip_dev,ocpip_$(VERSION),$(foreach file, $(wildcard src/ocpip_dev/*.tpp), $(INSTALLPATH)/mon/$(file)))
HPPS=$(subst ocpip_dev,ocpip_$(VERSION),$(foreach file, $(wildcard src/ocpip_dev/*.hpp), $(INSTALLPATH)/mon/$(file)))
G_HEADERS=$(foreach file, $(wildcard include/generic/*.h), $(INSTALLPATH)/mon/$(file))
V_HEADERS=$(subst ocpip_dev,ocpip_$(VERSION),$(foreach file, $(wildcard include/ocpip_dev/*.h), $(INSTALLPATH)/mon/$(file)))
TARGETLIB=$(INSTALLPATH)/lib-$(TARGET_ARCH)/$(FULL_LIBNAME)
EXAMPLE_MKF=$(wildcard $(INSTALLPATH)/examples/Makefile.conf)
LEGACY_SOURCE=$(foreach file, $(wildcard include/legacy_code_base/*.legacy.h), $(INSTALLPATH)/mon/$(file))

all: install

debug | opt : make_dirs $(G_HEADERS) $(V_HEADERS) $(TPPS) $(HPPS) $(LEGACY_SOURCE) Makefile

install: opt
	@echo $(EXAMPLE_MKF)
ifeq ($(EXAMPLE_MKF), $(INSTALLPATH)/examples/Makefile.conf)
	@echo Adding Makefile.mon.conf to examples
	@echo USE_OCP_MONITOR=1 >$(INSTALLPATH)/examples/Makefile.mon.conf;
	@echo ifndef SCV>>$(INSTALLPATH)/examples/Makefile.mon.conf;
	@echo SCV=$(SCV)>>$(INSTALLPATH)/examples/Makefile.mon.conf;
	@echo endif>>$(INSTALLPATH)/examples/Makefile.mon.conf;
	@echo GOLDEN_PATH=$(DIR)/../regression/golden_vectors>>$(INSTALLPATH)/examples/Makefile.mon.conf;
endif
	@echo Installation done

make_dirs:
	mkdir -p $(INSTALLPATH)/mon/include/ocpip_$(VERSION);
	mkdir -p $(INSTALLPATH)/mon/include/generic;
	mkdir -p $(INSTALLPATH)/mon/src/ocpip_$(VERSION);
	mkdir -p $(INSTALLPATH)/mon/include/legacy_code_base;
	mkdir -p $(INSTALLPATH)/mon/include/legacy_support;

$(INSTALLPATH)/mon/src/ocpip_$(VERSION)/%.tpp : ./src/ocpip_dev/%.tpp
	cp $< $@

$(INSTALLPATH)/mon/include/legacy_code_base/%.legacy.h : ./include/legacy_code_base/%.legacy.h
	../cp_legacy $< $@ $(INSTALLPATH)/mon $(@F) ../recent_version.txt ./

$(INSTALLPATH)/mon/src/ocpip_$(VERSION)/%.hpp : ./src/ocpip_dev/%.hpp
	cp $< $@

$(INSTALLPATH)/mon/include/ocpip_$(VERSION)/%.h : ./include/ocpip_dev/%.h
	cp $< $@

$(INSTALLPATH)/mon/include/generic/%.h : ./include/generic/%.h
	cp $< $@

