forked from carrierwrt/carrierwrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
314 lines (259 loc) · 8.54 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#
# Copyright (C) 2013 CarrierWrt.org
#
include config.mk
# ======================================================================
# Internal variables
# ======================================================================
V ?= 0
OPENWRT_BASE := svn://svn.openwrt.org/openwrt
OPENWRT_DIR := openwrt
OPENWRT_URL := $(OPENWRT_BASE)/$(CONFIG_OPENWRT_PATH)@$(CONFIG_OPENWRT_REV)
LUCI_BASE := http://svn.luci.subsignal.org/luci
LUCI_URL := $(LUCI_BASE)/$(CONFIG_LUCI_PATH)/contrib/package@$(CONFIG_LUCI_REV)
LUCI_FEEDS_DIR := $(OPENWRT_DIR)/feeds/luci
PACKAGES := $(wildcard package/*)
# Build in release mode by default
BUILD ?= release
# Required packages
CONFIG += CONFIG_PACKAGE_factory-defaults=y
# Reset variables
define ResetVariables
SETTINGS =
endef
# WriteConfig <line>
define WriteConfig
echo $(1) >> $(OPENWRT_DIR)/.config
endef
# Generate an OpenWrt config file for a given target
# Configure <config>
define Configure
rm -f $(OPENWRT_DIR)/.config
$(foreach line,$(1),$(call WriteConfig,$(line)) &&) true
$(MAKE) MAKEOVERRIDES='' -C $(OPENWRT_DIR) defconfig > /dev/null
endef
# CleanImage <image>
define CleanImage
rm -f $(OPENWRT_DIR)/bin/$(1)
rm -f firmware/$(PRODUCT)/$(CUSTOMIZATION)/$(notdir $(1))*
rm -f firmware/$(PRODUCT)/$(CUSTOMIZATION)/untested/$(notdir $(1))*
rm -f firmware/$(PRODUCT)/$(CUSTOMIZATION)/debug/$(notdir $(1))*
endef
# Clean <images>
define Clean
$(foreach image,$(1), \
$(call CleanImage,$(image))
)
endef
# PatchOne <patchdir>
define PatchOne
if [ -d $(1)/openwrt ]; then \
for f in $(1)/openwrt/*; do \
(cd $(OPENWRT_DIR) && patch -p0 < ../$$f); \
done; \
fi
if [ -d $(1)/package ]; then \
(cd $(1) && \
find package -name '*.patch' \
-printf 'mkdir -p $(OPENWRT_DIR)/%h/patches && \
cp $(1)/%p $(OPENWRT_DIR)/%h/patches/%f\n') | sh; \
fi
if [ -d $(1)/feeds ]; then \
(cd $(1) && \
find feeds -name '*.patch' \
-printf 'mkdir -p $(OPENWRT_DIR)/%h/patches && \
cp $(1)/%p $(OPENWRT_DIR)/%h/patches/%f\n') | sh; \
fi
endef
# Patch <config> <dir>
define Patch
$(foreach package,$(notdir $(wildcard $(2)/*)),\
$(if $(findstring CONFIG_PACKAGE_$(package)=y,$(1)),\
$(call PatchOne,$(2)/$(package)))
)
endef
# Build <config>
define Build
$(call Configure,$(1))
$(MAKE) MAKEOVERRIDES='' -C $(OPENWRT_DIR) V=$(V)
endef
# InstallImage <src> <dst>
define InstallImage
cp $(1) $(2)
md5sum $(2) > $(2).md5
endef
# Install <images> <tested>
define Install
mkdir -p firmware/$(PRODUCT)/$(CUSTOMIZATION)
mkdir -p firmware/$(PRODUCT)/$(CUSTOMIZATION)/untested
$(foreach image,$(1), \
$(call InstallImage, \
$(OPENWRT_DIR)/bin/$(image), \
firmware/$(PRODUCT)/$(CUSTOMIZATION)/$(if \
$(findstring $(image),$(2)),$(notdir $(image)),untested/$(notdir $(image))))
)
endef
# InstallDebug <images>
define InstallDebug
mkdir -p firmware/$(PRODUCT)/$(CUSTOMIZATION)/debug
$(foreach image,$(1), \
$(call InstallImage, \
$(OPENWRT_DIR)/bin/$(image), \
firmware/$(PRODUCT)/$(CUSTOMIZATION)/debug/$(notdir $(image)))
)
endef
# ======================================================================
# User targets
# ======================================================================
all: $(OPENWRT_DIR) $(OPENWRT_DIR)/feeds.conf
$(MAKE) _touch
$(MAKE) _build
$(MAKE) _info
help:
@echo "============================================================="
@echo "VARIABLES:"
@echo " BUILD Build mode \"release\" (default) or \"debug\""
@echo " PRODUCT Product profile (unset to build all)"
@echo " TARGET Target platform (unset to build all)"
@echo " CUSTOMIZATION Product variant (unset to build all)"
@echo ""
@echo "FILES:"
@echo " config.mk Common configuration options"
@echo " common/targets/* Target platform configurations"
@echo " products/* Product profile configurations"
@echo ""
@echo "EXAMPLES:"
@echo " make"
@echo " make PRODUCT=rgw TARGET=ar71xx"
@echo "============================================================="
# ======================================================================
# Internal targets
# ======================================================================
_info:
@echo "==============================================================="
@echo " BUILD: $(BUILD)"
@if [ -z "$(PRODUCT)" ]; \
then echo " PRODUCTS: $(PRODUCTS)"; \
else echo " PRODUCT: $(PRODUCT)"; \
fi
@if [ -z "$(TARGET)" ]; \
then echo " TARGET: (all)"; \
else echo " TARGET: $(TARGET)"; \
fi
@if [ -z "$(CUSTOMIZATION)" ]; \
then echo " CUSTOMIZATION: (all)"; \
else echo " CUSTOMIZATION: $(CUSTOMIZATION)"; \
fi
@echo " Firmware images are in $(PWD)/firmware/"
@echo "==============================================================="
_touch:
$(foreach package,$(PACKAGES),$(shell touch $(package)/Makefile))
PRODUCTS=$(notdir $(wildcard products/*))
ifeq ($(PRODUCT),)
_build: _build-products
else
include products/$(PRODUCT)/Makefile
include products/$(PRODUCT)/builds/$(BUILD)/Makefile
TARGETS=$(notdir $(wildcard products/$(PRODUCT)/targets/*))
ifeq ($(TARGET),)
_build: _build-targets
else
include products/$(PRODUCT)/targets/$(TARGET)/Makefile
CUSTOMIZATIONS=$(notdir $(wildcard products/$(PRODUCT)/customizations/*))
ifeq ($(CUSTOMIZATION),)
_build: _build-customizations
else
include products/$(PRODUCT)/customizations/$(CUSTOMIZATION)/Makefile
_build: _build-images
endif
endif
endif
_build-products:
$(foreach product,$(PRODUCTS),\
$(MAKE) _build-targets PRODUCT=$(product) &&) true
_build-targets:
$(foreach target,$(TARGETS),\
$(MAKE) _build-customizations TARGET=$(target) &&) true
_build-customizations:
$(MAKE) _build-images
$(foreach customization,$(CUSTOMIZATIONS),\
$(MAKE) _build-images CUSTOMIZATION=$(customization) &&) true
_build-images:
# Revert openwrt and luci to pristine condition
scripts/svn-pristine $(OPENWRT_DIR) | sh
scripts/svn-pristine $(LUCI_FEEDS_DIR) | sh
# The special 'files' dir is in svn:ignore so we need to manually delete it
rm -rf $(OPENWRT_DIR)/files/*
# Symlink all packages into OpenWrt
true && $(foreach package,$(PACKAGES), ln -fs ../../$(package) $(OPENWRT_DIR)/$(package) &&) true
# Prepare uci-defaults directory
mkdir -p $(OPENWRT_DIR)/files/etc/uci-defaults
# Load Build
ifneq ($(BUILD),)
$(eval $(Build/$(BUILD)))
endif
# Load Product
$(eval $(ResetVariables))
$(eval $(Product/$(PRODUCT)))
if [ -n "$(SETTINGS)" ]; then \
cp products/$(PRODUCT)/$(SETTINGS) $(OPENWRT_DIR)/files/etc/uci-defaults/z01-product || exit 1; \
fi
# Load Target
$(eval $(ResetVariables))
$(eval $(Target/$(TARGET)))
if [ -n "$(SETTINGS)" ]; then \
cp common/targets/$(TARGET)/$(SETTINGS) $(OPENWRT_DIR)/files/etc/uci-defaults/z02-target || exit 1; \
fi
# Load Customization
$(eval $(ResetVariables))
ifneq ($(CUSTOMIZATION),)
$(eval $(Customization/$(CUSTOMIZATION)))
if [ -n "$(SETTINGS)" ]; then \
cp products/$(PRODUCT)/customizations/$(CUSTOMIZATION)/$(SETTINGS) \
$(OPENWRT_DIR)/files/etc/uci-defaults/z03-customization || exit 1; \
fi
else
$(eval $(Customization/default))
if [ -n "$(SETTINGS)" ]; then \
cp products/$(PRODUCT)/$(SETTINGS) $(OPENWRT_DIR)/files/etc/uci-defaults/z03-customization || exit 1; \
fi
endif
# Lock LuCI to specific revision
sed -i 's|^PKG_BRANCH\:=.*|PKG_BRANCH\:=$(CONFIG_LUCI_PATH)@$(CONFIG_LUCI_REV)|' \
$(LUCI_FEEDS_DIR)/luci/Makefile
# Apply product changes
-cp -r products/$(PRODUCT)/files/* $(OPENWRT_DIR)/files/
# Apply target changes
-cp -r products/$(PRODUCT)/targets/$(TARGET)/files/* $(OPENWRT_DIR)/files/
ifneq ($(CUSTOMIZATION),)
# Apply customizations
-cp -r products/$(PRODUCT)/customizations/$(CUSTOMIZATION)/files/* $(OPENWRT_DIR)/files/
endif
# Apply base patches
$(call Patch,$(CONFIG),patches)
# Apply product patches
$(call Patch,$(CONFIG),products/$(PRODUCT)/patches)
# Apply target patches
$(call Patch,$(CONFIG),common/targets/$(TARGET)/patches)
ifneq ($(CUSTOMIZATION),)
# Apply customization patches
$(call Patch,$(CONFIG),products/$(PRODUCT)/customizations/$(CUSTOMIZATION)/patches)
endif
# Clean old images
$(call Clean,$(IMAGES))
# Build
$(call Build,$(CONFIG))
# Install
ifeq ($(BUILD),debug)
$(call InstallDebug,$(IMAGES))
else
$(call Install,$(IMAGES),$(TESTED))
endif
$(OPENWRT_DIR):
svn co $(OPENWRT_URL) $@
$(OPENWRT_DIR)/feeds.conf:
echo "src-svn packages svn://svn.openwrt.org/openwrt/packages" > $@
echo "src-svn luci $(LUCI_URL)" >> $@
$(OPENWRT_DIR)/scripts/feeds update
$(OPENWRT_DIR)/scripts/feeds install luci
.PHONY: all help _info _touch _build _build-products _build-targets _build-images