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