Makefile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. OS := $(shell uname -s)
  20. # We require bash because the vmlinux link and loader script cpp use bash
  21. # features.
  22. SHELL := /bin/bash
  23. filechk_gen_header = $<
  24. core-y += $(ARCH_DIR)/kernel/ \
  25. $(ARCH_DIR)/drivers/ \
  26. $(ARCH_DIR)/os-$(OS)/
  27. MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas
  28. HEADER_ARCH := $(SUBARCH)
  29. ifneq ($(filter $(SUBARCH),x86 x86_64 i386),)
  30. HEADER_ARCH := x86
  31. endif
  32. ifdef CONFIG_64BIT
  33. KBUILD_CFLAGS += -mcmodel=large
  34. endif
  35. HOST_DIR := arch/$(HEADER_ARCH)
  36. include $(ARCH_DIR)/Makefile-skas
  37. include $(HOST_DIR)/Makefile.um
  38. core-y += $(HOST_DIR)/um/
  39. SHARED_HEADERS := $(ARCH_DIR)/include/shared
  40. ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS)
  41. ARCH_INCLUDE += -I$(srctree)/$(HOST_DIR)/um/shared
  42. KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
  43. # -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
  44. # named - it's a common symbol in libpcap, so we get a binary which crashes.
  45. #
  46. # Same things for in6addr_loopback and mktime - found in libc. For these two we
  47. # only get link-time error, luckily.
  48. #
  49. # -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
  50. # embedded copy of longjmp, same thing for setjmp.
  51. #
  52. # These apply to USER_CFLAGS to.
  53. KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
  54. $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
  55. -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
  56. -Din6addr_loopback=kernel_in6addr_loopback \
  57. -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
  58. KBUILD_AFLAGS += $(ARCH_INCLUDE)
  59. USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
  60. $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
  61. -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
  62. -idirafter $(obj)/include -D__KERNEL__ -D__UM_HOST__
  63. #This will adjust *FLAGS accordingly to the platform.
  64. include $(ARCH_DIR)/Makefile-os-$(OS)
  65. KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \
  66. -I$(srctree)/$(HOST_DIR)/include/uapi \
  67. -I$(objtree)/$(HOST_DIR)/include/generated \
  68. -I$(objtree)/$(HOST_DIR)/include/generated/uapi
  69. # -Derrno=kernel_errno - This turns all kernel references to errno into
  70. # kernel_errno to separate them from the libc errno. This allows -fno-common
  71. # in KBUILD_CFLAGS. Otherwise, it would cause ld to complain about the two different
  72. # errnos.
  73. # These apply to kernelspace only.
  74. #
  75. # strip leading and trailing whitespace to make the USER_CFLAGS removal of these
  76. # defines more robust
  77. KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
  78. -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
  79. KBUILD_CFLAGS += $(KERNEL_DEFINES)
  80. PHONY += linux
  81. all: linux
  82. linux: vmlinux
  83. @echo ' LINK $@'
  84. $(Q)ln -f $< $@
  85. define archhelp
  86. echo '* linux - Binary kernel image (./linux) - for backward'
  87. echo ' compatibility only, this creates a hard link to the'
  88. echo ' real kernel binary, the "vmlinux" binary you'
  89. echo ' find in the kernel root.'
  90. endef
  91. archheaders:
  92. $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) asm-generic archheaders
  93. archprepare: include/generated/user_constants.h
  94. LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
  95. LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
  96. CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
  97. $(call cc-option, -fno-stack-protector,) \
  98. $(call cc-option, -fno-stack-protector-all,)
  99. # Options used by linker script
  100. export LDS_START := $(START)
  101. export LDS_ELF_ARCH := $(ELF_ARCH)
  102. export LDS_ELF_FORMAT := $(ELF_FORMAT)
  103. # The wrappers will select whether using "malloc" or the kernel allocator.
  104. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
  105. LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt))
  106. # Used by link-vmlinux.sh which has special support for um link
  107. export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
  108. # When cleaning we don't include .config, so we don't include
  109. # TT or skas makefiles and don't clean skas_ptregs.h.
  110. CLEAN_FILES += linux x.i gmon.out
  111. archclean:
  112. @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
  113. -o -name '*.gcov' \) -type f -print | xargs rm -f
  114. # Generated files
  115. $(HOST_DIR)/um/user-offsets.s: __headers FORCE
  116. $(Q)$(MAKE) $(build)=$(HOST_DIR)/um $@
  117. define filechk_gen-asm-offsets
  118. (set -e; \
  119. echo "/*"; \
  120. echo " * DO NOT MODIFY."; \
  121. echo " *"; \
  122. echo " * This file was generated by arch/$(ARCH)/Makefile"; \
  123. echo " *"; \
  124. echo " */"; \
  125. echo ""; \
  126. sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}" < $<; \
  127. echo ""; )
  128. endef
  129. include/generated/user_constants.h: $(HOST_DIR)/um/user-offsets.s
  130. $(call filechk,gen-asm-offsets)
  131. export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS DEV_NULL_PATH