1
0

toplevel.mk 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2007-2020 OpenWrt.org
  4. PREP_MK= LIBRECMC_BUILD= QUIET=0
  5. export IS_TTY=$(if $(MAKE_TERMOUT),1,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 ORIG_PATH:=$(if $(ORIG_PATH),$(ORIG_PATH),$(PATH))
  42. export PATH:=$(path)
  43. export STAGING_DIR_HOST:=$(if $(STAGING_DIR),$(abspath $(STAGING_DIR)/../host),$(TOPDIR)/staging_dir/host)
  44. unexport TAR_OPTIONS
  45. ifeq ($(FORCE),)
  46. .config scripts/config/conf scripts/config/mconf: $(STAGING_DIR_HOST)/.prereq-build
  47. endif
  48. SCAN_COOKIE?=$(shell echo $$$$)
  49. export SCAN_COOKIE
  50. SUBMAKE:=umask 022; $(SUBMAKE)
  51. ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024;
  52. prepare-mk: $(STAGING_DIR_HOST)/.prereq-build FORCE ;
  53. ifdef SDK
  54. IGNORE_PACKAGES = linux
  55. endif
  56. _ignore = $(foreach p,$(IGNORE_PACKAGES),--ignore $(p))
  57. prepare-tmpinfo: FORCE
  58. @+$(MAKE) -r -s $(STAGING_DIR_HOST)/.prereq-build $(PREP_MK)
  59. mkdir -p tmp/info
  60. $(_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=""
  61. $(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPTH=3 SCAN_EXTRA="" SCAN_MAKEOPTS="TARGET_BUILD=1"
  62. for type in package target; do \
  63. f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
  64. [ "$$t" -nt "$$f" ] || ./scripts/$${type}-metadata.pl $(_ignore) config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
  65. done
  66. [ tmp/.config-feeds.in -nt tmp/.packageauxvars ] || ./scripts/feeds feed_config > tmp/.config-feeds.in
  67. ./scripts/package-metadata.pl mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
  68. ./scripts/package-metadata.pl pkgaux tmp/.packageinfo > tmp/.packageauxvars || { rm -f tmp/.packageauxvars; false; }
  69. ./scripts/package-metadata.pl usergroup tmp/.packageinfo > tmp/.packageusergroup || { rm -f tmp/.packageusergroup; false; }
  70. touch $(TOPDIR)/tmp/.build
  71. .config: ./scripts/config/conf $(if $(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
  72. @+if [ \! -e .config ] || ! grep CONFIG_HAVE_DOT_CONFIG .config >/dev/null; then \
  73. [ -e $(HOME)/.librecmc/defconfig ] && cp $(HOME)/.librecmc/defconfig .config; \
  74. $(_SINGLE)$(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
  75. fi
  76. ifeq ($(RECURSIVE_DEP_IS_ERROR),1)
  77. KCONF_FLAGS=--fatalrecursive
  78. endif
  79. ifneq ($(DISTRO_PKG_CONFIG),)
  80. scripts/config/%onf: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  81. endif
  82. scripts/config/%onf: CFLAGS+= -O2
  83. scripts/config/%onf: FORCE
  84. @$(_SINGLE)$(SUBMAKE) $(if $(findstring s,$(LIBRECMC_VERBOSE)),,-s) \
  85. -C scripts/config $(notdir $@)
  86. $(eval $(call rdep,scripts/config,scripts/config/mconf))
  87. config: scripts/config/conf prepare-tmpinfo FORCE
  88. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  89. $< $(KCONF_FLAGS) Config.in
  90. config-clean: FORCE
  91. $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
  92. defconfig: scripts/config/conf prepare-tmpinfo FORCE
  93. touch .config
  94. @if [ ! -s .config -a -e $(HOME)/.librecmc/defconfig ]; then cp $(HOME)/.librecmc/defconfig .config; fi
  95. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  96. $< $(KCONF_FLAGS) --defconfig=.config Config.in
  97. confdefault-y=allyes
  98. confdefault-m=allmod
  99. confdefault-n=allno
  100. confdefault:=$(confdefault-$(CONFDEFAULT))
  101. oldconfig: scripts/config/conf prepare-tmpinfo FORCE
  102. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  103. $< $(KCONF_FLAGS) --$(if $(confdefault),$(confdefault),old)config Config.in
  104. menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
  105. if [ \! -e .config -a -e $(HOME)/.librecmc/defconfig ]; then \
  106. cp $(HOME)/.librecmc/defconfig .config; \
  107. fi
  108. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  109. $< Config.in
  110. nconfig: scripts/config/nconf prepare-tmpinfo FORCE
  111. if [ \! -e .config -a -e $(HOME)/.librecmc/defconfig ]; then \
  112. cp $(HOME)/.librecmc/defconfig .config; \
  113. fi
  114. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
  115. $< Config.in
  116. xconfig: scripts/config/qconf prepare-tmpinfo FORCE
  117. if [ \! -e .config -a -e $(HOME)/.librecmc/defconfig ]; then \
  118. cp $(HOME)/.librecmc/defconfig .config; \
  119. fi
  120. $< Config.in
  121. prepare_kernel_conf: .config toolchain/install FORCE
  122. ifeq ($(wildcard $(STAGING_DIR_HOST)/bin/quilt),)
  123. prepare_kernel_conf:
  124. @+$(SUBMAKE) -r tools/quilt/compile
  125. else
  126. prepare_kernel_conf: ;
  127. endif
  128. kernel_oldconfig: prepare_kernel_conf
  129. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
  130. ifneq ($(DISTRO_PKG_CONFIG),)
  131. kernel_menuconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  132. kernel_nconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  133. kernel_xconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  134. endif
  135. kernel_menuconfig: prepare_kernel_conf
  136. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
  137. kernel_nconfig: prepare_kernel_conf
  138. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
  139. kernel_xconfig: prepare_kernel_conf
  140. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux xconfig
  141. $(STAGING_DIR_HOST)/.prereq-build: include/prereq-build.mk
  142. mkdir -p tmp
  143. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
  144. echo "Prerequisite check failed. Use FORCE=1 to override."; \
  145. false; \
  146. }
  147. ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
  148. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
  149. echo "Preparation failed."; \
  150. false; \
  151. }
  152. endif
  153. touch $@
  154. printdb: FORCE
  155. @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
  156. ifndef SDK
  157. DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
  158. else
  159. DOWNLOAD_DIRS = package/download
  160. endif
  161. download: .config FORCE $(if $(wildcard $(STAGING_DIR_HOST)/bin/flock),,tools/flock/compile)
  162. @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
  163. clean dirclean: .config
  164. @+$(SUBMAKE) -r $@
  165. prereq:: prepare-tmpinfo .config
  166. @+$(NO_TRACE_MAKE) -r -s $@
  167. check: .config FORCE
  168. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  169. val.%: FORCE
  170. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  171. WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(LIBRECMC_VERBOSE))))
  172. ifeq ($(SDK),1)
  173. %::
  174. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  175. @./scripts/config/conf $(KCONF_FLAGS) --defconfig=.config Config.in
  176. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
  177. else
  178. %::
  179. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  180. @( \
  181. cp .config tmp/.config; \
  182. ./scripts/config/conf $(KCONF_FLAGS) --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
  183. if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
  184. printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
  185. fi \
  186. )
  187. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
  188. printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
  189. false; \
  190. } )
  191. endif
  192. # update all feeds, re-create index files, install symlinks
  193. package/symlinks:
  194. ./scripts/feeds update -a
  195. ./scripts/feeds install -a
  196. # re-create index files, install symlinks
  197. package/symlinks-install:
  198. ./scripts/feeds update -i
  199. ./scripts/feeds install -a
  200. # remove all symlinks, don't touch ./feeds
  201. package/symlinks-clean:
  202. ./scripts/feeds uninstall -a
  203. help:
  204. cat README.md
  205. distclean:
  206. rm -rf bin build_dir .ccache .config* dl feeds key-build* logs package/feeds staging_dir tmp
  207. @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
  208. ifeq ($(findstring v,$(DEBUG)),)
  209. .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
  210. endif
  211. .PHONY: help FORCE
  212. .NOTPARALLEL: