Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #
  2. # This file is included by the global makefile so that you can add your own
  3. # architecture-specific flags and dependencies.
  4. #
  5. # Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  6. # Licensed under the GPL
  7. #
  8. # select defconfig based on actual architecture
  9. ifeq ($(SUBARCH),x86)
  10. ifeq ($(shell uname -m),x86_64)
  11. KBUILD_DEFCONFIG := x86_64_defconfig
  12. else
  13. KBUILD_DEFCONFIG := i386_defconfig
  14. endif
  15. else
  16. KBUILD_DEFCONFIG := $(SUBARCH)_defconfig
  17. endif
  18. ARCH_DIR := arch/um
  19. # We require bash because the vmlinux link and loader script cpp use bash
  20. # features.
  21. SHELL := bash
  22. MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas
  23. HEADER_ARCH := $(SUBARCH)
  24. ifneq ($(filter $(SUBARCH),x86 x86_64 i386),)
  25. HEADER_ARCH := x86
  26. endif
  27. ifdef CONFIG_64BIT
  28. KBUILD_CFLAGS += -mcmodel=large
  29. endif
  30. HOST_DIR := arch/$(HEADER_ARCH)
  31. include $(srctree)/$(ARCH_DIR)/Makefile-skas
  32. include $(srctree)/$(HOST_DIR)/Makefile.um
  33. core-y += $(HOST_DIR)/um/
  34. SHARED_HEADERS := $(ARCH_DIR)/include/shared
  35. ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS)
  36. ARCH_INCLUDE += -I$(srctree)/$(HOST_DIR)/um/shared
  37. KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
  38. # -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
  39. # named - it's a common symbol in libpcap, so we get a binary which crashes.
  40. #
  41. # Same things for in6addr_loopback and mktime - found in libc. For these two we
  42. # only get link-time error, luckily.
  43. #
  44. # -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
  45. # embedded copy of longjmp, same thing for setjmp.
  46. #
  47. # These apply to USER_CFLAGS to.
  48. KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
  49. $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
  50. -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
  51. -Din6addr_loopback=kernel_in6addr_loopback \
  52. -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
  53. KBUILD_RUSTFLAGS += -Crelocation-model=pie
  54. KBUILD_AFLAGS += $(ARCH_INCLUDE)
  55. USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
  56. $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
  57. -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
  58. -idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__
  59. #This will adjust *FLAGS accordingly to the platform.
  60. include $(srctree)/$(ARCH_DIR)/Makefile-os-Linux
  61. KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \
  62. -I$(srctree)/$(HOST_DIR)/include/uapi \
  63. -I$(objtree)/$(HOST_DIR)/include/generated \
  64. -I$(objtree)/$(HOST_DIR)/include/generated/uapi
  65. # -Derrno=kernel_errno - This turns all kernel references to errno into
  66. # kernel_errno to separate them from the libc errno. This allows -fno-common
  67. # in KBUILD_CFLAGS. Otherwise, it would cause ld to complain about the two different
  68. # errnos.
  69. # These apply to kernelspace only.
  70. #
  71. # strip leading and trailing whitespace to make the USER_CFLAGS removal of these
  72. # defines more robust
  73. KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
  74. -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
  75. KBUILD_CFLAGS += $(KERNEL_DEFINES)
  76. PHONY += linux
  77. all: linux
  78. linux: vmlinux
  79. @echo ' LINK $@'
  80. $(Q)ln -f $< $@
  81. define archhelp
  82. echo '* linux - Binary kernel image (./linux) - for backward'
  83. echo ' compatibility only, this creates a hard link to the'
  84. echo ' real kernel binary, the "vmlinux" binary you'
  85. echo ' find in the kernel root.'
  86. endef
  87. archheaders:
  88. $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) asm-generic archheaders
  89. archprepare:
  90. $(Q)$(MAKE) $(build)=$(HOST_DIR)/um include/generated/user_constants.h
  91. LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
  92. ifdef CONFIG_LD_SCRIPT_DYN
  93. LINK-$(call gcc-min-version, 60100)$(CONFIG_CC_IS_CLANG) += -no-pie
  94. endif
  95. LINK-$(CONFIG_LD_SCRIPT_DYN_RPATH) += -Wl,-rpath,/lib
  96. CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
  97. -fno-stack-protector $(call cc-option, -fno-stack-protector-all)
  98. # Options used by linker script
  99. export LDS_START := $(START)
  100. export LDS_ELF_ARCH := $(ELF_ARCH)
  101. export LDS_ELF_FORMAT := $(ELF_FORMAT)
  102. # The wrappers will select whether using "malloc" or the kernel allocator.
  103. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
  104. # Avoid binutils 2.39+ warnings by marking the stack non-executable and
  105. # ignorning warnings for the kallsyms sections.
  106. LDFLAGS_EXECSTACK = -z noexecstack
  107. ifeq ($(CONFIG_LD_IS_BFD),y)
  108. LDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments)
  109. endif
  110. LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS) $(LDFLAGS_EXECSTACK),-Wl,$(opt))
  111. # Used by link-vmlinux.sh which has special support for um link
  112. export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) $(CC_FLAGS_LTO)
  113. # When cleaning we don't include .config, so we don't include
  114. # TT or skas makefiles and don't clean skas_ptregs.h.
  115. CLEAN_FILES += linux x.i gmon.out
  116. MRPROPER_FILES += $(HOST_DIR)/include/generated
  117. archclean:
  118. @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
  119. -o -name '*.gcov' \) -type f -print | xargs rm -f
  120. $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) clean
  121. export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING DEV_NULL_PATH