Makefile 12 KB

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