toplevel.mk 8.6 KB

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