DEVP_CHANGIE_CONFIG_PATH := $(if $(DEVP_CHANGIE_CONFIG_PATH),$(DEVP_CHANGIE_CONFIG_PATH),"./.changes/.changie.yaml")
DEVP_CHANGIE_EDITOR := $(if $(DEVP_CHANGIE_EDITOR),$(DEVP_CHANGIE_EDITOR),$(EDITOR))
DEVP_CHANGIE_USE_EDITOR := $(if $(DEVP_CHANGIE_EDITOR),true,false)
DEVP_CHANGIE_CMD := CHANGIE_CONFIG_PATH=${DEVP_CHANGIE_CONFIG_PATH} EDITOR="${DEVP_CHANGIE_EDITOR}" ${DEVP_CHANGIE_EXE}

.PHONY: devp/changes/new
devp/changes/new: ${DEVP_CHANGIE_EXE}
	@# Add changelog record
	$(Q) ${DEVP_CHANGIE_CMD} new --editor=${DEVP_CHANGIE_USE_EDITOR} ${DEVP_CHANGIE_NEW_ARGS}

.PHONY: devp/changes/render
devp/changes/render: ${DEVP_CHANGIE_EXE}
	@# Renders changelog. Debug target that allows developer to see how his changes will be displayed in a changelog
	$(Q) ${DEVP_CHANGIE_CMD} batch patch --keep

.PHONY: devp/changes/release
devp/changes/release: ${DEVP_CHANGIE_EXE}
	@# Renders changelog for release
	$(Q) ${DEVP_CHANGIE_CMD} batch ${DEVP_CHANGIE_NEXT_VERSION}

.PHONY: devp/changes/merge
devp/changes/merge: ${DEVP_CHANGIE_EXE}
	@# Merges last changelog to the main changelog file
	$(Q) ${DEVP_CHANGIE_CMD} merge

.PHONY: devp/changes/latest
devp/changes/latest: ${DEVP_CHANGIE_EXE}
	@# Get latest release version
	$(Q) ${DEVP_CHANGIE_CMD} latest

.PHONY: devp/changes/get-text
devp/changes/get-text: ${DEVP_DEVPTOOL_EXE} ${DEVP_CHANGIE_EXE}
	@# Generates latest release announce text and copies it to clipboard
	$(Q) DEVP_CHANGIE_CONFIG_PATH=${DEVP_CHANGIE_CONFIG_PATH} \
	DEVP_CHANGES_TITLE=${DEVP_CHANGES_TITLE} \
	DEVP_CHANGES_FOOTER=${DEVP_CHANGES_FOOTER} \
	${DEVP_DEVPTOOL_EXE} changes get-text
