INSTALL_DIR := /usr/sbin
CURR_DIR := $(shell pwd)
TOOLS := $(CURR_DIR)/mx-rtc-battery-detect
DEP_LIBS = mx-gpio-lib mx-common-lib
SYSTEMDDIR = $(DESTDIR)/etc/systemd/system
SERVICE_NAME = $(CURR_DIR)/mx-rtc-battery-detect.service

.PHONY: install $(TOOLS) clean

all: install

install: $(TOOLS) install_dep_libs install_systemd_service

$(TOOLS): install_dep_libs install_systemd_service
	@echo "Install $(notdir $@) to $(INSTALL_DIR)"
	@install -m 755 $@ $(INSTALL_DIR)

install_dep_libs:
	@make -C $(SRC_DIR)/lib/ LIBS="$(DEP_LIBS)"

install_systemd_service:
	@install -m 644 $(SERVICE_NAME) $(SYSTEMDDIR)/

clean:
	@rm -f $(addprefix $(INSTALL_DIR)/, $(notdir $(TOOLS)))
	@make -C $(SRC_DIR)/lib clean
	rm -f $(SYSTEMDDIR)/$(SERVICE_NAME)
