toplevel.mk 7.7 KB

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