RM             := rm -f
SOCLIB_CC      := soclib-cc
SOCLIB_CC_MODE := -m release
SOCLIB_CC_ARGS := -P -I.

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

objs           := $(wildcard *.o)
objs           += $(wildcard $(TARGET))
objs           := $(strip $(objs))

extra_objs     += $(wildcard $(TAGS))
extra_objs     := $(strip $(extra_objs))

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

.PHONY: $(TARGET)
$(TARGET): top.desc top.cpp
	$(SOCLIB_CC) $(SOCLIB_CC_MODE) $(SOCLIB_CC_ARGS) -p $< -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
