target.mk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #
  2. # Copyright (C) 2007 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifneq ($(DUMP),)
  8. all: dumpinfo
  9. endif
  10. ifneq ($(__target_inc),1)
  11. __target_inc=1
  12. TARGET_BUILD?=0
  13. target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  14. ifeq ($(DUMP),)
  15. PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
  16. SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
  17. else
  18. PLATFORM_DIR:=${CURDIR}
  19. endif
  20. TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
  21. PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
  22. define Target
  23. KERNEL_TARGETS+=$(1)
  24. ifeq ($(DUMP),1)
  25. ifeq ($(SUBTARGET),)
  26. BuildTarget=$$(BuildTargets/DumpAll)
  27. endif
  28. endif
  29. endef
  30. ifneq ($(TARGET_BUILD),1)
  31. include $(PLATFORM_DIR)/Makefile
  32. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  33. include $(PLATFORM_SUBDIR)/target.mk
  34. endif
  35. else
  36. ifneq ($(SUBTARGET),)
  37. -include ./$(SUBTARGET)/target.mk
  38. endif
  39. endif
  40. define Profile/Default
  41. NAME:=
  42. PACKAGES:=
  43. endef
  44. define Profile
  45. $(eval $(call Profile/Default))
  46. $(eval $(call Profile/$(1)))
  47. $(eval $(call shexport,Profile/$(1)/Config))
  48. $(eval $(call shexport,Profile/$(1)/Description))
  49. DUMPINFO += \
  50. echo "Target-Profile: $(1)"; \
  51. echo "Target-Profile-Name: $(NAME)"; \
  52. echo "Target-Profile-Packages: $(PACKAGES)"; \
  53. if [ -f ./config/profile-$(1) ]; then \
  54. echo "Target-Profile-Kconfig: yes"; \
  55. fi; \
  56. echo "Target-Profile-Config: "; \
  57. getvar "$(call shvar,Profile/$(1)/Config)"; \
  58. echo "@@"; \
  59. echo "Target-Profile-Description:"; \
  60. getvar "$(call shvar,Profile/$(1)/Description)"; \
  61. echo "@@"; \
  62. echo;
  63. ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_)$(1))),y)
  64. PROFILE=$(1)
  65. endif
  66. endef
  67. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  68. define IncludeProfiles
  69. -include $(PLATFORM_DIR)/profiles/*.mk
  70. -include $(PLATFORM_SUBDIR)/profiles/*.mk
  71. endef
  72. else
  73. define IncludeProfiles
  74. -include $(PLATFORM_DIR)/profiles/*.mk
  75. endef
  76. endif
  77. ifeq ($(TARGET_BUILD),1)
  78. $(eval $(call IncludeProfiles))
  79. else
  80. ifeq ($(DUMP),)
  81. $(eval $(call IncludeProfiles))
  82. endif
  83. endif
  84. $(eval $(call shexport,Target/Description))
  85. include $(INCLUDE_DIR)/kernel-version.mk
  86. GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic-$(KERNEL)
  87. GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(shell [ -d "$(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
  88. GENERIC_LINUX_CONFIG?=$(firstword $(wildcard $(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER) $(GENERIC_PLATFORM_DIR)/config-default))
  89. LINUX_CONFIG?=$(firstword $(wildcard $(foreach subdir,$(PLATFORM_DIR) $(PLATFORM_SUBDIR),$(subdir)/config-$(KERNEL_PATCHVER) $(subdir)/config-default)))
  90. LINUX_SUBCONFIG?=$(firstword $(wildcard $(PLATFORM_SUBDIR)/config-$(KERNEL_PATCHVER) $(PLATFORM_SUBDIR)/config-default))
  91. ifeq ($(LINUX_CONFIG),$(LINUX_SUBCONFIG))
  92. LINUX_SUBCONFIG:=
  93. endif
  94. LINUX_CONFCMD=$(if $(LINUX_CONFIG),$(SCRIPT_DIR)/kconfig.pl + $(GENERIC_LINUX_CONFIG) $(if $(LINUX_SUBCONFIG),+ $(LINUX_CONFIG) $(LINUX_SUBCONFIG),$(LINUX_CONFIG)),true)
  95. ifeq ($(DUMP),1)
  96. BuildTarget=$(BuildTargets/DumpCurrent)
  97. ifneq ($(BOARD),)
  98. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
  99. $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) $(LINUX_SUBCONFIG)
  100. $(LINUX_CONFCMD) > $@ || rm -f $@
  101. -include $(TMP_CONFIG)
  102. .SILENT: $(TMP_CONFIG)
  103. .PRECIOUS: $(TMP_CONFIG)
  104. ifneq ($(CONFIG_PCI),)
  105. FEATURES += pci
  106. endif
  107. ifneq ($(CONFIG_USB),)
  108. FEATURES += usb
  109. endif
  110. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  111. FEATURES += pcmcia
  112. endif
  113. # remove duplicates
  114. FEATURES:=$(sort $(FEATURES))
  115. endif
  116. endif
  117. define BuildTargets/DumpAll
  118. dumpinfo:
  119. @$(foreach SUBTARGET,$(KERNEL_TARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); )
  120. endef
  121. define BuildTargets/DumpCurrent
  122. dumpinfo:
  123. @echo 'Target: $(TARGETID)'; \
  124. echo 'Target-Board: $(BOARD)'; \
  125. echo 'Target-Kernel: $(KERNEL)'; \
  126. echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'; \
  127. echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'; \
  128. echo 'Target-Arch: $(ARCH)'; \
  129. echo 'Target-Features: $(FEATURES)'; \
  130. echo 'Target-Depends: $(DEPENDS)'; \
  131. echo 'Linux-Version: $(LINUX_VERSION)'; \
  132. echo 'Linux-Release: $(LINUX_RELEASE)'; \
  133. echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
  134. echo 'Target-Description:'; \
  135. getvar $(call shvar,Target/Description); \
  136. echo '@@'; \
  137. echo 'Default-Packages: $(DEFAULT_PACKAGES)'; \
  138. $(DUMPINFO)
  139. endef
  140. include $(INCLUDE_DIR)/kernel.mk
  141. ifeq ($(TARGET_BUILD),1)
  142. include $(INCLUDE_DIR)/kernel-build.mk
  143. BuildTarget?=$(BuildKernel)
  144. endif
  145. endif #__target_inc