forked from jlopp/statoshi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGNUmakefile
More file actions
executable file
·283 lines (251 loc) · 9.34 KB
/
GNUmakefile
File metadata and controls
executable file
·283 lines (251 loc) · 9.34 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
SHELL := /bin/bash
PWD ?= pwd_unknown
TIME := $(shell date +%s)
export TIME
OS :=$(shell uname -s)
export OS
OS_VERSION :=$(shell uname -r)
export OS_VERSION
ARCH :=$(shell uname -m)
export ARCH
ifeq ($(ARCH),x86_64)
TRIPLET :=x86_64-linux-gnu
export TRIPLET
endif
ifeq ($(ARCH),arm64)
TRIPLET :=aarch64-linux-gnu
export TRIPLET
endif
ifeq ($(ARCH),arm64)
TRIPLET :=aarch64-linux-gnu
export TRIPLET
endif
HOMEBREW := $(shell type -P brew)
export HOMEBREW
PYTHON := $(shell which python || echo)
export PYTHON
#PYTHON2 := $(shell which python2 || echo)
#export PYTHON2
PYTHON3 := $(shell which python3 || echo)
ifeq ($(PYTHON3),)
PYTHON3 :=$(shell which python || echo)
endif
export PYTHON3
PIP := $(notdir $(shell which pip || echo))
export PIP
PIP2 := $(notdir $(shell which pip2 || echo))
export PIP2
PIP3 := $(notdir $(shell which pip3 || echo))
export PIP3
ifeq ($(PYTHON3),/usr/local/bin/python3)
PIP := pip
PIP3 := pip
export PIP
export PIP3
endif
#detect python
PYTHON_ENV = $(shell python -c "import sys; sys.stdout.write('1') if hasattr(sys, 'base_prefix') else sys.stdout.write('0')" 2>/dev/null)
#detect python3
PYTHON3_ENV = $(shell python3 -c "import sys; sys.stdout.write('1') if hasattr(sys, 'base_prefix') else sys.stdout.write('0')")
export PYTHON_ENV
export PYTHON3_ENV
ifeq ($(PYTHON_ENV),1)
#likely in virtualenv
PYTHON_VENV := $(shell python -c "import sys; sys.stdout.write('1') if sys.prefix != sys.base_prefix else sys.stdout.write('0')" 2>/dev/null)
endif
export PYTHON_VENV
ifeq ($(PYTHON_VENV),1)
PYTHON3_VENV := $(shell python3 -c "import sys; sys.stdout.write('1') if sys.prefix != sys.base_prefix else sys.stdout.write('0')")
else
PYTHON_VENV :=$(PYTHON_ENV)
PYTHON3_VENV :=$(PYTHON3_ENV)
endif
export PYTHON3_VENV
ifeq ($(PYTHON_VENV),0)
USER_FLAG :=--user
else
USER_FLAG :=
endif
ifeq ($(project),)
PROJECT_NAME := $(notdir $(PWD))
else
PROJECT_NAME := $(project)
endif
export PROJECT_NAME
GIT_USER_NAME := $(shell git config user.name || echo $(PROJECT_NAME))
export GIT_USER_NAME
GH_USER_NAME := $(shell git config user.name || echo $(PROJECT_NAME))
ifneq ($(ghuser),)
GH_USER_NAME := $(ghuser)
endif
export GIT_USER_NAME
GIT_USER_EMAIL := $(shell git config user.email || echo $(PROJECT_NAME))
export GIT_USER_EMAIL
GIT_SERVER := https://github.com
export GIT_SERVER
GIT_SSH_SERVER := git@github.com
export GIT_SSH_SERVER
GIT_PROFILE := $(shell git config user.name || echo $(PROJECT_NAME))
export GIT_PROFILE
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo $(PROJECT_NAME))
export GIT_BRANCH
GIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo $(PROJECT_NAME))
export GIT_HASH
GIT_PREVIOUS_HASH := $(shell git rev-parse --short master@{1} 2>/dev/null || echo $(PROJECT_NAME))
export GIT_PREVIOUS_HASH
GIT_REPO_ORIGIN := $(shell git remote get-url origin 2>/dev/null || echo $(PROJECT_NAME))
export GIT_REPO_ORIGIN
GIT_REPO_NAME := $(PROJECT_NAME)
export GIT_REPO_NAME
GIT_REPO_PATH := $(HOME)/$(GIT_REPO_NAME)
export GIT_REPO_PATH
NODE_VERSION :=v14.21.3
export NODE_VERSION
NODE_ALIAS :=v14.21.0
export NODE_ALIAS
NVM_DIR :=$(HOME)/.nvm
export NVM_DIR
PACKAGE_MANAGER :=yarn
export PACKAGE_MANAGER
PACKAGE_INSTALL :=add
export PACKAGE_INSTALL
-:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
## help
.PHONY: init
.ONESHELL:
init:initialize venv## initialize venv
## init
@echo $(PYTHON)
@echo $(PYTHON2)
@echo $(PYTHON3)
@echo $(PIP)
@echo $(PIP2)
@echo $(PIP3)
@echo PATH=$(PATH):/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/bin
@echo PATH=$(PATH):$(HOME)/Library/Python/3.10/bin
test -d .venv || $(PYTHON3) -m virtualenv .venv
( \
source .venv/bin/activate; pip install -q -r requirements.txt; \
$(PYTHON3) -m pip install $(USER_FLAG) --upgrade pip; \
$(PYTHON3) -m pip install $(USER_FLAG) -r requirements.txt; \
$(PYTHON3) -m pip install -q omegaconf \
pip install -q --upgrade pip; \
);
( \
while ! docker system info > /dev/null 2>&1; do\
echo 'Waiting for docker to start...';\
if [[ '$(OS)' == 'Linux' ]]; then\
type -P systemctl && systemctl restart docker.service || type -P apk && apk add openrc docker && rc-service docker restart;\
fi;\
if [[ '$(OS)' == 'Darwin' ]]; then\
open --background -a /./Applications/Docker.app/Contents/MacOS/Docker;\
fi;\
sleep 1;\
done\
)
@bash -c ". .venv/bin/activate &"
help:## verbose help
@sed -n 's/^## //p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
.PHONY: report
report:## report
## report
@echo ''
@echo '[ENV VARIABLES] '
@echo ''
@echo 'TIME=${TIME}'
@echo 'BASENAME=${BASENAME}'
@echo 'PROJECT_NAME=${PROJECT_NAME}'
@echo ''
@echo 'PYTHON_ENV=${PYTHON_ENV}'
@echo 'PYTHON3_ENV=${PYTHON3_ENV}'
@echo ''
@echo 'PYTHON_VENV=${PYTHON_VENV}'
@echo 'PYTHON3_VENV=${PYTHON3_VENV}'
@echo ''
@echo 'PYTHON=${PYTHON}'
@echo 'PIP=${PIP}'
@echo 'PYTHON2=${PYTHON2}'
@echo 'PIP2=${PIP2}'
@echo 'PYTHON3=${PYTHON3}'
@echo 'PIP3=${PIP3}'
@echo ''
@echo 'HOMEBREW=${HOMEBREW}'
@echo ''
@echo 'GIT_USER_NAME=${GIT_USER_NAME}'
@echo 'GH_USER_REPO=${GH_USER_REPO}'
@echo 'GH_USER_SPECIAL_REPO=${GH_USER_SPECIAL_REPO}'
@echo 'GIT_USER_EMAIL=${GIT_USER_EMAIL}'
@echo 'GIT_SERVER=${GIT_SERVER}'
@echo 'GIT_PROFILE=${GIT_PROFILE}'
@echo 'GIT_BRANCH=${GIT_BRANCH}'
@echo 'GIT_HASH=${GIT_HASH}'
@echo 'GIT_PREVIOUS_HASH=${GIT_PREVIOUS_HASH}'
@echo 'GIT_REPO_ORIGIN=${GIT_REPO_ORIGIN}'
@echo 'GIT_REPO_NAME=${GIT_REPO_NAME}'
@echo 'GIT_REPO_PATH=${GIT_REPO_PATH}'
.PHONY: super
.ONESHELL:
super:
ifneq ($(shell id -u),0)
@echo switch to superuser
@echo cd $(TARGET_DIR)
sudo -s
endif
checkbrew:##
## checkbrew
ifeq ($(HOMEBREW),)
@/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" && $(MAKE) success || $(MAKE) failure
else
@type -P brew && $(MAKE) success || $(MAKE) failure
endif
submodules:## submodules
## submodules
git submodule update --init --recursive
git submodule foreach --recursive "git submodule update --init; git fetch --all --tags"
.ONESHELL:
docker-start:
## docker-start
@touch requirements.txt && $(PYTHON3) -m pip install -q -r requirements.txt
@test -d .venv || $(PYTHON3) -m virtualenv .venv
@( \
source .venv/bin/activate; $(PYTHON3) -m pip install -q -r requirements.txt; \
$(PYTHON3) -m pip install -q --upgrade pip; \
);
( \
while ! docker system info > /dev/null 2>&1; do\
echo 'Waiting for docker to start...';\
if [[ '$(OS)' == 'Linux' ]]; then\
type -P apt && apt install docker*;\
type -P systemctl && systemctl restart docker.service || type -P service && service docker.service restart || type -P apk && apk add openrc docker && rc-service docker restart || echo "try installing docker manually...";\
fi;\
if [[ '$(OS)' == 'Darwin' ]]; then\
open --background -a /./Applications/Docker.app/Contents/MacOS/Docker;\
fi;\
sleep 1;\
done\
)
initialize:## initialize
## initialize
@[[ '$(shell uname -m)' == 'x86_64' ]] && [[ '$(shell uname -s)' == 'Darwin' ]] && echo "is_Darwin/x86_64" || echo "not_Darwin/x86_64"
@[[ '$(shell uname -m)' == 'x86_64' ]] && [[ '$(shell uname -s)' == 'Linux' ]] && echo "is_Linux/x86_64" || echo "not_Linux/x86_64"
failure:
@-/usr/bin/false && ([ $$? -eq 0 ] && echo "success!") || echo "failure!"
success:
@-/usr/bin/true && ([ $$? -eq 0 ] && echo "success!") || echo "failure!"
venv:submodules## python3.10 virtualenv
$(MAKE) -f $(PWD)/venv.mk venv-3-10
venv-test:submodules## venv-3-10-test
$(MAKE) -f $(PWD)/venv.mk venv-3-10-test
tag:## tag
@git tag $(OS)-$(OS_VERSION)-$(ARCH)-$(shell date +%s)
@git push -f --tags || echo "unable to push tags..."
clean:## clean
@git clean -xfd && git submodule foreach --recursive git clean -xfd && git reset --hard && git submodule foreach --recursive git reset --hard && git submodule update --init --recursive
@if [[ -d $(PWD)/stm32/built ]]; then \
rm -rf $(PWD)/stm32/built/**.bin; fi;
-include Makefile
-include venv.mk
-include act.mk
# vim: set noexpandtab:
# vim: set setfiletype make