Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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
  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. ifneq ($(KBUILD_SRC),)
  37. ARCH_INCLUDE += -I$(ARCH_DIR)/include2
  38. ARCH_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include
  39. MRPROPER_DIRS += $(ARCH_DIR)/include2
  40. endif
  41. SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
  42. # -Dvmap=kernel_vmap affects everything, and prevents anything from
  43. # referencing the libpcap.o symbol so named.
  44. CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
  45. $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap
  46. AFLAGS += $(ARCH_INCLUDE)
  47. USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
  48. USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
  49. $(MODE_INCLUDE)
  50. # -Derrno=kernel_errno - This turns all kernel references to errno into
  51. # kernel_errno to separate them from the libc errno. This allows -fno-common
  52. # in CFLAGS. Otherwise, it would cause ld to complain about the two different
  53. # errnos.
  54. CFLAGS += -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask
  55. CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
  56. include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
  57. #This will adjust *FLAGS accordingly to the platform.
  58. include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
  59. # These are needed for clean and mrproper, since in that case .config is not
  60. # included; the values here are meaningless
  61. CONFIG_NEST_LEVEL ?= 0
  62. CONFIG_KERNEL_HALF_GIGS ?= 0
  63. SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)
  64. ifeq ($(CONFIG_MODE_SKAS), y)
  65. $(SYS_HEADERS) : $(ARCH_DIR)/include/skas_ptregs.h
  66. endif
  67. .PHONY: linux
  68. all: linux
  69. linux: vmlinux
  70. ln -f $< $@
  71. define archhelp
  72. echo '* linux - Binary kernel image (./linux) - for backward'
  73. echo ' compatibility only, this creates a hard link to the'
  74. echo ' real kernel binary, the the "vmlinux" binary you'
  75. echo ' find in the kernel root.'
  76. endef
  77. ifneq ($(KBUILD_SRC),)
  78. $(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch)
  79. else
  80. $(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch)
  81. endif
  82. archprepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS)
  83. LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
  84. LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
  85. CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
  86. CONFIG_KERNEL_STACK_ORDER ?= 2
  87. STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
  88. ifndef START
  89. START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
  90. endif
  91. CPPFLAGS_vmlinux.lds = -U$(SUBARCH) \
  92. -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
  93. -DELF_FORMAT="$(ELF_FORMAT)" $(CPP_MODE-y) \
  94. -DKERNEL_STACK_SIZE=$(STACK_SIZE) \
  95. -DUNMAP_PATH=arch/um/sys-$(SUBARCH)/unmap_fin.o
  96. #The wrappers will select whether using "malloc" or the kernel allocator.
  97. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
  98. CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS)
  99. define cmd_vmlinux__
  100. $(CC) $(CFLAGS_vmlinux) -o $@ \
  101. -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
  102. -Wl,--start-group $(vmlinux-main) -Wl,--end-group \
  103. -lutil \
  104. $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) \
  105. FORCE ,$^) ; rm -f linux
  106. endef
  107. #When cleaning we don't include .config, so we don't include
  108. #TT or skas makefiles and don't clean skas_ptregs.h.
  109. CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
  110. $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h \
  111. $(ARCH_DIR)/include/user_constants.h $(ARCH_DIR)/Kconfig.arch
  112. MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
  113. $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os
  114. archclean:
  115. $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/util
  116. $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/os-$(OS)/util
  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. ln -fsn $(srctree)/include/asm-um/$(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $@
  123. else
  124. $(Q)cd $(TOPDIR)/$(dir $@) ; \
  125. ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
  126. endif
  127. include/asm-um/arch:
  128. @echo ' SYMLINK $@'
  129. ifneq ($(KBUILD_SRC),)
  130. $(Q)mkdir -p include/asm-um
  131. $(Q)ln -fsn $(srctree)/include/asm-$(SUBARCH) include/asm-um/arch
  132. else
  133. $(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
  134. endif
  135. $(ARCH_DIR)/include/sysdep:
  136. @echo ' SYMLINK $@'
  137. ifneq ($(KBUILD_SRC),)
  138. $(Q)mkdir -p $(ARCH_DIR)/include
  139. $(Q)mkdir -p $(ARCH_DIR)/include2
  140. $(Q)ln -fsn sysdep-$(SUBARCH) $(ARCH_DIR)/include/sysdep
  141. $(Q)ln -fsn $(srctree)/$(ARCH_DIR)/include/sysdep-$(SUBARCH) $(ARCH_DIR)/include2/sysdep
  142. else
  143. $(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
  144. endif
  145. $(ARCH_DIR)/os:
  146. @echo ' SYMLINK $@'
  147. ifneq ($(KBUILD_SRC),)
  148. $(Q)ln -fsn $(srctree)/$(ARCH_DIR)/os-$(OS) $(ARCH_DIR)/os
  149. else
  150. $(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
  151. endif
  152. # Generated files
  153. define filechk_umlconfig
  154. sed 's/ CONFIG/ UML_CONFIG/'
  155. endef
  156. define filechk_gen-asm-offsets
  157. (set -e; \
  158. echo "#ifndef __ASM_OFFSETS_H__"; \
  159. echo "#define __ASM_OFFSETS_H__"; \
  160. echo "/*"; \
  161. echo " * DO NOT MODIFY."; \
  162. echo " *"; \
  163. echo " * This file was generated by arch/$(ARCH)/Makefile"; \
  164. echo " *"; \
  165. echo " */"; \
  166. echo ""; \
  167. sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
  168. echo ""; \
  169. echo "#endif" )
  170. endef
  171. $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
  172. $(call filechk,umlconfig)
  173. $(ARCH_DIR)/user-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.c
  174. $(CC) $(USER_CFLAGS) -S -o $@ $<
  175. $(ARCH_DIR)/user-offsets.h: $(ARCH_DIR)/user-offsets.s
  176. $(call filechk,gen-asm-offsets)
  177. CLEAN_FILES += $(ARCH_DIR)/user-offsets.s $(ARCH_DIR)/user-offsets.h
  178. $(ARCH_DIR)/kernel-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/kernel-offsets.c \
  179. $(ARCH_SYMLINKS) \
  180. $(SYS_DIR)/sc.h \
  181. include/asm include/linux/version.h \
  182. include/config/MARKER \
  183. $(ARCH_DIR)/include/user_constants.h
  184. $(CC) $(CFLAGS) $(NOSTDINC_FLAGS) $(CPPFLAGS) -S -o $@ $<
  185. $(ARCH_DIR)/kernel-offsets.h: $(ARCH_DIR)/kernel-offsets.s
  186. $(call filechk,gen-asm-offsets)
  187. CLEAN_FILES += $(ARCH_DIR)/kernel-offsets.s $(ARCH_DIR)/kernel-offsets.h
  188. $(ARCH_DIR)/include/task.h: $(ARCH_DIR)/util/mk_task
  189. $(call filechk,gen_header)
  190. $(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/os-$(OS)/util/mk_user_constants
  191. $(call filechk,gen_header)
  192. $(ARCH_DIR)/include/kern_constants.h: $(ARCH_DIR)/util/mk_constants
  193. $(call filechk,gen_header)
  194. $(ARCH_DIR)/include/skas_ptregs.h: $(ARCH_DIR)/kernel/skas/util/mk_ptregs
  195. $(call filechk,gen_header)
  196. $(ARCH_DIR)/os-$(OS)/util/mk_user_constants: $(ARCH_DIR)/os-$(OS)/util FORCE ;
  197. $(ARCH_DIR)/util/mk_task $(ARCH_DIR)/util/mk_constants: $(ARCH_DIR)/include/user_constants.h $(ARCH_DIR)/util \
  198. FORCE ;
  199. $(ARCH_DIR)/kernel/skas/util/mk_ptregs: $(ARCH_DIR)/kernel/skas/util FORCE ;
  200. $(ARCH_DIR)/util: scripts_basic $(SYS_DIR)/sc.h $(ARCH_DIR)/kernel-offsets.h FORCE
  201. $(Q)$(MAKE) $(build)=$@
  202. $(ARCH_DIR)/kernel/skas/util: scripts_basic $(ARCH_DIR)/user-offsets.h FORCE
  203. $(Q)$(MAKE) $(build)=$@
  204. $(ARCH_DIR)/os-$(OS)/util: scripts_basic $(ARCH_DIR)/user-offsets.h FORCE
  205. $(Q)$(MAKE) $(build)=$@
  206. export SUBARCH USER_CFLAGS OS