Makefile 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #
  2. # Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. # Licensed under the GPL
  4. #
  5. ARCH_DIR := arch/um
  6. OS := $(shell uname -s)
  7. # We require bash because the vmlinux link and loader script cpp use bash
  8. # features.
  9. SHELL := /bin/bash
  10. filechk_gen_header = $<
  11. core-y += $(ARCH_DIR)/kernel/ \
  12. $(ARCH_DIR)/drivers/ \
  13. $(ARCH_DIR)/os-$(OS)/
  14. # Have to precede the include because the included Makefiles reference them.
  15. SYMLINK_HEADERS := archparam.h system.h sigcontext.h processor.h ptrace.h \
  16. module.h vm-flags.h elf.h ldt.h
  17. SYMLINK_HEADERS := $(foreach header,$(SYMLINK_HEADERS),include/asm-um/$(header))
  18. # XXX: The "os" symlink is only used by arch/um/include/os.h, which includes
  19. # ../os/include/file.h
  20. #
  21. # These are cleaned up during mrproper. Please DO NOT fix it again, this is
  22. # the Correct Thing(tm) to do!
  23. ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
  24. $(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
  25. um-modes-$(CONFIG_MODE_TT) += tt
  26. um-modes-$(CONFIG_MODE_SKAS) += skas
  27. MODE_INCLUDE += $(foreach mode,$(um-modes-y),\
  28. -I$(srctree)/$(ARCH_DIR)/include/$(mode))
  29. MAKEFILES-INCL += $(foreach mode,$(um-modes-y),\
  30. $(srctree)/$(ARCH_DIR)/Makefile-$(mode))
  31. ifneq ($(MAKEFILES-INCL),)
  32. include $(MAKEFILES-INCL)
  33. endif
  34. ARCH_INCLUDE := -I$(ARCH_DIR)/include
  35. ifneq ($(KBUILD_SRC),)
  36. ARCH_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include
  37. endif
  38. SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
  39. # -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
  40. # named - it's a common symbol in libpcap, so we get a binary which crashes.
  41. #
  42. # Same things for in6addr_loopback and mktime - found in libc. For these two we
  43. # only get link-time error, luckily.
  44. #
  45. # These apply to USER_CFLAGS to.
  46. CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
  47. $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
  48. -Din6addr_loopback=kernel_in6addr_loopback
  49. AFLAGS += $(ARCH_INCLUDE)
  50. USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
  51. USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
  52. $(MODE_INCLUDE) -D_FILE_OFFSET_BITS=64
  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 CFLAGS. Otherwise, it would cause ld to complain about the two different
  56. # errnos.
  57. # These apply to kernelspace only.
  58. CFLAGS += -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
  59. -Dmktime=kernel_mktime
  60. CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
  61. include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
  62. #This will adjust *FLAGS accordingly to the platform.
  63. include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
  64. # These are needed for clean and mrproper, since in that case .config is not
  65. # included; the values here are meaningless
  66. CONFIG_NEST_LEVEL ?= 0
  67. CONFIG_KERNEL_HALF_GIGS ?= 0
  68. SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)
  69. .PHONY: linux
  70. all: linux
  71. linux: vmlinux
  72. ln -f $< $@
  73. define archhelp
  74. echo '* linux - Binary kernel image (./linux) - for backward'
  75. echo ' compatibility only, this creates a hard link to the'
  76. echo ' real kernel binary, the the "vmlinux" binary you'
  77. echo ' find in the kernel root.'
  78. endef
  79. ifneq ($(KBUILD_SRC),)
  80. $(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch)
  81. else
  82. $(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch)
  83. endif
  84. archprepare: $(ARCH_SYMLINKS) $(ARCH_DIR)/include/user_constants.h
  85. prepare: $(ARCH_DIR)/include/kern_constants.h
  86. LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
  87. LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
  88. CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
  89. CONFIG_KERNEL_STACK_ORDER ?= 2
  90. STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
  91. ifndef START
  92. START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
  93. endif
  94. CPPFLAGS_vmlinux.lds = -U$(SUBARCH) \
  95. -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
  96. -DELF_FORMAT="$(ELF_FORMAT)" $(CPP_MODE-y) \
  97. -DKERNEL_STACK_SIZE=$(STACK_SIZE) \
  98. -DUNMAP_PATH=arch/um/sys-$(SUBARCH)/unmap_fin.o
  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) \
  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 += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
  116. $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os
  117. archclean:
  118. @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
  119. -o -name '*.gcov' \) -type f -print | xargs rm -f
  120. $(SYMLINK_HEADERS):
  121. @echo ' SYMLINK $@'
  122. ifneq ($(KBUILD_SRC),)
  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 include/asm-um
  132. $(Q)ln -fsn $(srctree)/include/asm-$(SUBARCH) include/asm-um/arch
  133. else
  134. $(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) 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 -sf 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 -sf 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)/user-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.c
  160. $(CC) $(USER_CFLAGS) -S -o $@ $<
  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)/user-offsets.s
  174. $(call filechk,gen-asm-offsets)
  175. CLEAN_FILES += $(ARCH_DIR)/user-offsets.s
  176. $(ARCH_DIR)/include/kern_constants.h: $(objtree)/$(ARCH_DIR)/include
  177. @echo ' SYMLINK $@'
  178. $(Q) ln -sf ../../../include/asm-um/asm-offsets.h $@
  179. export SUBARCH USER_CFLAGS OS