toplevel.mk 7.9 KB

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