toplevel.mk 8.2 KB

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