forked from confine-project/confine-dist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
229 lines (190 loc) · 8.59 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
# CONFINE firmware generator (http://confine-project.eu)
#
# Copyright (C) 2011, 2012, 2013 Universitat Politecnica de Barcelona (UPC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
TIMESTAMP = $(shell date -u +%Y%m%d-%H%M)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
GIT_HASH = $(shell git rev-parse HEAD)
BUILD_DIR = openwrt
FILES_DIR = files
PACKAGE_DIR = packages
OWRT_PKG_DIR = $(PACKAGE_DIR)/openwrt
OWRT_FEEDS = feeds.conf.in
MY_CONFIGS = my_configs
DOWNLOAD_DIR = dl
#TARGET values: x86, ar71xx, realview
TARGET ?= x86
SUBTARGET ?= generic
# Some targets (not x86) need a profile.
PROFILE ?=
PARTSIZE ?= 256
MAXINODE ?= $$(( $(PARTSIZE) * 100 ))
PACKAGES ?= confine-system confine-recommended
CONFIG = $(BUILD_DIR)/.config
KCONF = target/linux/$(TARGET)/config-3.3
KCONFIG = $(BUILD_DIR)/$(KCONF)
IMAGES = images
# This is a build sequence number automatically set by Jenkins.
BUILD_NUMBER ?= unknown
NIGHTLY_IMAGES_DIR ?= www
IMAGE ?= openwrt-$(TARGET)-$(SUBTARGET)-combined
IMAGE_TYPE ?= ext4
J ?= 1
V ?= 0
MAKE_SRC_OPTS = -j$(J) V=$(V)
define prepare_workspace
git submodule update --init
[ ! -d "$(DOWNLOAD_DIR)" ] && mkdir -p "$(DOWNLOAD_DIR)" || true
rm -f $(BUILD_DIR)/dl
ln -s "`readlink -f $(DOWNLOAD_DIR)`" "$(BUILD_DIR)/dl"
rm -rf "$(BUILD_DIR)/files"
ln -s "../$(FILES_DIR)" "$(BUILD_DIR)/files"
endef
define update_feeds
cat $(OWRT_FEEDS) | sed -e "s|@PACKAGE_DIR@|`pwd`/$(PACKAGE_DIR)|" > $(BUILD_DIR)/feeds.conf
@echo "Updating feeds"
"$(BUILD_DIR)/scripts/feeds" update -a
"$(BUILD_DIR)/scripts/feeds" install -a
endef
define create_configs
@( echo "reverting $(KCONFIG) for TARGET=$(TARGET)" )
# This command restores OpenWrt's default configuration and adds answers
# to some options to avoid the configuration process asking for them.
# This should be fixed in mainstream soon.
( cd $(BUILD_DIR) && git checkout -- $(KCONF) && \
echo "# CONFIG_MSI_LAPTOP is not set" >> $(KCONF) && \
echo "# CONFIG_COMPAL_LAPTOP is not set" >> $(KCONF) && \
echo "# CONFIG_SAMSUNG_LAPTOP is not set" >> $(KCONF) && \
echo "# CONFIG_INTEL_OAKTRAIL is not set" >> $(KCONF) )
@( echo "creating $(CONFIG) for TARGET=$(TARGET) SUBTARGET=$(SUBTARGET) PROFILE=$(PROFILE) PARTSIZE=$(PARTSIZE) MAXINODE=$(MAXINODE) PACKAGES=\"$(PACKAGES)\"" )
@( echo "$(TARGET)" | grep -q -e "^x86$$" -e "^ar71xx$$" -e "^realview$$" && \
echo "CONFIG_TARGET_$(TARGET)=y" > $(CONFIG) && \
echo "CONFIG_KERNEL_CGROUPS=y" >> $(CONFIG) && \
echo "CONFIG_KERNEL_NAMESPACES=y" >> $(CONFIG) )
@( ! [ "static binaries for confine slivers" ] && \
echo "CONFIG_BUILD_STATIC_TOOLS=y" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_STATIC=y" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_FEATURE_SH_STANDALONE=y" >> $(CONFIG) && \
echo "# CONFIG_BUSYBOX_CONFIG_ASH is not set" >> $(CONFIG) && \
echo "# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_IS_ASH is not set" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_FEATURE_SH_IS_NONE=y" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_ARP=y" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_IP=y" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_FEATURE_IP_ADDRESS=y" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_FEATURE_IP_LINK=y" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_FEATURE_IP_ROUTE=y" >> $(CONFIG) && \
echo "# CONFIG_BUSYBOX_CONFIG_FEATURE_IP_TUNNEL is not set" >> $(CONFIG) && \
echo "# CONFIG_BUSYBOX_CONFIG_FEATURE_IP_RULE is not set" >> $(CONFIG) && \
echo "# CONFIG_BUSYBOX_CONFIG_FEATURE_IP_SHORT_FORMS is not set" >> $(CONFIG) && \
echo "# CONFIG_BUSYBOX_CONFIG_FEATURE_IP_RARE_PROTOCOLS is not set" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_IPCALC=y" >> $(CONFIG) && \
echo "# CONFIG_BUSYBOX_CONFIG_FEATURE_IPCALC_FANCY is not set" >> $(CONFIG) && \
echo "CONFIG_BUSYBOX_CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y" >> $(CONFIG) && \
echo "CONFIG_PACKAGE_openssh-client=y" >> $(CONFIG) && \
echo "CONFIG_PACKAGE_openssh-sftp-server=y" >> $(CONFIG) || true )
@( [ "$(SUBTARGET)" ] && \
echo "CONFIG_TARGET_$(TARGET)_$(SUBTARGET)=y" >> $(CONFIG) || true )
@( [ "$(PROFILE)" ] && \
echo "CONFIG_TARGET_$(TARGET)_$(SUBTARGET)_$(PROFILE)=y" >> $(CONFIG) || true )
@( [ "$(PARTSIZE)" ] && \
echo "CONFIG_TARGET_ROOTFS_PARTSIZE=$(PARTSIZE)" >> $(CONFIG) && \
echo "CONFIG_TARGET_ROOTFS_MAXINODE=$(MAXINODE)" >> $(CONFIG) || true )
@( for PACKAGE in ${PACKAGES}; do echo "CONFIG_PACKAGE_$${PACKAGE}=y" >> $(CONFIG); done )
@( echo "created $(CONFIG) before calling defconfig:" && cat $(CONFIG) )
@make -C "$(BUILD_DIR)" defconfig > /dev/null
endef
define menuconfig_owrt
make -C "$(BUILD_DIR)" menuconfig
mkdir -p "$(MY_CONFIGS)"
(cd "$(BUILD_DIR)" && scripts/diffconfig.sh) > $(MY_CONFIGS)/owrt_config
@echo "New OpenWRT configuration file saved on $(MY_CONFIGS)/owrt_config"
endef
define kmenuconfig_owrt
make -C "$(BUILD_DIR)" kernel_menuconfig
mkdir -p $(MY_CONFIGS)
[ -f $(KCONFIG) ] && cp -f $(KCONFIG) $(MY_CONFIGS)/kernel_config
@echo "New Kernel configuration file saved on $(MY_CONFIGS)/kernel_config"
endef
define set_version
: > files/etc/confine.version
echo "$(TIMESTAMP)" >> files/etc/confine.version
echo "$(GIT_BRANCH)" >> files/etc/confine.version
echo "$(GIT_HASH)" >> files/etc/confine.version
endef
define build_src
make -C "$(BUILD_DIR)" $(MAKE_SRC_OPTS)
endef
define post_build
mkdir -p "$(IMAGES)"
# [ -f "$(BUILD_DIR)/bin/$(TARGET)/$(IMAGE)-$(IMAGE_TYPE).img.gz" ] && gunzip "$(BUILD_DIR)/bin/$(TARGET)/$(IMAGE)-$(IMAGE_TYPE).img.gz" || true
# cp -f "$(BUILD_DIR)/bin/$(TARGET)/$(IMAGE)-$(IMAGE_TYPE).img" "$(IMAGES)/CONFINE-owrt-$(TIMESTAMP).img"
# cp -f "$(BUILD_DIR)/bin/$(TARGET)/$(IMAGE)-ext4.vdi" "$(IMAGES)/CONFINE-owrt-$(TIMESTAMP).vdi"
cp -f "$(BUILD_DIR)/bin/$(TARGET)/$(IMAGE)-$(IMAGE_TYPE).img.gz" "$(IMAGES)/CONFINE-owrt-$(TIMESTAMP).img.gz"
cp -f files/etc/confine.version "$(IMAGES)/CONFINE-owrt-$(TIMESTAMP).version"
ln -fs "CONFINE-owrt-$(TIMESTAMP).version" "$(IMAGES)/CONFINE-owrt-current.version"
ln -fs "CONFINE-owrt-$(TIMESTAMP).img.gz" "$(IMAGES)/CONFINE-owrt-current.img.gz"
@echo
@echo "CONFINE firmware compiled, you can find output files in $(IMAGES)/ directory"
endef
define nightly_build
$(eval REV_ID := $(shell git log -n 1 --format=format:%h))
$(eval OWRT_REV_ID := $(shell cd $(BUILD_DIR); git log -n 1 --format=format:%h))
$(eval PACKAGES_REV_ID := $(shell cd $(OWRT_PKG_DIR); git log -n 1 --format=format:%h))
$(eval BUILD_ID := $(BUILD_NUMBER)-$(REV_ID)-$(OWRT_REV_ID)-$(PACKAGES_REV_ID))
@echo $(BUILD_ID)
$(eval CONFINE_VERSION := $(shell git branch | grep ^* | cut -d " " -f 2))
mkdir -p "$(NIGHTLY_IMAGES_DIR)"
cp -f "$(BUILD_DIR)/bin/$(TARGET)/$(IMAGE)-$(IMAGE_TYPE).img.gz" "$(NIGHTLY_IMAGES_DIR)/CONFINE-openwrt-$(CONFINE_VERSION)-$(BUILD_ID).img.gz"
ln -fs "$(NIGHTLY_IMAGES_DIR)/CONFINE-openwrt-$(CONFINE_VERSION)-$(BUILD_ID).img.gz" "$(NIGHTLY_IMAGES_DIR)/CONFINE-openwrt-$(CONFINE_VERSION)-latest.img.gz"
endef
all: target
target: prepare
$(call set_version)
$(call build_src)
$(call post_build)
nightly: prepare
$(call set_version)
$(call build_src)
$(call nightly_build)
prepare: .prepared
.prepared:
@echo "Using $(IMAGE_TYPE)."
$(call prepare_workspace)
$(call update_feeds)
$(call create_configs)
@touch .prepared
sync: prepare
$(call update_feeds)
$(call create_configs)
menuconfig: prepare
$(call menuconfig_owrt)
kernel_menuconfig: prepare
$(call kmenuconfig_owrt)
confclean: prepare
$(call create_configs)
clean:
make -C "$(BUILD_DIR)" clean
dirclean:
make -C "$(BUILD_DIR)" dirclean
distclean:
make -C "$(BUILD_DIR)" distclean
$(call create_configs)
mrproper:
rm -f .prepared
rm -rf "$(DOWNLOAD_DIR)"
git submodule foreach 'find . -mindepth 1 -maxdepth 1 | xargs rm -rf'
help:
@cat README