toplevel.mk 8.9 KB

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