Makefile 11 KB

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