xref: /linux/arch/um/Makefile (revision 831c1926ee728c3e747255f7c0f434762e8e863d)
11da177e4SLinus Torvalds#
24f193362SPaul Smith# This file is included by the global makefile so that you can add your own
34f193362SPaul Smith# architecture-specific flags and dependencies.
44f193362SPaul Smith#
54c9e1385SJeff Dike# Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
61da177e4SLinus Torvalds# Licensed under the GPL
71da177e4SLinus Torvalds#
81da177e4SLinus Torvalds
9e40f04d0SRamkumar Ramachandra# select defconfig based on actual architecture
10e40f04d0SRamkumar Ramachandraifeq ($(SUBARCH),x86)
11e40f04d0SRamkumar Ramachandra  ifeq ($(shell uname -m),x86_64)
12e40f04d0SRamkumar Ramachandra        KBUILD_DEFCONFIG := x86_64_defconfig
13e40f04d0SRamkumar Ramachandra  else
14e40f04d0SRamkumar Ramachandra        KBUILD_DEFCONFIG := i386_defconfig
15e40f04d0SRamkumar Ramachandra  endif
16e40f04d0SRamkumar Ramachandraelse
17e40f04d0SRamkumar Ramachandra        KBUILD_DEFCONFIG := $(SUBARCH)_defconfig
18e40f04d0SRamkumar Ramachandraendif
19e40f04d0SRamkumar Ramachandra
201da177e4SLinus TorvaldsARCH_DIR := arch/um
211da177e4SLinus Torvalds# We require bash because the vmlinux link and loader script cpp use bash
221da177e4SLinus Torvalds# features.
2319ee6923SYueh-Shun LiSHELL := bash
241da177e4SLinus Torvalds
258569c914SAl ViroMODE_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/include/shared/skas
261da177e4SLinus Torvalds
277bbe7204SAl ViroHEADER_ARCH 	:= $(SUBARCH)
287bbe7204SAl Viro
29fff6540cSRichard Weinbergerifneq ($(filter $(SUBARCH),x86 x86_64 i386),)
307bbe7204SAl Viro	HEADER_ARCH := x86
317bbe7204SAl Viroendif
32fff6540cSRichard Weinberger
33fff6540cSRichard Weinbergerifdef CONFIG_64BIT
3412783aa0SRichard Weinberger	KBUILD_CFLAGS += -mcmodel=large
357bbe7204SAl Viroendif
367bbe7204SAl Viro
375c48b108SAl ViroHOST_DIR := arch/$(HEADER_ARCH)
385c48b108SAl Viro
39d8285639SMasahiro Yamadainclude $(srctree)/$(ARCH_DIR)/Makefile-skas
40d8285639SMasahiro Yamadainclude $(srctree)/$(HOST_DIR)/Makefile.um
415c48b108SAl Viro
425c48b108SAl Virocore-y += $(HOST_DIR)/um/
431da177e4SLinus Torvalds
4422409f9cSAl ViroSHARED_HEADERS	:= $(ARCH_DIR)/include/shared
4522409f9cSAl ViroARCH_INCLUDE	:= -I$(srctree)/$(SHARED_HEADERS)
465c48b108SAl ViroARCH_INCLUDE	+= -I$(srctree)/$(HOST_DIR)/um/shared
475c48b108SAl ViroKBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
481da177e4SLinus Torvalds
4998105d47SPaolo 'Blaisorblade' Giarrusso# -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
5098105d47SPaolo 'Blaisorblade' Giarrusso# named - it's a common symbol in libpcap, so we get a binary which crashes.
51fd748104SPaolo 'Blaisorblade' Giarrusso#
5298105d47SPaolo 'Blaisorblade' Giarrusso# Same things for in6addr_loopback and mktime - found in libc. For these two we
5398105d47SPaolo 'Blaisorblade' Giarrusso# only get link-time error, luckily.
5498105d47SPaolo 'Blaisorblade' Giarrusso#
55f44f1e7dSFlorian Fainelli# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
56f44f1e7dSFlorian Fainelli# embedded copy of longjmp, same thing for setjmp.
57f44f1e7dSFlorian Fainelli#
5898105d47SPaolo 'Blaisorblade' Giarrusso# These apply to USER_CFLAGS to.
59ecc354a9SPaolo 'Blaisorblade' Giarrusso
60dc5be20aSAl ViroKBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
61fd748104SPaolo 'Blaisorblade' Giarrusso	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
62f44f1e7dSFlorian Fainelli	-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
63818f6ef4SJeff Dike	-Din6addr_loopback=kernel_in6addr_loopback \
6432e8eaf2SBenjamin Berg	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \
6532e8eaf2SBenjamin Berg	-D__close_range=kernel__close_range
66fd748104SPaolo 'Blaisorblade' Giarrusso
67905a7707SDavid GowKBUILD_RUSTFLAGS += -Crelocation-model=pie
68905a7707SDavid Gow
69222d394dSSam RavnborgKBUILD_AFLAGS += $(ARCH_INCLUDE)
70ecc354a9SPaolo 'Blaisorblade' Giarrusso
71298e20baSRichard WeinbergerUSER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
72298e20baSRichard Weinberger		$(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
730b5aedfeSRichard Weinberger		-D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
74*2f278b59SBenjamin Berg		-idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__ \
75*2f278b59SBenjamin Berg		-include $(srctree)/include/linux/compiler-version.h \
76*2f278b59SBenjamin Berg		-include $(srctree)/include/linux/kconfig.h
77d45e44d4Sakpm@osdl.org
78d45e44d4Sakpm@osdl.org#This will adjust *FLAGS accordingly to the platform.
79d32df108SMasahiro Yamadainclude $(srctree)/$(ARCH_DIR)/Makefile-os-Linux
80ecc354a9SPaolo 'Blaisorblade' Giarrusso
81c9b284b2SH. Peter AnvinKBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \
82abbf1590SDavid Howells		   -I$(srctree)/$(HOST_DIR)/include/uapi \
8358ab5e0cSArnd Bergmann		   -I$(objtree)/$(HOST_DIR)/include/generated \
8458ab5e0cSArnd Bergmann		   -I$(objtree)/$(HOST_DIR)/include/generated/uapi
851de1502cSAl Viro
861da177e4SLinus Torvalds# -Derrno=kernel_errno - This turns all kernel references to errno into
871da177e4SLinus Torvalds# kernel_errno to separate them from the libc errno.  This allows -fno-common
88a0f97e06SSam Ravnborg# in KBUILD_CFLAGS.  Otherwise, it would cause ld to complain about the two different
891da177e4SLinus Torvalds# errnos.
9098105d47SPaolo 'Blaisorblade' Giarrusso# These apply to kernelspace only.
91f15cf515SJeff Dike#
92f15cf515SJeff Dike# strip leading and trailing whitespace to make the USER_CFLAGS removal of these
93f15cf515SJeff Dike# defines more robust
941da177e4SLinus Torvalds
95f15cf515SJeff DikeKERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
96f15cf515SJeff Dike			 -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
97a0f97e06SSam RavnborgKBUILD_CFLAGS += $(KERNEL_DEFINES)
981da177e4SLinus Torvalds
994f193362SPaul SmithPHONY += linux
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvaldsall: linux
1021da177e4SLinus Torvalds
1031da177e4SLinus Torvaldslinux: vmlinux
104a4b741e3SJeff Dike	@echo '  LINK $@'
105cb8aa3d2SPaolo 'Blaisorblade' Giarrusso	$(Q)ln -f $< $@
1061da177e4SLinus Torvalds
1071da177e4SLinus Torvaldsdefine archhelp
1081da177e4SLinus Torvalds  echo '* linux		- Binary kernel image (./linux) - for backward'
1091da177e4SLinus Torvalds  echo '		   compatibility only, this creates a hard link to the'
1104b3f686dSMatt LaPlante  echo '		   real kernel binary, the "vmlinux" binary you'
1111da177e4SLinus Torvalds  echo '		   find in the kernel root.'
1121da177e4SLinus Torvaldsendef
1131da177e4SLinus Torvalds
114c9b284b2SH. Peter Anvinarchheaders:
1150004438aSMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) asm-generic archheaders
116699d7a57SAl Viro
11765bba042SMasahiro Yamadaarchprepare:
11865bba042SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(HOST_DIR)/um include/generated/user_constants.h
1191da177e4SLinus Torvalds
1201da177e4SLinus TorvaldsLINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
121846cfbeeSNathan Chancellorifdef CONFIG_LD_SCRIPT_DYN
122846cfbeeSNathan ChancellorLINK-$(call gcc-min-version, 60100)$(CONFIG_CC_IS_CLANG) += -no-pie
123846cfbeeSNathan Chancellorendif
124386093c6SJohannes BergLINK-$(CONFIG_LD_SCRIPT_DYN_RPATH) += -Wl,-rpath,/lib
1251da177e4SLinus Torvalds
126275e6e1eSPaolo 'Blaisorblade' GiarrussoCFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
127893ab004SMasahiro Yamada	-fno-stack-protector $(call cc-option, -fno-stack-protector-all)
128275e6e1eSPaolo 'Blaisorblade' Giarrusso
12951b563fcSSam Ravnborg# Options used by linker script
13051b563fcSSam Ravnborgexport LDS_START      := $(START)
13151b563fcSSam Ravnborgexport LDS_ELF_ARCH   := $(ELF_ARCH)
13251b563fcSSam Ravnborgexport LDS_ELF_FORMAT := $(ELF_FORMAT)
1331da177e4SLinus Torvalds
1341da177e4SLinus Torvalds# The wrappers will select whether using "malloc" or the kernel allocator.
1351da177e4SLinus TorvaldsLINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
1361da177e4SLinus Torvalds
137bd71558dSDavid Gow# Avoid binutils 2.39+ warnings by marking the stack non-executable and
138bd71558dSDavid Gow# ignorning warnings for the kallsyms sections.
139bd71558dSDavid GowLDFLAGS_EXECSTACK = -z noexecstack
140bd71558dSDavid Gowifeq ($(CONFIG_LD_IS_BFD),y)
141bd71558dSDavid GowLDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments)
142bd71558dSDavid Gowendif
143bd71558dSDavid Gow
1446aa56115SPeter FoleyLD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS) $(LDFLAGS_EXECSTACK),-Wl,$(opt))
1450ba7fe03SJeff Dike
1461f2bfbd0SSam Ravnborg# Used by link-vmlinux.sh which has special support for um link
14783e913f5SPeter Foleyexport CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) $(CC_FLAGS_LTO)
1481da177e4SLinus Torvalds
1491da177e4SLinus Torvalds# When cleaning we don't include .config, so we don't include
1501da177e4SLinus Torvalds# TT or skas makefiles and don't clean skas_ptregs.h.
1519e636452SAl ViroCLEAN_FILES += linux x.i gmon.out
152a5a319ecSKees CookMRPROPER_FILES += $(HOST_DIR)/include/generated
1531da177e4SLinus Torvalds
1541da177e4SLinus Torvaldsarchclean:
1551da177e4SLinus Torvalds	@find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
1561da177e4SLinus Torvalds		-o -name '*.gcov' \) -type f -print | xargs rm -f
1571da177e4SLinus Torvalds
158d32df108SMasahiro Yamadaexport HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING DEV_NULL_PATH
159