2 # Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 # Licensed under the GPL
7 OS := $(shell uname -s)
8 # We require bash because the vmlinux link and loader script cpp use bash
12 filechk_gen_header = $<
14 core-y += $(ARCH_DIR)/kernel/ \
15 $(ARCH_DIR)/drivers/ \
16 $(ARCH_DIR)/sys-$(SUBARCH)/
18 # Have to precede the include because the included Makefiles reference them.
19 SYMLINK_HEADERS = archparam.h system.h sigcontext.h processor.h ptrace.h \
20 arch-signal.h module.h
21 SYMLINK_HEADERS := $(foreach header,$(SYMLINK_HEADERS),include/asm-um/$(header))
23 ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
24 $(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
26 GEN_HEADERS += $(ARCH_DIR)/include/task.h $(ARCH_DIR)/include/kern_constants.h
28 MAKEFILE-$(CONFIG_MODE_TT) += Makefile-tt
29 MAKEFILE-$(CONFIG_MODE_SKAS) += Makefile-skas
31 ifneq ($(MAKEFILE-y),)
32 include $(addprefix $(srctree)/$(ARCH_DIR)/,$(MAKEFILE-y))
35 ARCH_INCLUDE := -I$(ARCH_DIR)/include
36 SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
38 include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
39 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
41 # -Derrno=kernel_errno - This turns all kernel references to errno into
42 # kernel_errno to separate them from the libc errno. This allows -fno-common
43 # in CFLAGS. Otherwise, it would cause ld to complain about the two different
46 CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
47 -D_LARGEFILE64_SOURCE $(ARCH_INCLUDE) -Derrno=kernel_errno \
48 -Dsigprocmask=kernel_sigprocmask $(MODE_INCLUDE)
50 CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
52 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
54 # These are needed for clean and mrproper, since in that case .config is not
55 # included; the values here are meaningless
57 CONFIG_NEST_LEVEL ?= 0
58 CONFIG_KERNEL_HALF_GIGS ?= 0
60 SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)
62 ifeq ($(CONFIG_MODE_SKAS), y)
63 $(SYS_HEADERS) : $(ARCH_DIR)/include/skas_ptregs.h
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.'
80 prepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS) \
81 $(ARCH_DIR)/kernel/vmlinux.lds.S
83 # These aren't in Makefile-tt because they are needed in the !CONFIG_MODE_TT +
84 # CONFIG_MODE_SKAS + CONFIG_STATIC_LINK case.
87 LD_SCRIPT_TT := uml.lds.S
89 ifeq ($(CONFIG_STATIC_LINK),y)
91 LD_SCRIPT-y := $(LD_SCRIPT_TT)
93 ifeq ($(CONFIG_MODE_TT),y)
95 LD_SCRIPT-y := $(LD_SCRIPT_TT)
97 ifeq ($(CONFIG_MODE_SKAS),y)
98 LINK-y += $(LINK_SKAS)
99 LD_SCRIPT-y := $(LD_SCRIPT_SKAS)
104 CPP_MODE_TT := $(shell [ "$(CONFIG_MODE_TT)" = "y" ] && echo -DMODE_TT)
105 CONFIG_KERNEL_STACK_ORDER ?= 2
106 STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
109 START = $$(($(TOP_ADDR) - $(SIZE)))
112 CPPFLAGS_vmlinux.lds = $(shell echo -U$(SUBARCH) \
113 -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
114 -DELF_FORMAT=\"$(ELF_FORMAT)\" $(CPP_MODE_TT) \
115 -DKERNEL_STACK_SIZE=$(STACK_SIZE))
117 CFLAGS_vmlinux = $(LINK-y) $(LINK_WRAPS)
119 $(CC) $(CFLAGS_vmlinux) -o $@ \
120 -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
121 -Wl,--start-group $(vmlinux-main) -Wl,--end-group \
123 $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) \
124 FORCE ,$^) ; rm -f linux
127 USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
128 USER_CFLAGS := $(patsubst -Derrno=kernel_errno,,$(USER_CFLAGS))
129 USER_CFLAGS := $(patsubst -Dsigprocmask=kernel_sigprocmask,,$(USER_CFLAGS))
130 USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
132 USER_CFLAGS += $(ARCH_USER_CFLAGS)
134 # To get a definition of F_SETSIG
135 USER_CFLAGS += -D_GNU_SOURCE
137 #When cleaning we don't include .config, so we don't include
138 #TT or skas makefiles and don't clean skas_ptregs.h.
139 CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
140 $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h
142 MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
143 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os
149 $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/util
150 @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
151 -o -name '*.gcov' \) -type f -print | xargs rm -f
153 #We need to re-preprocess this when the symlink dest changes.
155 $(ARCH_DIR)/kernel/vmlinux.lds.S: FORCE
157 $(Q)ln -sf $(LD_SCRIPT-y) $@
162 $(Q)cd $(TOPDIR)/$(dir $@) ; \
163 ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
167 $(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
169 $(ARCH_DIR)/include/sysdep:
171 $(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
175 $(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
178 define filechk_umlconfig
179 sed 's/ CONFIG/ UML_CONFIG/'
182 $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
183 $(call filechk,umlconfig)
185 $(ARCH_DIR)/include/task.h: $(ARCH_DIR)/util/mk_task
186 $(call filechk,gen_header)
188 $(ARCH_DIR)/include/kern_constants.h: $(ARCH_DIR)/util/mk_constants
189 $(call filechk,gen_header)
191 $(ARCH_DIR)/include/skas_ptregs.h: $(ARCH_DIR)/kernel/skas/util/mk_ptregs
192 $(call filechk,gen_header)
194 $(ARCH_DIR)/util/mk_task $(ARCH_DIR)/util/mk_constants: $(ARCH_DIR)/util \
197 $(ARCH_DIR)/kernel/skas/util/mk_ptregs: $(ARCH_DIR)/kernel/skas/util FORCE ;
199 $(ARCH_DIR)/util: scripts_basic $(SYS_DIR)/sc.h FORCE
200 $(Q)$(MAKE) $(build)=$@
202 $(ARCH_DIR)/kernel/skas/util: scripts_basic FORCE
203 $(Q)$(MAKE) $(build)=$@
205 export SUBARCH USER_CFLAGS OS