toplevel.mk 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. xconfig: scripts/config/qconf prepare-tmpinfo FORCE
  114. if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
  115. cp $(HOME)/.openwrt/defconfig .config; \
  116. fi
  117. $< Config.in
  118. prepare_kernel_conf: .config toolchain/install FORCE
  119. ifeq ($(wildcard staging_dir/host/bin/quilt),)
  120. prepare_kernel_conf:
  121. @+$(SUBMAKE) -r tools/quilt/compile
  122. else
  123. prepare_kernel_conf: ;
  124. endif
  125. kernel_oldconfig: prepare_kernel_conf
  126. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
  127. ifneq ($(DISTRO_PKG_CONFIG),)
  128. kernel_menuconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  129. kernel_nconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
  130. endif
  131. kernel_menuconfig: prepare_kernel_conf
  132. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
  133. kernel_nconfig: prepare_kernel_conf
  134. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
  135. staging_dir/host/.prereq-build: include/prereq-build.mk
  136. mkdir -p tmp
  137. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
  138. echo "Prerequisite check failed. Use FORCE=1 to override."; \
  139. false; \
  140. }
  141. ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
  142. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
  143. echo "Preparation failed."; \
  144. false; \
  145. }
  146. endif
  147. touch $@
  148. printdb: FORCE
  149. @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
  150. ifndef SDK
  151. DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
  152. else
  153. DOWNLOAD_DIRS = package/download
  154. endif
  155. download: .config FORCE $(if $(wildcard $(TOPDIR)/staging_dir/host/bin/flock),,tools/flock/compile)
  156. @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
  157. clean dirclean: .config
  158. @+$(SUBMAKE) -r $@
  159. prereq:: prepare-tmpinfo .config
  160. @+$(NO_TRACE_MAKE) -r -s $@
  161. check: .config FORCE
  162. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  163. val.%: FORCE
  164. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  165. WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
  166. ifeq ($(SDK),1)
  167. %::
  168. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  169. @./scripts/config/conf $(KCONF_FLAGS) --defconfig=.config Config.in
  170. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
  171. else
  172. %::
  173. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  174. @( \
  175. cp .config tmp/.config; \
  176. ./scripts/config/conf $(KCONF_FLAGS) --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
  177. if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
  178. printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
  179. fi \
  180. )
  181. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
  182. printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
  183. false; \
  184. } )
  185. endif
  186. # update all feeds, re-create index files, install symlinks
  187. package/symlinks:
  188. ./scripts/feeds update -a
  189. ./scripts/feeds install -a
  190. # re-create index files, install symlinks
  191. package/symlinks-install:
  192. ./scripts/feeds update -i
  193. ./scripts/feeds install -a
  194. # remove all symlinks, don't touch ./feeds
  195. package/symlinks-clean:
  196. ./scripts/feeds uninstall -a
  197. help:
  198. cat README
  199. distclean:
  200. rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
  201. @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
  202. ifeq ($(findstring v,$(DEBUG)),)
  203. .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
  204. endif
  205. .PHONY: help FORCE
  206. .NOTPARALLEL: