#-- start of constituent ------

cmt_${CONSTITUENT}_${HASTARGETTAG} = 1

#--------------------------------------------------------

!if defined (cmt_${CONSTITUENT}_has_target_tag)

#cmt_local_tagfile_${CONSTITUENT} = $(${PACKAGE}_tag)_${CONSTITUENT}.nmake
cmt_local_tagfile_${CONSTITUENT} = $(bin)$(${PACKAGE}_tag)_${CONSTITUENT}.nmake
cmt_local_setup_${CONSTITUENT} = $(bin)setup_${CONSTITUENT}.nmake.tmp
cmt_final_setup_${CONSTITUENT} = $(bin)setup_${CONSTITUENT}.nmake
#cmt_final_setup_${CONSTITUENT} = $(bin)${PACKAGE}_${CONSTITUENT}_setup.nmake
cmt_local_${CONSTITUENT}_makefile = $(bin)${CONSTITUENT}.nmake

${CONSTITUENT}_extratags = -tag_add=target_${CONSTITUENT}

#!if [if not exist $(bin) mkdir $(bin)] == 0
#!endif

#!if "$(QUICK)" == "" || !exist ($(cmt_local_tagfile_${CONSTITUENT}))

#!if [$(echo) (constituents.nmake) Rebuilding $(cmt_local_tagfile_${CONSTITUENT})] == 0
#!endif
#!if [cmt -tag=$(tags) $(${CONSTITUENT}_extratags) build tag_makefile >$(cmt_local_tagfile_${CONSTITUENT})] == 0
#!endif

#!if [$(echo) (constituents.nmake) Rebuilding $(cmt_final_setup_${CONSTITUENT})] == 0
#!endif
#!if [$(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) show setup >$(cmt_local_setup_${CONSTITUENT})] == 0
#!endif

#!if exist ($(cmt_final_setup_${CONSTITUENT})) && [ echo n|comp $(cmt_final_setup_${CONSTITUENT}) $(cmt_local_setup_${CONSTITUENT}) >nul 2>&1 ] == 0
#!if [ del $(cmt_local_setup_${CONSTITUENT}) ] == 0
#!endif
#!else
#!if [ move /y $(cmt_local_setup_${CONSTITUENT}) $(cmt_final_setup_${CONSTITUENT}) >nul ] == 0
#!endif
#!endif

#!endif

!else

#cmt_local_tagfile_${CONSTITUENT} = $(${PACKAGE}_tag).nmake
cmt_local_tagfile_${CONSTITUENT} = $(bin)$(${PACKAGE}_tag).nmake
#cmt_local_setup_${CONSTITUENT} = $(bin)setup.nmake.tmp
cmt_final_setup_${CONSTITUENT} = $(bin)setup.nmake
#cmt_final_setup_${CONSTITUENT} = $(bin)${PACKAGE}_setup.nmake
cmt_local_${CONSTITUENT}_makefile = $(bin)${CONSTITUENT}.nmake

!endif

#!if "$(QUICK)" == ""
#$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_local_tagfile_${CONSTITUENT})
#!else
#$(cmt_local_${CONSTITUENT}_makefile) : $(cmt_local_tagfile_${CONSTITUENT})
#!endif

!if defined (cmt_${CONSTITUENT}_has_target_tag)

!if "$(QUICK)" == "" || !exist ($(cmt_local_${CONSTITUENT}_makefile)) || !exist ($(cmt_local_tagfile_${CONSTITUENT})) || !exist ($(cmt_final_setup_${CONSTITUENT}))
$(cmt_local_${CONSTITUENT}_makefile) :: $(${CONSTITUENT}_dependencies) dirs
	$(echo) (constituents.nmake) Building ${CONSTITUENT}.nmake
	@set include=$(include)
	@set lib=$(lib)
	@$(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_config -out=$@ ${CONSTITUENT}
!else
$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(use_requirements)
	@set include=$(include)
	@set lib=$(lib)
	@if not "$?"=="$(${CONSTITUENT}_dependencies)" ((if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) Rebuilding ${CONSTITUENT}.nmake") & $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_config -out=$@ ${CONSTITUENT}) else (if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) ${CONSTITUENT}.nmake up-to-date")
!endif

!else

!if "$(QUICK)" == "" || !exist ($(cmt_local_${CONSTITUENT}_makefile)) || !exist ($(cmt_local_tagfile_${CONSTITUENT})) || !exist ($(cmt_final_setup_${CONSTITUENT}))
$(cmt_local_${CONSTITUENT}_makefile) :: $(${CONSTITUENT}_dependencies) dirs
	$(echo) (constituents.nmake) Building ${CONSTITUENT}.nmake
	@set include=$(include)
	@set lib=$(lib)
	@$(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_makefile -without_cmt -out=$@ ${CONSTITUENT}
!else
$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(use_requirements) $(bin)${CONSTITUENT}.in
	@set include=$(include)
	@set lib=$(lib)
	@if not "$?"=="$(${CONSTITUENT}_dependencies)" ((if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) Rebuilding ${CONSTITUENT}.nmake") & $(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_makefile -without_cmt -out=$@ ${CONSTITUENT}) else (if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) ${CONSTITUENT}.nmake up-to-date")
!endif

!endif

cmt_${CONSTITUENT}_${HASDEPENDENCIES} = 1

!if defined (cmt_${CONSTITUENT}_has_dependencies)

${CONSTITUENT}dependencies : $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile) dirs
	@set include=$(include)
	@set lib=$(lib)
	@$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles dependencies tag=$(tag)

${CONSTITUENT} :: ${CONSTITUENT}dependencies
!else
${CONSTITUENT} :: $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile) dirs
!endif
	$(echo) (constituents.nmake) Starting ${CONSTITUENT}
	@set include=$(include)
	@set lib=$(lib)
	@$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles ${CONSTITUENT} tag=$(tag)
	$(echo) (constituents.nmake) ${CONSTITUENT} done

clean :: ${CONSTITUENT}clean

${CONSTITUENT}clean :: $(${CONSTITUENT}clean_dependencies) ##$(cmt_local_${CONSTITUENT}_makefile)
	$(echo) (constituents.nmake) Starting ${CONSTITUENT}clean
	@set include=$(include)
	@set lib=$(lib)
	@-if exist $(cmt_local_${CONSTITUENT}_makefile) $(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles ${CONSTITUENT}clean tag=$(tag)
	$(echo) (constituents.nmake) ${CONSTITUENT}clean done
#	@$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles ${CONSTITUENT}clean tag=$(tag)

install :: ${CONSTITUENT}install

${CONSTITUENT}install :: $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile)
	$(echo) (constituents.nmake) Starting install ${CONSTITUENT}
	@set include=$(include)
	@set lib=$(lib)
	@-$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles install tag=$(tag)
	$(echo) (constituents.nmake) install ${CONSTITUENT} done

uninstall :: ${CONSTITUENT}uninstall

#${CONSTITUENT}uninstall :: $(cmt_local_${CONSTITUENT}_makefile)
#${CONSTITUENT}uninstall :: $(cmt_local_tagfile_${CONSTITUENT})
${CONSTITUENT}uninstall :: $(${CONSTITUENT}uninstall_dependencies)
	$(echo) (constituents.nmake) Starting uninstall ${CONSTITUENT}
	@set include=$(include)
	@set lib=$(lib)
	@-if exist $(cmt_local_${CONSTITUENT}_makefile) $(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles uninstall tag=$(tag)
#	@if not exist $(cmt_local_${CONSTITUENT}_makefile) $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
#	@if not exist $(cmt_local_${CONSTITUENT}_makefile) $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_makefile -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
#	@-$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles uninstall tag=$(tag)
	$(echo) (constituents.nmake) uninstall ${CONSTITUENT} done

#-- end of constituent ------
