1
1
SHELL = bash
2
2
PROJECT_ROOT := $(patsubst % /,% ,$(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) ) )
3
3
4
+ THIS_OS := $(shell uname | cut -d- -f1)
5
+ THIS_ARCH := $(shell uname -m)
6
+
4
7
GIT_COMMIT := $(shell git rev-parse HEAD)
5
8
GIT_DIRTY := $(if $(shell git status --porcelain) ,+CHANGES)
6
9
7
10
GO_LDFLAGS ?= -X=github.com/seashell/drago/version.GitCommit=$(GIT_COMMIT )$(GIT_DIRTY )
8
11
9
12
CGO_ENABLED ?= 0
10
13
14
+ ifeq ($(CI ) ,true)
15
+ $(info Running in a CI environment, verbose mode is disabled)
16
+ else
17
+ VERBOSE="true"
18
+ endif
19
+
20
+ # List of supported OS
21
+ SUPPORTED_OSES = Linux
22
+
11
23
# User defined flags
24
+ OS := $(or $(OS ) ,$(O ) ) # # Define build target OS, e.g linux (coming soon)
25
+ ARCH := $(or $(ARCH ) ,$(A ) ) # # Define build target architecture, e.g amd64 (coming soon)
12
26
STATIC := $(or $(STATIC ) ,$(S ) ) # # If set to 1, build statically linked binary
13
- DOCKER := $(or $(DOCKER ) ,$(D ) ) # # If set to 1, build using docker container
14
- OS := $(or $(OS ) ,$(O ) ) # (coming soon) Define build target OS, e.g linux
15
- ARCH := $(or $(ARCH ) ,$(A ) ) # (coming soon) Define build target architecture, e.g amd64
27
+ DOCKER := $(or $(DOCKER ) ,$(D ) ) # # If set to 1, run build within a Docker container
16
28
17
- # Handle static builds
29
+ # ---- Handle static builds
18
30
ifeq ($(STATIC ) ,1)
19
- GO_LDFLAGS := "${GO_LDFLAGS} -linkmode external -extldflags -static"
31
+ GO_LDFLAGS := "${GO_LDFLAGS} -w -extldflags -static"
20
32
endif
21
-
33
+
34
+ # ---- In case of a Dockerized build, check if the builder image is available.
22
35
ifeq ($(DOCKER ) ,1)
23
- CHECK_DOCKER := $(shell docker images --filter LABEL=com.drago.builder=true -q)
24
- ifeq ($(user ) ,)
25
- # USER retrieved from env, UID from shell.
26
36
HOST_USER ?= $(strip $(if $(USER),$(USER),nodummy))
27
37
HOST_UID ?= $(strip $(if $(shell id -u),$(shell id -u),4000))
28
- else
29
- # allow override by adding user= and/ or uid= (lowercase!).
30
- # uid= defaults to 0 if user= set (i.e. root).
31
- HOST_USER = $(user)
32
- HOST_UID = $(strip $(if $(uid),$(uid),0))
33
- endif
34
- BUILD_DOCKER := (docker build --label com.drago.builder=true --build-arg HOST_UID=${HOST_UID} --build-arg HOST_USER=${HOST_USER} -t drago_builder . -f ./docker/Dockerfile.builder)
38
+ DOCKER_BUILDER_IMAGE_AVAILABLE := $(shell docker images --filter LABEL=com.drago.builder=true -q)
39
+ BUILD_DOCKER_BUILDER_IMAGE_CMD := (docker build --label com.drago.builder=true --build-arg HOST_UID=${HOST_UID} --build-arg HOST_USER=${HOST_USER} -t drago_builder . -f ./build/Dockerfile.builder)
35
40
endif
36
41
37
- # targets
38
- ALL_TARGETS += linux_amd64 \
42
+ # =========== Targets ===========
43
+
44
+ ifeq (Linux,$(THIS_OS ) )
45
+ ALL_TARGETS = linux_amd64
46
+ endif
39
47
40
48
default : help
41
49
42
- build/linux_amd64/drago : CMD='CGO_ENABLED=$(CGO_ENABLED ) GOOS=linux GOARCH=amd64 \
50
+ # ====> Current platform
51
+ .PHONY : dev
52
+ dev : GOOS=$(shell go env GOOS)
53
+ dev : GOARCH=$(shell go env GOARCH)
54
+ dev : DEV_TARGET=$(GOOS ) _$(GOARCH )
55
+ dev : # # Build for the current platform
56
+ @rm -rf $(PROJECT_ROOT ) /bin
57
+ @$(MAKE ) --no-print-directory $(DEV_TARGET )
58
+
59
+ # ====> Container
60
+ .PHONY : container
61
+ container : # # Build container with the Drago binary inside
62
+ @$(MAKE ) ui dev STATIC=1
63
+ @echo " ==> Building container image " drago:latest" ..."
64
+ @docker build -t drago:latest . -f ./build/Dockerfile.linux_amd64
65
+
66
+ # ====> All
67
+ .PHONY : all
68
+ all : clean ui $(foreach t,$(ALL_TARGETS ) ,$(t ) ) # # Build all targets supported by this platform
69
+ @echo " ==> Results:"
70
+ @tree --dirsfirst $(PROJECT_ROOT ) /bin
71
+
72
+ # ====> Tidy
73
+ .PHONY : tidy
74
+ tidy :
75
+ @echo " --> Tidying up Drago modules"
76
+ @go mod tidy
77
+
78
+ # ====> Linux AMD 64
79
+ .PHONY : linux_amd64
80
+ linux_amd64 : CMD='CGO_ENABLED=$(CGO_ENABLED ) GOOS=linux GOARCH=amd64 \
43
81
go build \
44
82
-trimpath \
45
- -ldflags $(GO_LDFLAGS ) \
46
- -o " $@ " '
47
- build/linux_amd64/drago : $(SOURCE_FILES ) # # Build drago for linux/amd64
48
- @echo " ==> Building $@ with tags $( GO_TAGS) ..."
83
+ -ldflags " " $(GO_LDFLAGS ) " " \
84
+ -o " bin/$@ /drago" '
85
+ linux_amd64 : $(SOURCE_FILES ) # # Build Drago for linux/amd64
86
+ @echo " ==> Building $@ ..."
87
+ @echo " ==> COMMAND $( CMD) ..."
49
88
ifeq ($(DOCKER ) ,1)
50
- ifeq ($(CHECK_DOCKER ) ,)
51
- @echo "==> Building docker container builder image..."
52
- @$(call BUILD_DOCKER )
89
+ ifeq ($(DOCKER_BUILDER_IMAGE_AVAILABLE ) ,)
90
+ @echo "==> Building Docker builder image..."
91
+ @$(call BUILD_DOCKER_BUILDER_IMAGE_CMD )
53
92
endif
54
93
docker run --rm -v ${PROJECT_ROOT}:${PROJECT_ROOT} --workdir=${PROJECT_ROOT} drago_builder \
55
94
/bin/sh -c ${CMD}
56
95
else
57
96
@eval ${CMD}
58
97
endif
59
98
60
- build/linux_arm64/drago : # (coming soon) Build drago for linux/arm64
99
+ # ====> Linux ARM 64
100
+ .PHONY : linux/arm64
101
+ linux/arm64 : # # Build Drago for linux/arm64 (coming soon)
61
102
@echo " ==> Coming soon..."
62
103
63
- build/linux_arm/drago : # (coming soon) Build drago for linux/arm
104
+ # ====> Linux ARM
105
+ .PHONY : linux/arm
106
+ linux/arm : # # Build drago for linux/arm (coming soon)
64
107
@echo " ==> Coming soon..."
65
108
109
+ # ====> Web UI
66
110
.PHONY : ui
67
111
ui : CMD="go generate"
68
- ui : # # Generate UI .go bindings
69
- @echo " ==> Generating UI .go bindings ..."
112
+ ui : # # Build Web UI
113
+ @echo " ==> Building Web UI ..."
70
114
ifeq ($(DOCKER ) ,1)
71
- ifeq ($(CHECK_DOCKER ) ,)
72
- @echo "==> Generating docker builder..."
73
- @$(call BUILD_DOCKER )
115
+ ifeq ($(DOCKER_BUILDER_IMAGE_AVAILABLE ) ,)
116
+ @echo "==> Building Docker builder image ..."
117
+ @$(call BUILD_DOCKER_BUILDER_IMAGE_CMD )
74
118
endif
75
119
docker run --rm -v ${PROJECT_ROOT}:${PROJECT_ROOT} --workdir=${PROJECT_ROOT} drago_builder \
76
120
/bin/sh -c ${CMD}
77
121
else
78
122
@eval ${CMD}
79
123
endif
80
124
81
- .PHONY : dev
82
- dev : GOOS=$(shell go env GOOS)
83
- dev : GOARCH=$(shell go env GOARCH)
84
- dev : DEV_TARGET=build/$(GOOS ) _$(GOARCH ) /drago
85
- dev : # # Build for the current development platform
86
- @echo " ==> Removing old development binary..."
87
- @rm -rf $(PROJECT_ROOT ) /build
88
- @$(MAKE ) --no-print-directory $(DEV_TARGET )
89
-
90
- .PHONY : container
91
- container : # # Build container with drago binary inside
92
- @$(MAKE ) ui dev STATIC=1
93
- @echo " ==> Building container image " drago:latest" ..."
94
- @docker build -t drago:latest . -f ./docker/Dockerfile.linux_amd64
95
-
96
- .PHONY : release
97
- release : clean ui $(foreach t,$(ALL_TARGETS ) ,build/$(t ) /drago) # # Build all release packages which can be built on this platform
98
- @echo " ==> Results:"
99
- @tree --dirsfirst $(PROJECT_ROOT ) /build
100
-
101
-
102
125
.PHONY : clean
103
126
clean : # # Remove build artifacts
104
127
@echo " ==> Cleaning build artifacts..."
105
- @rm -rf " $( PROJECT_ROOT) /build /"
106
- @rm -rf " $( PROJECT_ROOT) /ui/build/"
128
+ @rm -rf " $( PROJECT_ROOT) /bin /"
129
+ @rm -rf " $( PROJECT_ROOT) /ui/build/* "
107
130
@rm -rf " $( PROJECT_ROOT) /ui/node_modules/"
108
131
109
132
HELP_FORMAT =" \033[36m%-25s\033[0m %s\n"
110
133
EG_FORMAT =" \033[36m%s\033[0m %s\n"
134
+
111
135
.PHONY : help
112
- help : # # Display this usage information
136
+ help : # # Display usage information
113
137
@echo " Valid targets:"
114
138
@grep -E ' ^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST ) | \
115
139
sort | \
@@ -126,6 +150,6 @@ help: ## Display this usage information
126
150
{printf $(HELP_FORMAT ) , $$ 1, $$ 2}'
127
151
@echo " "
128
152
@echo " Examples:"
129
- @printf $(EG_FORMAT ) " ~${PWD} " " $$ make ui dev DOCKER=1"
130
153
@printf $(EG_FORMAT ) " ~${PWD} " " $$ make dev STATIC=1"
154
+ @printf $(EG_FORMAT ) " ~${PWD} " " $$ make ui dev DOCKER=1"
131
155
@printf $(EG_FORMAT ) " ~${PWD} " " $$ make container DOCKER=1"
0 commit comments