Skip to content

Commit a8ccf58

Browse files
yxiecalguohan
authored andcommitted
[build]: Makefile: make new step "make stretch" optional (#1936)
* [makefile] Rename Makefile to Makefile.work Signed-off-by: Ying Xie <[email protected]> * [makefile] Add new make file to avoid extra step * avoiding calling "make stretch" Signed-off-by: Ying Xie <[email protected]> * [makefile] allow skipping "make stretch" Signed-off-by: Ying Xie <[email protected]> * [makefile] add all PHONY targets to pass through list Signed-off-by: Ying Xie <[email protected]>
1 parent 986a857 commit a8ccf58

File tree

3 files changed

+162
-142
lines changed

3 files changed

+162
-142
lines changed

Makefile

+14-141
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,20 @@
1-
###############################################################################
2-
## Wrapper for starting make inside sonic-slave container
3-
#
4-
# Supported parameters:
5-
#
6-
# * PLATFORM: Specific platform we wish to build images for.
7-
# * BUILD_NUMBER: Desired version-number to pass to the building-system.
8-
# * ENABLE_DHCP_GRAPH_SERVICE: Enables get-graph service to fetch minigraph files
9-
# through http.
10-
# * SHUTDOWN_BGP_ON_START: Sets admin-down state for all bgp peerings after restart.
11-
# * ENABLE_PFCWD_ON_START: Enable PFC Watchdog (PFCWD) on server-facing ports
12-
# * by default for TOR switch.
13-
# * SONIC_ENABLE_SYNCD_RPC: Enables rpc-based syncd builds.
14-
# * USERNAME: Desired username -- default at rules/config
15-
# * PASSWORD: Desired password -- default at rules/config
16-
# * KEEP_SLAVE_ON: Keeps slave container up after building-process concludes.
17-
# * SOURCE_FOLDER: host path to be mount as /var/$(USER)/src, only effective when KEEP_SLAVE_ON=yes
18-
# * SONIC_BUILD_JOBS: Specifying number of concurrent build job(s) to run
19-
# * KERNEL_PROCURE_METHOD: Specifying method of obtaining kernel Debian package: download or build
20-
#
21-
###############################################################################
1+
# SONiC make file
222

23-
SHELL = /bin/bash
24-
25-
USER := $(shell id -un)
26-
PWD := $(shell pwd)
27-
28-
ifeq ($(USER), root)
29-
$(error Add your user account to docker group and use your user account to make. root or sudo are not supported!)
30-
endif
31-
32-
# Remove lock file in case previous run was forcefully stopped
33-
$(shell rm -f .screen)
34-
35-
MAKEFLAGS += -B
36-
37-
ifeq ($(BLDENV), stretch)
38-
SLAVE_BASE_TAG = $(shell sha1sum sonic-slave-stretch/Dockerfile | awk '{print substr($$1,0,11);}')
39-
SLAVE_TAG = $(shell cat sonic-slave-stretch/Dockerfile.user sonic-slave-stretch/Dockerfile | sha1sum | awk '{print substr($$1,0,11);}')
40-
SLAVE_BASE_IMAGE = sonic-slave-stretch-base
41-
SLAVE_IMAGE = sonic-slave-stretch-$(USER)
42-
SLAVE_DIR = sonic-slave-stretch
43-
else
44-
SLAVE_BASE_TAG = $(shell sha1sum sonic-slave/Dockerfile | awk '{print substr($$1,0,11);}')
45-
SLAVE_TAG = $(shell cat sonic-slave/Dockerfile.user sonic-slave/Dockerfile | sha1sum | awk '{print substr($$1,0,11);}')
46-
SLAVE_BASE_IMAGE = sonic-slave-base
47-
SLAVE_IMAGE = sonic-slave-$(USER)
48-
SLAVE_DIR = sonic-slave
49-
endif
50-
51-
INSMOD_OVERLAY := sudo modprobe overlay
52-
DOCKER_RUN := docker run --rm=true --privileged \
53-
-v $(PWD):/sonic \
54-
-w /sonic \
55-
-e "http_proxy=$(http_proxy)" \
56-
-e "https_proxy=$(https_proxy)" \
57-
-i$(if $(TERM),t,)
58-
59-
DOCKER_BASE_BUILD = docker build --no-cache \
60-
-t $(SLAVE_BASE_IMAGE) \
61-
--build-arg http_proxy=$(http_proxy) \
62-
--build-arg https_proxy=$(https_proxy) \
63-
$(SLAVE_DIR) && \
64-
docker tag $(SLAVE_BASE_IMAGE):latest $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
65-
66-
DOCKER_BUILD = docker build --no-cache \
67-
--build-arg user=$(USER) \
68-
--build-arg uid=$(shell id -u) \
69-
--build-arg guid=$(shell id -g) \
70-
--build-arg hostname=$(shell echo $$HOSTNAME) \
71-
-t $(SLAVE_IMAGE) \
72-
-f $(SLAVE_DIR)/Dockerfile.user \
73-
$(SLAVE_DIR) && \
74-
docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG)
75-
76-
SONIC_BUILD_INSTRUCTION := make \
77-
-f slave.mk \
78-
PLATFORM=$(PLATFORM) \
79-
BUILD_NUMBER=$(BUILD_NUMBER) \
80-
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
81-
SHUTDOWN_BGP_ON_START=$(SHUTDOWN_BGP_ON_START) \
82-
SONIC_ENABLE_PFCWD_ON_START=$(ENABLE_PFCWD_ON_START) \
83-
ENABLE_SYNCD_RPC=$(ENABLE_SYNCD_RPC) \
84-
PASSWORD=$(PASSWORD) \
85-
USERNAME=$(USERNAME) \
86-
SONIC_BUILD_JOBS=$(SONIC_BUILD_JOBS) \
87-
KERNEL_PROCURE_METHOD=$(KERNEL_PROCURE_METHOD) \
88-
HTTP_PROXY=$(http_proxy) \
89-
HTTPS_PROXY=$(https_proxy) \
90-
SONIC_ENABLE_SYSTEM_TELEMETRY=$(ENABLE_SYSTEM_TELEMETRY)
91-
92-
.PHONY: sonic-slave-build sonic-slave-bash init reset
93-
94-
.DEFAULT_GOAL := all
3+
NOSTRETCH ?= 0
954

965
%::
97-
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
98-
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
99-
$(DOCKER_BASE_BUILD) ; }
100-
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
101-
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
102-
$(DOCKER_BUILD) ; }
103-
@$(INSMOD_OVERLAY)
104-
ifeq "$(KEEP_SLAVE_ON)" "yes"
105-
ifdef SOURCE_FOLDER
106-
@$(DOCKER_RUN) -v $(SOURCE_FOLDER):/var/$(USER)/src $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
107-
else
108-
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
109-
endif
110-
else
111-
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) $(SONIC_BUILD_INSTRUCTION) $@
6+
@echo "+++ --- Making $@ --- +++"
7+
ifeq ($(NOSTRETCH), 0)
8+
BLDENV=stretch make -f Makefile.work stretch
1129
endif
10+
make -f Makefile.work $@
11311

114-
sonic-slave-build :
115-
$(DOCKER_BASE_BUILD)
116-
$(DOCKER_BUILD)
117-
118-
sonic-slave-bash :
119-
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
120-
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
121-
$(DOCKER_BASE_BUILD) ; }
122-
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
123-
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
124-
$(DOCKER_BUILD) ; }
125-
@$(INSMOD_OVERLAY)
126-
@$(DOCKER_RUN) -t $(SLAVE_IMAGE):$(SLAVE_TAG) bash
127-
128-
showtag:
129-
@echo $(SLAVE_IMAGE):$(SLAVE_TAG)
130-
@echo $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
131-
132-
init :
133-
@git submodule update --init --recursive
134-
@git submodule foreach --recursive '[ -f .git ] && echo "gitdir: $$(realpath --relative-to=. $$(cut -d" " -f2 .git))" > .git'
12+
stretch:
13+
@echo "+++ Making $@ +++"
14+
ifeq ($(NOSTRETCH), 0)
15+
BLDENV=stretch make -f Makefile.work stretch
16+
endif
13517

136-
reset :
137-
@echo && echo -n "Warning! All local changes will be lost. Proceed? [y/N]: "
138-
@read ans && \
139-
if [ $$ans == y ]; then \
140-
git clean -xfdf; \
141-
git reset --hard; \
142-
git submodule foreach --recursive git clean -xfdf; \
143-
git submodule foreach --recursive git reset --hard; \
144-
git submodule update --init --recursive;\
145-
else \
146-
echo "Reset aborted"; \
147-
fi
18+
clean reset init configure showtag sonic-slave-build sonic-slave-bash :
19+
@echo "+++ Making $@ +++"
20+
make -f Makefile.work $@

Makefile.work

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
###############################################################################
2+
## Wrapper for starting make inside sonic-slave container
3+
#
4+
# Supported parameters:
5+
#
6+
# * PLATFORM: Specific platform we wish to build images for.
7+
# * BUILD_NUMBER: Desired version-number to pass to the building-system.
8+
# * ENABLE_DHCP_GRAPH_SERVICE: Enables get-graph service to fetch minigraph files
9+
# through http.
10+
# * SHUTDOWN_BGP_ON_START: Sets admin-down state for all bgp peerings after restart.
11+
# * ENABLE_PFCWD_ON_START: Enable PFC Watchdog (PFCWD) on server-facing ports
12+
# * by default for TOR switch.
13+
# * SONIC_ENABLE_SYNCD_RPC: Enables rpc-based syncd builds.
14+
# * USERNAME: Desired username -- default at rules/config
15+
# * PASSWORD: Desired password -- default at rules/config
16+
# * KEEP_SLAVE_ON: Keeps slave container up after building-process concludes.
17+
# * SOURCE_FOLDER: host path to be mount as /var/$(USER)/src, only effective when KEEP_SLAVE_ON=yes
18+
# * SONIC_BUILD_JOBS: Specifying number of concurrent build job(s) to run
19+
# * KERNEL_PROCURE_METHOD: Specifying method of obtaining kernel Debian package: download or build
20+
#
21+
###############################################################################
22+
23+
SHELL = /bin/bash
24+
25+
USER := $(shell id -un)
26+
PWD := $(shell pwd)
27+
28+
ifeq ($(USER), root)
29+
$(error Add your user account to docker group and use your user account to make. root or sudo are not supported!)
30+
endif
31+
32+
# Remove lock file in case previous run was forcefully stopped
33+
$(shell rm -f .screen)
34+
35+
MAKEFLAGS += -B
36+
37+
ifeq ($(BLDENV), stretch)
38+
SLAVE_BASE_TAG = $(shell sha1sum sonic-slave-stretch/Dockerfile | awk '{print substr($$1,0,11);}')
39+
SLAVE_TAG = $(shell cat sonic-slave-stretch/Dockerfile.user sonic-slave-stretch/Dockerfile | sha1sum | awk '{print substr($$1,0,11);}')
40+
SLAVE_BASE_IMAGE = sonic-slave-stretch-base
41+
SLAVE_IMAGE = sonic-slave-stretch-$(USER)
42+
SLAVE_DIR = sonic-slave-stretch
43+
else
44+
SLAVE_BASE_TAG = $(shell sha1sum sonic-slave/Dockerfile | awk '{print substr($$1,0,11);}')
45+
SLAVE_TAG = $(shell cat sonic-slave/Dockerfile.user sonic-slave/Dockerfile | sha1sum | awk '{print substr($$1,0,11);}')
46+
SLAVE_BASE_IMAGE = sonic-slave-base
47+
SLAVE_IMAGE = sonic-slave-$(USER)
48+
SLAVE_DIR = sonic-slave
49+
endif
50+
51+
INSMOD_OVERLAY := sudo modprobe overlay
52+
DOCKER_RUN := docker run --rm=true --privileged \
53+
-v $(PWD):/sonic \
54+
-w /sonic \
55+
-e "http_proxy=$(http_proxy)" \
56+
-e "https_proxy=$(https_proxy)" \
57+
-i$(if $(TERM),t,)
58+
59+
DOCKER_BASE_BUILD = docker build --no-cache \
60+
-t $(SLAVE_BASE_IMAGE) \
61+
--build-arg http_proxy=$(http_proxy) \
62+
--build-arg https_proxy=$(https_proxy) \
63+
$(SLAVE_DIR) && \
64+
docker tag $(SLAVE_BASE_IMAGE):latest $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
65+
66+
DOCKER_BUILD = docker build --no-cache \
67+
--build-arg user=$(USER) \
68+
--build-arg uid=$(shell id -u) \
69+
--build-arg guid=$(shell id -g) \
70+
--build-arg hostname=$(shell echo $$HOSTNAME) \
71+
-t $(SLAVE_IMAGE) \
72+
-f $(SLAVE_DIR)/Dockerfile.user \
73+
$(SLAVE_DIR) && \
74+
docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG)
75+
76+
SONIC_BUILD_INSTRUCTION := make \
77+
-f slave.mk \
78+
PLATFORM=$(PLATFORM) \
79+
BUILD_NUMBER=$(BUILD_NUMBER) \
80+
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
81+
SHUTDOWN_BGP_ON_START=$(SHUTDOWN_BGP_ON_START) \
82+
SONIC_ENABLE_PFCWD_ON_START=$(ENABLE_PFCWD_ON_START) \
83+
ENABLE_SYNCD_RPC=$(ENABLE_SYNCD_RPC) \
84+
PASSWORD=$(PASSWORD) \
85+
USERNAME=$(USERNAME) \
86+
SONIC_BUILD_JOBS=$(SONIC_BUILD_JOBS) \
87+
KERNEL_PROCURE_METHOD=$(KERNEL_PROCURE_METHOD) \
88+
HTTP_PROXY=$(http_proxy) \
89+
HTTPS_PROXY=$(https_proxy) \
90+
SONIC_ENABLE_SYSTEM_TELEMETRY=$(ENABLE_SYSTEM_TELEMETRY)
91+
92+
.PHONY: sonic-slave-build sonic-slave-bash init reset
93+
94+
.DEFAULT_GOAL := all
95+
96+
%::
97+
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
98+
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
99+
$(DOCKER_BASE_BUILD) ; }
100+
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
101+
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
102+
$(DOCKER_BUILD) ; }
103+
@$(INSMOD_OVERLAY)
104+
ifeq "$(KEEP_SLAVE_ON)" "yes"
105+
ifdef SOURCE_FOLDER
106+
@$(DOCKER_RUN) -v $(SOURCE_FOLDER):/var/$(USER)/src $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
107+
else
108+
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
109+
endif
110+
else
111+
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) $(SONIC_BUILD_INSTRUCTION) $@
112+
endif
113+
114+
sonic-slave-build :
115+
$(DOCKER_BASE_BUILD)
116+
$(DOCKER_BUILD)
117+
118+
sonic-slave-bash :
119+
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
120+
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
121+
$(DOCKER_BASE_BUILD) ; }
122+
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
123+
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
124+
$(DOCKER_BUILD) ; }
125+
@$(INSMOD_OVERLAY)
126+
@$(DOCKER_RUN) -t $(SLAVE_IMAGE):$(SLAVE_TAG) bash
127+
128+
showtag:
129+
@echo $(SLAVE_IMAGE):$(SLAVE_TAG)
130+
@echo $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
131+
132+
init :
133+
@git submodule update --init --recursive
134+
@git submodule foreach --recursive '[ -f .git ] && echo "gitdir: $$(realpath --relative-to=. $$(cut -d" " -f2 .git))" > .git'
135+
136+
reset :
137+
@echo && echo -n "Warning! All local changes will be lost. Proceed? [y/N]: "
138+
@read ans && \
139+
if [ $$ans == y ]; then \
140+
git clean -xfdf; \
141+
git reset --hard; \
142+
git submodule foreach --recursive git clean -xfdf; \
143+
git submodule foreach --recursive git reset --hard; \
144+
git submodule update --init --recursive;\
145+
else \
146+
echo "Reset aborted"; \
147+
fi

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ To build SONiC installer image and docker images, run the following commands:
5858
# Execute make configure once to configure ASIC
5959
make configure PLATFORM=[ASIC_VENDOR]
6060

61-
# build debian stretch required targets
61+
# build debian stretch required targets (optional)
6262
BLDENV=stretch make stretch
6363

6464
# build SONiC image

0 commit comments

Comments
 (0)