SRC_DIR        := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SPACEMACSD := ~/.spacemacs.d
EMACSD     := ~/.emacs.d
SPACEMACS_URL  := https://github.com/syl20bnr/spacemacs

include ../lib/shared.mk

install: | init update

init:
ifndef IS_SSH
	$(info Remote connection. Not installing emacs.)
else ifneq ($(call cmd_exist,emacs), true)
	$(info Emacs not installed )
else
	$(info => installing spacemacs.)
	$(MAKE) -C $(SRC_DIR) spacemacs_init
	$(mk_link) $(SRC_DIR) $(SPACEMACSD)
endif

spacemacs_init:
ifeq ($(shell [ ! -e $(EMACSD) ] $(return_val_truthy) ), true)
	git clone $(SPACEMACS_URL) $(EMACSD) ; $(report) "Spacemacs installed"
else
	$(report) warn "$(EMACSD) already exist. Skipping."
endif

update:

remove:
	$(info => Removing Emacs config)
	@ $(rm_link) $(EMACSD)
	@ $(rm_link) $(SPACEMACSD)