# Makefile - makefile for generation of object identification tags in
# the vxWorks libraries
#
# Copyright (c) 2009, 2013 Wind River Systems, Inc.
#
# The right to copy, distribute, modify or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
#
# modification history
# --------------------
# 01e,11jan13,v_r  Added clean rules.
# 01d,27jul09,pee  adding CPU variant support
# 01c,23jul09,pee  adding default empty rule.
# 01b,22jul09,pee  fix include file name.
# 01a,30jun09,pee	created

TGT_DIR =  $(WIND_BASE)/target

include $(WIND_BASE)/target/h/make/defs.library
include $(WIND_BASE)/target/h/make/defs.base.mk
include $(WIND_BASE)/target/h/make/defs.pal

# tag values to represent TRUE/FALSE
_TAG_TRUE = 1
_TAG_FALSE = 0

# this is the list of VSB configuration values to convert to tag / assert
# tags will be set to the VSB configration value. Asserts will simply test against the same value.
VSB_KERNEL_TAGS = SMP
VSB_KERNEL_ASSERT = SMP
VSB_DKM_TAGS = SMP
# VSB_DKM_ASSERT = SMP


# convert VSB configuration into tag value

define vsb2tag

ifdef _WRS_CONFIG_$1
ifeq ($(_WRS_CONFIG_$1),y)
_TAG_$1 = $(_TAG_TRUE)
else
_TAG_$1 = $(_WRS_CONFIG_$1)
endif
else
_TAG_$1 = $(_TAG_FALSE)
endif

endef

_ALL_KERNEL_TAGS = $(sort $(VSB_KERNEL_TAGS) $(VSB_KERNEL_ASSERT))

$(foreach tag,$(_ALL_KERNEL_TAGS),$(eval $(call vsb2tag,$(tag))))

# this is the header to be inserted in the generated kernel tag file.

define kerneltagheader
# VxWorks kernel tag definition
# 
# This file is automatically generated
#
# Do not edit manually


endef

# this is the header to be inserted in the generated dkm tag file.

define dkmtagheader
# VxWorks downloadable kernel module tag definition
# 
# This file is automatically generated
#
# Do not edit manually


endef

# this funtion outputs the tag definition to put into the generated file.
# This defines the format for tag definition
define settag
tag $1 $(_TAG_$1)

endef

#this defines the format for a simple assert 
define asserttag 
assert $$($1)==$(_TAG_$1)

endef

# insert custom kernel tags in this variable
define kerneltags

endef

# insert custom dkm tags in this variable
define dkmtags

endef

.PHONY : $(VSB_TAG_FILE_KERNEL) $(VSB_TAG_FILE_DKM) release all

all : tags
	-

tags : $(VSB_TAG_FILE_KERNEL) $(VSB_TAG_FILE_DKM)
	-

ifneq ($(_ADDITIONAL_CPU_SUPPORT),)
tags : additional_cpus

additional_cpus:
	$(foreach cpu,$(_ADDITIONAL_CPU_SUPPORT),$(if $(wildcard $(TGT_DIR)/h/tool/$(TOOL_FAMILY)/make.$(cpu)$(TOOL)),$(tab)$(MAKE) CPU=$(cpu) tags $(newline)))

endif

ifdef CPU_VARIANT_MAKE_TAGS

tags : variant_tags

variant_tags :
ifneq ($(NO_RECURSE), TRUE)
	$(CPU_VARIANT_MAKE_TAGS)
endif
endif



$(VSB_TAG_FILE_KERNEL) : | $(VSB_TAG_DIR)
	@ echo updating tag file $@
	@ $(RM) $@
	$(call print,$(kerneltagheader),$@)
	$(call print,$(foreach tag,$(VSB_KERNEL_TAGS),$(call settag,$(tag))),$@)
	$(call print,$(foreach tag,$(VSB_KERNEL_ASSERT),$(call asserttag,$(tag))),$@)
	$(call print,$(kerneltags),$@)

$(VSB_TAG_FILE_DKM) : | $(VSB_TAG_DIR)
	@ echo updating tag file $@
	@ $(RM) $@
	$(call print,$(dkmtagheader),$@)
	$(call print,$(foreach tag,$(VSB_DKM_TAGS),$(call settag,$(tag))),$@)
	$(call print,$(foreach tag,$(VSB_DKM_ASSERT),$(call asserttag,$(tag))),$@)
	$(call print,$(dkmtags),$@)

$(VSB_TAG_DIR) :
	$(MKDIR) $@

clean:
	$(RMDIR) $(VSB_TAG_DIR)

rclean:
	$(RMDIR) $(VSB_TAG_DIR)

release : all

# catch all default do nothing.

%:
	@echo nothing to be done for target $@
