Makefile 11 KB

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