target.mk 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #
  2. # Copyright (C) 2007-2008 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 ($(__target_inc),1)
  8. __target_inc=1
  9. # default device type
  10. DEVICE_TYPE?=router
  11. # Default packages - the really basic set
  12. DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg udevtrigger hotplug2
  13. # For router targets
  14. DEFAULT_PACKAGES.router:=dnsmasq iptables ppp ppp-mod-pppoe kmod-ipt-nathelper firewall
  15. DEFAULT_PACKAGES.bootloader:=
  16. # Add device specific packages
  17. DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
  18. ifneq ($(DUMP),)
  19. all: dumpinfo
  20. endif
  21. target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  22. ifeq ($(DUMP),)
  23. PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
  24. SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
  25. else
  26. PLATFORM_DIR:=${CURDIR}
  27. endif
  28. TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
  29. PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
  30. ifneq ($(TARGET_BUILD),1)
  31. ifndef DUMP
  32. include $(PLATFORM_DIR)/Makefile
  33. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  34. include $(PLATFORM_SUBDIR)/target.mk
  35. endif
  36. endif
  37. else
  38. ifneq ($(SUBTARGET),)
  39. -include ./$(SUBTARGET)/target.mk
  40. endif
  41. endif
  42. define Profile/Default
  43. NAME:=
  44. PACKAGES:=
  45. endef
  46. ifndef Profile
  47. define Profile
  48. $(eval $(call Profile/Default))
  49. $(eval $(call Profile/$(1)))
  50. $(eval $(call shexport,Profile/$(1)/Config))
  51. $(eval $(call shexport,Profile/$(1)/Description))
  52. DUMPINFO += \
  53. echo "Target-Profile: $(1)"; \
  54. echo "Target-Profile-Name: $(NAME)"; \
  55. echo "Target-Profile-Packages: $(PACKAGES)"; \
  56. if [ -f ./config/profile-$(1) ]; then \
  57. echo "Target-Profile-Kconfig: yes"; \
  58. fi; \
  59. echo "Target-Profile-Config: "; \
  60. $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Config)"; \
  61. echo "@@"; \
  62. echo "Target-Profile-Description:"; \
  63. $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Description)"; \
  64. echo "@@"; \
  65. echo;
  66. ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_)$(1))),y)
  67. PROFILE=$(1)
  68. endif
  69. endef
  70. endif
  71. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  72. define IncludeProfiles
  73. -include $(PLATFORM_DIR)/profiles/*.mk
  74. -include $(PLATFORM_SUBDIR)/profiles/*.mk
  75. endef
  76. else
  77. define IncludeProfiles
  78. -include $(PLATFORM_DIR)/profiles/*.mk
  79. endef
  80. endif
  81. ifeq ($(TARGET_BUILD),1)
  82. $(eval $(call IncludeProfiles))
  83. else
  84. ifeq ($(DUMP),)
  85. $(eval $(call IncludeProfiles))
  86. endif
  87. endif
  88. $(eval $(call shexport,Target/Description))
  89. ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
  90. include $(INCLUDE_DIR)/kernel-version.mk
  91. endif
  92. GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
  93. GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  94. GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
  95. GENERIC_LINUX_CONFIG?=$(firstword $(wildcard $(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER) $(GENERIC_PLATFORM_DIR)/config-default))
  96. LINUX_CONFIG?=$(firstword $(wildcard $(foreach subdir,$(PLATFORM_DIR) $(PLATFORM_SUBDIR),$(subdir)/config-$(KERNEL_PATCHVER) $(subdir)/config-default)) $(PLATFORM_DIR)/config-$(KERNEL_PATCHVER))
  97. LINUX_SUBCONFIG?=$(if $(SHARED_LINUX_CONFIG),,$(firstword $(wildcard $(PLATFORM_SUBDIR)/config-$(KERNEL_PATCHVER) $(PLATFORM_SUBDIR)/config-default)))
  98. ifeq ($(LINUX_CONFIG),$(LINUX_SUBCONFIG))
  99. LINUX_SUBCONFIG:=
  100. endif
  101. LINUX_CONFCMD=$(if $(LINUX_CONFIG), \
  102. $(if $(GENERIC_LINUX_CONFIG),,$(error The generic kernel config for your kernel version is missing)) \
  103. $(if $(LINUX_CONFIG),,$(error The target kernel config for your kernel version is missing)) \
  104. $(SCRIPT_DIR)/kconfig.pl \
  105. + $(GENERIC_LINUX_CONFIG) \
  106. $(if $(LINUX_SUBCONFIG),+ $(LINUX_CONFIG) $(LINUX_SUBCONFIG),$(LINUX_CONFIG)), \
  107. true)
  108. ifeq ($(DUMP),1)
  109. BuildTarget=$(BuildTargets/DumpCurrent)
  110. ifneq ($(BOARD),)
  111. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
  112. $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) $(LINUX_SUBCONFIG)
  113. $(LINUX_CONFCMD) > $@ || rm -f $@
  114. -include $(TMP_CONFIG)
  115. .SILENT: $(TMP_CONFIG)
  116. .PRECIOUS: $(TMP_CONFIG)
  117. ifneq ($(CONFIG_GENERIC_GPIO),)
  118. FEATURES += gpio
  119. endif
  120. ifneq ($(CONFIG_PCI),)
  121. FEATURES += pci
  122. endif
  123. ifneq ($(CONFIG_PCIEPORTBUS),)
  124. FEATURES += pcie
  125. endif
  126. ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
  127. ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
  128. FEATURES += usb
  129. endif
  130. endif
  131. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  132. FEATURES += pcmcia
  133. endif
  134. ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
  135. FEATURES += display
  136. endif
  137. # remove duplicates
  138. FEATURES:=$(sort $(FEATURES))
  139. endif
  140. DEFAULT_CFLAGS_i386=-O2 -pipe -march=i486 -funit-at-a-time
  141. DEFAULT_CFLAGS_x86_64=-O2 -pipe -march=athlon64 -funit-at-a-time
  142. DEFAULT_CFLAGS_m68k=-Os -pipe -mcfv4e -funit-at-a-time
  143. DEFAULT_CFLAGS_mips=-Os -pipe -mips32 -mtune=mips32 -funit-at-a-time
  144. DEFAULT_CFLAGS_mipsel=$(DEFAULT_CFLAGS_mips)
  145. DEFAULT_CFLAGS_mips64=-Os -pipe -mips64 -mtune=mips64 -mabi=64 -funit-at-a-time
  146. DEFAULT_CFLAGS_mips64el=$(DEFAULT_CFLAGS_mips64)
  147. DEFAULT_CFLAGS_arm=-Os -pipe -march=armv5te -mtune=xscale -funit-at-a-time
  148. DEFAULT_CFLAGS_armeb=$(DEFAULT_CFLAGS_arm)
  149. DEFAULT_CFLAGS=$(if $(DEFAULT_CFLAGS_$(ARCH)),$(DEFAULT_CFLAGS_$(ARCH)),-Os -pipe -funit-at-a-time)
  150. endif
  151. define BuildTargets/DumpCurrent
  152. .PHONY: dumpinfo
  153. dumpinfo:
  154. @echo 'Target: $(TARGETID)'; \
  155. echo 'Target-Board: $(BOARD)'; \
  156. echo 'Target-Kernel: $(KERNEL)'; \
  157. echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
  158. echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'; \
  159. echo 'Target-Arch: $(ARCH)'; \
  160. echo 'Target-Features: $(FEATURES)'; \
  161. echo 'Target-Depends: $(DEPENDS)'; \
  162. echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
  163. echo 'Linux-Version: $(LINUX_VERSION)'; \
  164. echo 'Linux-Release: $(LINUX_RELEASE)'; \
  165. echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
  166. echo 'Target-Description:'; \
  167. $(SH_FUNC) getvar $(call shvar,Target/Description); \
  168. echo '@@'; \
  169. echo 'Default-Packages: $(DEFAULT_PACKAGES)'; \
  170. $(DUMPINFO)
  171. $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
  172. endef
  173. include $(INCLUDE_DIR)/kernel.mk
  174. ifeq ($(TARGET_BUILD),1)
  175. include $(INCLUDE_DIR)/kernel-build.mk
  176. BuildTarget?=$(BuildKernel)
  177. endif
  178. endif #__target_inc