18c2ecf20Sopenharmony_ci#
28c2ecf20Sopenharmony_ci# This file is included by the global makefile so that you can add your own
38c2ecf20Sopenharmony_ci# architecture-specific flags and dependencies.
48c2ecf20Sopenharmony_ci#
58c2ecf20Sopenharmony_ci# Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
68c2ecf20Sopenharmony_ci# Licensed under the GPL
78c2ecf20Sopenharmony_ci#
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci# select defconfig based on actual architecture
108c2ecf20Sopenharmony_ciifeq ($(SUBARCH),x86)
118c2ecf20Sopenharmony_ci  ifeq ($(shell uname -m),x86_64)
128c2ecf20Sopenharmony_ci        KBUILD_DEFCONFIG := x86_64_defconfig
138c2ecf20Sopenharmony_ci  else
148c2ecf20Sopenharmony_ci        KBUILD_DEFCONFIG := i386_defconfig
158c2ecf20Sopenharmony_ci  endif
168c2ecf20Sopenharmony_cielse
178c2ecf20Sopenharmony_ci        KBUILD_DEFCONFIG := $(SUBARCH)_defconfig
188c2ecf20Sopenharmony_ciendif
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciARCH_DIR := arch/um
218c2ecf20Sopenharmony_ciOS := $(shell uname -s)
228c2ecf20Sopenharmony_ci# We require bash because the vmlinux link and loader script cpp use bash
238c2ecf20Sopenharmony_ci# features.
248c2ecf20Sopenharmony_ciSHELL := /bin/bash
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cicore-y			+= $(ARCH_DIR)/kernel/		\
278c2ecf20Sopenharmony_ci			   $(ARCH_DIR)/drivers/		\
288c2ecf20Sopenharmony_ci			   $(ARCH_DIR)/os-$(OS)/
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciMODE_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/include/shared/skas
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciHEADER_ARCH 	:= $(SUBARCH)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciifneq ($(filter $(SUBARCH),x86 x86_64 i386),)
358c2ecf20Sopenharmony_ci	HEADER_ARCH := x86
368c2ecf20Sopenharmony_ciendif
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciifdef CONFIG_64BIT
398c2ecf20Sopenharmony_ci	KBUILD_CFLAGS += -mcmodel=large
408c2ecf20Sopenharmony_ciendif
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciHOST_DIR := arch/$(HEADER_ARCH)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciinclude $(ARCH_DIR)/Makefile-skas
458c2ecf20Sopenharmony_ciinclude $(HOST_DIR)/Makefile.um
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cicore-y += $(HOST_DIR)/um/
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciSHARED_HEADERS	:= $(ARCH_DIR)/include/shared
508c2ecf20Sopenharmony_ciARCH_INCLUDE	:= -I$(srctree)/$(SHARED_HEADERS)
518c2ecf20Sopenharmony_ciARCH_INCLUDE	+= -I$(srctree)/$(HOST_DIR)/um/shared
528c2ecf20Sopenharmony_ciKBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci# -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
558c2ecf20Sopenharmony_ci# named - it's a common symbol in libpcap, so we get a binary which crashes.
568c2ecf20Sopenharmony_ci#
578c2ecf20Sopenharmony_ci# Same things for in6addr_loopback and mktime - found in libc. For these two we
588c2ecf20Sopenharmony_ci# only get link-time error, luckily.
598c2ecf20Sopenharmony_ci#
608c2ecf20Sopenharmony_ci# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
618c2ecf20Sopenharmony_ci# embedded copy of longjmp, same thing for setjmp.
628c2ecf20Sopenharmony_ci#
638c2ecf20Sopenharmony_ci# These apply to USER_CFLAGS to.
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
668c2ecf20Sopenharmony_ci	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
678c2ecf20Sopenharmony_ci	-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
688c2ecf20Sopenharmony_ci	-Din6addr_loopback=kernel_in6addr_loopback \
698c2ecf20Sopenharmony_ci	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciKBUILD_AFLAGS += $(ARCH_INCLUDE)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciUSER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
748c2ecf20Sopenharmony_ci		$(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
758c2ecf20Sopenharmony_ci		-D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
768c2ecf20Sopenharmony_ci		-idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#This will adjust *FLAGS accordingly to the platform.
798c2ecf20Sopenharmony_ciinclude $(ARCH_DIR)/Makefile-os-$(OS)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciKBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \
828c2ecf20Sopenharmony_ci		   -I$(srctree)/$(HOST_DIR)/include/uapi \
838c2ecf20Sopenharmony_ci		   -I$(objtree)/$(HOST_DIR)/include/generated \
848c2ecf20Sopenharmony_ci		   -I$(objtree)/$(HOST_DIR)/include/generated/uapi
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci# -Derrno=kernel_errno - This turns all kernel references to errno into
878c2ecf20Sopenharmony_ci# kernel_errno to separate them from the libc errno.  This allows -fno-common
888c2ecf20Sopenharmony_ci# in KBUILD_CFLAGS.  Otherwise, it would cause ld to complain about the two different
898c2ecf20Sopenharmony_ci# errnos.
908c2ecf20Sopenharmony_ci# These apply to kernelspace only.
918c2ecf20Sopenharmony_ci#
928c2ecf20Sopenharmony_ci# strip leading and trailing whitespace to make the USER_CFLAGS removal of these
938c2ecf20Sopenharmony_ci# defines more robust
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciKERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
968c2ecf20Sopenharmony_ci			 -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
978c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(KERNEL_DEFINES)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciPHONY += linux
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciall: linux
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cilinux: vmlinux
1048c2ecf20Sopenharmony_ci	@echo '  LINK $@'
1058c2ecf20Sopenharmony_ci	$(Q)ln -f $< $@
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cidefine archhelp
1088c2ecf20Sopenharmony_ci  echo '* linux		- Binary kernel image (./linux) - for backward'
1098c2ecf20Sopenharmony_ci  echo '		   compatibility only, this creates a hard link to the'
1108c2ecf20Sopenharmony_ci  echo '		   real kernel binary, the "vmlinux" binary you'
1118c2ecf20Sopenharmony_ci  echo '		   find in the kernel root.'
1128c2ecf20Sopenharmony_ciendef
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ciarchheaders:
1158c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) asm-generic archheaders
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ciarchprepare:
1188c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(HOST_DIR)/um include/generated/user_constants.h
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ciLINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
1218c2ecf20Sopenharmony_ciLINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciCFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
1248c2ecf20Sopenharmony_ci	-fno-stack-protector $(call cc-option, -fno-stack-protector-all)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci# Options used by linker script
1278c2ecf20Sopenharmony_ciexport LDS_START      := $(START)
1288c2ecf20Sopenharmony_ciexport LDS_ELF_ARCH   := $(ELF_ARCH)
1298c2ecf20Sopenharmony_ciexport LDS_ELF_FORMAT := $(ELF_FORMAT)
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci# The wrappers will select whether using "malloc" or the kernel allocator.
1328c2ecf20Sopenharmony_ciLINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci# Avoid binutils 2.39+ warnings by marking the stack non-executable and
1358c2ecf20Sopenharmony_ci# ignorning warnings for the kallsyms sections.
1368c2ecf20Sopenharmony_ciLDFLAGS_EXECSTACK = -z noexecstack
1378c2ecf20Sopenharmony_ciifeq ($(CONFIG_LD_IS_BFD),y)
1388c2ecf20Sopenharmony_ciLDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments)
1398c2ecf20Sopenharmony_ciendif
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ciLD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt))
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci# Used by link-vmlinux.sh which has special support for um link
1448c2ecf20Sopenharmony_ciexport CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
1458c2ecf20Sopenharmony_ciexport LDFLAGS_vmlinux := $(LDFLAGS_EXECSTACK)
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci# When cleaning we don't include .config, so we don't include
1488c2ecf20Sopenharmony_ci# TT or skas makefiles and don't clean skas_ptregs.h.
1498c2ecf20Sopenharmony_ciCLEAN_FILES += linux x.i gmon.out
1508c2ecf20Sopenharmony_ciMRPROPER_FILES += $(HOST_DIR)/include/generated
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ciarchclean:
1538c2ecf20Sopenharmony_ci	@find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
1548c2ecf20Sopenharmony_ci		-o -name '*.gcov' \) -type f -print | xargs rm -f
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ciexport HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS DEV_NULL_PATH
157