homeservice/Makefile
Thomas Klaehn 7575193024 Fix: build
Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
2023-02-09 10:22:38 +01:00

70 lines
1.5 KiB
Makefile

PROJECT_NAME := homeservice
PREFIX ?= /usr/bin
CONFIG_DIR := /etc/$(PROJECT_NAME)
SYSTEM_DIR := /usr/lib/systemd/system
WEB_DIR := /var/lib/$(PROJECT_NAME)
CONFIG_FILE := config/config.json
BIN_FILE := build/bin/$(PROJECT_NAME)
UNIT_FILE := $(PROJECT_NAME).service
README_FILE := README.md
.PHONY: all
all: webui service
.PHONY: service
service:
mkdir -p bin
go clean
go mod tidy
go build -o $(BIN_FILE)
.PHONY: webui
webui:
npm install --prefix webui
npm run build --prefix webui
.PHONY: clean
clean:
go clean
rm -rf bin
rm -rf webui/build webui/node_modules webui/.svelte-kit
-rm $(PROJECT_NAME).tar.gz
.PHONY: install
install: all
# Config file
@if [ -f $(CONFIG_DIR)/$(notdir $(CONFIG_FILE)) ]; then \
echo "$(CONFIG_DIR)/$(notdir $(CONFIG_FILE)) already exists - skipping..."; \
else \
install -d $(CONFIG_DIR); \
install -m 0644 $(CONFIG_FILE) $(CONFIG_DIR); \
echo "install -d $(CONFIG_DIR)"; \
echo "install -m 0644 $(CONFIG_FILE) $(CONFIG_DIR)"; \
fi
# Binary
install -d $(PREFIX)
install -m 0755 $(BIN_FILE) $(PREFIX)
# System unit
install -d $(SYSTEM_DIR)
install -m 0644 $(UNIT_FILE) $(SYSTEM_DIR)
# Web ui
install -d $(WEB_DIR)
cp -r webui/build/* $(WEB_DIR)
.PHONY: uninstall
uninstall:
rm -rf $(CONFIG_DIR)
rm -rf $(SYSTEM_DIR)/$(UNIT_FILE)
rm -rf $(PREFIX)/$(PROJECT_NAME)
rm -rf $(WEB_DIR)
.PHONY: package
package: all
tar cvzf $(PROJECT_NAME).tar.gz $(CONFIG_FILE) $(BIN_FILE) $(UNIT_FILE) $(README_FILE) webui/build/*