metadata.pl: add support for forcing sorting of profiles
[openwrt/staging/wigyori.git] / include / target.mk
1 #
2 # Copyright (C) 2007-2008 OpenWrt.org
3 # Copyright (C) 2016 LEDE Project
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 ifneq ($(__target_inc),1)
10 __target_inc=1
11
12 # default device type
13 DEVICE_TYPE?=router
14
15 # Default packages - the really basic set
16 DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg netifd fstools uclient-fetch logd
17 # For nas targets
18 DEFAULT_PACKAGES.nas:=block-mount fdisk lsblk mdadm
19 # For router targets
20 DEFAULT_PACKAGES.router:=dnsmasq iptables ip6tables ppp ppp-mod-pppoe firewall odhcpd odhcp6c
21 DEFAULT_PACKAGES.bootloader:=
22
23 ifneq ($(DUMP),)
24 all: dumpinfo
25 endif
26
27 target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
28 ifeq ($(DUMP),)
29 PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
30 SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
31 else
32 PLATFORM_DIR:=${CURDIR}
33 ifeq ($(SUBTARGETS),)
34 SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
35 endif
36 endif
37
38 TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
39 PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
40
41 ifneq ($(TARGET_BUILD),1)
42 ifndef DUMP
43 include $(PLATFORM_DIR)/Makefile
44 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
45 include $(PLATFORM_SUBDIR)/target.mk
46 endif
47 endif
48 else
49 ifneq ($(SUBTARGET),)
50 -include ./$(SUBTARGET)/target.mk
51 endif
52 endif
53
54 # Add device specific packages (here below to allow device type set from subtarget)
55 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
56
57 filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
58 extra_packages = $(if $(filter wpad-mini wpad nas,$(1)),iwinfo)
59
60 define ProfileDefault
61 NAME:=
62 PRIORITY:=
63 PACKAGES:=
64 endef
65
66 ifndef Profile
67 define Profile
68 $(eval $(call ProfileDefault))
69 $(eval $(call Profile/$(1)))
70 dumpinfo : $(call shexport,Profile/$(1)/Config)
71 dumpinfo : $(call shexport,Profile/$(1)/Description)
72 DUMPINFO += \
73 echo "Target-Profile: $(1)"; \
74 $(if $(PRIORITY), echo "Target-Profile-Priority: $(PRIORITY)"; ) \
75 echo "Target-Profile-Name: $(NAME)"; \
76 echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
77 if [ -f ./config/profile-$(1) ]; then \
78 echo "Target-Profile-Kconfig: yes"; \
79 fi; \
80 echo "Target-Profile-Config: "; \
81 echo "$$$$$$$$$(call shvar,Profile/$(1)/Config)"; \
82 echo "@@"; \
83 echo "Target-Profile-Description:"; \
84 echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
85 echo "@@"; \
86 echo;
87 ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_))$(1)),y)
88 PROFILE=$(1)
89 endif
90 endef
91 endif
92
93 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
94 define IncludeProfiles
95 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
96 -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
97 endef
98 else
99 define IncludeProfiles
100 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
101 endef
102 endif
103
104 ifeq ($(TARGET_BUILD),1)
105 $(eval $(call IncludeProfiles))
106 else
107 ifeq ($(DUMP),)
108 $(eval $(call IncludeProfiles))
109 endif
110 endif
111
112 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
113 include $(INCLUDE_DIR)/kernel-version.mk
114 endif
115
116 GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
117 GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
118 GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
119
120 __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
121 __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
122 find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
123
124 GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
125 LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
126 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
127 LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
128 endif
129
130 # config file list used for compiling
131 LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
132
133 # default config list for reconfiguring
134 # defaults to subtarget if subtarget exists and target does not
135 # defaults to target otherwise
136 USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
137
138 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
139 LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
140
141 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
142 ifeq ($(CONFIG_TARGET),platform)
143 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
144 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
145 endif
146 ifeq ($(CONFIG_TARGET),subtarget)
147 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
148 LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
149 endif
150 ifeq ($(CONFIG_TARGET),subtarget_platform)
151 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
152 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
153 endif
154 ifeq ($(CONFIG_TARGET),env)
155 LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
156 LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
157 endif
158
159 __linux_confcmd = $(SCRIPT_DIR)/kconfig.pl $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
160
161 LINUX_CONF_CMD = $(call __linux_confcmd,$(LINUX_KCONFIG_LIST),)
162 LINUX_RECONF_CMD = $(call __linux_confcmd,$(LINUX_RECONFIG_LIST),)
163 LINUX_RECONF_DIFF = $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST)),'>')
164
165 ifeq ($(DUMP),1)
166 BuildTarget=$(BuildTargets/DumpCurrent)
167
168 ifneq ($(BOARD),)
169 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
170 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
171 $(LINUX_CONF_CMD) > $@ || rm -f $@
172 -include $(TMP_CONFIG)
173 .SILENT: $(TMP_CONFIG)
174 .PRECIOUS: $(TMP_CONFIG)
175
176 ifneq ($(CONFIG_OF),)
177 FEATURES += dt
178 endif
179 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
180 FEATURES += gpio
181 endif
182 ifneq ($(CONFIG_PCI),)
183 FEATURES += pci
184 endif
185 ifneq ($(CONFIG_PCIEPORTBUS),)
186 FEATURES += pcie
187 endif
188 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
189 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
190 FEATURES += usb
191 endif
192 endif
193 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
194 FEATURES += pcmcia
195 endif
196 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
197 FEATURES += display
198 endif
199 ifneq ($(CONFIG_RTC_CLASS),)
200 FEATURES += rtc
201 endif
202 FEATURES += $(foreach v,v4 v5 v6 v7,$(if $(findstring -march=arm$(v),$(CFLAGS)),arm_$(v)))
203
204 # remove duplicates
205 FEATURES:=$(sort $(FEATURES))
206 endif
207 CPU_CFLAGS = -Os -pipe
208 ifneq ($(findstring mips,$(ARCH)),)
209 ifneq ($(findstring mips64,$(ARCH)),)
210 CPU_TYPE ?= mips64
211 else
212 CPU_TYPE ?= mips32
213 endif
214 CPU_CFLAGS += -mno-branch-likely
215 CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
216 CPU_CFLAGS_mips32r2 = -mips32r2 -mtune=mips32r2
217 CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
218 CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc
219 CPU_CFLAGS_24kec = -mips32r2 -mtune=24kec
220 CPU_CFLAGS_34kc = -mips32r2 -mtune=34kc
221 CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
222 CPU_CFLAGS_octeon = -march=octeon -mabi=64
223 CPU_CFLAGS_dsp = -mdsp
224 CPU_CFLAGS_dsp2 = -mdspr2
225 endif
226 ifeq ($(ARCH),i386)
227 CPU_TYPE ?= i486
228 CPU_CFLAGS_i486 = -march=i486
229 CPU_CFLAGS_pentium4 = -march=pentium4
230 CPU_CFLAGS_geode = -march=geode -mmmx -m3dnow
231 endif
232 ifneq ($(findstring arm,$(ARCH)),)
233 CPU_TYPE ?= xscale
234 CPU_CFLAGS_arm920t = -march=armv4t -mtune=arm920t
235 CPU_CFLAGS_arm926ej-s = -march=armv5te -mtune=arm926ej-s
236 CPU_CFLAGS_arm1136j-s = -march=armv6 -mtune=arm1136j-s
237 CPU_CFLAGS_arm1176jzf-s = -march=armv6 -mtune=arm1176jzf-s
238 CPU_CFLAGS_cortex-a5 = -march=armv7-a -mtune=cortex-a5
239 CPU_CFLAGS_cortex-a7 = -march=armv7-a -mtune=cortex-a7
240 CPU_CFLAGS_cortex-a8 = -march=armv7-a -mtune=cortex-a8
241 CPU_CFLAGS_cortex-a9 = -march=armv7-a -mtune=cortex-a9
242 CPU_CFLAGS_cortex-a15 = -march=armv7-a -mtune=cortex-a15
243 CPU_CFLAGS_cortex-a53 = -march=armv8-a -mtune=cortex-a53
244 CPU_CFLAGS_fa526 = -march=armv4 -mtune=fa526
245 CPU_CFLAGS_mpcore = -march=armv6k -mtune=mpcore
246 CPU_CFLAGS_xscale = -march=armv5te -mtune=xscale
247 ifeq ($(CONFIG_SOFT_FLOAT),)
248 CPU_CFLAGS_neon = -mfpu=neon
249 CPU_CFLAGS_vfp = -mfpu=vfp
250 CPU_CFLAGS_vfpv3 = -mfpu=vfpv3-d16
251 CPU_CFLAGS_neon-vfpv4 = -mfpu=neon-vfpv4
252 endif
253 endif
254 ifeq ($(ARCH),powerpc)
255 CPU_CFLAGS_603e:=-mcpu=603e
256 CPU_CFLAGS_8540:=-mcpu=8540
257 CPU_CFLAGS_405:=-mcpu=405
258 CPU_CFLAGS_440:=-mcpu=440
259 endif
260 ifeq ($(ARCH),sparc)
261 CPU_TYPE = sparc
262 CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
263 endif
264 ifeq ($(ARCH),aarch64)
265 CPU_TYPE ?= armv8-a
266 CPU_CFLAGS_armv8-a = -mcpu=armv8-a
267 endif
268 ifeq ($(ARCH),arc)
269 CPU_TYPE ?= arc700
270 CPU_CFLAGS += -matomic
271 CPU_CFLAGS_arc700 = -marc700
272 CPU_CFLAGS_archs = -marchs
273 endif
274 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
275 endif
276
277 CUR_SUBTARGET:=$(SUBTARGET)
278 ifeq ($(SUBTARGETS),)
279 CUR_SUBTARGET ?= default
280 endif
281
282 define BuildTargets/DumpCurrent
283 .PHONY: dumpinfo
284 dumpinfo : export DESCRIPTION=$$(Target/Description)
285 dumpinfo:
286 @echo 'Target: $(TARGETID)'; \
287 echo 'Target-Board: $(BOARD)'; \
288 echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
289 echo 'Target-Arch: $(ARCH)'; \
290 echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
291 echo 'Target-Features: $(FEATURES)'; \
292 echo 'Target-Depends: $(DEPENDS)'; \
293 echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
294 echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
295 echo 'Linux-Version: $(LINUX_VERSION)'; \
296 echo 'Linux-Release: $(LINUX_RELEASE)'; \
297 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
298 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
299 echo 'Target-Description:'; \
300 echo "$$$$DESCRIPTION"; \
301 echo '@@'; \
302 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
303 $(DUMPINFO)
304 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
305 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
306 endef
307
308 include $(INCLUDE_DIR)/kernel.mk
309 ifeq ($(TARGET_BUILD),1)
310 include $(INCLUDE_DIR)/kernel-build.mk
311 BuildTarget?=$(BuildKernel)
312 endif
313
314 endif #__target_inc