Makefile 10.6 KB
Newer Older
1
2
3
4
5
6
all:

LC_ALL:=C
LANG:=C
export LC_ALL LANG

7
8
9
empty:=
space:= $(empty) $(empty)

10
GLUONMAKE_EARLY = $(SUBMAKE) -C $(GLUON_ORIGOPENWRTDIR) -f $(GLUONDIR)/Makefile GLUON_TOOLS=0
11
12
13
14
GLUONMAKE = $(SUBMAKE) -C $(GLUON_OPENWRTDIR) -f $(GLUONDIR)/Makefile

ifneq ($(OPENWRT_BUILD),1)

15
GLUONDIR:=${CURDIR}
Matthias Schiffer's avatar
Matthias Schiffer committed
16

17
include $(GLUONDIR)/include/gluon.mk
Matthias Schiffer's avatar
Matthias Schiffer committed
18

19
TOPDIR:=$(GLUON_ORIGOPENWRTDIR)
20
21
export TOPDIR

22

23
24
25
26
GLUON_TARGET ?= ar71xx-generic
export GLUON_TARGET


27
28
update: FORCE
	$(GLUONDIR)/scripts/update.sh $(GLUONDIR)
29
	$(GLUONDIR)/scripts/patch.sh $(GLUONDIR)
30

31
32
33
34
35
36
patch: FORCE
	$(GLUONDIR)/scripts/patch.sh $(GLUONDIR)

unpatch: FORCE
	$(GLUONDIR)/scripts/unpatch.sh $(GLUONDIR)

Matthias Schiffer's avatar
Matthias Schiffer committed
37
update-patches: FORCE
38
	$(GLUONDIR)/scripts/update.sh $(GLUONDIR)
Matthias Schiffer's avatar
Matthias Schiffer committed
39
40
41
	$(GLUONDIR)/scripts/update-patches.sh $(GLUONDIR)
	$(GLUONDIR)/scripts/patch.sh $(GLUONDIR)

42
-include $(TOPDIR)/include/host.mk
43
44
45
46

_SINGLE=export MAKEFLAGS=$(space);

override OPENWRT_BUILD=1
47
override GLUON_TOOLS=1
48
GREP_OPTIONS=
49
export OPENWRT_BUILD GLUON_TOOLS GREP_OPTIONS
50

51
52
-include $(TOPDIR)/include/debug.mk
-include $(TOPDIR)/include/depends.mk
53
include $(GLUONDIR)/include/toplevel.mk
54

55
56
57
58
59
define GluonProfile
image/$(1): FORCE
	+@$$(GLUONMAKE) $$@
endef

60
61
62
define GluonModel
endef

63
include $(GLUONDIR)/targets/targets.mk
64
include $(GLUONDIR)/targets/$(GLUON_TARGET)/profiles.mk
65

66

67
CheckExternal := test -d $(GLUON_ORIGOPENWRTDIR) || (echo 'You don'"'"'t seem to have obtained the external repositories needed by Gluon; please call `make update` first!'; false)
68

69
70
71
72
73
74
75

prepare-target: FORCE
	@$(CheckExternal)
	+@$(GLUONMAKE_EARLY) prepare-target


all: prepare-target
76
77
78
	+@$(GLUONMAKE) prepare
	+@$(GLUONMAKE) images

79
prepare: prepare-target
80
	+@$(GLUONMAKE) $@
81

82
83
84
clean dirclean download images: FORCE
	@$(CheckExternal)
	+@$(GLUONMAKE_EARLY) maybe-prepare-target
85
86
	+@$(GLUONMAKE) $@

87
88
89
toolchain/% package/% target/%: FORCE
	@$(CheckExternal)
	+@$(GLUONMAKE_EARLY) maybe-prepare-target
Matthias Schiffer's avatar
Matthias Schiffer committed
90
91
	+@$(GLUONMAKE) $@

92
93
manifest: FORCE
	[ -n "$(GLUON_BRANCH)" ] || (echo 'Please set GLUON_BRANCH to create a manifest.'; false)
94
	@$(CheckExternal)
95
96
	+@$(GLUONMAKE_EARLY) maybe-prepare-target
	+@$(GLUONMAKE) $@
97
98

else
99

100
101
102
TOPDIR=${CURDIR}
export TOPDIR

103
include rules.mk
Matthias Schiffer's avatar
Matthias Schiffer committed
104

105
include $(GLUONDIR)/include/gluon.mk
106

107
include $(INCLUDE_DIR)/host.mk
108
109
include $(INCLUDE_DIR)/depends.mk
include $(INCLUDE_DIR)/subdir.mk
110

111
112
113
include package/Makefile
include tools/Makefile
include toolchain/Makefile
114
include target/Makefile
115

116

117
118
119
PROFILES :=
PROFILE_PACKAGES :=

120
121
122
123
124
125
define Profile
  $(eval $(call Profile/Default))
  $(eval $(call Profile/$(1)))
  $(1)_PACKAGES := $(PACKAGES)
endef

126
127
define GluonProfile
PROFILES += $(1)
128
PROFILE_PACKAGES += $(filter-out -%,$($(1)_PACKAGES) $(2) $(GLUON_$(1)_SITE_PACKAGES))
129
GLUON_$(1)_DEFAULT_PACKAGES := $(2)
130
131
132
133
134
135
GLUON_$(1)_MODELS :=
endef

define GluonModel
GLUON_$(1)_MODELS += $(2)
GLUON_$(1)_MODEL_$(2) := $(3)
136
137
endef

138
139

include $(GLUONDIR)/targets/targets.mk
140
include $(GLUONDIR)/targets/$(GLUON_TARGET)/profiles.mk
141
142
143
144

BOARD := $(GLUON_TARGET_$(GLUON_TARGET)_BOARD)
override SUBTARGET := $(GLUON_TARGET_$(GLUON_TARGET)_SUBTARGET)

145
target_prepared_stamp := $(BOARD_BUILDDIR)/target-prepared
146
147
148
gluon_prepared_stamp := $(BOARD_BUILDDIR)/prepared


149
include $(INCLUDE_DIR)/target.mk
150

151

152
153
154
prereq: FORCE
	+$(NO_TRACE_MAKE) prereq

Matthias Schiffer's avatar
Matthias Schiffer committed
155
package/lua/host/install: tools/sed/install
156
gluon-tools: package/lua/host/install
157

158
159
160
161
162
163
164
165
166
167
168
prepare-tmpinfo: FORCE
	mkdir -p tmp/info
	$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="packageinfo" SCAN_DIR="package" SCAN_NAME="package" SCAN_DEPS="$(TOPDIR)/include/package*.mk $(TOPDIR)/overlay/*/*.mk" SCAN_EXTRA=""
	$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPS="profiles/*.mk $(TOPDIR)/include/kernel*.mk $(TOPDIR)/include/target.mk" SCAN_DEPTH=2 SCAN_EXTRA="" SCAN_MAKEOPTS="TARGET_BUILD=1"
	for type in package target; do \
		f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
		[ "$$t" -nt "$$f" ] || ./scripts/metadata.pl $${type}_config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
	done
	./scripts/metadata.pl package_mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
	touch $(TOPDIR)/tmp/.build

169
170
171
172
173
feeds: FORCE
	rm -rf $(TOPDIR)/package/feeds
	mkdir $(TOPDIR)/package/feeds
	[ ! -f $(GLUON_SITEDIR)/modules ] || . $(GLUON_SITEDIR)/modules && for feed in $$GLUON_SITE_FEEDS; do ln -s ../../../packages/$$feed $(TOPDIR)/package/feeds/$$feed; done
	. $(GLUONDIR)/modules && for feed in $$GLUON_FEEDS; do ln -s ../../../packages/$$feed $(TOPDIR)/package/feeds/$$feed; done
174
	+$(GLUONMAKE_EARLY) prepare-tmpinfo
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

config: FORCE
	( \
		cat $(GLUONDIR)/include/config $(GLUONDIR)/targets/$(GLUON_TARGET)/config; \
		echo '$(patsubst %,CONFIG_PACKAGE_%=m,$(sort $(filter-out -%,$(GLUON_DEFAULT_PACKAGES) $(GLUON_SITE_PACKAGES) $(PROFILE_PACKAGES))))' \
			| sed -e 's/ /\n/g'; \
	) > .config
	+$(NO_TRACE_MAKE) defconfig OPENWRT_BUILD=0

prepare-target: FORCE
	mkdir -p $(GLUON_OPENWRTDIR)
	for dir in build_dir dl staging_dir tmp; do \
		mkdir -p $(GLUON_ORIGOPENWRTDIR)/$$dir; \
	done
	for link in build_dir Config.in dl include Makefile package rules.mk scripts staging_dir target tmp toolchain tools; do \
		ln -sf $(GLUON_ORIGOPENWRTDIR)/$$link $(GLUON_OPENWRTDIR); \
	done
	+$(GLUONMAKE_EARLY) feeds
	+$(GLUONMAKE_EARLY) gluon-tools
	+$(GLUONMAKE) config
	touch $(target_prepared_stamp)

$(target_prepared_stamp):
	+$(GLUONMAKE_EARLY) prepare-target

maybe-prepare-target: $(target_prepared_stamp)
201

202
203
204
205
206
$(BUILD_DIR)/.prepared: Makefile
	@mkdir -p $$(dirname $@)
	@touch $@

$(toolchain/stamp-install): $(tools/stamp-install)
207
$(package/stamp-compile): $(package/stamp-cleanup)
208

209

210
211
clean: FORCE
	+$(SUBMAKE) clean
212
	rm -f $(gluon_prepared_stamp)
213

214
215
216
dirclean: FORCE
	+$(SUBMAKE) dirclean
	rm -rf $(GLUON_BUILDDIR)
217
218


219
220
221
export MD5SUM := $(GLUONDIR)/scripts/md5sum.sh
export SHA512SUM := $(GLUONDIR)/scripts/sha512sum.sh

222

223
download: FORCE
Matthias Schiffer's avatar
Matthias Schiffer committed
224
225
226
227
	+$(SUBMAKE) tools/download
	+$(SUBMAKE) toolchain/download
	+$(SUBMAKE) package/download
	+$(SUBMAKE) target/download
228

229
toolchain: $(toolchain/stamp-install) $(tools/stamp-install)
230

Matthias Schiffer's avatar
Matthias Schiffer committed
231
232
include $(INCLUDE_DIR)/kernel.mk

233
kernel: FORCE
Matthias Schiffer's avatar
Matthias Schiffer committed
234
235
	+$(NO_TRACE_MAKE) -C $(TOPDIR)/target/linux/$(BOARD) -f $(GLUONDIR)/include/Makefile.target $(LINUX_DIR)/.image TARGET_BUILD=1
	+$(NO_TRACE_MAKE) -C $(TOPDIR)/target/linux/$(BOARD) -f $(GLUONDIR)/include/Makefile.target $(LINUX_DIR)/.modules TARGET_BUILD=1
236

237
packages: $(package/stamp-compile)
238
239
240
241
242
243
	$(_SINGLE)$(SUBMAKE) -r package/index

prepare-image: FORCE
	rm -rf $(BOARD_KDIR)
	mkdir -p $(BOARD_KDIR)
	cp $(KERNEL_BUILD_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.elf $(BOARD_KDIR)/
Matthias Schiffer's avatar
Matthias Schiffer committed
244
	+$(SUBMAKE) -C $(TOPDIR)/target/linux/$(BOARD)/image -f $(GLUONDIR)/include/Makefile.image prepare KDIR="$(BOARD_KDIR)"
245
246

prepare: FORCE
247
248
	@$(STAGING_DIR_HOST)/bin/lua $(GLUONDIR)/packages/gluon/gluon/gluon-core/files/usr/lib/lua/gluon/site_config.lua \
		|| (echo 'Your site configuration did not pass validation.'; false)
249

250
251
	mkdir -p $(GLUON_IMAGEDIR) $(BOARD_BUILDDIR)
	echo 'src packages file:../openwrt/bin/$(BOARD)/packages' > $(BOARD_BUILDDIR)/opkg.conf
252

Matthias Schiffer's avatar
Matthias Schiffer committed
253
254
255
256
	+$(GLUONMAKE) toolchain
	+$(GLUONMAKE) kernel
	+$(GLUONMAKE) packages
	+$(GLUONMAKE) prepare-image
257

258
	echo "$(GLUON_RELEASE)" > $(gluon_prepared_stamp)
259

260
$(gluon_prepared_stamp):
Matthias Schiffer's avatar
Matthias Schiffer committed
261
	+$(GLUONMAKE) prepare
262

263
264
265
266
267
268
269
270

include $(INCLUDE_DIR)/package-ipkg.mk

# override variables from rules.mk
PACKAGE_DIR = $(GLUON_OPENWRTDIR)/bin/$(BOARD)/packages

PROFILE_BUILDDIR = $(BOARD_BUILDDIR)/$(PROFILE)
PROFILE_KDIR = $(PROFILE_BUILDDIR)/kernel
271
BIN_DIR = $(PROFILE_BUILDDIR)/images
272
273
274
275

TMP_DIR = $(PROFILE_BUILDDIR)/tmp
TARGET_DIR = $(PROFILE_BUILDDIR)/root

276
IMAGE_PREFIX = gluon-$(GLUON_SITE_CODE)-$$(cat $(gluon_prepared_stamp))
277

278
279
280
281
282
283
284
285
286
OPKG:= \
  IPKG_TMP="$(TMP_DIR)/ipkgtmp" \
  IPKG_INSTROOT="$(TARGET_DIR)" \
  IPKG_CONF_DIR="$(TMP_DIR)" \
  IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
  $(STAGING_DIR_HOST)/bin/opkg \
	-f $(BOARD_BUILDDIR)/opkg.conf \
	--cache $(TMP_DIR)/dl \
	--offline-root $(TARGET_DIR) \
287
	--force-postinstall \
288
289
290
291
292
293
	--add-dest root:/ \
	--add-arch all:100 \
	--add-arch $(ARCH_PACKAGES):200

EnableInitscript = ! grep -q '\#!/bin/sh /etc/rc.common' $(1) || bash ./etc/rc.common $(1) enable

294

295
296
297
enable_initscripts: FORCE
	cd $(TARGET_DIR) && ( export IPKG_INSTROOT=$(TARGET_DIR); \
		$(foreach script,$(wildcard $(TARGET_DIR)/etc/init.d/*), \
298
			$(call EnableInitscript,$(script)); \
299
300
301
		) : \
	)

302

303
304
# Generate package list
$(eval $(call merge-lists,INSTALL_PACKAGES,DEFAULT_PACKAGES $(PROFILE)_PACKAGES GLUON_DEFAULT_PACKAGES GLUON_SITE_PACKAGES GLUON_$(PROFILE)_DEFAULT_PACKAGES GLUON_$(PROFILE)_SITE_PACKAGES))
305

306
307
308
309
310
package_install: FORCE
	$(OPKG) update
	$(OPKG) install $(PACKAGE_DIR)/libc_*.ipk
	$(OPKG) install $(PACKAGE_DIR)/kernel_*.ipk

311
312
	$(OPKG) install $(INSTALL_PACKAGES)
	+$(GLUONMAKE) enable_initscripts
313
314
315
316
317

	rm -f $(TARGET_DIR)/usr/lib/opkg/lists/* $(TARGET_DIR)/tmp/opkg.lock

image: FORCE
	rm -rf $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(PROFILE_KDIR)
318
	mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(TARGET_DIR)/tmp $(GLUON_IMAGEDIR)/factory $(GLUON_IMAGEDIR)/sysupgrade
319
320
	cp -r $(BOARD_KDIR) $(PROFILE_KDIR)

Matthias Schiffer's avatar
Matthias Schiffer committed
321
	+$(GLUONMAKE) package_install
322
323

	$(call Image/mkfs/prepare)
324
	$(_SINGLE)$(NO_TRACE_MAKE) -C $(TOPDIR)/target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 IMG_PREFIX=gluon \
325
326
		PROFILE="$(PROFILE)" KDIR="$(PROFILE_KDIR)" TARGET_DIR="$(TARGET_DIR)" BIN_DIR="$(BIN_DIR)" TMP_DIR="$(TMP_DIR)"

327
	$(foreach model,$(GLUON_$(PROFILE)_MODELS), \
Matthias Schiffer's avatar
Matthias Schiffer committed
328
329
		rm -f $(GLUON_IMAGEDIR)/factory/gluon-*-$(GLUON_$(PROFILE)_MODEL_$(model)).bin && \
		rm -f $(GLUON_IMAGEDIR)/sysupgrade/gluon-*-$(GLUON_$(PROFILE)_MODEL_$(model))-sysupgrade.bin && \
330
		\
331
332
		cp $(BIN_DIR)/gluon-$(model)-factory.bin $(GLUON_IMAGEDIR)/factory/$(IMAGE_PREFIX)-$(GLUON_$(PROFILE)_MODEL_$(model)).bin && \
		cp $(BIN_DIR)/gluon-$(model)-sysupgrade.bin $(GLUON_IMAGEDIR)/sysupgrade/$(IMAGE_PREFIX)-$(GLUON_$(PROFILE)_MODEL_$(model))-sysupgrade.bin && \
333
	) :
334

335
336
337
image/%: $(gluon_prepared_stamp)
	+$(GLUONMAKE) image PROFILE="$(patsubst image/%,%,$@)" V=s$(OPENWRT_VERBOSE)

338
call_image/%: FORCE
Matthias Schiffer's avatar
Matthias Schiffer committed
339
	+$(GLUONMAKE) $(patsubst call_image/%,image/%,$@)
340
341

images: $(patsubst %,call_image/%,$(PROFILES)) ;
Matthias Schiffer's avatar
Matthias Schiffer committed
342

Matthias Schiffer's avatar
Matthias Schiffer committed
343
344
manifest: FORCE
	mkdir -p $(GLUON_IMAGEDIR)/sysupgrade
345
	(cd $(GLUON_IMAGEDIR)/sysupgrade && echo 'BRANCH=$(GLUON_BRANCH)' && echo && ($(foreach profile,$(PROFILES), \
Matthias Schiffer's avatar
Matthias Schiffer committed
346
		$(foreach model,$(GLUON_$(profile)_MODELS), \
347
			for file in gluon-*-'$(GLUON_$(profile)_MODEL_$(model))-sysupgrade.bin'; do \
Matthias Schiffer's avatar
Matthias Schiffer committed
348
				[ -e "$$file" ] && echo \
349
350
					'$(GLUON_$(profile)_MODEL_$(model))' \
					"$$(echo "$$file" | sed -n -r -e 's/^gluon-$(call regex-escape,$(GLUON_SITE_CODE))-(.*)-$(call regex-escape,$(GLUON_$(profile)_MODEL_$(model)))-sysupgrade\.bin$$/\1/p')" \
351
					"$$($(SHA512SUM) "$$file")" \
Matthias Schiffer's avatar
Matthias Schiffer committed
352
353
354
					"$$file" && break; \
			done; \
		) \
355
	) :)) > $(GLUON_IMAGEDIR)/sysupgrade/$(GLUON_BRANCH).manifest
Matthias Schiffer's avatar
Matthias Schiffer committed
356
357


358
.PHONY: all images prepare clean gluon-tools
359
360

endif