PRODUCT = pbhush

PREFIX = /usr/local
exec_prefix = $(PREFIX)
bindir = $(DESTDIR)$(exec_prefix)/bin
INSTALLED_PRODUCT_PATH = $(bindir)/$(PRODUCT)

BUILD_OUTPUT_PATH = $(shell swift build -c "release" --show-bin-path)/$(PRODUCT)

ifndef SKIP_BUILD
	INSTALL_DEPENDENCY = build-release
endif

ifdef VERSION
	export VERSION
endif

uninstall-local install-local: PREFIX = $(HOME)/.local

.PHONY: default build build-% install install-% uninstall uninstall-% clean

all: build


install: $(INSTALL_DEPENDENCY)
	@./build-scripts/install.sh "$(BUILD_OUTPUT_PATH)" "$(INSTALLED_PRODUCT_PATH)"
	@./build-scripts/check-bin-path.sh "$(bindir)"
	@echo Installed "$(INSTALLED_PRODUCT_PATH)"


install-local: install


build: build-release


build-%:
	./build-scripts/build-with-version.sh swift build -c "$*" --product "$(PRODUCT)" $(ARGS)


uninstall:
	@./build-scripts/rm.sh "$(INSTALLED_PRODUCT_PATH)"
	@echo Removed "$(INSTALLED_PRODUCT_PATH)"


uninstall-local: uninstall


clean:
	swift package clean
