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