toplevel.mk 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
  22. # prevent perforce from messing with the patch utility
  23. unexport P4PORT P4USER P4CONFIG P4CLIENT
  24. # prevent user defaults for quilt from interfering
  25. unexport QUILT_PATCHES QUILT_PATCH_OPTS
  26. unexport C_INCLUDE_PATH CROSS_COMPILE ARCH
  27. # prevent distro default LPATH from interfering
  28. unexport LPATH
  29. # make sure that a predefined CFLAGS variable does not disturb packages
  30. export CFLAGS=
  31. export LDFLAGS=
  32. empty:=
  33. space:= $(empty) $(empty)
  34. path:=$(subst :,$(space),$(PATH))
  35. path:=$(filter-out .%,$(path))
  36. path:=$(subst $(space),:,$(path))
  37. export PATH:=$(path)
  38. unexport TAR_OPTIONS
  39. ifneq ($(shell $(HOSTCC) 2>&1 | grep clang),)
  40. export HOSTCC_REAL?=$(HOSTCC)
  41. export HOSTCC_WRAPPER:=$(TOPDIR)/scripts/clang-gcc-wrapper
  42. else
  43. export HOSTCC_WRAPPER:=$(HOSTCC)
  44. endif
  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_DEPS="$(TOPDIR)/include/package*.mk $(TOPDIR)/overlay/*/*.mk" 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_DEPS="image/Makefile profiles/*.mk $(TOPDIR)/include/kernel*.mk $(TOPDIR)/include/target.mk" SCAN_DEPTH=2 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/.packagesubdirs ] || ./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 subdirs tmp/.packageinfo > tmp/.packagesubdirs || { rm -f tmp/.packagesubdirs; false; }
  69. touch $(TOPDIR)/tmp/.build
  70. .config: ./scripts/config/conf $(if $(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
  71. @+if [ \! -e .config ] || ! grep CONFIG_HAVE_DOT_CONFIG .config >/dev/null; then \
  72. [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \
  73. $(_SINGLE)$(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
  74. fi
  75. scripts/config/mconf:
  76. @$(_SINGLE)$(SUBMAKE) -s -C scripts/config all CC="$(HOSTCC_WRAPPER)"
  77. $(eval $(call rdep,scripts/config,scripts/config/mconf))
  78. scripts/config/conf:
  79. @$(_SINGLE)$(SUBMAKE) -s -C scripts/config conf CC="$(HOSTCC_WRAPPER)"
  80. config: scripts/config/conf prepare-tmpinfo FORCE
  81. $< Config.in
  82. config-clean: FORCE
  83. $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
  84. defconfig: scripts/config/conf prepare-tmpinfo FORCE
  85. touch .config
  86. @if [ ! -s .config -a -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
  87. $< --defconfig=.config Config.in
  88. confdefault-y=allyes
  89. confdefault-m=allmod
  90. confdefault-n=allno
  91. confdefault:=$(confdefault-$(CONFDEFAULT))
  92. oldconfig: scripts/config/conf prepare-tmpinfo FORCE
  93. $< --$(if $(confdefault),$(confdefault),old)config Config.in
  94. menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
  95. if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
  96. cp $(HOME)/.openwrt/defconfig .config; \
  97. fi
  98. $< Config.in
  99. prepare_kernel_conf: .config FORCE
  100. ifeq ($(wildcard staging_dir/host/bin/quilt),)
  101. prepare_kernel_conf:
  102. @+$(SUBMAKE) -r tools/quilt/install
  103. else
  104. prepare_kernel_conf: ;
  105. endif
  106. kernel_oldconfig: prepare_kernel_conf
  107. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
  108. kernel_menuconfig: prepare_kernel_conf
  109. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
  110. kernel_nconfig: prepare_kernel_conf
  111. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
  112. staging_dir/host/.prereq-build: include/prereq-build.mk
  113. mkdir -p tmp
  114. rm -f tmp/.host.mk
  115. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
  116. echo "Prerequisite check failed. Use FORCE=1 to override."; \
  117. false; \
  118. }
  119. ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
  120. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
  121. echo "Preparation failed."; \
  122. false; \
  123. }
  124. endif
  125. touch $@
  126. printdb: FORCE
  127. @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
  128. ifndef SDK
  129. DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
  130. else
  131. DOWNLOAD_DIRS = package/download
  132. endif
  133. download: .config FORCE
  134. @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
  135. clean dirclean: .config
  136. @+$(SUBMAKE) -r $@
  137. prereq:: prepare-tmpinfo .config
  138. @+$(NO_TRACE_MAKE) -r -s $@
  139. check: .config FORCE
  140. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  141. WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
  142. ifeq ($(SDK),1)
  143. %::
  144. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  145. @./scripts/config/conf --defconfig=.config Config.in
  146. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
  147. else
  148. %::
  149. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  150. @( \
  151. cp .config tmp/.config; \
  152. ./scripts/config/conf --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
  153. if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
  154. printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
  155. fi \
  156. )
  157. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
  158. printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
  159. false; \
  160. } )
  161. endif
  162. # update all feeds, re-create index files, install symlinks
  163. package/symlinks:
  164. ./scripts/feeds update -a
  165. ./scripts/feeds install -a
  166. # re-create index files, install symlinks
  167. package/symlinks-install:
  168. ./scripts/feeds update -i
  169. ./scripts/feeds install -a
  170. # remove all symlinks, don't touch ./feeds
  171. package/symlinks-clean:
  172. ./scripts/feeds uninstall -a
  173. help:
  174. cat README
  175. distclean:
  176. rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
  177. @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
  178. ifeq ($(findstring v,$(DEBUG)),)
  179. .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
  180. endif
  181. .PHONY: help FORCE
  182. .NOTPARALLEL: