2024-06-11 00:16:41 +08:00
|
|
|
ifdef ComSpec
|
|
|
|
SHELL := powershell.exe
|
|
|
|
else
|
|
|
|
SHELL := /bin/bash
|
|
|
|
endif
|
|
|
|
|
2024-02-09 00:16:34 +08:00
|
|
|
APP_NAME := teldrive
|
2024-04-19 04:55:07 +08:00
|
|
|
BUILD_DIR := bin
|
|
|
|
FRONTEND_DIR := ui/dist
|
|
|
|
FRONTEND_ASSET := https://github.com/divyam234/teldrive-ui/releases/download/v1/teldrive-ui.zip
|
2024-03-20 01:14:00 +08:00
|
|
|
GIT_TAG := $(shell git describe --tags --abbrev=0)
|
2024-02-09 00:16:34 +08:00
|
|
|
GIT_COMMIT := $(shell git rev-parse --short HEAD)
|
|
|
|
GIT_LINK := $(shell git remote get-url origin)
|
2024-02-13 02:22:52 +08:00
|
|
|
MODULE_PATH := $(shell go list -m)
|
2024-02-09 00:16:34 +08:00
|
|
|
GOOS ?= $(shell go env GOOS)
|
|
|
|
GOARCH ?= $(shell go env GOARCH)
|
2024-06-22 20:29:59 +08:00
|
|
|
VERSION:= $(GIT_TAG)
|
|
|
|
BINARY_EXTENSION :=
|
2024-02-09 00:16:34 +08:00
|
|
|
|
2024-03-22 14:46:12 +08:00
|
|
|
.PHONY: all build run clean frontend backend run sync-ui retag patch-version minor-version
|
2024-02-09 01:31:13 +08:00
|
|
|
|
2024-02-09 00:16:34 +08:00
|
|
|
all: build
|
|
|
|
|
2024-04-19 04:55:07 +08:00
|
|
|
frontend:
|
|
|
|
@echo "Extract UI"
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
powershell -Command "Remove-Item -Path $(FRONTEND_DIR) -Recurse -Force"
|
|
|
|
powershell -Command "Invoke-WebRequest -Uri $(FRONTEND_ASSET) -OutFile teldrive-ui.zip"
|
|
|
|
powershell -Command "if (!(Test-Path -Path $(subst /,\\,$(FRONTEND_DIR)))) { New-Item -ItemType Directory -Force -Path $(subst /,\\,$(FRONTEND_DIR)) }"
|
|
|
|
powershell -Command "Expand-Archive -Path teldrive-ui.zip -DestinationPath $(FRONTEND_DIR) -Force"
|
|
|
|
powershell -Command "Remove-Item -Path teldrive-ui.zip -Force"
|
2024-02-09 00:16:34 +08:00
|
|
|
else
|
2024-04-19 04:55:07 +08:00
|
|
|
rm -rf $(FRONTEND_DIR)
|
|
|
|
curl -LO $(FRONTEND_ASSET) -o teldrive-ui.zip
|
|
|
|
mkdir -p $(FRONTEND_DIR)
|
|
|
|
unzip -d $(FRONTEND_DIR) teldrive-ui.zip
|
|
|
|
rm -rf teldrive-ui.zip
|
2024-02-09 00:16:34 +08:00
|
|
|
endif
|
|
|
|
|
2024-06-22 20:29:59 +08:00
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
BINARY_EXTENSION := .exe
|
|
|
|
endif
|
2024-04-19 04:55:07 +08:00
|
|
|
|
2024-02-09 00:16:34 +08:00
|
|
|
backend:
|
|
|
|
@echo "Building backend for $(GOOS)/$(GOARCH)..."
|
2024-06-22 20:29:59 +08:00
|
|
|
go build -trimpath -ldflags "-s -w -X $(MODULE_PATH)/internal/config.Version=$(VERSION) -extldflags=-static" -o $(BUILD_DIR)/$(APP_NAME)$(BINARY_EXTENSION)
|
2024-02-09 00:16:34 +08:00
|
|
|
|
|
|
|
build: frontend backend
|
|
|
|
@echo "Building complete."
|
|
|
|
|
|
|
|
run:
|
|
|
|
@echo "Running $(APP_NAME)..."
|
2024-02-12 04:52:41 +08:00
|
|
|
$(BUILD_DIR)/$(APP_NAME) run
|
2024-02-09 00:16:34 +08:00
|
|
|
|
|
|
|
clean:
|
|
|
|
@echo "Cleaning up..."
|
|
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
cd $(FRONTEND_DIR) && rm -rf dist node_modules
|
|
|
|
|
|
|
|
deps:
|
|
|
|
@echo "Installing Go dependencies..."
|
|
|
|
go mod download
|
|
|
|
|
|
|
|
retag:
|
|
|
|
@echo "Retagging..."
|
2024-03-20 01:14:00 +08:00
|
|
|
git tag -d $(GIT_TAG)
|
|
|
|
git push --delete origin $(GIT_TAG)
|
|
|
|
git tag -a $(GIT_TAG) -m "Recreated tag $(GIT_TAG)"
|
|
|
|
git push origin $(GIT_TAG)
|
2024-02-09 00:16:34 +08:00
|
|
|
|
|
|
|
patch-version:
|
|
|
|
@echo "Patching version..."
|
2024-03-20 01:14:00 +08:00
|
|
|
git tag -a $(shell semver -i patch $(GIT_TAG)) -m "Release $(shell semver -i patch $(GIT_TAG))"
|
|
|
|
git push origin $(shell semver -i patch $(GIT_TAG))
|
2023-09-08 21:15:47 +08:00
|
|
|
|
2024-02-09 00:16:34 +08:00
|
|
|
minor-version:
|
|
|
|
@echo "Minoring version..."
|
2024-03-20 01:14:00 +08:00
|
|
|
git tag -a $(shell semver -i minor $(GIT_TAG)) -m "Release $(shell semver -i minor $(GIT_TAG))"
|
|
|
|
git push origin $(shell semver -i minor $(GIT_TAG))
|