2
0

toplevel.mk 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. $< Config.in
  83. config-clean: FORCE
  84. $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
  85. defconfig: scripts/config/conf prepare-tmpinfo FORCE
  86. touch .config
  87. @if [ ! -s .config -a -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
  88. $< --defconfig=.config Config.in
  89. confdefault-y=allyes
  90. confdefault-m=allmod
  91. confdefault-n=allno
  92. confdefault:=$(confdefault-$(CONFDEFAULT))
  93. oldconfig: scripts/config/conf prepare-tmpinfo FORCE
  94. $< --$(if $(confdefault),$(confdefault),old)config Config.in
  95. menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
  96. if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
  97. cp $(HOME)/.openwrt/defconfig .config; \
  98. fi
  99. [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; $< Config.in
  100. prepare_kernel_conf: .config FORCE
  101. ifeq ($(wildcard staging_dir/host/bin/quilt),)
  102. prepare_kernel_conf:
  103. @+$(SUBMAKE) -r tools/quilt/install
  104. else
  105. prepare_kernel_conf: ;
  106. endif
  107. kernel_oldconfig: prepare_kernel_conf
  108. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
  109. kernel_menuconfig: prepare_kernel_conf
  110. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
  111. kernel_nconfig: prepare_kernel_conf
  112. $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
  113. staging_dir/host/.prereq-build: include/prereq-build.mk
  114. mkdir -p tmp
  115. rm -f tmp/.host.mk
  116. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
  117. echo "Prerequisite check failed. Use FORCE=1 to override."; \
  118. false; \
  119. }
  120. ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
  121. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
  122. echo "Preparation failed."; \
  123. false; \
  124. }
  125. endif
  126. touch $@
  127. printdb: FORCE
  128. @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
  129. ifndef SDK
  130. DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
  131. else
  132. DOWNLOAD_DIRS = package/download
  133. endif
  134. download: .config FORCE $(if $(wildcard $(TOPDIR)/staging_dir/host/bin/flock),,tools/flock/compile)
  135. @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
  136. clean dirclean: .config
  137. @+$(SUBMAKE) -r $@
  138. prereq:: prepare-tmpinfo .config
  139. @+$(NO_TRACE_MAKE) -r -s $@
  140. check: .config FORCE
  141. @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
  142. WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
  143. ifeq ($(SDK),1)
  144. %::
  145. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  146. @./scripts/config/conf --defconfig=.config Config.in
  147. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
  148. else
  149. %::
  150. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  151. @( \
  152. cp .config tmp/.config; \
  153. ./scripts/config/conf --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
  154. if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
  155. printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
  156. fi \
  157. )
  158. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
  159. printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
  160. false; \
  161. } )
  162. endif
  163. # update all feeds, re-create index files, install symlinks
  164. package/symlinks:
  165. ./scripts/feeds update -a
  166. ./scripts/feeds install -a
  167. # re-create index files, install symlinks
  168. package/symlinks-install:
  169. ./scripts/feeds update -i
  170. ./scripts/feeds install -a
  171. # remove all symlinks, don't touch ./feeds
  172. package/symlinks-clean:
  173. ./scripts/feeds uninstall -a
  174. help:
  175. cat README
  176. distclean:
  177. rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
  178. @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
  179. ifeq ($(findstring v,$(DEBUG)),)
  180. .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
  181. endif
  182. .PHONY: help FORCE
  183. .NOTPARALLEL: