|
1 | | -.DEFAULT_GOAL = build |
| 1 | +.DEFAULT_GOAL = default |
2 | 2 |
|
3 | 3 | default : build |
4 | 4 | all : setup build |
5 | 5 |
|
6 | | -.ONESHELL: # Applies to every targets in the file! |
7 | | - |
8 | | -export PATH := $(shell pwd)/node_modules/.bin:$(PATH) |
9 | | - |
10 | | -export PXT_FORCE_LOCAL := 1 |
11 | | -export PXT_RUNTIME_DEV := 1 |
12 | | -export PXT_ASMDEBUG := 1 |
13 | | -export PXT_NODOCKER := 1 |
14 | | - |
15 | | -PXT_LIBRARIES := pxt pxt-common-packages pxt-steami pxt-steami-backend |
16 | | -PXT_COMMANDS := add buildcss buildjres buildsimjs buildsprites buildtarget bump checkdocs checkpkgcfg ci console deploy extract help init install npminstallnative run serve staticpkg tag testghpkgs update usedblocks |
17 | | -# Arguments par défaut pour chaque commande PXT |
18 | | -PXT_ADD_ARGS ?= |
19 | | -PXT_BUILDCSS_ARGS ?= |
20 | | -PXT_BUILDJRES_ARGS ?= |
21 | | -PXT_BUILDSIMJS_ARGS ?= |
22 | | -PXT_BUILDSPRITES_ARGS ?= |
23 | | -PXT_BUILDTARGET_ARGS ?= --localbuild --force |
24 | | -PXT_BUMP_ARGS ?= |
25 | | -PXT_CHECKDOCS_ARGS ?= |
26 | | -PXT_CHECKPKGCFG_ARGS ?= |
27 | | -PXT_CI_ARGS ?= |
28 | | -PXT_CONSOLE_ARGS ?= |
29 | | -PXT_DEPLOY_ARGS ?= |
30 | | -PXT_EXTRACT_ARGS ?= |
31 | | -PXT_HELP_ARGS ?= |
32 | | -PXT_INIT_ARGS ?= |
33 | | -PXT_INSTALL_ARGS ?= |
34 | | -PXT_NPMINSTALLNATIVE_ARGS ?= |
35 | | -PXT_RUN_ARGS ?= |
36 | | -PXT_SERVE_ARGS ?= --localbuild --rebundle --noauth --no-browser --no-serial -h '0.0.0.0' |
37 | | -PXT_STATICPKG_ARGS ?= -o ../static/ --localbuild |
38 | | -PXT_TAG_ARGS ?= |
39 | | -PXT_TESTGHPKGS_ARGS ?= |
40 | | -PXT_UPDATE_ARGS ?= |
41 | | -PXT_USEDBLOCKS_ARGS ?= |
42 | | - |
43 | | -PXT="/workspaces/makecode-steami/node_modules/.bin/pxt" |
44 | | - |
45 | | -define install_node_package |
46 | | - echo "Installing $1 ..." |
47 | | - cd $1 || exit |
48 | | - npm install --link |
49 | | -endef |
50 | | - |
51 | | -define _remove_file_if_exist |
52 | | - if [ -f $1 ] ; then |
53 | | - echo "Remove $1" |
54 | | - rm -f $1 |
55 | | - fi |
56 | | -endef |
57 | | - |
58 | | -define _remove_directory_if_exist |
59 | | - if [ -d $1 ] ; then |
60 | | - echo "Remove directory $1" |
61 | | - rm -Rf $1 |
62 | | - fi |
63 | | -endef |
64 | | - |
65 | | -define deepclean_node_package |
66 | | - echo "Deep cleanning $1 .." |
67 | | - $(call _remove_file_if_exist,$1/package-lock.json) |
68 | | - $(call _remove_directory_if_exist,$1/node_modules) |
69 | | -endef |
70 | | - |
71 | | -define pxt_command |
72 | | - echo "PXT = $(PXT)" |
73 | | - echo "Call pxt $1" |
74 | | - if ! [ -x $(PXT) ]; then |
75 | | - echo "pxt is not installed ! Please run make setup first" |
76 | | - exit |
77 | | - fi |
78 | | - cd pxt-steami || exit |
79 | | - pxt $1 |
80 | | -endef |
81 | | - |
82 | | -define _clean_static |
83 | | - echo "Clean static build" |
84 | | - $(call _remove_directory_if_exist,static) |
85 | | -endef |
86 | | - |
87 | | -define _clean_pxt_steami |
88 | | - echo "Clean pxt-steami build" |
89 | | - |
90 | | - if [ -x "$(PXT)" ]; then |
91 | | - echo "pxt found ! \n Automatic cleanning" |
92 | | - if [ -d pxt-steami/built ]; then |
93 | | - cd pxt-steami || exit |
94 | | - pxt clean |
95 | | - fi |
96 | | - else |
97 | | - echo "pxt not found ! \n Manual cleanning" |
98 | | - $(call _remove_directory_if_exist,pxt-steami/built) |
99 | | - $(call _remove_directory_if_exist,pxt-steami/libs/core/built) |
100 | | - $(call _remove_directory_if_exist,pxt-steami/libs/blocksprj/built) |
101 | | - fi |
102 | | -endef |
103 | | - |
104 | | -define _clean_pxt_core |
105 | | - echo "Clean pxt-core build" |
106 | | - $(call _remove_directory_if_exist,pxt/built) |
107 | | -endef |
108 | | - |
109 | | -define _clean_pxt_common_packages |
110 | | - echo "Clean pxt-common-packages build" |
111 | | - $(call _remove_directory_if_exist,pxt-common-packages/built) |
112 | | -endef |
113 | | - |
114 | | -define _clean_pxt_steami_backend_certificates |
115 | | - echo "Clean pxt-steami-backend certificates ..." |
116 | | - $(call _remove_file_if_exist,pxt-steami-backend/https/fastify.cert) |
117 | | - $(call _remove_file_if_exist,pxt-steami-backend/https/fastify.key) |
118 | | - $(call _remove_file_if_exist,pxt-steami-backend/https/rootCA.pem) |
119 | | -endef |
120 | | - |
121 | | -define _clean |
122 | | - $(call _clean_static) |
123 | | - $(call _clean_pxt_steami) |
124 | | -endef |
125 | | - |
126 | | -define _deepclean |
127 | | - $(call _clean) |
128 | | - $(call _clean_pxt_common_packages) |
129 | | - $(call _clean_pxt_core) |
130 | | - $(call deepclean_node_package,pxt) |
131 | | - $(call deepclean_node_package,pxt-common-packages) |
132 | | - $(call deepclean_node_package,pxt-steami) |
133 | | - $(call deepclean_node_package,pxt-steami-backend) |
134 | | - $(call deepclean_node_package,.) |
135 | | -endef |
136 | | - |
137 | | -define _generate_localcertificates |
138 | | - export CAROOT=$(PWD)/pxt-steami-backend/https |
139 | | - mkcert -install |
140 | | - mkcert -cert-file pxt-steami-backend/https/fastify.cert -key-file pxt-steami-backend/https/fastify.key 'makecode.local' localhost 127.0.0.1 ::1 |
141 | | -endef |
142 | | - |
143 | | -define _install_cert_for_local_dev |
144 | | - if [ -f /.dockerenv ]; then |
145 | | - echo "This rule work only for the host system" |
146 | | - else |
147 | | - sudo cp pxt-steami-backend/https/rootCA.pem /usr/local/share/ca-certificates/rootCA.crt |
148 | | - sudo update-ca-certificates |
149 | | - sudo sh -c "echo 127.0.0.1 makecode.local>>/etc/hosts" |
150 | | - fi |
151 | | -endef |
152 | | - |
153 | | -.PHONY : prepare |
154 | | -prepare : |
| 6 | +.ONESHELL: # Applies to every targets |
| 7 | + |
| 8 | +include env.mk |
| 9 | +include commons.mk |
| 10 | +include pxt.mk |
| 11 | + |
| 12 | +# Setup commands |
| 13 | +.PHONY: prepare |
| 14 | +prepare: |
155 | 15 | @echo "Install Git hooks" |
156 | 16 | git config core.hooksPath .hooks |
157 | 17 |
|
158 | | -.PHONY : setup |
159 | | -setup : prepare clean $(PXT) install-makecode-steami $(addprefix install-,$(PXT_LIBRARIES)) |
| 18 | +.PHONY: setup |
| 19 | +setup: prepare clean $(PXT) |
160 | 20 |
|
161 | 21 | .PHONY : clean |
162 | 22 | clean : ;@$(call _clean) |
163 | 23 |
|
| 24 | +.PHONY : clean-local-certificates |
| 25 | +clean-local-certificates:;@$(call _clean_pxt_steami_backend_certificates) |
| 26 | + |
164 | 27 | .PHONY : deepclean |
165 | 28 | deepclean : ;@$(call _deepclean) |
166 | 29 |
|
167 | | -# Création des cibles de build pour chaque package pxt |
168 | | -define _install_node_package_template |
169 | | -.PHONY: install-$1 |
170 | | -install-$1: $2/node_modules/.package-lock.json $2/package-lock.json |
171 | | - |
172 | | -$2/node_modules/.package-lock.json $2/package-lock.json: $2/package.json |
173 | | - @$$(call install_node_package,$$(<D)) |
174 | | - |
175 | | -endef |
| 30 | +# Create make rule for each PXT command |
| 31 | +$(foreach command,$(PXT_COMMANDS),$(eval $(call _call_pxt_command_template,$(command),$(command),$(PXT)))) |
176 | 32 |
|
177 | | -# Création de la target install-makecode-steami |
| 33 | +# Create install rules for each node package |
178 | 34 | $(eval $(call _install_node_package_template,makecode-steami,.)) |
179 | | - |
180 | | -# Création des targets install-pxt-XXX |
181 | 35 | $(foreach target,$(PXT_LIBRARIES),$(eval $(call _install_node_package_template,$(target),$(target)))) |
182 | 36 |
|
183 | | -$(PXT) : pxt/built/target.json pxt-common-packages/node_modules/.package-lock.json node_modules/.package-lock.json |
| 37 | +# Install pxt CLI |
| 38 | +$(PXT) : | install-makecode-steami $(addprefix install-,$(PXT_LIBRARIES)) pxt/built/target.json |
184 | 39 |
|
| 40 | +# Build pxt cli |
185 | 41 | pxt/built/target.json : pxt/node_modules/.package-lock.json |
| 42 | + @echo "Build pxt core" |
186 | 43 | cd pxt || exit |
187 | 44 | npm run build |
188 | 45 |
|
189 | | -define _call_pxt_command_template |
190 | | -.PHONY: $1 |
191 | | -$1: $3 |
192 | | - @$$(call pxt_command,$2 $$(PXT_$(shell echo $2 | tr '[:lower:]' '[:upper:]')_ARGS)) |
193 | | - |
194 | | -endef |
195 | | - |
196 | | -$(eval $(call _call_pxt_command_template,build,buildtarget,$(PXT))) |
197 | | - |
198 | | -$(foreach command,$(PXT_COMMANDS),$(eval $(call _call_pxt_command_template,$(command),$(command),$(PXT)))) |
| 46 | +# Create build rule by aliasing pxt buildtarget command |
| 47 | +.PHONY : build |
| 48 | +build : buildtarget |
199 | 49 |
|
| 50 | +# Create package rule by aliasing pxt staticpkg command |
200 | 51 | .PHONY : package |
201 | | -package : static/target.json |
| 52 | +package : staticpkg |
202 | 53 |
|
203 | | -static/target.json : $(PXT) |
204 | | - @$(call pxt_command,staticpkg $(PXT_STATICPKG_ARGS)) |
| 54 | +static/target.json : staticpkg |
205 | 55 |
|
206 | 56 | .PHONY : staticserve |
207 | 57 | staticserve : static/target.json pxt-steami-backend/https/fastify.cert pxt-steami-backend/https/fastify.key pxt-steami-backend/node_modules/.package-lock.json |
| 58 | + @echo "Serve static editor" |
208 | 59 | nodemon pxt-steami-backend/server.js |
209 | 60 |
|
210 | | -.PHONY : clean_localcertificates |
211 | | -clean_localcertificates:;@$(call _clean_pxt_steami_backend_certificates) |
212 | | - |
213 | 61 | .PHONY : localcertificates |
214 | 62 | localcertificates: pxt-steami-backend/https/fastify.cert pxt-steami-backend/https/fastify.key pxt-steami-backend/https/rootCA.pem |
215 | 63 |
|
216 | | -pxt-steami-backend/https/fastify.cert pxt-steami-backend/https/fastify.key pxt-steami-backend/https/rootCA.pem & : ;@$(call _generate_localcertificates) |
217 | | - |
218 | | -.PHONY : install_cert_for_local_dev |
219 | | -install_cert_for_local_dev : pxt-steami-backend/https/rootCA.pem |
| 64 | +.PHONY : install-cert-for-local-dev |
| 65 | +install-cert-for-local-dev : localcertificates |
220 | 66 | @$(call _install_cert_for_local_dev) |
221 | 67 |
|
| 68 | +pxt-steami-backend/https/fastify.cert pxt-steami-backend/https/fastify.key pxt-steami-backend/https/rootCA.pem & : ;@$(call _generate_localcertificates) |
| 69 | + |
222 | 70 | # A useful debug Make Target - found from |
223 | 71 | # http://lists.gnu.org/archive/html/help-make/2005-08/msg00137.html |
224 | 72 | .PHONY: printvars |
|
0 commit comments