# -*- mode: makefile-gmake; -*-
SRC := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

include ../lib/shared.mk
TARGET :=  $(XDG_DIR)/rofi

DESKTOP_SRC := $(SRC)/desktop
DESKTOP_TARGET := ~/.local/share/applications

install: | init update

init:
	if (( $$+commands[rofi] )) ; then
		$(report) header "Setting up rofi"
		$(mk_link) $(SRC) $(TARGET)
		$(MAKE) -C $(SRC) desktop_init
	else
		$(report) debug "rofi not installed. Skipping."
	fi

update:

remove:
	$(report) header "Removing rofi"
	$(rm_link) $(TARGET)
	$(MAKE) -C $(SRC) desktop_remove

desktop_init:
	if [[ ! -e $(DESKTOP_TARGET) ]] ; then
		$(report) warn "$(DESKTOP_TARGET) does not exist. Skipping."
	else
		$(report) header "Adding .desktop files"
		cd $(DESKTOP_SRC)
		for i in *.desktop ; do
			$(mk_link) $(DESKTOP_SRC)/$$i $(DESKTOP_TARGET)/$$i	
		done
	fi

desktop_remove:
	if [[ ! -e $(DESKTOP_TARGET) ]] ; then
		$(report) warn "$(DESKTOP_TARGET) does not exist. Skipping."
	else
		$(report) header "Removing .desktop files"
		cd $(DESKTOP_SRC)
		for i in *.desktop ; do
			$(rm_link) $(DESKTOP_TARGET)/$$i
		done
	fi