toplevel.mk 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2007-2020 OpenWrt.org
  4. PREP_MK= OPENWRT_BUILD= QUIET=0
  5. export IS_TTY=$(shell tty -s && echo 1 || echo 0)
  6. include $(TOPDIR)/include/verbose.mk
  7. ifeq ($(SDK),1)
  8. include $(TOPDIR)/include/version.mk
  9. else
  10. REVISION:=$(shell $(TOPDIR)/scripts/getver.sh)
  11. SOURCE_DATE_EPOCH:=$(shell $(TOPDIR)/scripts/get_source_date_epoch.sh)
  12. endif
  13. export REVISION
  14. export SOURCE_DATE_EPOCH
  15. export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
  16. export GIT_ASKPASS:=/bin/true
  17. export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
  18. export GNU_HOST_NAME:=$(shell $(TOPDIR)/scripts/config.guess)
  19. export HOST_OS:=$(shell uname)
  20. export HOST_ARCH:=$(shell uname -m)
  21. ifeq ($(HOST_OS),Darwin)
  22. ifneq ($(filter /Applications/Xcode.app/% /Library/Developer/%,$(MAKE)),)
  23. $(error Please use a newer version of GNU make. The version shipped by Apple is not supported)
  24. endif
  25. endif
  26. # prevent perforce from messing with the patch utility
  27. unexport P4PORT P4USER P4CONFIG P4CLIENT
  28. # prevent user defaults for quilt from interfering
  29. unexport QUILT_PATCHES QUILT_PATCH_OPTS
  30. unexport C_INCLUDE_PATH CROSS_COMPILE ARCH
  31. # prevent distro default LPATH from interfering
  32. unexport LPATH
  33. # make sure that a predefined CFLAGS variable does not disturb packages
  34. export CFLAGS=
  35. export LDFLAGS=
  36. empty:=
  37. space:= $(empty) $(empty)
  38. path:=$(subst :,$(space),$(PATH))
  39. path:=$(filter-out .%,$(path))
  40. path:=$(subst $(space),:,$(path))
  41. export PATH:=$(path)
  42. unexport TAR_OPTIONS
  43. ifeq ($(FORCE),)
  44. .config scripts/config/conf scripts/config/mconf: staging_dir/host/.prereq-build
  45. endif
  46. SCAN_COOKIE?=$(shell echo $$$$)
  47. export SCAN_COOKIE
  48. SUBMAKE:=umask 022; $(SUBMAKE)
  49. ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024;
  50. prepare-mk: staging_dir/host/.prereq-build FORCE ;
  51. ifdef SDK
  52. IGNORE_PACKAGES = linux
  53. endif
  54. _ignore = $(foreach p,$(IGNORE_PACKAGES),--ignore $(p))
  55. prepare-tmpinfo: FORCE
  56. @+$(MAKE) -r -s staging_dir/host/.prereq-build $(PREP_MK)
  57. mkdir -p tmp/info
  58. $(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="packageinfo" SCAN_DIR="package" SCAN_NAME="package" SCAN_DEPTH=5 SCAN_EXTRA=""
  59. $(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPTH=2 SCAN_EXTRA="" SCAN_MAKEOPTS="TARGET_BUILD=1"
  60. for type in package target; do \
  61. f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
  62. [ "$$t" -nt "$$f" ] || ./scripts/$${type}-metadata.pl $(_ignore) config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
  63. done
  64. [ tmp/.config-feeds.in -nt tmp/.packageauxvars ] || ./scripts/feeds feed_config > tmp/.config-feeds.in
  65. ./scripts/package-metadata.pl mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
  66. ./scripts/package-metadata.pl pkgaux tmp/.packageinfo > tmp/.packageauxvars || { rm -f tmp/.packageauxvars; false; }
  67. ./scripts/package-metadata.pl usergroup tmp/.packageinfo > tmp/.packageusergroup || { rm -f tmp/.packageusergroup; false; }
  68. touch $(TOPDIR)/tmp/.build
  69. .config: ./scripts/config/conf $(if $(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
  70. @+if [ \! -e .config ] || ! grep CONFIG_HAVE_DOT_CONFIG .config >/dev/null; then \
  71. [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \
  72. $(_SINGLE)$(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
  73. fi
  74. ifeq ($(RECURSIVE_DEP_IS_ERROR),1)
  75. KCONF_FLAGS=--fatalrecursive
  76. endif
  77. ifneq ($(DISTRO_PKG_CONFIG),)
  78. scripts/config/%onf: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  79. endif
  80. scripts/config/%onf: CFLAGS+= -O2
  81. scripts/config/%onf:
  82. @$(_SINGLE)$(SUBMAKE) $(if $(findstring s,$(OPENWRT_VERBOSE)),,-s) \
  83. -C scripts/config $(notdir $@)
  84. $(eval $(call rdep,scripts/config,scripts/config/mconf))
  85. config: scripts/config/conf prepare-tmpinfo FORCE
  86. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  87. $< $(KCONF_FLAGS) Config.in
  88. config-clean: FORCE
  89. $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
  90. defconfig: scripts/config/conf prepare-tmpinfo FORCE
  91. touch .config
  92. @if [ ! -s .config -a -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
  93. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  94. $< $(KCONF_FLAGS) --defconfig=.config Config.in
  95. confdefault-y=allyes
  96. confdefault-m=allmod
  97. confdefault-n=allno
  98. confdefault:=$(confdefault-$(CONFDEFAULT))
  99. oldconfig: scripts/config/conf prepare-tmpinfo FORCE
  100. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  101. $< $(KCONF_FLAGS) --$(if $(confdefault),$(confdefault),old)config Config.in
  102. menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
  103. if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
  104. cp $(HOME)/.openwrt/defconfig .config; \
  105. fi
  106. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  107. $< Config.in
  108. nconfig: scripts/config/nconf prepare-tmpinfo FORCE
  109. if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
  110. cp $(HOME)/.openwrt/defconfig .config; \
  111. fi
  112. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  113. $< Config.in
  114. xconfig: scripts/config/qconf prepare-tmpinfo FORCE
  115. if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
  116. cp $(HOME)/.openwrt/defconfig .config; \
  117. fi
  118. $< Config.in
  119. prepare_kernel_conf: .config toolchain/install FORCE
  120. ifeq ($(wildcard staging_dir/host/bin/quilt),)
  121. prepare_kernel_conf:
  122. @+$(SUBMAKE) -r tools/quilt/compile
  123. else
  124. prepare_kernel_conf: ;
  125. endif
  126. kernel_oldconfig: prepare_kernel_conf
  127. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
  128. ifneq ($(DISTRO_PKG_CONFIG),)
  129. kernel_menuconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  130. kernel_nconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  131. kernel_xconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  132. endif
  133. kernel_menuconfig: prepare_kernel_conf
  134. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
  135. kernel_nconfig: prepare_kernel_conf
  136. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
  137. kernel_xconfig: prepare_kernel_conf
  138. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux xconfig
  139. staging_dir/host/.prereq-build: include/prereq-build.mk
  140. mkdir -p tmp
  141. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
  142. echo "Prerequisite check failed. Use FORCE=1 to override."; \
  143. false; \
  144. }
  145. ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
  146. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
  147. echo "Preparation failed."; \
  148. false; \
  149. }
  150. endif
  151. touch $@
  152. printdb: FORCE
  153. @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
  154. ifndef SDK
  155. DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
  156. else
  157. DOWNLOAD_DIRS = package/download
  158. endif
  159. download: .config FORCE $(if $(wildcard $(TOPDIR)/staging_dir/host/bin/flock),,tools/flock/compile)
  160. @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
  161. clean dirclean: .config
  162. @+$(SUBMAKE) -r $@
  163. prereq:: prepare-tmpinfo .config
  164. @+$(NO_TRACE_MAKE) -r -s $@
  165. check: .config FORCE
  166. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  167. val.%: FORCE
  168. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  169. WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
  170. ifeq ($(SDK),1)
  171. %::
  172. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  173. @./scripts/config/conf $(KCONF_FLAGS) --defconfig=.config Config.in
  174. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
  175. else
  176. %::
  177. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  178. @( \
  179. cp .config tmp/.config; \
  180. ./scripts/config/conf $(KCONF_FLAGS) --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
  181. if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
  182. printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
  183. fi \
  184. )
  185. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
  186. printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
  187. false; \
  188. } )
  189. endif
  190. # update all feeds, re-create index files, install symlinks
  191. package/symlinks:
  192. ./scripts/feeds update -a
  193. ./scripts/feeds install -a
  194. # re-create index files, install symlinks
  195. package/symlinks-install:
  196. ./scripts/feeds update -i
  197. ./scripts/feeds install -a
  198. # remove all symlinks, don't touch ./feeds
  199. package/symlinks-clean:
  200. ./scripts/feeds uninstall -a
  201. help:
  202. cat README.md
  203. distclean:
  204. rm -rf bin build_dir .ccache .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
  205. @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
  206. ifeq ($(findstring v,$(DEBUG)),)
  207. .SILENT: symlinkclean clean dirclean distclean config-clean download help tmpinfo-clean .config scripts/config/mconf scripts/config/conf menuconfig staging_dir/host/.prereq-build tmp/.prereq-package prepare-tmpinfo
  208. endif
  209. .PHONY: help FORCE
  210. .NOTPARALLEL: