Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. all:
  2. LC_ALL:=C
  3. LANG:=C
  4. export LC_ALL LANG
  5. empty:=
  6. space:= $(empty) $(empty)
  7. GLUONMAKE_EARLY = $(SUBMAKE) -C $(GLUON_ORIGOPENWRTDIR) -f $(GLUONDIR)/Makefile GLUON_TOOLS=0
  8. GLUONMAKE = $(SUBMAKE) -C $(GLUON_OPENWRTDIR) -f $(GLUONDIR)/Makefile
  9. ifneq ($(OPENWRT_BUILD),1)
  10. GLUONDIR:=${CURDIR}
  11. include $(GLUONDIR)/include/gluon.mk
  12. TOPDIR:=$(GLUON_ORIGOPENWRTDIR)
  13. export TOPDIR
  14. GLUON_TARGET ?= ar71xx-generic
  15. export GLUON_TARGET
  16. update: FORCE
  17. $(GLUONDIR)/scripts/update.sh
  18. $(GLUONDIR)/scripts/patch.sh
  19. patch: FORCE
  20. $(GLUONDIR)/scripts/patch.sh
  21. unpatch: FORCE
  22. $(GLUONDIR)/scripts/unpatch.sh
  23. update-patches: FORCE
  24. $(GLUONDIR)/scripts/update.sh
  25. $(GLUONDIR)/scripts/update-patches.sh
  26. $(GLUONDIR)/scripts/patch.sh
  27. -include $(TOPDIR)/include/host.mk
  28. _SINGLE=export MAKEFLAGS=$(space);
  29. override OPENWRT_BUILD=1
  30. override GLUON_TOOLS=1
  31. GREP_OPTIONS=
  32. export OPENWRT_BUILD GLUON_TOOLS GREP_OPTIONS
  33. -include $(TOPDIR)/include/debug.mk
  34. -include $(TOPDIR)/include/depends.mk
  35. include $(GLUONDIR)/include/toplevel.mk
  36. define GluonProfile
  37. image/$(1): FORCE
  38. +@$$(GLUONMAKE) $$@
  39. endef
  40. define GluonProfileFactorySuffix
  41. endef
  42. define GluonProfileSysupgradeSuffix
  43. endef
  44. define GluonProfileExtraSuffix
  45. endef
  46. define GluonModel
  47. endef
  48. include $(GLUONDIR)/targets/targets.mk
  49. include $(GLUONDIR)/targets/$(GLUON_TARGET)/profiles.mk
  50. 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)
  51. prepare-target: FORCE
  52. @$(CheckExternal)
  53. +@$(GLUONMAKE_EARLY) prepare-target
  54. all: prepare-target
  55. +@$(GLUONMAKE) prepare
  56. +@$(GLUONMAKE) images
  57. prepare: prepare-target
  58. +@$(GLUONMAKE) $@
  59. clean dirclean download images: FORCE
  60. @$(CheckExternal)
  61. +@$(GLUONMAKE_EARLY) maybe-prepare-target
  62. +@$(GLUONMAKE) $@
  63. toolchain/% package/% target/%: FORCE
  64. @$(CheckExternal)
  65. +@$(GLUONMAKE_EARLY) maybe-prepare-target
  66. +@$(GLUONMAKE) $@
  67. manifest: FORCE
  68. [ -n '$(GLUON_BRANCH)' ] || (echo 'Please set GLUON_BRANCH to create a manifest.'; false)
  69. echo '$(GLUON_PRIORITY)' | grep -qE '^([0-9]*\.)?[0-9]+$$' || (echo 'Please specify a numeric value for GLUON_PRIORITY to create a manifest.'; false)
  70. @$(CheckExternal)
  71. +@$(GLUONMAKE_EARLY) maybe-prepare-target
  72. +@$(GLUONMAKE) $@
  73. else
  74. TOPDIR=${CURDIR}
  75. export TOPDIR
  76. include rules.mk
  77. include $(GLUONDIR)/include/gluon.mk
  78. include $(INCLUDE_DIR)/host.mk
  79. include $(INCLUDE_DIR)/depends.mk
  80. include $(INCLUDE_DIR)/subdir.mk
  81. include package/Makefile
  82. include tools/Makefile
  83. include toolchain/Makefile
  84. include target/Makefile
  85. PROFILES :=
  86. PROFILE_PACKAGES :=
  87. define Profile
  88. $(eval $(call Profile/Default))
  89. $(eval $(call Profile/$(1)))
  90. endef
  91. define GluonProfile
  92. PROFILES += $(1)
  93. PROFILE_PACKAGES += $(filter-out -%,$(2) $(GLUON_$(1)_SITE_PACKAGES))
  94. GLUON_$(1)_DEFAULT_PACKAGES := $(2)
  95. GLUON_$(1)_FACTORY_SUFFIX := .bin
  96. GLUON_$(1)_SYSUPGRADE_SUFFIX := .bin
  97. GLUON_$(1)_EXTRA_SUFFIX :=
  98. GLUON_$(1)_MODELS :=
  99. endef
  100. define GluonProfileFactorySuffix
  101. GLUON_$(1)_FACTORY_SUFFIX := $(2)
  102. endef
  103. define GluonProfileSysupgradeSuffix
  104. GLUON_$(1)_SYSUPGRADE_SUFFIX := $(2)
  105. endef
  106. define GluonProfileExtraSuffix
  107. GLUON_$(1)_EXTRA_SUFFIX := $(2)
  108. endef
  109. define GluonModel
  110. GLUON_$(1)_MODELS += $(3)
  111. GLUON_$(1)_MODEL_$(3) := $(2)
  112. endef
  113. include $(GLUONDIR)/targets/targets.mk
  114. include $(GLUONDIR)/targets/$(GLUON_TARGET)/profiles.mk
  115. BOARD := $(GLUON_TARGET_$(GLUON_TARGET)_BOARD)
  116. override SUBTARGET := $(GLUON_TARGET_$(GLUON_TARGET)_SUBTARGET)
  117. target_prepared_stamp := $(BOARD_BUILDDIR)/target-prepared
  118. gluon_prepared_stamp := $(BOARD_BUILDDIR)/prepared
  119. include $(INCLUDE_DIR)/target.mk
  120. prereq: FORCE
  121. +$(NO_TRACE_MAKE) prereq
  122. gluon-tools: FORCE
  123. +$(GLUONMAKE_EARLY) tools/sed/install
  124. +$(GLUONMAKE_EARLY) package/lua/host/install
  125. prepare-tmpinfo: FORCE
  126. mkdir -p tmp/info
  127. $(_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=""
  128. $(_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"
  129. for type in package target; do \
  130. f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
  131. [ "$$t" -nt "$$f" ] || ./scripts/metadata.pl $${type}_config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
  132. done
  133. ./scripts/metadata.pl package_mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
  134. touch $(TOPDIR)/tmp/.build
  135. feeds: FORCE
  136. rm -rf $(TOPDIR)/package/feeds
  137. mkdir $(TOPDIR)/package/feeds
  138. [ ! -f $(GLUON_SITEDIR)/modules ] || . $(GLUON_SITEDIR)/modules && for feed in $$GLUON_SITE_FEEDS; do ln -s ../../../packages/$$feed $(TOPDIR)/package/feeds/$$feed; done
  139. . $(GLUONDIR)/modules && for feed in $$GLUON_FEEDS; do ln -s ../../../packages/$$feed $(TOPDIR)/package/feeds/$$feed; done
  140. +$(GLUONMAKE_EARLY) prepare-tmpinfo
  141. config: FORCE
  142. ( \
  143. cat $(GLUONDIR)/include/config $(GLUONDIR)/targets/$(GLUON_TARGET)/config; \
  144. echo '$(patsubst %,CONFIG_PACKAGE_%=m,$(sort $(filter-out -%,$(GLUON_DEFAULT_PACKAGES) $(GLUON_SITE_PACKAGES) $(PROFILE_PACKAGES))))' \
  145. | sed -e 's/ /\n/g'; \
  146. ) > .config
  147. +$(NO_TRACE_MAKE) defconfig OPENWRT_BUILD=0
  148. prepare-target: FORCE
  149. mkdir -p $(GLUON_OPENWRTDIR)
  150. for dir in build_dir dl staging_dir tmp; do \
  151. mkdir -p $(GLUON_ORIGOPENWRTDIR)/$$dir; \
  152. done
  153. for link in build_dir config Config.in dl include Makefile package rules.mk scripts staging_dir target tmp toolchain tools; do \
  154. ln -sf $(GLUON_ORIGOPENWRTDIR)/$$link $(GLUON_OPENWRTDIR); \
  155. done
  156. +$(GLUONMAKE_EARLY) feeds
  157. +$(GLUONMAKE_EARLY) gluon-tools
  158. +$(GLUONMAKE) config
  159. touch $(target_prepared_stamp)
  160. $(target_prepared_stamp):
  161. +$(GLUONMAKE_EARLY) prepare-target
  162. maybe-prepare-target: $(target_prepared_stamp)
  163. $(BUILD_DIR)/.prepared: Makefile
  164. @mkdir -p $$(dirname $@)
  165. @touch $@
  166. $(toolchain/stamp-install): $(tools/stamp-install)
  167. $(package/stamp-compile): $(package/stamp-cleanup)
  168. clean: FORCE
  169. +$(SUBMAKE) clean
  170. rm -f $(gluon_prepared_stamp)
  171. dirclean: FORCE
  172. +$(SUBMAKE) dirclean
  173. rm -rf $(GLUON_BUILDDIR)
  174. export MD5SUM := $(GLUONDIR)/scripts/md5sum.sh
  175. export SHA512SUM := $(GLUONDIR)/scripts/sha512sum.sh
  176. download: FORCE
  177. +$(SUBMAKE) tools/download
  178. +$(SUBMAKE) toolchain/download
  179. +$(SUBMAKE) package/download
  180. +$(SUBMAKE) target/download
  181. toolchain: $(toolchain/stamp-install) $(tools/stamp-install)
  182. include $(INCLUDE_DIR)/kernel.mk
  183. kernel: FORCE
  184. +$(NO_TRACE_MAKE) -C $(TOPDIR)/target/linux/$(BOARD) -f $(GLUONDIR)/include/Makefile.target $(LINUX_DIR)/.image TARGET_BUILD=1
  185. +$(NO_TRACE_MAKE) -C $(TOPDIR)/target/linux/$(BOARD) -f $(GLUONDIR)/include/Makefile.target $(LINUX_DIR)/.modules TARGET_BUILD=1
  186. packages: $(package/stamp-compile)
  187. $(_SINGLE)$(SUBMAKE) -r package/index
  188. prepare-image: FORCE
  189. rm -rf $(BOARD_KDIR)
  190. mkdir -p $(BOARD_KDIR)
  191. cp $(KERNEL_BUILD_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.elf $(BOARD_KDIR)/
  192. +$(SUBMAKE) -C $(TOPDIR)/target/linux/$(BOARD)/image -f $(GLUONDIR)/include/Makefile.image prepare KDIR="$(BOARD_KDIR)"
  193. prepare: FORCE
  194. @$(STAGING_DIR_HOST)/bin/lua $(GLUONDIR)/packages/gluon/gluon/gluon-core/files/usr/lib/lua/gluon/site_config.lua \
  195. || (echo 'Your site configuration did not pass validation.'; false)
  196. mkdir -p $(GLUON_IMAGEDIR) $(BOARD_BUILDDIR)
  197. echo 'src packages file:../openwrt/bin/$(BOARD)/packages' > $(BOARD_BUILDDIR)/opkg.conf
  198. +$(GLUONMAKE) toolchain
  199. +$(GLUONMAKE) kernel
  200. +$(GLUONMAKE) packages
  201. +$(GLUONMAKE) prepare-image
  202. echo "$(GLUON_RELEASE)" > $(gluon_prepared_stamp)
  203. $(gluon_prepared_stamp):
  204. +$(GLUONMAKE) prepare
  205. include $(INCLUDE_DIR)/package-ipkg.mk
  206. # override variables from rules.mk
  207. PACKAGE_DIR = $(GLUON_OPENWRTDIR)/bin/$(BOARD)/packages
  208. PROFILE_BUILDDIR = $(BOARD_BUILDDIR)/$(PROFILE)
  209. PROFILE_KDIR = $(PROFILE_BUILDDIR)/kernel
  210. BIN_DIR = $(PROFILE_BUILDDIR)/images
  211. TMP_DIR = $(PROFILE_BUILDDIR)/tmp
  212. TARGET_DIR = $(PROFILE_BUILDDIR)/root
  213. IMAGE_PREFIX = gluon-$(GLUON_SITE_CODE)-$$(cat $(gluon_prepared_stamp))
  214. OPKG:= \
  215. IPKG_TMP="$(TMP_DIR)/ipkgtmp" \
  216. IPKG_INSTROOT="$(TARGET_DIR)" \
  217. IPKG_CONF_DIR="$(TMP_DIR)" \
  218. IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
  219. $(STAGING_DIR_HOST)/bin/opkg \
  220. -f $(BOARD_BUILDDIR)/opkg.conf \
  221. --cache $(TMP_DIR)/dl \
  222. --offline-root $(TARGET_DIR) \
  223. --force-postinstall \
  224. --add-dest root:/ \
  225. --add-arch all:100 \
  226. --add-arch $(ARCH_PACKAGES):200
  227. EnableInitscript = ! grep -q '\#!/bin/sh /etc/rc.common' $(1) || bash ./etc/rc.common $(1) enable
  228. enable_initscripts: FORCE
  229. cd $(TARGET_DIR) && ( export IPKG_INSTROOT=$(TARGET_DIR); \
  230. $(foreach script,$(wildcard $(TARGET_DIR)/etc/init.d/*), \
  231. $(call EnableInitscript,$(script)); \
  232. ) : \
  233. )
  234. # Generate package list
  235. $(eval $(call merge-lists,INSTALL_PACKAGES,DEFAULT_PACKAGES GLUON_DEFAULT_PACKAGES GLUON_SITE_PACKAGES GLUON_$(PROFILE)_DEFAULT_PACKAGES GLUON_$(PROFILE)_SITE_PACKAGES))
  236. package_install: FORCE
  237. $(OPKG) update
  238. $(OPKG) install $(PACKAGE_DIR)/libc_*.ipk
  239. $(OPKG) install $(PACKAGE_DIR)/kernel_*.ipk
  240. $(OPKG) install $(INSTALL_PACKAGES)
  241. +$(GLUONMAKE) enable_initscripts
  242. rm -f $(TARGET_DIR)/usr/lib/opkg/lists/* $(TARGET_DIR)/tmp/opkg.lock
  243. ifeq ($(GLUON_OPKG_CONFIG),1)
  244. include $(INCLUDE_DIR)/version.mk
  245. endif
  246. opkg_config: FORCE
  247. cp $(GLUON_OPENWRTDIR)/package/system/opkg/files/opkg.conf $(TARGET_DIR)/etc/opkg.conf
  248. for d in base luci packages routing telephony management oldpackages; do \
  249. echo "src/gz %n_$$d %U/$$d" >> $(TARGET_DIR)/etc/opkg.conf; \
  250. done
  251. $(VERSION_SED) $(TARGET_DIR)/etc/opkg.conf
  252. image: FORCE
  253. rm -rf $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(PROFILE_KDIR)
  254. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(TARGET_DIR)/tmp $(GLUON_IMAGEDIR)/factory $(GLUON_IMAGEDIR)/sysupgrade
  255. cp -r $(BOARD_KDIR) $(PROFILE_KDIR)
  256. +$(GLUONMAKE) package_install
  257. +$(GLUONMAKE) opkg_config GLUON_OPKG_CONFIG=1
  258. $(call Image/mkfs/prepare)
  259. $(_SINGLE)$(NO_TRACE_MAKE) -C $(TOPDIR)/target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 IMG_PREFIX=gluon \
  260. PROFILE="$(PROFILE)" KDIR="$(PROFILE_KDIR)" TARGET_DIR="$(TARGET_DIR)" BIN_DIR="$(BIN_DIR)" TMP_DIR="$(TMP_DIR)"
  261. $(foreach model,$(GLUON_$(PROFILE)_MODELS), \
  262. $(if $(GLUON_$(PROFILE)_SYSUPGRADE_SUFFIX), \
  263. rm -f $(GLUON_IMAGEDIR)/sysupgrade/gluon-*-$(model)-sysupgrade$(GLUON_$(PROFILE)_SYSUPGRADE_SUFFIX) && \
  264. cp $(BIN_DIR)/gluon-$(GLUON_$(PROFILE)_MODEL_$(model))-sysupgrade$(GLUON_$(PROFILE)_SYSUPGRADE_SUFFIX) $(GLUON_IMAGEDIR)/sysupgrade/$(IMAGE_PREFIX)-$(model)-sysupgrade$(GLUON_$(PROFILE)_SYSUPGRADE_SUFFIX) && \
  265. ) \
  266. $(if $(GLUON_$(PROFILE)_FACTORY_SUFFIX), \
  267. rm -f $(GLUON_IMAGEDIR)/factory/gluon-*-$(model)$(GLUON_$(PROFILE)_FACTORY_SUFFIX) && \
  268. cp $(BIN_DIR)/gluon-$(GLUON_$(PROFILE)_MODEL_$(model))-factory$(GLUON_$(PROFILE)_FACTORY_SUFFIX) $(GLUON_IMAGEDIR)/factory/$(IMAGE_PREFIX)-$(model)$(GLUON_$(PROFILE)_FACTORY_SUFFIX) && \
  269. ) \
  270. $(if $(GLUON_$(PROFILE)_EXTRA_SUFFIX), \
  271. rm -f $(GLUON_IMAGEDIR)/factory/gluon-*-$(model)$(GLUON_$(PROFILE)_EXTRA_SUFFIX) && \
  272. cp $(BIN_DIR)/gluon-$(GLUON_$(PROFILE)_MODEL_$(model))$(GLUON_$(PROFILE)_EXTRA_SUFFIX) $(GLUON_IMAGEDIR)/factory/$(IMAGE_PREFIX)-$(model)$(GLUON_$(PROFILE)_EXTRA_SUFFIX) && \
  273. ) \
  274. ) :
  275. image/%: $(gluon_prepared_stamp)
  276. +$(GLUONMAKE) image PROFILE="$(patsubst image/%,%,$@)" V=s$(OPENWRT_VERBOSE)
  277. call_image/%: FORCE
  278. +$(GLUONMAKE) $(patsubst call_image/%,image/%,$@)
  279. images: $(patsubst %,call_image/%,$(PROFILES)) ;
  280. manifest: FORCE
  281. mkdir -p $(GLUON_IMAGEDIR)/sysupgrade
  282. (cd $(GLUON_IMAGEDIR)/sysupgrade && \
  283. echo 'BRANCH=$(GLUON_BRANCH)' && \
  284. echo 'DATE=$(shell $(STAGING_DIR_HOST)/bin/lua $(GLUONDIR)/scripts/rfc3339date.lua)' && \
  285. echo 'PRIORITY=$(GLUON_PRIORITY)' && \
  286. echo && \
  287. ($(foreach profile,$(PROFILES), \
  288. $(foreach model,$(GLUON_$(profile)_MODELS), \
  289. for file in gluon-*-'$(model)-sysupgrade.bin'; do \
  290. [ -e "$$file" ] && echo \
  291. '$(model)' \
  292. "$$(echo "$$file" | sed -n -r -e 's/^gluon-$(call regex-escape,$(GLUON_SITE_CODE))-(.*)-$(call regex-escape,$(model))-sysupgrade\.bin$$/\1/p')" \
  293. "$$($(SHA512SUM) "$$file")" \
  294. "$$file" && break; \
  295. done; \
  296. ) \
  297. ) :) \
  298. ) > $(GLUON_IMAGEDIR)/sysupgrade/$(GLUON_BRANCH).manifest
  299. .PHONY: all images prepare clean gluon-tools
  300. endif