Makefile 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. ARCH_DIR := arch/um
  9. OS := $(shell uname -s)
  10. # We require bash because the vmlinux link and loader script cpp use bash
  11. # features.
  12. SHELL := /bin/bash
  13. filechk_gen_header = $<
  14. core-y += $(ARCH_DIR)/kernel/ \
  15. $(ARCH_DIR)/drivers/ \
  16. $(ARCH_DIR)/os-$(OS)/
  17. # Have to precede the include because the included Makefiles reference them.
  18. SYMLINK_HEADERS := archparam.h system.h sigcontext.h processor.h ptrace.h \
  19. module.h vm-flags.h elf.h host_ldt.h
  20. SYMLINK_HEADERS := $(foreach header,$(SYMLINK_HEADERS),include/asm-um/$(header))
  21. # XXX: The "os" symlink is only used by arch/um/include/os.h, which includes
  22. # ../os/include/file.h
  23. #
  24. # These are cleaned up during mrproper. Please DO NOT fix it again, this is
  25. # the Correct Thing(tm) to do!
  26. ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
  27. $(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
  28. MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/skas
  29. include $(srctree)/$(ARCH_DIR)/Makefile-skas
  30. ARCH_INCLUDE := -I$(ARCH_DIR)/include
  31. ifneq ($(KBUILD_SRC),)
  32. ARCH_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include
  33. endif
  34. SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
  35. # -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
  36. # named - it's a common symbol in libpcap, so we get a binary which crashes.
  37. #
  38. # Same things for in6addr_loopback and mktime - found in libc. For these two we
  39. # only get link-time error, luckily.
  40. #
  41. # These apply to USER_CFLAGS to.
  42. KBUILD_CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
  43. $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
  44. -Din6addr_loopback=kernel_in6addr_loopback \
  45. -Din6addr_any=kernel_in6addr_any
  46. KBUILD_AFLAGS += $(ARCH_INCLUDE)
  47. USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
  48. $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
  49. -D_FILE_OFFSET_BITS=64
  50. include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
  51. #This will adjust *FLAGS accordingly to the platform.
  52. include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
  53. # -Derrno=kernel_errno - This turns all kernel references to errno into
  54. # kernel_errno to separate them from the libc errno. This allows -fno-common
  55. # in KBUILD_CFLAGS. Otherwise, it would cause ld to complain about the two different
  56. # errnos.
  57. # These apply to kernelspace only.
  58. #
  59. # strip leading and trailing whitespace to make the USER_CFLAGS removal of these
  60. # defines more robust
  61. KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
  62. -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
  63. KBUILD_CFLAGS += $(KERNEL_DEFINES)
  64. KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
  65. # These are needed for clean and mrproper, since in that case .config is not
  66. # included; the values here are meaningless
  67. CONFIG_NEST_LEVEL ?= 0
  68. SIZE = ($(CONFIG_NEST_LEVEL) * 0x20000000)
  69. PHONY += linux
  70. all: linux
  71. linux: vmlinux
  72. @echo ' LINK $@'
  73. $(Q)ln -f $< $@
  74. define archhelp
  75. echo '* linux - Binary kernel image (./linux) - for backward'
  76. echo ' compatibility only, this creates a hard link to the'
  77. echo ' real kernel binary, the "vmlinux" binary you'
  78. echo ' find in the kernel root.'
  79. endef
  80. ifneq ($(KBUILD_SRC),)
  81. $(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch)
  82. else
  83. $(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch)
  84. endif
  85. archprepare: $(ARCH_SYMLINKS) $(ARCH_DIR)/include/user_constants.h
  86. prepare: $(ARCH_DIR)/include/kern_constants.h
  87. LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
  88. LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
  89. CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
  90. $(call cc-option, -fno-stack-protector,) \
  91. $(call cc-option, -fno-stack-protector-all,)
  92. CONFIG_KERNEL_STACK_ORDER ?= 2
  93. STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
  94. ifndef START
  95. START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
  96. endif
  97. CPPFLAGS_vmlinux.lds = -U$(SUBARCH) -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
  98. -DELF_FORMAT="$(ELF_FORMAT)" -DKERNEL_STACK_SIZE=$(STACK_SIZE)
  99. # The wrappers will select whether using "malloc" or the kernel allocator.
  100. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
  101. CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS)
  102. define cmd_vmlinux__
  103. $(CC) $(CFLAGS_vmlinux) -o $@ \
  104. -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
  105. -Wl,--start-group $(vmlinux-main) -Wl,--end-group \
  106. -lutil \
  107. $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o \
  108. FORCE ,$^) ; rm -f linux
  109. endef
  110. # When cleaning we don't include .config, so we don't include
  111. # TT or skas makefiles and don't clean skas_ptregs.h.
  112. CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
  113. $(ARCH_DIR)/include/user_constants.h \
  114. $(ARCH_DIR)/include/kern_constants.h $(ARCH_DIR)/Kconfig.arch
  115. MRPROPER_FILES += $(ARCH_SYMLINKS)
  116. archclean:
  117. @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
  118. -o -name '*.gcov' \) -type f -print | xargs rm -f
  119. $(SYMLINK_HEADERS):
  120. @echo ' SYMLINK $@'
  121. ifneq ($(KBUILD_SRC),)
  122. $(Q)mkdir -p $(objtree)/include/asm-um
  123. $(Q)ln -fsn $(srctree)/include/asm-um/$(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $@
  124. else
  125. $(Q)cd $(TOPDIR)/$(dir $@) ; \
  126. ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
  127. endif
  128. include/asm-um/arch:
  129. @echo ' SYMLINK $@'
  130. ifneq ($(KBUILD_SRC),)
  131. $(Q)mkdir -p $(objtree)/include/asm-um
  132. $(Q)ln -fsn $(srctree)/include/asm-$(HEADER_ARCH) include/asm-um/arch
  133. else
  134. $(Q)cd $(TOPDIR)/include/asm-um && ln -fsn ../asm-$(HEADER_ARCH) arch
  135. endif
  136. $(objtree)/$(ARCH_DIR)/include:
  137. @echo ' MKDIR $@'
  138. $(Q)mkdir -p $@
  139. $(ARCH_DIR)/include/sysdep: $(objtree)/$(ARCH_DIR)/include
  140. @echo ' SYMLINK $@'
  141. ifneq ($(KBUILD_SRC),)
  142. $(Q)ln -fsn $(srctree)/$(ARCH_DIR)/include/sysdep-$(SUBARCH) $(ARCH_DIR)/include/sysdep
  143. else
  144. $(Q)cd $(ARCH_DIR)/include && ln -fsn sysdep-$(SUBARCH) sysdep
  145. endif
  146. $(ARCH_DIR)/os:
  147. @echo ' SYMLINK $@'
  148. ifneq ($(KBUILD_SRC),)
  149. $(Q)ln -fsn $(srctree)/$(ARCH_DIR)/os-$(OS) $(ARCH_DIR)/os
  150. else
  151. $(Q)cd $(ARCH_DIR) && ln -fsn os-$(OS) os
  152. endif
  153. # Generated files
  154. define filechk_umlconfig
  155. sed 's/ CONFIG/ UML_CONFIG/'
  156. endef
  157. $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
  158. $(call filechk,umlconfig)
  159. $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s: FORCE
  160. $(Q)$(MAKE) $(build)=$(ARCH_DIR)/sys-$(SUBARCH) $@
  161. define filechk_gen-asm-offsets
  162. (set -e; \
  163. echo "/*"; \
  164. echo " * DO NOT MODIFY."; \
  165. echo " *"; \
  166. echo " * This file was generated by arch/$(ARCH)/Makefile"; \
  167. echo " *"; \
  168. echo " */"; \
  169. echo ""; \
  170. sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
  171. echo ""; )
  172. endef
  173. $(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s
  174. $(call filechk,gen-asm-offsets)
  175. $(ARCH_DIR)/include/kern_constants.h: $(objtree)/$(ARCH_DIR)/include
  176. @echo ' SYMLINK $@'
  177. $(Q)ln -sf ../../../include/asm-um/asm-offsets.h $@
  178. export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS HEADER_ARCH