toplevel.mk 8.7 KB

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