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