Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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) $(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. $(filter -I%,$(CFLAGS)) -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. PHONY += linux
  66. all: linux
  67. linux: vmlinux
  68. @echo ' LINK $@'
  69. $(Q)ln -f $< $@
  70. define archhelp
  71. echo '* linux - Binary kernel image (./linux) - for backward'
  72. echo ' compatibility only, this creates a hard link to the'
  73. echo ' real kernel binary, the "vmlinux" binary you'
  74. echo ' find in the kernel root.'
  75. endef
  76. ifneq ($(KBUILD_SRC),)
  77. $(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch)
  78. else
  79. $(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch)
  80. endif
  81. archprepare: $(ARCH_SYMLINKS) $(ARCH_DIR)/include/user_constants.h
  82. prepare: $(ARCH_DIR)/include/kern_constants.h
  83. LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
  84. LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
  85. CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
  86. $(call cc-option, -fno-stack-protector,) \
  87. $(call cc-option, -fno-stack-protector-all,)
  88. CONFIG_KERNEL_STACK_ORDER ?= 2
  89. STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
  90. CPPFLAGS_vmlinux.lds = -U$(SUBARCH) -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
  91. -DELF_FORMAT="$(ELF_FORMAT)" -DKERNEL_STACK_SIZE=$(STACK_SIZE)
  92. # The wrappers will select whether using "malloc" or the kernel allocator.
  93. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
  94. LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
  95. CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
  96. define cmd_vmlinux__
  97. $(CC) $(CFLAGS_vmlinux) -o $@ \
  98. -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
  99. -Wl,--start-group $(vmlinux-main) -Wl,--end-group \
  100. -lutil \
  101. $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o \
  102. FORCE ,$^) ; rm -f linux
  103. endef
  104. # When cleaning we don't include .config, so we don't include
  105. # TT or skas makefiles and don't clean skas_ptregs.h.
  106. CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
  107. $(ARCH_DIR)/include/user_constants.h \
  108. $(ARCH_DIR)/include/kern_constants.h $(ARCH_DIR)/Kconfig.arch
  109. MRPROPER_FILES += $(ARCH_SYMLINKS)
  110. archclean:
  111. @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
  112. -o -name '*.gcov' \) -type f -print | xargs rm -f
  113. $(SYMLINK_HEADERS):
  114. @echo ' SYMLINK $@'
  115. ifneq ($(KBUILD_SRC),)
  116. $(Q)mkdir -p $(objtree)/include/asm-um
  117. $(Q)ln -fsn $(srctree)/include/asm-um/$(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $@
  118. else
  119. $(Q)cd $(srctree)/$(dir $@) ; \
  120. ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
  121. endif
  122. include/asm-um/arch:
  123. @echo ' SYMLINK $@'
  124. ifneq ($(KBUILD_SRC),)
  125. $(Q)mkdir -p $(objtree)/include/asm-um
  126. $(Q)ln -fsn $(srctree)/include/asm-$(HEADER_ARCH) include/asm-um/arch
  127. else
  128. $(Q)cd $(srctree)/include/asm-um && ln -fsn ../asm-$(HEADER_ARCH) arch
  129. endif
  130. $(objtree)/$(ARCH_DIR)/include:
  131. @echo ' MKDIR $@'
  132. $(Q)mkdir -p $@
  133. $(ARCH_DIR)/include/sysdep: $(objtree)/$(ARCH_DIR)/include
  134. @echo ' SYMLINK $@'
  135. ifneq ($(KBUILD_SRC),)
  136. $(Q)ln -fsn $(srctree)/$(ARCH_DIR)/include/sysdep-$(SUBARCH) $(ARCH_DIR)/include/sysdep
  137. else
  138. $(Q)cd $(ARCH_DIR)/include && ln -fsn sysdep-$(SUBARCH) sysdep
  139. endif
  140. $(ARCH_DIR)/os:
  141. @echo ' SYMLINK $@'
  142. ifneq ($(KBUILD_SRC),)
  143. $(Q)ln -fsn $(srctree)/$(ARCH_DIR)/os-$(OS) $(ARCH_DIR)/os
  144. else
  145. $(Q)cd $(ARCH_DIR) && ln -fsn os-$(OS) os
  146. endif
  147. # Generated files
  148. define filechk_umlconfig
  149. sed 's/ CONFIG/ UML_CONFIG/'
  150. endef
  151. $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
  152. $(call filechk,umlconfig)
  153. $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s: FORCE
  154. $(Q)$(MAKE) $(build)=$(ARCH_DIR)/sys-$(SUBARCH) $@
  155. define filechk_gen-asm-offsets
  156. (set -e; \
  157. echo "/*"; \
  158. echo " * DO NOT MODIFY."; \
  159. echo " *"; \
  160. echo " * This file was generated by arch/$(ARCH)/Makefile"; \
  161. echo " *"; \
  162. echo " */"; \
  163. echo ""; \
  164. sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
  165. echo ""; )
  166. endef
  167. $(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s
  168. $(call filechk,gen-asm-offsets)
  169. $(ARCH_DIR)/include/kern_constants.h: $(objtree)/$(ARCH_DIR)/include
  170. @echo ' SYMLINK $@'
  171. $(Q)ln -sf ../../../include/asm-um/asm-offsets.h $@
  172. export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS HEADER_ARCH