2 # Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 # Licensed under the GPL
7 OS := $(shell uname -s)
8 #We require it or things break.
11 filechk_gen_header = $<
13 core-y += $(ARCH_DIR)/kernel/ \
14 $(ARCH_DIR)/drivers/ \
15 $(ARCH_DIR)/sys-$(SUBARCH)/
17 # Have to precede the include because the included Makefiles reference them.
18 SYMLINK_HEADERS = archparam.h system.h sigcontext.h processor.h ptrace.h \
19 arch-signal.h module.h
20 SYMLINK_HEADERS := $(foreach header,$(SYMLINK_HEADERS),include/asm-um/$(header))
22 ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
23 $(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
25 GEN_HEADERS += $(ARCH_DIR)/include/task.h $(ARCH_DIR)/include/kern_constants.h
27 MAKEFILE-$(CONFIG_MODE_TT) += Makefile-tt
28 MAKEFILE-$(CONFIG_MODE_SKAS) += Makefile-skas
30 ifneq ($(MAKEFILE-y),)
31 include $(addprefix $(ARCH_DIR)/,$(MAKEFILE-y))
34 ARCH_INCLUDE := -I$(ARCH_DIR)/include
35 SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
37 include $(ARCH_DIR)/Makefile-$(SUBARCH)
38 include $(ARCH_DIR)/Makefile-os-$(OS)
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
45 CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
46 -D_LARGEFILE64_SOURCE $(ARCH_INCLUDE) -Derrno=kernel_errno \
47 -Dsigprocmask=kernel_sigprocmask $(MODE_INCLUDE)
49 CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
51 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
53 # These are needed for clean and mrproper, since in that case .config is not
54 # included; the values here are meaningless
56 CONFIG_NEST_LEVEL ?= 0
57 CONFIG_KERNEL_HALF_GIGS ?= 0
59 SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)
61 ifeq ($(CONFIG_MODE_SKAS), y)
62 $(SYS_HEADERS) : $(ARCH_DIR)/include/skas_ptregs.h
65 prepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS) \
66 $(ARCH_DIR)/kernel/vmlinux.lds.S
68 # These aren't in Makefile-tt because they are needed in the !CONFIG_MODE_TT +
69 # CONFIG_MODE_SKAS + CONFIG_STATIC_LINK case.
72 LD_SCRIPT_TT := uml.lds.S
74 ifeq ($(CONFIG_STATIC_LINK),y)
76 LD_SCRIPT-y := $(LD_SCRIPT_TT)
78 ifeq ($(CONFIG_MODE_TT),y)
80 LD_SCRIPT-y := $(LD_SCRIPT_TT)
82 ifeq ($(CONFIG_MODE_SKAS),y)
83 LINK-y += $(LINK_SKAS)
84 LD_SCRIPT-y := $(LD_SCRIPT_SKAS)
89 CPP_MODE_TT := $(shell [ "$(CONFIG_MODE_TT)" = "y" ] && echo -DMODE_TT)
90 CONFIG_KERNEL_STACK_ORDER ?= 2
91 STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
94 START = $$(($(TOP_ADDR) - $(SIZE)))
97 CPPFLAGS_vmlinux.lds = $(shell echo -U$(SUBARCH) \
98 -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
99 -DELF_FORMAT=\"$(ELF_FORMAT)\" $(CPP_MODE_TT) \
100 -DKERNEL_STACK_SIZE=$(STACK_SIZE))
102 CFLAGS_vmlinux = $(LINK-y) $(LINK_WRAPS)
104 $(CC) $(CFLAGS_vmlinux) -o $@ \
105 -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
106 -Wl,--start-group $(vmlinux-main) -Wl,--end-group \
108 $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
111 USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
112 USER_CFLAGS := $(patsubst -Derrno=kernel_errno,,$(USER_CFLAGS))
113 USER_CFLAGS := $(patsubst -Dsigprocmask=kernel_sigprocmask,,$(USER_CFLAGS))
114 USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
117 # To get a definition of F_SETSIG
118 USER_CFLAGS += -D_GNU_SOURCE
120 #When cleaning we don't include .config, so we don't include
121 #TT or skas makefiles and don't clean skas_ptregs.h.
122 CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
123 $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h
125 MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
126 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os
132 $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/util
133 @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
134 -o -name '*.gcov' \) -type f -print | xargs rm -f
136 #We need to re-preprocess this when the symlink dest changes.
138 $(ARCH_DIR)/kernel/vmlinux.lds.S: FORCE
140 $(Q)ln -sf $(LD_SCRIPT-y) $@
145 $(Q)cd $(TOPDIR)/$(dir $@) ; \
146 ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
150 $(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
152 $(ARCH_DIR)/include/sysdep:
154 $(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
158 $(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
161 define filechk_umlconfig
162 sed 's/ CONFIG/ UML_CONFIG/'
165 $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
166 $(call filechk,umlconfig)
168 $(ARCH_DIR)/include/task.h: $(ARCH_DIR)/util/mk_task
169 $(call filechk,gen_header)
171 $(ARCH_DIR)/include/kern_constants.h: $(ARCH_DIR)/util/mk_constants
172 $(call filechk,gen_header)
174 $(ARCH_DIR)/include/skas_ptregs.h: $(ARCH_DIR)/kernel/skas/util/mk_ptregs
175 $(call filechk,gen_header)
177 $(ARCH_DIR)/util/mk_task $(ARCH_DIR)/util/mk_constants: $(ARCH_DIR)/util \
180 $(ARCH_DIR)/kernel/skas/util/mk_ptregs: $(ARCH_DIR)/kernel/skas/util FORCE ;
182 $(ARCH_DIR)/util: scripts_basic $(SYS_DIR)/sc.h FORCE
183 $(Q)$(MAKE) $(build)=$@
185 $(ARCH_DIR)/kernel/skas/util: scripts_basic FORCE
186 $(Q)$(MAKE) $(build)=$@
189 echo '* linux - Binary kernel image (./linux)'