@@ -12,79 +12,116 @@ WEBROOT_DIR=$(CURDIR)/webroot
12
12
APPS_DIR =$(WEBROOT_DIR ) /apps
13
13
GO_DIRS =./overlord/... ./cmd/...
14
14
15
+ # Supported architectures for ghost binary
16
+ GHOST_ARCHS =amd64 386 arm64 armv7
17
+ GHOST_BINS =$(addprefix $(BIN ) /ghost., $(addsuffix .linux,$(GHOST_ARCHS ) ) )
18
+
19
+ # Output formatting
20
+ cmd_msg = @echo " $(1 ) $(2 ) "
21
+
15
22
ifeq ($(STATIC ) , true)
16
23
LDFLAGS=-a -tags netgo -installsuffix netgo \
17
24
-ldflags '-extldflags "-static"'
18
25
endif
19
26
20
- .PHONY : all build build-bin build-apps clean clean-apps install go-fmt go-lint
27
+ .PHONY : all \
28
+ build build-go build-py build-apps \
29
+ ghost overlordd \
30
+ go-fmt go-lint \
31
+ clean clean-apps \
32
+ install
21
33
22
34
all : build
23
35
24
- build : build-bin build-apps
36
+ build : build-go build-py build-apps
25
37
26
38
deps :
27
- mkdir -p $(BIN )
28
- if $( DEPS) ; then \
39
+ @mkdir -p $(BIN )
40
+ @if $(DEPS ) ; then \
41
+ $(call cmd_msg,GET,dependencies) ; \
29
42
cd $(CURDIR ) ; \
30
43
$(GO ) get ./...; \
31
44
fi
32
45
33
46
overlordd : deps
34
- GOBIN=$(BIN ) $(GO ) install $(LDFLAGS ) $(CURDIR ) /cmd/$@
35
- rm -f $(BIN ) /webroot
36
- ln -s $(WEBROOT_DIR ) $(BIN ) /webroot
47
+ $(call cmd_msg,GO,cmd/$@ )
48
+ @GOBIN=$(BIN ) $(GO ) install $(LDFLAGS ) $(CURDIR ) /cmd/$@
49
+ @rm -f $(BIN ) /webroot
50
+ @ln -s $(WEBROOT_DIR ) $(BIN ) /webroot
37
51
38
52
ghost : deps
39
- GOBIN=$(BIN ) $(GO ) install $(LDFLAGS ) $(CURDIR ) /cmd/$@
53
+ @for arch in $(GHOST_ARCHS ) ; do \
54
+ $(call cmd_msg,GO,ghost.$$arch.linux) ; \
55
+ GOARCH_VAL=$$ arch; \
56
+ if [ " $$ arch" = " armv7" ]; then \
57
+ GOARCH_VAL=" arm" ; \
58
+ GOARM=7 GOOS=linux GOARCH=$$ GOARCH_VAL \
59
+ $(GO ) build $(LDFLAGS ) \
60
+ -o $(BIN ) /ghost.$$ arch.linux \
61
+ $(CURDIR ) /cmd/ghost; \
62
+ else \
63
+ GOOS=linux GOARCH=$$ GOARCH_VAL \
64
+ $(GO ) build $(LDFLAGS ) \
65
+ -o $(BIN ) /ghost.$$ arch.linux \
66
+ $(CURDIR ) /cmd/ghost; \
67
+ fi ; \
68
+ done
69
+ @cd $(BIN ) && for arch in $( GHOST_ARCHS) ; do \
70
+ $(call cmd_msg,SHA1,ghost.$$arch.linux) ; \
71
+ sha1sum ghost.$$ arch.linux > ghost.$$ arch.linux.sha1; \
72
+ done
40
73
41
74
build-go : overlordd ghost
42
75
43
- build-bin :
44
- mkdir -p $(BUILD )
45
- # Create virtualenv environment
46
- rm -rf $(BUILD ) /.venv
47
- python -m venv $(BUILD ) /.venv
48
- # Build ovl binary with pyinstaller
49
- cd $(BUILD ) ; \
76
+ build-py :
77
+ @ln -sf ../scripts/ghost.py bin
78
+ @mkdir -p $(BUILD )
79
+ $(call cmd_msg,VENV,creating virtualenv)
80
+ @rm -rf $(BUILD ) /.venv
81
+ @python -m venv $(BUILD ) /.venv
82
+ $(call cmd_msg,PIP,installing requirements)
83
+ @cd $(BUILD ) ; \
50
84
. $(BUILD ) /.venv/bin/activate; \
51
- pip install -r $(CURDIR ) /requirements.txt; \
52
- pip install pyinstaller; \
53
- pyinstaller --onefile $(CURDIR ) /scripts/ovl.py; \
54
- pyinstaller --onefile $(CURDIR ) /scripts/ghost.py
55
- # Move built binary to bin
56
- mv $(BUILD ) /dist/ovl $(BIN ) /ovl.py.bin
57
- mv $(BUILD ) /dist/ghost $(BIN ) /ghost.py.bin
58
-
85
+ pip install -q -r $(CURDIR ) /requirements.txt; \
86
+ pip install -q pyinstaller; \
87
+ $(call cmd_msg,GEN,ovl.py.bin) ; \
88
+ pyinstaller --onefile $(CURDIR ) /scripts/ovl.py > /dev/null; \
89
+ $(call cmd_msg,GEN,ghost.py.bin) ; \
90
+ pyinstaller --onefile $(CURDIR ) /scripts/ghost.py > /dev/null
91
+ $(call cmd_msg,MV,binaries to $(BIN ) )
92
+ @mv $(BUILD ) /dist/ovl $(BIN ) /ovl.py.bin
93
+ @mv $(BUILD ) /dist/ghost $(BIN ) /ghost.py.bin
59
94
60
95
go-fmt :
61
- $(GO ) fmt $(GO_DIRS )
96
+ $(call cmd_msg,FMT,$(GO_DIRS ) )
97
+ @$(GO ) fmt $(GO_DIRS )
62
98
63
99
go-lint :
64
- $(GO ) vet $(GO_DIRS )
100
+ $(call cmd_msg,VET,$(GO_DIRS ) )
101
+ @$(GO ) vet $(GO_DIRS )
65
102
@if ! command -v golint > /dev/null; then \
66
- echo " Installing golint... " ; \
103
+ $( call cmd_msg,GO,installing golint) ; \
67
104
$(GO ) install golang.org/x/lint/golint@latest; \
68
105
fi
69
- golint -set_exit_status $(GO_DIRS )
106
+ $(call cmd_msg,LINT,$(GO_DIRS ) )
107
+ @golint -set_exit_status $(GO_DIRS )
70
108
71
109
# Build all apps that have a package.json
72
110
build-apps :
73
- @echo " Building apps ..."
74
111
@mkdir -p $(APPS_DIR )
75
112
@cd apps && \
76
113
for dir in * /; do \
77
114
if [ ! -f " $$ dir/package.json" ]; then \
78
115
continue ; \
79
116
fi ; \
80
- echo " Building $$ dir ... " ; \
81
- (cd " $$ dir" && npm install && npm run build); \
117
+ $( call cmd_msg,NPM, $$dir) ; \
118
+ (cd " $$ dir" && npm install --silent && npm run build --silent ); \
82
119
if [ -d " $$ dir/dist" ]; then \
83
- echo " Copying $$ dir dist to apps directory ... " ; \
120
+ $( call cmd_msg,CP, $$dir to apps) ; \
84
121
mkdir -p $(APPS_DIR ) /" $$ {dir%/}" ; \
85
122
cp -r " $$ dir/dist/" * $(APPS_DIR ) /" $$ {dir%/}" /; \
86
123
if [ " $$ dir" = " dashboard/" ]; then \
87
- echo " Copying dashboard to webroot ... " ; \
124
+ $( call cmd_msg,CP, dashboard to webroot) ; \
88
125
cp $(APPS_DIR ) /dashboard/index.html \
89
126
$(CURDIR ) /webroot/index.html; \
90
127
fi ; \
@@ -96,16 +133,17 @@ build-apps:
96
133
97
134
# Install the built apps to the system directory
98
135
install : build
99
- @echo " Installing apps..."
100
- mkdir -p /usr/local/share/overlord/apps
101
- cp -r $(APPS_DIR ) /* /usr/local/share/overlord/apps/
102
- @echo " Installation complete"
136
+ $(call cmd_msg,CP,apps to system)
137
+ @mkdir -p /usr/local/share/overlord/apps
138
+ @cp -r $(APPS_DIR ) /* /usr/local/share/overlord/apps/
103
139
104
140
clean-apps :
105
- rm -rf $(APPS_DIR )
106
- rm -rf $(WEBROOT_DIR ) /index.html
141
+ $(call cmd_msg,RM,apps)
142
+ @rm -rf $(APPS_DIR )
143
+ @rm -rf $(WEBROOT_DIR ) /index.html
107
144
108
145
clean : clean-apps
109
- rm -rf $(BIN ) /ghost $(BIN ) /overlordd $(BUILD ) \
146
+ $(call cmd_msg,RM,build artifacts)
147
+ @rm -rf $(BIN ) /ghost* $(BIN ) /overlordd $(BUILD ) \
110
148
$(BIN ) /ghost.py.bin $(BIN ) /ovl.py.bin \
111
149
$(APPS_DIR )
0 commit comments