-
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathMakefile
More file actions
121 lines (96 loc) · 2.86 KB
/
Copy pathMakefile
File metadata and controls
121 lines (96 loc) · 2.86 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
-include config.mk
export PROJECT ?= pikvm-packages
export BOARD ?= rpi2
export ARCH ?= arm
export STAGES ?= __init__ buildenv
export HOSTNAME = buildenv
export ARCH_DIST_REPO_URL ?= http://mirror.archlinuxarm.org/
export DOCKER ?= docker
export DISTCC_HOSTS ?=
export DISTCC_J ?=
export J ?= $(shell nproc)
export NC ?=
export NOINT ?=
# =====
_TARGET = $(BOARD)-$(ARCH)
_TARGET_REPO_NAME = pikvm
_TARGET_REPO_KEY = 912C773ABBD1B584
_ALARM_UID := $(shell id -u)
_ALARM_GID := $(shell id -g)
_BUILDENV_IMAGE = $(PROJECT).$(_TARGET).$(_ALARM_UID)-$(_ALARM_GID)
_BUILDENV_DIR = ./.pi-builder/$(_TARGET)
_BUILD_DIR = ./.build/$(_TARGET)
_BASE_REPOS_DIR = ./repos
_TARGET_REPO_DIR = $(_BASE_REPOS_DIR)/$(_TARGET)
# =====
define optbool
$(filter $(shell echo $(1) | tr A-Z a-z),yes on 1)
endef
define say
@ tput bold
@ tput setaf 2
@ echo "===== $1 ====="
@ tput sgr0
endef
# =====
all:
true
build:
test -n "$(PKG)"
$(call say,"Ensuring package $(PKG) for $(_TARGET)")
$(MAKE) _run \
OPTS="--shm-size=4gb --tty $(if $(call optbool,$(NOINT)),,--interactive)" \
CMD="/tools/buildpkg \
$(if $(call optbool,$(FORCE)),--force,) \
$(if $(call optbool,$(NOREPO)),--no-repo,) \
$(if $(call optbool,$(NOEXTRACT)),--no-extract,) \
$(if $(call optbool,$(NOSIGN)),--no-sign,) \
$(if $(DISTCC_HOSTS),--distcc-hosts $(DISTCC_HOSTS),) \
$(if $(DISTCC_J),--distcc-make-j $(DISTCC_J),) \
--make-j $(J) \
$(PKG) \
"
$(call say,"Complete package $(PKG) for $(_TARGET)")
shell: buildenv
$(MAKE) _run \
OPTS="--tty --interactive"
binfmt: $(_BUILDENV_DIR)
$(MAKE) -C $(_BUILDENV_DIR) binfmt
buildenv: binfmt
$(call say,"Ensuring $(_TARGET) buildenv")
rm -rf $(_BUILDENV_DIR)/stages/arch/buildenv
cp -a buildenv $(_BUILDENV_DIR)/stages/arch/buildenv
$(MAKE) -C $(_BUILDENV_DIR) os \
PASS_ENSURE_TOOLBOX=1 \
PASS_ENSURE_BINFMT=1 \
TAG=$(_BUILDENV_IMAGE) \
BUILD_OPTS=" \
--build-arg TARGET_REPO_NAME=$(_TARGET_REPO_NAME) \
--build-arg TARGET_REPO_KEY=$(_TARGET_REPO_KEY) \
--build-arg ALARM_UID=$(_ALARM_UID) \
--build-arg ALARM_GID=$(_ALARM_GID) \
"
$(call say,"Buildenv $(_TARGET) is ready")
.PHONY: buildenv
# =====
_run: $(_BUILD_DIR) $(_TARGET_REPO_DIR)
$(DOCKER) run \
--rm \
--privileged \
--ulimit "nofile=65536:1048576" \
--volume $(shell pwd)/$(_TARGET_REPO_DIR):/repo:rw \
--volume $(shell pwd)/$(_BUILD_DIR):/build:rw \
--volume $(shell pwd)/packages:/packages:ro \
--env TARGET_REPO_DIR=/repo \
--env BUILD_DIR=/build \
--env PACKAGES_DIR=/packages \
--volume $$HOME/.gnupg/:/home/alarm/.gnupg/:rw \
--volume /run/user/$(_ALARM_UID)/gnupg:/run/user/$(_ALARM_UID)/gnupg:rw \
--mount type=tmpfs,destination=/tmp \
$(OPTS) \
$(_BUILDENV_IMAGE) \
$(if $(CMD),$(CMD),/bin/bash)
$(_BUILDENV_DIR):
git clone --depth=1 https://github.com/pikvm/pi-builder $(_BUILDENV_DIR)
$(_BUILD_DIR):
mkdir -p $(_BUILD_DIR)