#-- start of constituent_lock ------

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
	$(echo) (constituents.nmake) Building ${CONSTITUENT}.nmake
	@set include=$(include)
	@set lib=$(lib)
	@$(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_makefile -out=$@ ${CONSTITUENT}
#	$(echo) (constituents.nmake) ${CONSTITUENT}.nmake done

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) Creating ${CONSTITUENT}$(lock_suffix)
	@$(lock_command) ${CONSTITUENT}$(lock_suffix)
	$(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) \
	|| ($(unlock_command) ${CONSTITUENT}$(lock_suffix) & exit 1)
	@$(unlock_command) ${CONSTITUENT}$(lock_suffix)
	$(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})
	$(echo) (constituents.nmake) Starting uninstall ${CONSTITUENT}
	@set include=$(include)
	@set lib=$(lib)
	@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_lock ------
