Makefile 10 KB

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