@@ -9,103 +9,120 @@ DEPS?=true
9
9
STATIC? =false
10
10
LDFLAGS =
11
11
WEBROOT_DIR =$(CURDIR ) /webroot
12
- APPS_DIR =$(WEBROOT_DIR ) /apps
12
+ DIST_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 arm
17
+ GHOST_BINS =$(addprefix $(BIN ) /ghost., $(addsuffix .linux,$(GHOST_ARCHS ) ) )
18
+
19
+ # Get list of apps with package.json
20
+ APP_DIRS =$(shell find apps -maxdepth 1 -mindepth 1 \
21
+ -type d -exec test -f '{}/package.json' \; -print | sed 's|apps/||')
22
+ APP_TARGETS =$(addprefix $(DIST_APPS_DIR ) /,$(APP_DIRS ) )
23
+
24
+ # Output formatting
25
+ cmd_msg = @echo " $(1 ) $(2 ) "
26
+
15
27
ifeq ($(STATIC ) , true)
16
28
LDFLAGS=-a -tags netgo -installsuffix netgo \
17
29
-ldflags '-extldflags "-static"'
18
30
endif
19
31
20
- .PHONY : all build build-bin build-apps clean clean-apps install go-fmt go-lint
32
+ .PHONY : all \
33
+ build build-go build-py build-apps \
34
+ ghost ghost-all overlordd \
35
+ go-fmt go-lint \
36
+ clean clean-apps \
37
+ install
21
38
22
39
all : build
23
40
24
- build : build-bin build-apps
41
+ build : build-go build-py build-apps
25
42
26
43
deps :
27
- mkdir -p $(BIN )
28
- if $( DEPS) ; then \
44
+ @ mkdir -p $(BIN )
45
+ @ if $(DEPS ) ; then \
29
46
cd $(CURDIR ) ; \
30
47
$(GO ) get ./...; \
31
48
fi
32
49
33
50
overlordd : deps
34
- GOBIN=$(BIN ) $(GO ) install $(LDFLAGS ) $(CURDIR ) /cmd/$@
35
- rm -f $(BIN ) /webroot
36
- ln -s $(WEBROOT_DIR ) $(BIN ) /webroot
51
+ $(call cmd_msg,GO,cmd/$@ )
52
+ @GOBIN=$(BIN ) $(GO ) install $(LDFLAGS ) $(CURDIR ) /cmd/$@
53
+ @rm -f $(BIN ) /webroot
54
+ @ln -s $(WEBROOT_DIR ) $(BIN ) /webroot
37
55
38
56
ghost : deps
39
- GOBIN=$(BIN ) $(GO ) install $(LDFLAGS ) $(CURDIR ) /cmd/$@
57
+ $(call cmd_msg,GO,cmd/$@ )
58
+ @GOBIN=$(BIN ) $(GO ) install $(LDFLAGS ) $(CURDIR ) /cmd/$@
40
59
41
- build-go : overlordd ghost
60
+ $(BIN ) /ghost.% .linux :
61
+ $(call cmd_msg,GO,$(notdir $@ ) )
62
+ @GOOS=linux GOARCH=$* $(GO ) build $(LDFLAGS ) -o $@ $(CURDIR ) /cmd/ghost
42
63
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 ) ; \
50
- . $(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
64
+ $(BIN ) /ghost.% .linux.sha1 : $(BIN ) /ghost.% .linux
65
+ $(call cmd_msg,SHA1,$(notdir $< ) )
66
+ @cd $(BIN ) && sha1sum $(notdir $< ) > $(notdir $@ )
58
67
68
+ ghost-all : $(GHOST_BINS ) $(GHOST_BINS:=.sha1 )
69
+
70
+ build-go : overlordd ghost ghost-all
71
+
72
+ build-py :
73
+ @ln -sf ../scripts/ghost.py bin
74
+ @mkdir -p $(BUILD )
75
+ $(call cmd_msg,VENV,creating virtualenv)
76
+ @rm -rf $(BUILD ) /.venv
77
+ @python -m venv $(BUILD ) /.venv
78
+ $(call cmd_msg,PIP,installing requirements)
79
+ @cd $(BUILD ) ; \
80
+ . $(BUILD ) /.venv/bin/activate; \
81
+ pip install -q -r $(CURDIR ) /requirements.txt; \
82
+ pip install -q pyinstaller; \
83
+ $(call cmd_msg,GEN,ovl.py.bin) ; \
84
+ pyinstaller --onefile $(CURDIR ) /scripts/ovl.py > /dev/null; \
85
+ $(call cmd_msg,GEN,ghost.py.bin) ; \
86
+ pyinstaller --onefile $(CURDIR ) /scripts/ghost.py > /dev/null
87
+ $(call cmd_msg,MV,binaries to $(BIN ) )
88
+ @mv $(BUILD ) /dist/ovl $(BIN ) /ovl.py.bin
89
+ @mv $(BUILD ) /dist/ghost $(BIN ) /ghost.py.bin
59
90
60
91
go-fmt :
61
- $(GO ) fmt $(GO_DIRS )
92
+ $(call cmd_msg,FMT,$(GO_DIRS ) )
93
+ @$(GO ) fmt $(GO_DIRS )
62
94
63
95
go-lint :
64
- $(GO ) vet $(GO_DIRS )
65
- @if ! command -v golint > /dev/null; then \
66
- echo " Installing golint..." ; \
67
- $(GO ) install golang.org/x/lint/golint@latest; \
68
- fi
69
- golint -set_exit_status $(GO_DIRS )
70
-
71
- # Build all apps that have a package.json
72
- build-apps :
73
- @echo " Building apps ..."
74
- @mkdir -p $(APPS_DIR )
75
- @cd apps && \
76
- for dir in * /; do \
77
- if [ ! -f " $$ dir/package.json" ]; then \
78
- continue ; \
79
- fi ; \
80
- echo " Building $$ dir ..." ; \
81
- (cd " $$ dir" && npm install && npm run build); \
82
- if [ -d " $$ dir/dist" ]; then \
83
- echo " Copying $$ dir dist to apps directory ..." ; \
84
- mkdir -p $(APPS_DIR ) /" $$ {dir%/}" ; \
85
- cp -r " $$ dir/dist/" * $(APPS_DIR ) /" $$ {dir%/}" /; \
86
- if [ " $$ dir" = " dashboard/" ]; then \
87
- echo " Copying dashboard to webroot ..." ; \
88
- cp $(APPS_DIR ) /dashboard/index.html \
89
- $(CURDIR ) /webroot/index.html; \
90
- fi ; \
91
- else \
92
- echo " Error: No dist directory found for $$ dir" ; \
93
- exit 1; \
94
- fi ; \
95
- done
96
+ $(call cmd_msg,VET,$(GO_DIRS ) )
97
+ @$(GO ) vet $(GO_DIRS )
98
+ $(call cmd_msg,GO,installing golint)
99
+ @$(GO ) install golang.org/x/lint/golint@latest
100
+ $(call cmd_msg,LINT,$(GO_DIRS ) )
101
+ @golint -set_exit_status $(GO_DIRS )
102
+
103
+ # Pattern rule for building individual apps
104
+ $(DIST_APPS_DIR ) /% :
105
+ $(call cmd_msg,NPM,$* )
106
+ @mkdir -p $(DIST_APPS_DIR )
107
+ @cd apps/$* && npm install --silent && npm run build --silent
108
+ @cp -r apps/$* /dist $(DIST_APPS_DIR ) /$*
109
+
110
+ build-apps : $(APP_TARGETS )
111
+ @cp $(DIST_APPS_DIR ) /dashboard/index.html $(WEBROOT_DIR )
96
112
97
113
# Install the built apps to the system directory
98
114
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"
115
+ $(call cmd_msg,CP,apps to system)
116
+ @mkdir -p /usr/local/share/overlord/apps
117
+ @cp -r $(DIST_APPS_DIR ) /* /usr/local/share/overlord/apps/
103
118
104
119
clean-apps :
105
- rm -rf $(APPS_DIR )
106
- rm -rf $(WEBROOT_DIR ) /index.html
120
+ $(call cmd_msg,RM,apps)
121
+ @rm -rf $(DIST_APPS_DIR )
122
+ @rm -rf $(WEBROOT_DIR ) /index.html
107
123
108
124
clean : clean-apps
109
- rm -rf $(BIN ) /ghost $(BIN ) /overlordd $(BUILD ) \
125
+ $(call cmd_msg,RM,build artifacts)
126
+ @rm -rf $(BIN ) /ghost* $(BIN ) /overlordd $(BUILD ) \
110
127
$(BIN ) /ghost.py.bin $(BIN ) /ovl.py.bin \
111
- $(APPS_DIR )
128
+ $(DIST_APPS_DIR )
0 commit comments