-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
67 lines (52 loc) · 1.68 KB
/
Makefile
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
59
60
61
62
63
64
65
66
67
# Define Go command and flags
GO = go
GOFLAGS = -ldflags="-s -w"
# Define the target executable
TARGET = cuedo
# Default target: build the executable
all: $(TARGET)
# Rule to build the target executable
$(TARGET): main.go
$(GO) build $(GOFLAGS) -o $(TARGET) main.go
# Clean target: remove the target executable
clean:
rm -f $(TARGET)
# Run target: build and run the target executable
run: $(TARGET)
./$(TARGET)
# Test target: run Go tests for the project
test:
$(GO) test ./...
# Test target: run Go tests for the project with verbose output
vtest:
$(GO) test -v ./...
.PHONY: build install
GIT_REV_PARSE=git rev-parse HEAD
GIT_SHOW_DATE=git show -s --format=%cI
SET_VARS=date_now=$$(date -Iseconds); \
user=$$(whoami); \
cuedo_sha=$$($(GIT_REV_PARSE)); \
cuedo_date=$$($(GIT_SHOW_DATE) $$cuedo_sha); \
replace_path=$$(awk '/replace cuelang.org\/go => / {print $$4}' go.mod); \
if [ -n "$$replace_path" ]; then \
cd $$replace_path; \
cue_sha=$$($(GIT_REV_PARSE)); \
cue_date=$$($(GIT_SHOW_DATE) $$cue_sha); \
cd -; \
else \
cue_sha=$$(go list -m -json cuelang.org/go | jq -r .Version); \
cue_date=$$(go list -m -json cuelang.org/go | jq -r .Time); \
fi;
# WARNING the else branc above is not tested yet
LD_FLAGS="-X github.com/rudifa/cuedo/cmd.cueCommitSHA=$$cue_sha \
-X github.com/rudifa/cuedo/cmd.cueCommitDate=$$cue_date \
-X github.com/rudifa/cuedo/cmd.cuedoCommitSHA=$$cuedo_sha \
-X github.com/rudifa/cuedo/cmd.cuedoCommitDate=$$cuedo_date \
-X github.com/rudifa/cuedo/cmd.DateNow=$$date_now \
-X github.com/rudifa/cuedo/cmd.User=$$user"
build: $(TARGET)
$(SET_VARS) \
go build -v -ldflags $(LD_FLAGS)
install: $(TARGET)
$(SET_VARS) \
go install -v -ldflags $(LD_FLAGS)