Skip to content

Commit

Permalink
build: adjust logic && add more cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
StrayDragon committed Mar 7, 2025
1 parent 1c511ec commit c90c0f7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
52 changes: 34 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
.PHONY: all build prepare package clean

BUILD_OUTPUT_DIR ?= build
BINARY_SUFFIX=$(if $(filter windows,$(GOOS)),.exe)
# Get GOOS and GOARCH from go env
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)

BINARIES := bookxnote-local-ocr server certgen
APP_NAME := bookxnote-local-ocr
BINARIES := $(APP_NAME) server certgen

ifdef GOOS
ifdef GOARCH
PLATFORM_SUFFIX := $(GOOS)-$(GOARCH)
BUILD_OUTPUT_DIR := $(BUILD_OUTPUT_DIR)/bookxnote-local-ocr-$(PLATFORM_SUFFIX)
ARCHIVE_NAME := bookxnote-local-ocr-$(PLATFORM_SUFFIX)
ARCHIVE_EXT := $(if $(filter windows,$(GOOS)),.zip,.tar.gz)
endif
endif
# Set platform suffix and build directory
PLATFORM_SUFFIX := $(GOOS)-$(GOARCH)
BUILD_ROOT := build
BUILD_OUTPUT_DIR := $(BUILD_ROOT)/$(APP_NAME)-$(PLATFORM_SUFFIX)
ARCHIVE_NAME := $(APP_NAME)-$(PLATFORM_SUFFIX)
ARCHIVE_EXT := $(if $(filter windows,$(GOOS)),.zip,.tar.gz)
BINARY_SUFFIX := $(if $(filter windows,$(GOOS)),.exe,)

all: package

build:
evalate-linux-build-privilege:
sudo ./$(BUILD_OUTPUT_DIR)/setup-privileges.sh

generate-gui-resources:
go generate ./cmd/bookxnote-local-ocr/

build: generate-gui-resources clean
@echo "building..."
@mkdir -p $(BUILD_OUTPUT_DIR)
@for binary in $(BINARIES); do \
echo "building $$binary..."; \
go build -o $(BUILD_OUTPUT_DIR)/$$binary$(BINARY_SUFFIX) cmd/$$binary/main.go; \
go build -o $(BUILD_OUTPUT_DIR)/$$binary$(BINARY_SUFFIX) ./cmd/$$binary/...; \
done
@cp artifact/config.yml $(BUILD_OUTPUT_DIR)/

prepare: build
@echo "prepare..."
@cp README.md LICENSE $(BUILD_OUTPUT_DIR)/
@mkdir -p $(BUILD_OUTPUT_DIR)/docs
@cp docs/tutorial.md $(BUILD_OUTPUT_DIR)/docs/tutorial.md
@cp artifact/config.yml $(BUILD_OUTPUT_DIR)/
@if [ "$(GOOS)" = "windows" ]; then \
cp artifact/windows/*.bat $(BUILD_OUTPUT_DIR)/; \
elif [ "$(GOOS)" = "linux" ]; then \
cp artifact/linux/setup-privileges.sh $(BUILD_OUTPUT_DIR)/; \
chmod +x $(BUILD_OUTPUT_DIR)/setup-privileges.sh; \
fi

package: prepare
@echo "packaging..."
@cd $(dir $(BUILD_OUTPUT_DIR)) && \
@cd $(BUILD_ROOT) && \
if [ "$(GOOS)" = "windows" ]; then \
zip -r $(ARCHIVE_NAME)$(ARCHIVE_EXT) $(notdir $(BUILD_OUTPUT_DIR)); \
zip -r $(ARCHIVE_NAME)$(ARCHIVE_EXT) $(APP_NAME)-$(PLATFORM_SUFFIX); \
else \
tar czf $(ARCHIVE_NAME)$(ARCHIVE_EXT) $(notdir $(BUILD_OUTPUT_DIR)); \
tar czf $(ARCHIVE_NAME)$(ARCHIVE_EXT) $(APP_NAME)-$(PLATFORM_SUFFIX); \
fi
@echo "done: $(ARCHIVE_NAME)$(ARCHIVE_EXT)"

dev-build: prepare evalate-linux-build-privilege
@echo "Done"

dev-run-gui: dev-build
./build/bookxnote-local-ocr-linux-amd64/bookxnote-local-ocr gui

clean:
@echo "clean..."
@rm -rf $(BUILD_OUTPUT_DIR)
@rm -rf $(BUILD_ROOT)
13 changes: 13 additions & 0 deletions artifact/linux/setup-privileges.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [ "$EUID" -ne 0 ]; then
echo "please run this script with sudo!"
exit 1
fi

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

setcap CAP_NET_BIND_SERVICE=+eip "$SCRIPT_DIR/server"
setcap 'CAP_DAC_OVERRIDE,CAP_SYS_ADMIN+ep' "$SCRIPT_DIR/certgen"

echo "privileges set successfully"
25 changes: 17 additions & 8 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,28 @@

以下命令均需要在解压后的程序根目录下运行!

## Linux/macOS
## Linux

首次运行需要调用该命令, 查看运行提示操作
1. 下载并解压 tar.gz 文件
2. 进入解压后的目录
3. 运行配置权限脚本:
```
chmod +x setup-privileges.sh
sudo ./setup-privileges.sh
```
4. 安装一些配置, 查看运行提示操作
```sh
sudo ./bookxnote-local-ocr install
./bookxnote-local-ocr install
```

之后仅需要在使用BookxNote OCR功能时, 运行该命令, 保持终端存在, 不要关闭
```sh
sudo ./bookxnote-local-ocr server
./bookxnote-local-ocr server
```

可以使用GUI程序(功能和Cli一致, 但是可以托盘管理)
```sh
./bookxnote-local-ocr gui
```

## Windows
Expand Down Expand Up @@ -52,7 +64,7 @@ sudo ./bookxnote-local-ocr server

在解压后的目录中运行以下命令

## Linux/macOS
## Linux
```
sudo ./bookxnote-local-ocr uninstall
```
Expand Down Expand Up @@ -107,9 +119,6 @@ ocr:
1. ~/.local/share/bookxnote-local-ocr/config.yml
2. ~/.config/bookxnote-local-ocr/config.yml
### macOS
1. ~/Library/Application Support/bookxnote-local-ocr/config.yml
### Windows
1. %APPDATA%/bookxnote-local-ocr/config.yml -->

Expand Down

0 comments on commit c90c0f7

Please sign in to comment.