ath79: ensure QCA956x gmac0 mux selects sgmii
[openwrt/openwrt.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:=\
17 base-files \
18 ca-bundle \
19 dropbear \
20 fstools \
21 libc \
22 libgcc \
23 libustream-wolfssl \
24 logd \
25 mtd \
26 netifd \
27 opkg \
28 uci \
29 uclient-fetch \
30 urandom-seed \
31 urngd
32
33 ifneq ($(CONFIG_SELINUX),)
34 DEFAULT_PACKAGES+=busybox-selinux procd-selinux
35 else
36 DEFAULT_PACKAGES+=busybox procd
37 endif
38
39 # For the basic set
40 DEFAULT_PACKAGES.basic:=
41 # For nas targets
42 DEFAULT_PACKAGES.nas:=\
43 block-mount \
44 fdisk \
45 lsblk \
46 mdadm
47 # For router targets
48 DEFAULT_PACKAGES.router:=\
49 dnsmasq \
50 firewall \
51 ip6tables \
52 iptables \
53 kmod-ipt-offload \
54 odhcp6c \
55 odhcpd-ipv6only \
56 ppp \
57 ppp-mod-pppoe
58
59 ifneq ($(DUMP),)
60 all: dumpinfo
61 endif
62
63 target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
64 ifeq ($(DUMP),)
65 PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
66 SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
67 else
68 PLATFORM_DIR:=${CURDIR}
69 ifeq ($(SUBTARGETS),)
70 SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
71 endif
72 endif
73
74 TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
75 PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
76
77 ifneq ($(TARGET_BUILD),1)
78 ifndef DUMP
79 include $(PLATFORM_DIR)/Makefile
80 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
81 include $(PLATFORM_SUBDIR)/target.mk
82 endif
83 endif
84 else
85 ifneq ($(SUBTARGET),)
86 -include ./$(SUBTARGET)/target.mk
87 endif
88 endif
89
90 # Add device specific packages (here below to allow device type set from subtarget)
91 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
92
93 filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
94 extra_packages = $(if $(filter wpad wpad-% nas,$(1)),iwinfo)
95
96 define ProfileDefault
97 NAME:=
98 PRIORITY:=
99 PACKAGES:=
100 endef
101
102 ifndef Profile
103 define Profile
104 $(eval $(call ProfileDefault))
105 $(eval $(call Profile/$(1)))
106 dumpinfo : $(call shexport,Profile/$(1)/Description)
107 PACKAGES := $(filter-out -%,$(PACKAGES))
108 DUMPINFO += \
109 echo "Target-Profile: $(1)"; \
110 $(if $(PRIORITY), echo "Target-Profile-Priority: $(PRIORITY)"; ) \
111 echo "Target-Profile-Name: $(NAME)"; \
112 echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
113 echo "Target-Profile-Description:"; \
114 echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
115 echo "@@"; \
116 echo;
117 endef
118 endif
119
120 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
121 define IncludeProfiles
122 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
123 -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
124 endef
125 else
126 define IncludeProfiles
127 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
128 endef
129 endif
130
131 PROFILE?=$(call qstrip,$(CONFIG_TARGET_PROFILE))
132
133 ifeq ($(TARGET_BUILD),1)
134 ifneq ($(DUMP),)
135 $(eval $(call IncludeProfiles))
136 endif
137 endif
138
139 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
140 include $(INCLUDE_DIR)/kernel-version.mk
141 endif
142
143 GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
144 GENERIC_BACKPORT_DIR := $(GENERIC_PLATFORM_DIR)/backport$(if $(wildcard $(GENERIC_PLATFORM_DIR)/backport-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
145 GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/pending$(if $(wildcard $(GENERIC_PLATFORM_DIR)/pending-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
146 GENERIC_HACK_DIR := $(GENERIC_PLATFORM_DIR)/hack$(if $(wildcard $(GENERIC_PLATFORM_DIR)/hack-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
147 GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
148
149 __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
150 __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
151 find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
152
153 GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
154 LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
155 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
156 LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
157 endif
158
159 # config file list used for compiling
160 LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
161
162 # default config list for reconfiguring
163 # defaults to subtarget if subtarget exists and target does not
164 # defaults to target otherwise
165 USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
166
167 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
168 LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
169
170 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
171 ifeq ($(CONFIG_TARGET),platform)
172 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
173 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
174 endif
175 ifeq ($(CONFIG_TARGET),subtarget)
176 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
177 LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
178 endif
179 ifeq ($(CONFIG_TARGET),subtarget_platform)
180 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
181 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
182 endif
183 ifeq ($(CONFIG_TARGET),env)
184 LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
185 LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
186 endif
187
188 __linux_confcmd = $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
189
190 LINUX_CONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_KCONFIG_LIST))
191 LINUX_RECONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_RECONFIG_LIST))
192 LINUX_RECONF_DIFF = $(SCRIPT_DIR)/kconfig.pl - '>' $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST))) $(1) $(GENERIC_PLATFORM_DIR)/config-filter
193
194 ifeq ($(DUMP),1)
195 BuildTarget=$(BuildTargets/DumpCurrent)
196
197 CPU_CFLAGS = -Os -pipe
198 ifneq ($(findstring mips,$(ARCH)),)
199 ifneq ($(findstring mips64,$(ARCH)),)
200 CPU_TYPE ?= mips64
201 else
202 CPU_TYPE ?= mips32
203 endif
204 CPU_CFLAGS += -mno-branch-likely
205 CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
206 CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
207 CPU_CFLAGS_mips64r2 = -mips64r2 -mtune=mips64r2 -mabi=64
208 CPU_CFLAGS_4kec = -mips32r2 -mtune=4kec
209 CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc
210 CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
211 CPU_CFLAGS_octeonplus = -march=octeon+ -mabi=64
212 endif
213 ifeq ($(ARCH),i386)
214 CPU_TYPE ?= pentium-mmx
215 CPU_CFLAGS_pentium-mmx = -march=pentium-mmx
216 CPU_CFLAGS_pentium4 = -march=pentium4
217 endif
218 ifneq ($(findstring arm,$(ARCH)),)
219 CPU_TYPE ?= xscale
220 endif
221 ifeq ($(ARCH),powerpc)
222 CPU_CFLAGS_603e:=-mcpu=603e
223 CPU_CFLAGS_8540:=-mcpu=8540
224 CPU_CFLAGS_405:=-mcpu=405
225 CPU_CFLAGS_440:=-mcpu=440
226 CPU_CFLAGS_464fp:=-mcpu=464fp
227 endif
228 ifeq ($(ARCH),powerpc64)
229 CPU_TYPE ?= powerpc64
230 CPU_CFLAGS_powerpc64:=-mcpu=powerpc64
231 endif
232 ifeq ($(ARCH),sparc)
233 CPU_TYPE = sparc
234 CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
235 endif
236 ifeq ($(ARCH),aarch64)
237 CPU_TYPE ?= generic
238 CPU_CFLAGS_generic = -mcpu=generic
239 CPU_CFLAGS_cortex-a53 = -mcpu=cortex-a53
240 endif
241 ifeq ($(ARCH),arc)
242 CPU_TYPE ?= arc700
243 CPU_CFLAGS += -matomic
244 CPU_CFLAGS_arc700 = -mcpu=arc700
245 CPU_CFLAGS_archs = -mcpu=archs
246 endif
247 ifneq ($(CPU_TYPE),)
248 ifndef CPU_CFLAGS_$(CPU_TYPE)
249 $(warning CPU_TYPE "$(CPU_TYPE)" doesn't correspond to a known type)
250 endif
251 endif
252 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
253
254 ifneq ($(BOARD),)
255 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
256 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
257 $(LINUX_CONF_CMD) > $@ || rm -f $@
258 -include $(TMP_CONFIG)
259 .SILENT: $(TMP_CONFIG)
260 .PRECIOUS: $(TMP_CONFIG)
261
262 ifdef KERNEL_TESTING_PATCHVER
263 ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
264 FEATURES += testing-kernel
265 endif
266 endif
267 ifneq ($(CONFIG_OF),)
268 FEATURES += dt
269 endif
270 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
271 FEATURES += gpio
272 endif
273 ifneq ($(CONFIG_PCI),)
274 FEATURES += pci
275 endif
276 ifneq ($(CONFIG_PCIEPORTBUS),)
277 FEATURES += pcie
278 endif
279 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
280 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
281 FEATURES += usb
282 endif
283 endif
284 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
285 FEATURES += pcmcia
286 endif
287 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
288 FEATURES += display
289 endif
290 ifneq ($(CONFIG_RTC_CLASS),)
291 FEATURES += rtc
292 endif
293 ifneq ($(CONFIG_VIRTIO),)
294 FEATURES += virtio
295 endif
296 ifneq ($(CONFIG_CPU_MIPS32_R2),)
297 FEATURES += mips16
298 endif
299 FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
300
301 # remove duplicates
302 FEATURES:=$(sort $(FEATURES))
303 endif
304 endif
305
306 CUR_SUBTARGET:=$(SUBTARGET)
307 ifeq ($(SUBTARGETS),)
308 CUR_SUBTARGET := default
309 endif
310
311 define BuildTargets/DumpCurrent
312 .PHONY: dumpinfo
313 dumpinfo : export DESCRIPTION=$$(Target/Description)
314 dumpinfo:
315 @echo 'Target: $(TARGETID)'; \
316 echo 'Target-Board: $(BOARD)'; \
317 echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
318 echo 'Target-Arch: $(ARCH)'; \
319 echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
320 echo 'Target-Features: $(FEATURES)'; \
321 echo 'Target-Depends: $(DEPENDS)'; \
322 echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
323 echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
324 echo 'Linux-Version: $(LINUX_VERSION)'; \
325 $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version: $(LINUX_TESTING_VERSION)';) \
326 echo 'Linux-Release: $(LINUX_RELEASE)'; \
327 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
328 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
329 echo 'Target-Description:'; \
330 echo "$$$$DESCRIPTION"; \
331 echo '@@'; \
332 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
333 $(DUMPINFO)
334 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
335 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
336 endef
337
338 include $(INCLUDE_DIR)/kernel.mk
339 ifeq ($(TARGET_BUILD),1)
340 include $(INCLUDE_DIR)/kernel-build.mk
341 BuildTarget?=$(BuildKernel)
342 endif
343
344 endif #__target_inc