-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
247 lines (215 loc) · 6.78 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
#
# Makefile for building IoT-LAB images and packages
#
#
TARGET ?= a8
IMAGES = iotlab-image
IMAGES += iotlab-image-gateway
IMAGES += iotlab-image-autotest
EXTRA_BUILDS =
# Define variables specific to the given target
ifeq ($(TARGET), a8)
BUILD_DIR = build
TARGET_ARCH = cortexa8hf-neon
TARGET_IMG = var-som-am35
KERNEL_IMG = uImage
# Use a mapping between image target of make with image name in yocto
iotlab-image = iotlab-image-open-a8
iotlab-image-gateway = iotlab-image-gateway
iotlab-image-autotest = iotlab-image-open-a8-autotest
# We also build a mtd-rw version of the kernel for A8
EXTRA_BUILDS = build-kernel-mtd-rw
else ifeq ($(TARGET), rpi2)
BUILD_DIR = build-rpi2
TARGET_ARCH = cortexa7t2hf-neon-vfpv4
TARGET_IMG = raspberrypi2
KERNEL_IMG = zImage
# Use a mapping between image target of make with image name in yocto
iotlab-image = iotlab-image-rpi2
iotlab-image-gateway = iotlab-image-gateway-rpi2
iotlab-image-autotest = iotlab-image-rpi2-autotest
else ifeq ($(TARGET), rpi3)
BUILD_DIR = build-rpi3
TARGET_ARCH = cortexa7t2hf-neon-vfpv4
TARGET_IMG = raspberrypi3
KERNEL_IMG = zImage
# Use a mapping between image target of make with image name in yocto
iotlab-image = iotlab-image-rpi3
iotlab-image-gateway = iotlab-image-gateway-rpi3
iotlab-image-autotest = iotlab-image-rpi3-autotest
else ifeq ($(TARGET), rpi4)
BUILD_DIR = build-rpi4
TARGET_ARCH = cortexa7t2hf-neon-vfpv4
TARGET_IMG = raspberrypi4
KERNEL_IMG = zImage
# Use a mapping between image target of make with image name in yocto
iotlab-image = iotlab-image-rpi4
iotlab-image-gateway = iotlab-image-gateway-rpi4
iotlab-image-autotest = iotlab-image-rpi4-autotest
else
$(error Unsupported target, '$(TARGET)')
endif
PKGS_DIR = $(BUILD_DIR)/tmp/deploy/ipk/$(TARGET_ARCH)
IMGS_DIR = $(BUILD_DIR)/tmp/deploy/images/$(TARGET_IMG)
IMGS_MTD_RW_DIR = $(IMGS_DIR)-mtd-rw
.PHONY: init submodules $(BUILD_DIR)/conf/local.conf
ifeq (0,$(BUILD_IN_DOCKER))
# BUILD_IN_DOCKER set to 0 means we are running inside the container
IN_DOCKER = 1
endif
# only init when not in docker
init: $(if $(IN_DOCKER),,submodules $(BUILD_DIR)/conf/local.conf)
$(BUILD_DIR)/conf/local.conf:
sed -i "s/^BB_NUMBER_THREADS.*$$/BB_NUMBER_THREADS ?= \"$$(( $$(nproc) * 2 ))\"/" $@
sed -i "s/^PARALLEL_MAKE.*$$/PARALLEL_MAKE ?= \"-j $$(( $$(nproc) * 2 ))\"/" $@
ifdef BUILD_DOWNLOAD_DIR
sed -i "s/^\DL_DIR.*$$/DL_DIR ?= \"$(subst /,\/,$(BUILD_DOWNLOAD_DIR))\/downloads\"/" $@
endif
submodules:
git submodule update --init --force --remote
# # # # # # # # # # # # # # # # # # # # #
# Building images and packages targets #
# # # # # # # # # # # # # # # # # # # # #
.PHONY: target-info build-all build-img-% iotlab-image-%
target-info:
@echo Using target: $(TARGET)
@echo ""
@echo "Available image targets:"
@for img in $(IMAGES); do echo " - $$img"; done;
@if [ ! -z "$(EXTRA_BUILDS)" ]; \
then \
echo "\nOther build targets:"; \
for target in $(EXTRA_BUILDS); do echo " - $$target"; done; \
fi
build-all: $(IMAGES) $(EXTRA_BUILDS)
$(IMAGES): %: build-img-% clean-img-%
DOCKER_IMAGE ?= fitiotlab/iot-lab-yocto
DOCKER_IMAGE_VERSION ?= latest
# Use BUILD_IN_DOCKER=0 env to disable build in docker for sub-make, to avoid
# recursive calls to docker
DOCKER_CMD = docker run --rm --hostname yocto \
-v $(shell pwd):/shared \
$(if $(BUILD_DOWNLOAD_DIR),-v $(BUILD_DOWNLOAD_DIR):$(BUILD_DOWNLOAD_DIR),) \
-e BUILD_IN_DOCKER=0 \
-e TARGET=$(TARGET) \
-u $(shell id -u):$(shell id -g) \
$(DOCKER_IMAGE):$(DOCKER_IMAGE_VERSION)
.PHONY: build-pkg-%
build-pkg-%: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# build package
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -k $*"
@echo ""
@echo ""
@echo "$*" ipk package files should be found here:
@ls $(PKGS_DIR)/$**
endif
.PHONY: build-pkg-%-native
build-pkg-%-native: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# build native package
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -k $*-native"
endif
.PHONY: clean-pkg-%
clean-pkg-%: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# clean package
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -c cleanall $*"
endif
.PHONY: build-uboot
build-uboot: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# build u-Boot
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -k virtual/bootloader"
@echo ""
@echo ""
@echo "$*" U-Boot files should be found here:
@ls $(IMGS_DIR)/u-boot*
@ls $(IMGS_DIR)/MLO*
endif
.PHONY: clean-uboot
clean-uboot: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# clean u-boot
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -c cleanall virtual/bootloader"
endif
.PHONY: build-kernel
build-kernel: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# build kernel
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -k virtual/kernel"
@echo ""
@echo ""
@echo "$*" Kernel files should be found here:
@ls $(IMGS_DIR)/$(KERNEL_IMG)*
endif
.PHONY: clean-kernel
clean-kernel: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# clean kernel
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -c cleanall virtual/kernel"
endif
.PHONY: build-kernel-mtd-rw
build-kernel-mtd-rw: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# build mtd writeable Kernel
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); MACHINE=$(TARGET_IMG)-mtd-rw bitbake -k virtual/kernel"
@echo ""
@echo ""
@echo "$*" Kernel mtd writeable files should be found here:
@ls $(IMGS_MTD_RW_DIR)/$(KERNEL_IMG)*
endif
.PHONY: clean-kernel-mtd-rw
clean-kernel-mtd-rw: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# clean kernel mtd writeable package
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); MACHINE=$(TARGET_IMG)-mtd-rw bitbake -c cleanall virtual/kernel"
endif
.PHONY: build-img-%
build-img-%: init
ifeq (1,$(BUILD_IN_DOCKER))
$(DOCKER_CMD) make $@
else
@# build image
time bash -c \
"source ./poky/oe-init-build-env $(BUILD_DIR); bitbake -k $($*)"
@echo ""
@echo ""
@echo "$*" image files should be found here:
@ls $(IMGS_DIR)/$($*)*
endif
.PHONY: clean-img-%
clean-img-%:
@# keep only the last one
@# don't match the symlink or the last build image
rm -f $(shell find $(IMGS_DIR)/ -name '$($*)-$(TARGET_IMG)*' -type f \
! -name $(shell readlink $(IMGS_DIR)/$($*)-$(TARGET_IMG).tar.gz) \
! -name $(shell readlink $(IMGS_DIR)/$($*)-$(TARGET_IMG).manifest) \
)