toplevel.mk 7.4 KB

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