-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
150 lines (119 loc) · 3.5 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
# SPDX-License-Identifier: MIT
#
# Copyright (c) 2021-2022 Sartura Ltd.
#
# Command arguments
#
M4FLAGS :=
DBUILDOPTS :=
DRUNOPTS := --privileged --rm
envcache := environment.cache
m4common := modules/common.m4
# Verbosity
#
ifeq ($(V),1)
M4FLAGS += --debug=aefilpqt
DBUILDOPTS += --progress=plain
endif
# Detect the amount of available CPU cores
#
J ?= $(shell grep -c ^processor /proc/cpuinfo)
makeopts += --jobs=$(J)
ifneq ($(L),)
makeopts += --load-average=$(L)
endif
# NOTE: `MAKEOPTS` and `EMERGE_DEFAULT_OPTS` together affect system performance
# in a specific way. Please consult the Portage documentation for details.
# https://wiki.gentoo.org/wiki/EMERGE_DEFAULT_OPTS/en
M4FLAGS += -D__makeopts__="$(makeopts)"
M4FLAGS += -D__emergeopts__="$(makeopts)"
# Target architecture is represented by a tuple
#
# https://wiki.gentoo.org/wiki/Embedded_Handbook/Tuples
ifeq ($(CTARGET),)
$(warning CTARGET is not set on the command line, assuming `x86_64`)
DBUILDOPTS += --build-arg CTARGET="x86_64-multilib-linux-gnu"
M4FLAGS += -D__CTARGET__="x86_64-multilib-linux-gnu"
else
DBUILDOPTS += --build-arg CTARGET="${CTARGET}"
M4FLAGS += -D__CTARGET__="$(CTARGET)"
endif
# Target distribution
#
ifneq ($(TARGET_DISTRO),)
M4FLAGS += -D_TDISTRO_="$(TARGET_DISTRO)"
endif
# Build options and Docker setup
#
# NOTE: Docker will not otherwise include cache metadata into images!
# https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources
DBUILDOPTS += --build-arg BUILDKIT_INLINE_CACHE=1
DBUILDOPTS += --secret id=env,src=$(envcache)
DOCKER_BUILDKIT := 1
export DOCKER_BUILDKIT
ifeq ($(GENTOO_TAG),)
GENTOO_TAG := 20230717
endif
ifeq ($(NO_CACHE),1)
DBUILDOPTS += --no-cache
endif
ifneq ($(CACHE_FROM),)
DBUILDOPTS += --cache-from="$(CACHE_FROM)"
endif
ifneq ($(PACKAGE),)
DBUILDOPTS += --build-arg PACKAGE="$(PACKAGE)"
endif
ifneq ($(USE),)
DBUILDOPTS += --build-arg USE="$(USE)"
endif
ifneq ($(GENTOO_MIRRORS),)
M4FLAGS += -D__mirrors__="$(GENTOO_MIRRORS)"
endif
ifneq ($(USE_CCACHE),0)
M4FLAGS += -D_with_ccache_
endif
ifneq ($(KERNEL_REMOTE),)
M4FLAGS += -D__kernel_remote__="$(KERNEL_REMOTE)"
endif
ifneq ($(KERNEL_BRANCH),)
M4FLAGS += -D__kernel_branch__="$(KERNEL_BRANCH)"
endif
ifneq ($(KERNEL_CONFIG),)
M4FLAGS += -D__kernel_config__="$(KERNEL_CONFIG)"
endif
ifneq ($(DEBOOTSTRAP_RELEASE),)
M4FLAGS += -D__debootstrap_release__="$(DEBOOTSTRAP_RELEASE)"
endif
ifneq ($(DEBOOTSTRAP_URL),)
M4FLAGS += -D__debootstrap_url__="$(DEBOOTSTRAP_URL)"
endif
ifneq ($(DDR_TOPOLOGY),)
M4FLAGS += -D__atf_ddr_topology__="$(DDR_TOPOLOGY)"
endif
ifneq ($(WITH_ROOTFS),)
DRUNOPTS += --env WITH_ROOTFS=1
endif
# Get GIT HEAD hash
# This is used to identify origin of the running device image
GIT_HASH := $(shell git rev-parse HEAD)
M4FLAGS += -D__git_hash__="$(GIT_HASH)"
# Always rebuild these targets
#
.PHONY = pull update clean $(envcache)
# Preprocessing, building, and packaging targets
#
$(envcache): environment.in $(m4common)
@m4 $(m4common) $(M4FLAGS) $< > $@
targets/%.cache: targets/%.docker modules/*.docker $(m4common)
@m4 $(m4common) $(M4FLAGS) -D_BTARGET_="$*" $< > $@
build_%: targets/%.cache $(envcache) pull
docker build . -f targets/$*.cache $(DBUILDOPTS) --tag replica/$*:latest
package_%: build_%
docker run $(DRUNOPTS) --volume ${PWD}/output:/output -- replica/$*:latest
# Additional targets
#
pull:
docker pull gentoo/stage3:amd64-openrc-$(GENTOO_TAG)
@docker tag gentoo/stage3:amd64-openrc-$(GENTOO_TAG) gentoo/stage3:replica
clean:
rm -rf output/*