toplevel.mk 7.2 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. RELEASE:=Designated Driver
  9. PREP_MK= OPENWRT_BUILD= QUIET=0
  10. export IS_TTY=$(shell tty -s && echo 1 || echo 0)
  11. include $(TOPDIR)/include/verbose.mk
  12. ifeq ($(SDK),1)
  13. include $(TOPDIR)/include/version.mk
  14. else
  15. REVISION:=$(shell $(TOPDIR)/scripts/getver.sh)
  16. endif
  17. HOSTCC ?= $(CC)
  18. export RELEASE
  19. export REVISION
  20. export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
  21. export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
  22. export SOURCE_DATE_EPOCH:=$(shell $(TOPDIR)/scripts/get_source_date_epoch.sh)
  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: 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="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/metadata.pl $(_ignore) $${type}_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/metadata.pl package_mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
  69. ./scripts/metadata.pl package_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 [ -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. $< 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. download: .config FORCE
  130. @+$(SUBMAKE) tools/download
  131. @+$(SUBMAKE) toolchain/download
  132. @+$(SUBMAKE) package/download
  133. @+$(SUBMAKE) target/download
  134. clean dirclean: .config
  135. @+$(SUBMAKE) -r $@
  136. prereq:: prepare-tmpinfo .config
  137. @+$(NO_TRACE_MAKE) -r -s $@
  138. WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
  139. ifeq ($(SDK),1)
  140. %::
  141. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  142. @./scripts/config/conf --defconfig=.config Config.in
  143. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
  144. else
  145. %::
  146. @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
  147. @( \
  148. cp .config tmp/.config; \
  149. ./scripts/config/conf --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
  150. if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
  151. printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
  152. fi \
  153. )
  154. @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
  155. printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
  156. false; \
  157. } )
  158. endif
  159. # update all feeds, re-create index files, install symlinks
  160. package/symlinks:
  161. ./scripts/feeds update -a
  162. ./scripts/feeds install -a
  163. # re-create index files, install symlinks
  164. package/symlinks-install:
  165. ./scripts/feeds update -i
  166. ./scripts/feeds install -a
  167. # remove all symlinks, don't touch ./feeds
  168. package/symlinks-clean:
  169. ./scripts/feeds uninstall -a
  170. help:
  171. cat README
  172. docs docs/compile: FORCE
  173. @$(_SINGLE)$(SUBMAKE) -C docs compile
  174. docs/clean: FORCE
  175. @$(_SINGLE)$(SUBMAKE) -C docs clean
  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: