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/ \
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 vm-flags.h
21 SYMLINK_HEADERS := $(foreach header,$(SYMLINK_HEADERS),include/asm-um/$(header))
23 # The "os" symlink is only used by arch/um/include/os.h, which includes
24 # ../os/include/file.h
25 ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
26 $(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
28 GEN_HEADERS += $(ARCH_DIR)/include/task.h $(ARCH_DIR)/include/kern_constants.h
30 um-modes-$(CONFIG_MODE_TT) += tt
31 um-modes-$(CONFIG_MODE_SKAS) += skas
33 MODE_INCLUDE += $(foreach mode,$(um-modes-y),\
34 -I$(srctree)/$(ARCH_DIR)/kernel/$(mode)/include)
36 MAKEFILES-INCL += $(foreach mode,$(um-modes-y),\
37 $(srctree)/$(ARCH_DIR)/Makefile-$(mode))
39 ifneq ($(MAKEFILE-INCL),)
40 include $(MAKEFILE-INCL)
43 ARCH_INCLUDE := -I$(ARCH_DIR)/include
44 SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
46 include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
48 core-y += $(SUBARCH_CORE)
49 libs-y += $(SUBARCH_LIBS)
51 # -Derrno=kernel_errno - This turns all kernel references to errno into
52 # kernel_errno to separate them from the libc errno. This allows -fno-common
53 # in CFLAGS. Otherwise, it would cause ld to complain about the two different
56 CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
57 $(ARCH_INCLUDE) $(MODE_INCLUDE)
59 USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
60 USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
62 CFLAGS += -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask
63 CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
65 #This will adjust *FLAGS accordingly to the platform.
66 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
68 # These are needed for clean and mrproper, since in that case .config is not
69 # included; the values here are meaningless
71 CONFIG_NEST_LEVEL ?= 0
72 CONFIG_KERNEL_HALF_GIGS ?= 0
74 SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)
76 ifeq ($(CONFIG_MODE_SKAS), y)
77 $(SYS_HEADERS) : $(ARCH_DIR)/include/skas_ptregs.h
88 echo '* linux - Binary kernel image (./linux) - for backward'
89 echo ' compatibility only, this creates a hard link to the'
90 echo ' real kernel binary, the the "vmlinux" binary you'
91 echo ' find in the kernel root.'
94 $(shell cd $(ARCH_DIR) && ln -sf Kconfig_$(SUBARCH) Kconfig_arch)
96 prepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS) \
97 $(ARCH_DIR)/kernel/vmlinux.lds.S
99 LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
100 LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
102 LD_SCRIPT-$(CONFIG_LD_SCRIPT_STATIC) := uml.lds.S
103 LD_SCRIPT-$(CONFIG_LD_SCRIPT_DYN) := dyn.lds.S
105 CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
106 CONFIG_KERNEL_STACK_ORDER ?= 2
107 STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
110 START = $$(($(TOP_ADDR) - $(SIZE)))
113 CPPFLAGS_vmlinux.lds = $(shell echo -U$(SUBARCH) \
114 -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
115 -DELF_FORMAT=\"$(ELF_FORMAT)\" $(CPP_MODE-y) \
116 -DKERNEL_STACK_SIZE=$(STACK_SIZE))
118 #The wrappers will select whether using "malloc" or the kernel allocator.
119 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
121 CFLAGS_vmlinux = $(LINK-y) $(LINK_WRAPS)
123 $(CC) $(CFLAGS_vmlinux) -o $@ \
124 -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
125 -Wl,--start-group $(vmlinux-main) -Wl,--end-group \
127 $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) \
128 FORCE ,$^) ; rm -f linux
131 #When cleaning we don't include .config, so we don't include
132 #TT or skas makefiles and don't clean skas_ptregs.h.
133 CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
134 $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h
136 MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
137 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os
140 $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/util
141 @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
142 -o -name '*.gcov' \) -type f -print | xargs rm -f
144 #We need to re-preprocess this when the symlink dest changes.
145 #So we touch it when needed.
146 $(ARCH_DIR)/kernel/vmlinux.lds.S: FORCE
147 $(Q)if [ "$(shell readlink $@)" != "$(LD_SCRIPT-y)" ]; then \
148 echo ' SYMLINK $@'; \
149 ln -sf $(LD_SCRIPT-y) $@; \
155 $(Q)cd $(TOPDIR)/$(dir $@) ; \
156 ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
160 $(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
162 $(ARCH_DIR)/include/sysdep:
164 $(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
168 $(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
171 define filechk_umlconfig
172 sed 's/ CONFIG/ UML_CONFIG/'
175 $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
176 $(call filechk,umlconfig)
178 $(ARCH_DIR)/include/task.h: $(ARCH_DIR)/util/mk_task
179 $(call filechk,gen_header)
181 $(ARCH_DIR)/include/kern_constants.h: $(ARCH_DIR)/util/mk_constants
182 $(call filechk,gen_header)
184 $(ARCH_DIR)/include/skas_ptregs.h: $(ARCH_DIR)/kernel/skas/util/mk_ptregs
185 $(call filechk,gen_header)
187 $(ARCH_DIR)/util/mk_task $(ARCH_DIR)/util/mk_constants: $(ARCH_DIR)/util \
190 $(ARCH_DIR)/kernel/skas/util/mk_ptregs: $(ARCH_DIR)/kernel/skas/util FORCE ;
192 $(ARCH_DIR)/util: scripts_basic $(SYS_DIR)/sc.h FORCE
193 $(Q)$(MAKE) $(build)=$@
195 $(ARCH_DIR)/kernel/skas/util: scripts_basic FORCE
196 $(Q)$(MAKE) $(build)=$@
198 export SUBARCH USER_CFLAGS OS