Makefile 11 KB

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