Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. arch-signal.h module.h vm-flags.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. GEN_HEADERS += $(ARCH_DIR)/include/task.h $(ARCH_DIR)/include/kern_constants.h
  26. um-modes-$(CONFIG_MODE_TT) += tt
  27. um-modes-$(CONFIG_MODE_SKAS) += skas
  28. MODE_INCLUDE += $(foreach mode,$(um-modes-y),\
  29. -I$(srctree)/$(ARCH_DIR)/kernel/$(mode)/include)
  30. MAKEFILES-INCL += $(foreach mode,$(um-modes-y),\
  31. $(srctree)/$(ARCH_DIR)/Makefile-$(mode))
  32. ifneq ($(MAKEFILES-INCL),)
  33. include $(MAKEFILES-INCL)
  34. endif
  35. ARCH_INCLUDE := -I$(ARCH_DIR)/include
  36. SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
  37. include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
  38. core-y += $(SUBARCH_CORE)
  39. libs-y += $(SUBARCH_LIBS)
  40. # -Derrno=kernel_errno - This turns all kernel references to errno into
  41. # kernel_errno to separate them from the libc errno. This allows -fno-common
  42. # in CFLAGS. Otherwise, it would cause ld to complain about the two different
  43. # errnos.
  44. CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
  45. $(ARCH_INCLUDE) $(MODE_INCLUDE)
  46. USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
  47. USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
  48. $(MODE_INCLUDE) $(ARCH_USER_CFLAGS)
  49. CFLAGS += -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask
  50. CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
  51. #This will adjust *FLAGS accordingly to the platform.
  52. include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
  53. # These are needed for clean and mrproper, since in that case .config is not
  54. # included; the values here are meaningless
  55. CONFIG_NEST_LEVEL ?= 0
  56. CONFIG_KERNEL_HALF_GIGS ?= 0
  57. SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)
  58. ifeq ($(CONFIG_MODE_SKAS), y)
  59. $(SYS_HEADERS) : $(ARCH_DIR)/include/skas_ptregs.h
  60. endif
  61. .PHONY: linux
  62. all: linux
  63. linux: vmlinux
  64. ln -f $< $@
  65. define archhelp
  66. echo '* linux - Binary kernel image (./linux) - for backward'
  67. echo ' compatibility only, this creates a hard link to the'
  68. echo ' real kernel binary, the the "vmlinux" binary you'
  69. echo ' find in the kernel root.'
  70. endef
  71. $(shell cd $(ARCH_DIR) && ln -sf Kconfig_$(SUBARCH) Kconfig_arch)
  72. prepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS) \
  73. $(ARCH_DIR)/kernel/vmlinux.lds.S
  74. LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
  75. LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
  76. LD_SCRIPT-$(CONFIG_LD_SCRIPT_STATIC) := uml.lds.S
  77. LD_SCRIPT-$(CONFIG_LD_SCRIPT_DYN) := dyn.lds.S
  78. CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
  79. CONFIG_KERNEL_STACK_ORDER ?= 2
  80. STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
  81. ifndef START
  82. START = $$(($(TOP_ADDR) - $(SIZE)))
  83. endif
  84. CPPFLAGS_vmlinux.lds = $(shell echo -U$(SUBARCH) \
  85. -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
  86. -DELF_FORMAT=\"$(ELF_FORMAT)\" $(CPP_MODE-y) \
  87. -DKERNEL_STACK_SIZE=$(STACK_SIZE))
  88. #The wrappers will select whether using "malloc" or the kernel allocator.
  89. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
  90. CFLAGS_vmlinux = $(LINK-y) $(LINK_WRAPS)
  91. define cmd_vmlinux__
  92. $(CC) $(CFLAGS_vmlinux) -o $@ \
  93. -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
  94. -Wl,--start-group $(vmlinux-main) -Wl,--end-group \
  95. -L/usr/lib -lutil \
  96. $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) \
  97. FORCE ,$^) ; rm -f linux
  98. endef
  99. #When cleaning we don't include .config, so we don't include
  100. #TT or skas makefiles and don't clean skas_ptregs.h.
  101. CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
  102. $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h
  103. MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
  104. $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os \
  105. $(ARCH_DIR)/Kconfig_arch
  106. archclean:
  107. $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/util
  108. @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
  109. -o -name '*.gcov' \) -type f -print | xargs rm -f
  110. #We need to re-preprocess this when the symlink dest changes.
  111. #So we touch it when needed.
  112. $(ARCH_DIR)/kernel/vmlinux.lds.S: FORCE
  113. $(Q)if [ "$(shell readlink $@)" != "$(LD_SCRIPT-y)" ]; then \
  114. echo ' SYMLINK $@'; \
  115. ln -sf $(LD_SCRIPT-y) $@; \
  116. touch $@; \
  117. fi;
  118. $(SYMLINK_HEADERS):
  119. @echo ' SYMLINK $@'
  120. $(Q)cd $(TOPDIR)/$(dir $@) ; \
  121. ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
  122. include/asm-um/arch:
  123. @echo ' SYMLINK $@'
  124. $(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
  125. $(ARCH_DIR)/include/sysdep:
  126. @echo ' SYMLINK $@'
  127. $(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
  128. $(ARCH_DIR)/os:
  129. @echo ' SYMLINK $@'
  130. $(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
  131. # Generated files
  132. define filechk_umlconfig
  133. sed 's/ CONFIG/ UML_CONFIG/'
  134. endef
  135. $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
  136. $(call filechk,umlconfig)
  137. $(ARCH_DIR)/include/task.h: $(ARCH_DIR)/util/mk_task
  138. $(call filechk,gen_header)
  139. $(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/os/util/mk_user_constants
  140. $(call filechk,gen_header)
  141. $(ARCH_DIR)/include/kern_constants.h: $(ARCH_DIR)/util/mk_constants
  142. $(call filechk,gen_header)
  143. $(ARCH_DIR)/include/skas_ptregs.h: $(ARCH_DIR)/kernel/skas/util/mk_ptregs
  144. $(call filechk,gen_header)
  145. $(ARCH_DIR)/os/util/mk_user_constants: $(ARCH_DIR)/os/util FORCE ;
  146. $(ARCH_DIR)/util/mk_task $(ARCH_DIR)/util/mk_constants: $(ARCH_DIR)/include/user_constants.h $(ARCH_DIR)/util \
  147. FORCE ;
  148. $(ARCH_DIR)/kernel/skas/util/mk_ptregs: $(ARCH_DIR)/kernel/skas/util FORCE ;
  149. $(ARCH_DIR)/util: scripts_basic $(SYS_DIR)/sc.h FORCE
  150. $(Q)$(MAKE) $(build)=$@
  151. $(ARCH_DIR)/kernel/skas/util: scripts_basic FORCE
  152. $(Q)$(MAKE) $(build)=$@
  153. $(ARCH_DIR)/os/util: scripts_basic FORCE
  154. $(Q)$(MAKE) $(build)=$@
  155. export SUBARCH USER_CFLAGS OS