Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
59 lines (46 loc) · 1.72 KB
/
Copy pathMakefile
File metadata and controls
59 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Makefile
# Define the target platforms
PLATFORMS = linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/386
OUTPUT_DIR = build
MAIN = tsk.go
# Database and TSV
DB = example-sentences.sqlite
TSV = example-sentences.tsv
DB_BUILDER = build-example-sentences-db.sh
# Extract version from tsk.go (e.g. "v0.0.1") and replace dots with dashes
VERSION := $(shell grep -m1 'const version' tsk.go | cut -d'"' -f2 | sed 's/\./-/g')
# Installation directory (default: /usr/local/bin)
INSTALL_DIR ?= /usr/local/bin
.PHONY: all clean install
# Now all depends on generating words.txt, the output dir, the DB, and the Go builds
all: words.txt $(OUTPUT_DIR) $(DB) build-all
# Generate words.txt from glosses.jsonl before building
words.txt: glosses.jsonl
jq '.word' glosses.jsonl | sort -u > words.txt
# Rule to rebuild the SQLite FTS DB from TSV
$(DB): $(TSV) $(DB_BUILDER)
@echo "Rebuilding SQLite FTS DB: $@ from $<"
@./$(DB_BUILDER)
$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
build-all:
@for platform in $(PLATFORMS); do \
OS=$$(echo $$platform | cut -d'/' -f1); \
ARCH=$$(echo $$platform | cut -d'/' -f2); \
OUTPUT=$(OUTPUT_DIR)/tsk_$${OS}_$${ARCH}_$(VERSION); \
if [ "$$OS" = "windows" ]; then \
OUTPUT=$${OUTPUT}.exe; \
fi; \
echo "Building for $$OS/$$ARCH -> $$OUTPUT"; \
GOOS=$$OS GOARCH=$$ARCH CGO_ENABLED=0 \
go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o $$OUTPUT $(MAIN); \
done
install: all
@if [ "$(shell go env GOOS)" = "windows" ]; then \
echo "Install not supported on Windows"; \
exit 1; \
fi
@echo "Installing tsk to $(INSTALL_DIR)"; \
cp $(OUTPUT_DIR)/tsk_$(shell go env GOOS)_$(shell go env GOARCH)_$(VERSION) $(INSTALL_DIR)/tsk
clean:
rm -rf $(OUTPUT_DIR) $(DB)