RM             := rm -f
SOCLIB_CC      := soclib-cc
SOCLIB_CC_MODE := -m release
SOCLIB_CC_ARGS := $(SOCLIB_CC_MODE)
SOCLIB_CC_ARGS += -v
#SOCLIB_CC_ARGS += -t envsystemc
#SOCLIB_CC_ARGS += -bcaba:reconf:vci_xicu
#SOCLIB_CC_ARGS += -bcaba:vci_iopic
#SOCLIB_CC_ARGS += -bcaba:vci_block_device_tsar

TAGS           := cscope.out
TARGET         := simul.x

objs           := $(wildcard *.o)
objs           += $(wildcard term[0-9])
objs           += $(wildcard $(TARGET))
objs           := $(strip $(objs))

extra_objs     := $(wildcard scripts/*.pyc)
extra_objs     += $(wildcard hard_config.h)
extra_objs     += $(wildcard $(TAGS))
extra_objs     := $(strip $(extra_objs))

all: $(TARGET)
tags: $(TAGS)

.PHONY: $(TARGET)
$(TARGET): top.desc top.cpp
	$(SOCLIB_CC) $(SOCLIB_CC_ARGS) -P -p $< -I. -o $@

.PHONY: $(TAGS)
$(TAGS): top.desc
	$(SOCLIB_CC) -p $< --tags --tags-type=cscope --tags-output=$@

.PHONY: clean
clean:
	$(SOCLIB_CC) $(SOCLIB_CC_MODE) -x -p top.desc -I.
ifneq ($(objs),)
	$(RM) $(objs)
endif

.PHONY: distclean
distclean: clean
ifneq ($(extra_objs),)
	$(RM) $(extra_objs)
endif
