forked from knulli-cfw/distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
279 lines (237 loc) · 9.77 KB
/
Makefile
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
PROJECT_DIR := $(shell pwd)
DL_DIR ?= $(PROJECT_DIR)/dl
OUTPUT_DIR ?= $(PROJECT_DIR)/output
CCACHE_DIR ?= $(PROJECT_DIR)/buildroot-ccache
LOCAL_MK ?= $(PROJECT_DIR)/batocera.mk
EXTRA_PKGS ?=
DOCKER_OPTS ?=
MAKE_JLEVEL ?= $(shell nproc)
BATCH_MODE ?=
PARALLEL_BUILD ?=
DOCKER ?= docker
-include $(LOCAL_MK)
ifdef PARALLEL_BUILD
EXTRA_OPTS += BR2_PER_PACKAGE_DIRECTORIES=y
MAKE_OPTS += -j$(MAKE_JLEVEL)
endif
ifndef BATCH_MODE
DOCKER_OPTS += -i
endif
DOCKER_REPO := batoceralinux
IMAGE_NAME := batocera.linux-build
TARGETS := $(sort $(shell find $(PROJECT_DIR)/configs/ -name 'b*' | sed -n 's/.*\/batocera-\(.*\).board/\1/p'))
UID := $(shell id -u)
GID := $(shell id -g)
$(if $(shell which $(DOCKER) 2>/dev/null),, $(error "$(DOCKER) not found!"))
UC = $(shell echo '$1' | tr '[:lower:]' '[:upper:]')
vars:
@echo "Supported targets: $(TARGETS)"
@echo "Project directory: $(PROJECT_DIR)"
@echo "Download directory: $(DL_DIR)"
@echo "Build directory: $(OUTPUT_DIR)"
@echo "ccache directory: $(CCACHE_DIR)"
@echo "Extra options: $(EXTRA_OPTS)"
@echo "Docker options: $(DOCKER_OPTS)"
@echo "Make options: $(MAKE_OPTS)"
build-docker-image:
$(DOCKER) build . -t $(DOCKER_REPO)/$(IMAGE_NAME)
@touch .ba-docker-image-available
.ba-docker-image-available:
@$(DOCKER) pull $(DOCKER_REPO)/$(IMAGE_NAME)
@touch .ba-docker-image-available
batocera-docker-image: .ba-docker-image-available
update-docker-image:
-@rm .ba-docker-image-available > /dev/null
@$(MAKE) batocera-docker-image
publish-docker-image:
@$(DOCKER) push $(DOCKER_REPO)/$(IMAGE_NAME):latest
output-dir-%: %-supported
@mkdir -p $(OUTPUT_DIR)/$*
ccache-dir:
@mkdir -p $(CCACHE_DIR)
dl-dir:
@mkdir -p $(DL_DIR)
%-supported:
$(if $(findstring $*, $(TARGETS)),,$(error "$* not supported!"))
%-clean: batocera-docker-image output-dir-%
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-u $(UID):$(GID) \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make O=/$* BR2_EXTERNAL=/build -C /build/buildroot clean
%-config: batocera-docker-image output-dir-%
@$(PROJECT_DIR)/configs/createDefconfig.sh $(PROJECT_DIR)/configs/batocera-$*
@for opt in $(EXTRA_OPTS); do \
echo $$opt >> $(PROJECT_DIR)/configs/batocera-$*_defconfig ; \
done
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-u $(UID):$(GID) \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make O=/$* BR2_EXTERNAL=/build -C /build/buildroot batocera-$*_defconfig
%-build: batocera-docker-image %-config ccache-dir dl-dir
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
-u $(UID):$(GID) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot $(CMD)
%-source: batocera-docker-image %-config ccache-dir dl-dir
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
-u $(UID):$(GID) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot source
%-show-build-order: batocera-docker-image %-config ccache-dir dl-dir
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
-u $(UID):$(GID) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot show-build-order
%-kernel: batocera-docker-image %-config ccache-dir dl-dir
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
-u $(UID):$(GID) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot linux-menuconfig
%-graph-depends: batocera-docker-image %-config ccache-dir dl-dir
@$(DOCKER) run -it --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
-u $(UID):$(GID) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make O=/$* BR2_EXTERNAL=/build BR2_GRAPH_OUT=svg -C /build/buildroot graph-depends
%-shell: batocera-docker-image output-dir-%
$(if $(BATCH_MODE),$(if $(CMD),,$(error "not suppoorted in BATCH_MODE if CMD not specified!")),)
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-w /$* \
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
-u $(UID):$(GID) \
$(DOCKER_OPTS) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_REPO)/$(IMAGE_NAME) \
$(CMD)
%-ccache-stats: batocera-docker-image %-config ccache-dir dl-dir
@$(DOCKER) run -t --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
-u $(UID):$(GID) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME) \
make $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot ccache-stats
%-cleanbuild: %-clean %-build
@echo
%-pkg:
$(if $(PKG),,$(error "PKG not specified!"))
@$(MAKE) $*-build CMD=$(PKG)
%-webserver: output-dir-%
$(if $(wildcard $(OUTPUT_DIR)/$*/images/batocera/*),,$(error "$* not built!"))
$(if $(shell which python 2>/dev/null),,$(error "python not found!"))
ifeq ($(strip $(BOARD)),)
$(if $(wildcard $(OUTPUT_DIR)/$*/images/batocera/images/$*/.*),,$(error "Directory not found: $(OUTPUT_DIR)/$*/images/batocera/images/$*"))
python3 -m http.server --directory $(OUTPUT_DIR)/$*/images/batocera/images/$*/
else
$(if $(wildcard $(OUTPUT_DIR)/$*/images/batocera/images/$(BOARD)/.*),,$(error "Directory not found: $(OUTPUT_DIR)/$*/images/batocera/images/$(BOARD)"))
python3 -m http.server --directory $(OUTPUT_DIR)/$*/images/batocera/images/$(BOARD)/
endif
%-rsync: output-dir-%
$(eval TMP := $(call UC, $*)_IP)
$(if $(shell which rsync 2>/dev/null),, $(error "rsync not found!"))
$(if $($(TMP)),,$(error "$(TMP) not set!"))
rsync -e "ssh -o 'UserKnownHostsFile /dev/null' -o StrictHostKeyChecking=no" -av $(OUTPUT_DIR)/$*/target/ root@$($(TMP)):/
%-tail: output-dir-%
@tail -F $(OUTPUT_DIR)/$*/build/build-time.log
%-snapshot: %-supported
$(if $(shell which btrfs 2>/dev/null),, $(error "btrfs not found!"))
@mkdir -p $(OUTPUT_DIR)/snapshots
-@sudo btrfs sub del $(OUTPUT_DIR)/snapshots/$*-toolchain
@btrfs subvolume snapshot -r $(OUTPUT_DIR)/$* $(OUTPUT_DIR)/snapshots/$*-toolchain
%-rollback: %-supported
$(if $(shell which btrfs 2>/dev/null),, $(error "btrfs not found!"))
-@sudo btrfs sub del $(OUTPUT_DIR)/$*
@btrfs subvolume snapshot $(OUTPUT_DIR)/snapshots/$*-toolchain $(OUTPUT_DIR)/$*
%-flash: %-supported
$(if $(DEV),,$(error "DEV not specified!"))
@gzip -dc $(OUTPUT_DIR)/$*/images/batocera/images/$*/batocera-*.img.gz | sudo dd of=$(DEV) bs=5M status=progress
@sync
%-upgrade: %-supported
$(if $(DEV),,$(error "DEV not specified!"))
-@sudo umount /tmp/mount
-@mkdir /tmp/mount
@sudo mount $(DEV)1 /tmp/mount
-@sudo rm /tmp/mount/boot/batocera
@sudo tar xvf $(OUTPUT_DIR)/$*/images/batocera/boot.tar.xz -C /tmp/mount --no-same-owner
@sudo umount /tmp/mount
-@rmdir /tmp/mount
%-toolchain: %-supported
$(if $(shell which btrfs 2>/dev/null),, $(error "btrfs not found!"))
-@sudo btrfs sub del $(OUTPUT_DIR)/$*
@btrfs subvolume create $(OUTPUT_DIR)/$*
@$(MAKE) $*-config
@$(MAKE) $*-build CMD=toolchain
@$(MAKE) $*-build CMD=llvm
@$(MAKE) $*-snapshot
%-find-build-dups: %-supported
@find $(OUTPUT_DIR)/$*/build -maxdepth 1 -type d -printf '%T@ %p %f\n' | sed -r 's:\-[0-9a-f\.]+$$::' | sort -k3 -k1 | uniq -f 2 -d | cut -d' ' -f2
%-remove-build-dups: %-supported
@while [ -n "`find $(OUTPUT_DIR)/$*/build -maxdepth 1 -type d -printf '%T@ %p %f\n' | sed -r 's:\-[0-9a-f\.]+$$::' | sort -k3 -k1 | uniq -f 2 -d | cut -d' ' -f2 | grep .`" ]; do \
find $(OUTPUT_DIR)/$*/build -maxdepth 1 -type d -printf '%T@ %p %f\n' | sed -r 's:\-[0-9a-f\.]+$$::' | sort -k3 -k1 | uniq -f 2 -d | cut -d' ' -f2 | xargs rm -rf ; \
done
find-dl-dups:
@find $(DL_DIR) -maxdepth 2 -type f -name "*.zip" -o -name "*.tar.*" -printf '%T@ %p %f\n' | sed -r 's:\-[0-9a-f\.]+(\.zip|\.tar\.[2a-z]+)$$::' | sort -k3 -k1 | uniq -f 2 -d | cut -d' ' -f2
remove-dl-dups:
@while [ -n "`find $(DL_DIR) -maxdepth 2 -type f -name "*.zip" -o -name "*.tar.*" -printf '%T@ %p %f\n' | sed -r 's:\-[0-9a-f\.]+(\.zip|\.tar\.[2a-z]+)$$::' | sort -k3 -k1 | uniq -f 2 -d | cut -d' ' -f2 | grep .`" ] ; do \
find $(DL_DIR) -maxdepth 2 -type f -name "*.zip" -o -name "*.tar.*" -printf '%T@ %p %f\n' | sed -r 's:\-[0-9a-f\.]+(\.zip|\.tar\.[2a-z]+)$$::' | sort -k3 -k1 | uniq -f 2 -d | cut -d' ' -f2 | xargs rm -rf ; \
done
uart:
$(if $(shell which picocom 2>/dev/null),, $(error "picocom not found!"))
$(if $(SERIAL_DEV),,$(error "SERIAL_DEV not specified!"))
$(if $(SERIAL_BAUDRATE),,$(error "SERIAL_BAUDRATE not specified!"))
$(if $(wildcard $(SERIAL_DEV)),,$(error "$(SERIAL_DEV) not available!"))
@picocom $(SERIAL_DEV) -b $(SERIAL_BAUDRATE)