target.mk 6.8 KB

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