forked from REG-Linux/REG-Linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.jenkins
More file actions
198 lines (158 loc) · 7 KB
/
Makefile.jenkins
File metadata and controls
198 lines (158 loc) · 7 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
PROJECT_DIR := $(shell pwd)
DL_DIR ?= $(PROJECT_DIR)/dl
OUTPUT_DIR ?= $(PROJECT_DIR)/output
CCACHE_DIR ?= $(PROJECT_DIR)/buildroot-ccache
LOCAL_MK ?= $(PROJECT_DIR)/reglinux.mk
EXTRA_OPTS ?=
DOCKER_OPTS ?=
NPROC := $(shell nproc)
MAKE_JLEVEL ?= $(NPROC)
MAKE_LLEVEL ?= $(shell echo $$(($(NPROC) * 1)))
BATCH_MODE ?=
PARALLEL_BUILD ?= y
DEBUG_BUILD ?= y
DOCKER ?= docker
-include $(LOCAL_MK)
ifeq ($(PARALLEL_BUILD), y)
EXTRA_OPTS += BR2_PER_PACKAGE_DIRECTORIES=y
MAKE_OPTS += -j$(MAKE_JLEVEL)
MAKE_OPTS += -l$(MAKE_LLEVEL)
DOCKER_OPTS += -e MAKEFLAGS="$(MAKEFLAGS)"
endif
ifeq ($(DEBUG_BUILD), y)
EXTRA_OPTS += BR2_ENABLE_DEBUG=y
endif
ifndef BATCH_MODE
DOCKER_OPTS += -i
endif
DOCKER_REPO := reglinux
IMAGE_NAME := reglinux-build
TARGETS := $(sort $(shell find $(PROJECT_DIR)/configs/ -name 'r*' | sed -n 's/.*\/reglinux-\(.*\).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)"
define DOCKER_RUN
@$(DOCKER) run --pull=always --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 \
-e MPLCONFIGDIR=/tmp/matplotlib-config \
$(DOCKER_OPTS) \
$(DOCKER_REPO)/$(IMAGE_NAME)
endef
build-docker-image:
$(DOCKER) build . -t $(DOCKER_REPO)/$(IMAGE_NAME)
@touch .ba-docker-image-available
.ba-docker-image-available:
@$(DOCKER) --pull=always $(DOCKER_REPO)/$(IMAGE_NAME)
@touch .ba-docker-image-available
reglinux-docker-image: merge .ba-docker-image-available
update-docker-image:
-@rm .ba-docker-image-available > /dev/null
@$(MAKE) reglinux-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)
gh-token:
@cp ~/gh_token $(PROJECT_DIR)/gh_token
%-supported:
$(if $(findstring $*, $(TARGETS)),,$(error "$* not supported!"))
%-clean: gh-token reglinux-docker-image output-dir-%
@$(DOCKER_RUN) $(MAKE) $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot clean
%-config: gh-token reglinux-docker-image output-dir-%
@$(PROJECT_DIR)/configs/createDefconfig.sh $(PROJECT_DIR)/configs/reglinux-$*
@for opt in $(EXTRA_OPTS); do \
echo $$opt >> $(PROJECT_DIR)/configs/reglinux-$*_defconfig ; \
done
@$(DOCKER_RUN) $(MAKE) $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot reglinux-$*_defconfig
%-build: gh-token reglinux-docker-image %-config ccache-dir dl-dir
@$(DOCKER_RUN) $(MAKE) $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot $(CMD)
%-source: gh-token reglinux-docker-image %-config ccache-dir dl-dir
@$(DOCKER_RUN) $(MAKE) $(MAKE_OPTS) O=/$* BR2_EXTERNAL=/build -C /build/buildroot source
%-cleanbuild: gh-token %-clean %-build
@echo
%-pkg:
$(if $(PKG),,$(error "PKG not specified!"))
@$(MAKE) $*-build CMD=$(PKG)
%-webserver: output-dir-%
$(if $(wildcard $(OUTPUT_DIR)/$*/images/reglinux/*),,$(error "$* not built!"))
$(if $(shell which python 2>/dev/null),,$(error "python not found!"))
ifeq ($(strip $(BOARD)),)
$(if $(wildcard $(OUTPUT_DIR)/$*/images/reglinux/images/$*/.*),,$(error "Directory not found: $(OUTPUT_DIR)/$*/images/reglinux/images/$*"))
python3 -m http.server --directory $(OUTPUT_DIR)/$*/images/reglinux/images/$*/
else
$(if $(wildcard $(OUTPUT_DIR)/$*/images/reglinux/images/$(BOARD)/.*),,$(error "Directory not found: $(OUTPUT_DIR)/$*/images/reglinux/images/$(BOARD)"))
python3 -m http.server --directory $(OUTPUT_DIR)/$*/images/reglinux/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/reglinux/images/$*/reglinux-*.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/reglinux
@sudo tar xvf $(OUTPUT_DIR)/$*/images/reglinux/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
merge:
CUSTOM_DIR=$(PWD)/custom BUILDROOT_DIR=$(PWD)/buildroot $(PWD)/scripts/linux/mergeToBR.sh
generate:
CUSTOM_DIR=$(PWD)/custom BUILDROOT_DIR=$(PWD)/buildroot $(PWD)/scripts/linux/generateCustom.sh