2 # Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 # Licensed under the GPL
7 OS := $(shell uname -s)
9 # Recalculate MODLIB to reflect the EXTRAVERSION changes (via KERNELRELEASE)
10 # The way the toplevel Makefile is written EXTRAVERSION is not supposed
11 # to be changed outside the toplevel Makefile, but recalculating MODLIB is
12 # a sufficient workaround until we no longer need architecture dependent
14 MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
16 ifeq ($(CONFIG_DEBUG_INFO),y)
17 CFLAGS := $(subst -fomit-frame-pointer,,$(CFLAGS))
20 core-y += $(ARCH_DIR)/kernel/ \
21 $(ARCH_DIR)/drivers/ \
22 $(ARCH_DIR)/sys-$(SUBARCH)/
24 # Have to precede the include because the included Makefiles reference them.
25 SYMLINK_HEADERS = archparam.h system.h sigcontext.h processor.h ptrace.h \
26 arch-signal.h module.h
27 SYMLINK_HEADERS := $(foreach header,$(SYMLINK_HEADERS),include/asm-um/$(header))
29 ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
30 $(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
32 GEN_HEADERS += $(ARCH_DIR)/include/task.h $(ARCH_DIR)/include/kern_constants.h
34 # This target adds dependencies to "prepare". They are defined in the included
35 # Makefiles (see Makefile-i386).
41 MAKEFILE-$(CONFIG_MODE_TT) += Makefile-tt
42 MAKEFILE-$(CONFIG_MODE_SKAS) += Makefile-skas
44 ifneq ($(MAKEFILE-y),)
45 include $(addprefix $(ARCH_DIR)/,$(MAKEFILE-y))
48 include $(ARCH_DIR)/Makefile-$(SUBARCH)
49 include $(ARCH_DIR)/Makefile-os-$(OS)
51 EXTRAVERSION := $(EXTRAVERSION)-2um
53 ARCH_INCLUDE = -I$(ARCH_DIR)/include
55 # -Derrno=kernel_errno - This turns all kernel references to errno into
56 # kernel_errno to separate them from the libc errno. This allows -fno-common
57 # in CFLAGS. Otherwise, it would cause ld to complain about the two different
60 CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
61 -D_LARGEFILE64_SOURCE $(ARCH_INCLUDE) -Derrno=kernel_errno \
62 -Dsigprocmask=kernel_sigprocmask $(MODE_INCLUDE)
64 check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
66 CFLAGS += $(call check_gcc,-fno-unit-at-a-time,)
68 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
70 # These are needed for clean and mrproper, since in that case .config is not
71 # included; the values here are meaningless
73 CONFIG_NEST_LEVEL ?= 0
74 CONFIG_KERNEL_HALF_GIGS ?= 0
76 SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)
78 ifeq ($(CONFIG_MODE_SKAS), y)
79 $(SYS_HEADERS) : $(TOPDIR)/$(ARCH_DIR)/include/skas_ptregs.h
82 include/linux/version.h: arch/$(ARCH)/Makefile
84 $(ARCH_DIR)/vmlinux.lds.S :
87 prepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS)
91 vmlinux: $(ARCH_DIR)/main.o
93 # These aren't in Makefile-tt because they are needed in the !CONFIG_MODE_TT +
94 # CONFIG_MODE_SKAS + CONFIG_STATIC_LINK case.
97 LD_SCRIPT_TT := uml.lds.s
99 ifeq ($(CONFIG_STATIC_LINK),y)
101 LD_SCRIPT-y := $(LD_SCRIPT_TT)
103 ifeq ($(CONFIG_MODE_TT),y)
105 LD_SCRIPT-y := $(LD_SCRIPT_TT)
107 ifeq ($(CONFIG_MODE_SKAS),y)
108 LINK-y += $(LINK_SKAS)
109 LD_SCRIPT-y := $(LD_SCRIPT_SKAS)
114 CPP_MODE_TT := $(shell [ "$(CONFIG_MODE_TT)" = "y" ] && echo -DMODE_TT)
115 CONFIG_KERNEL_STACK_ORDER ?= 2
116 STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
119 START = $$(($(TOP_ADDR) - $(SIZE)))
122 AFLAGS_vmlinux.lds.o = $(shell echo -U$(SUBARCH) \
123 -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
124 -DELF_FORMAT=\"$(ELF_FORMAT)\" $(CPP_MODE_TT) \
125 -DKERNEL_STACK_SIZE=$(STACK_SIZE))
127 export AFLAGS_$(LD_SCRIPT-y:.s=).o = $(AFLAGS_vmlinux.lds.o) -P -C -Uum
129 LD_SCRIPT-y := $(ARCH_DIR)/$(LD_SCRIPT-y)
131 #$(LD_SCRIPT-y) : $(LD_SCRIPT-y:.s=.S) scripts FORCE
132 # $(call if_changed_dep,as_s_S)
134 linux: vmlinux $(LD_SCRIPT-y)
135 $(CC) -Wl,-T,$(LD_SCRIPT-y) $(LINK-y) $(LINK_WRAPS) \
136 -o linux $(ARCH_DIR)/main.o vmlinux -L/usr/lib -lutil
138 USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
139 USER_CFLAGS := $(patsubst -Derrno=kernel_errno,,$(USER_CFLAGS))
140 USER_CFLAGS := $(patsubst -Dsigprocmask=kernel_sigprocmask,,$(USER_CFLAGS))
141 USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
144 # To get a definition of F_SETSIG
145 USER_CFLAGS += -D_GNU_SOURCE
147 # From main Makefile, these options are set after including the ARCH makefile.
150 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
156 ifndef CONFIG_FRAME_POINTER
157 USER_CFLAGS += -fomit-frame-pointer
160 ifdef CONFIG_DEBUG_INFO
164 CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/uml.lds.s \
165 $(ARCH_DIR)/dyn_link.ld.s $(ARCH_DIR)/include/uml-config.h \
168 MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
169 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS))
171 $(ARCH_DIR)/main.o: $(ARCH_DIR)/main.c sys_prepare
173 @ $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
179 @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
180 -o -name '*.gcov' \) -type f -print | xargs rm -f
183 cd $(TOPDIR)/$(dir $@) ; \
184 ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
187 cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
189 $(ARCH_DIR)/include/sysdep:
190 cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
193 cd $(ARCH_DIR) && ln -sf os-$(OS) os
196 define filechk_umlconfig
197 sed 's/ CONFIG/ UML_CONFIG/'
200 $(ARCH_DIR)/include/uml-config.h : $(TOPDIR)/include/linux/autoconf.h
201 $(call filechk,umlconfig)
203 filechk_gen_header = $<
205 $(ARCH_DIR)/include/task.h : $(ARCH_DIR)/util/mk_task
206 $(call filechk,gen_header)
208 $(ARCH_DIR)/include/kern_constants.h : $(ARCH_DIR)/util/mk_constants
209 $(call filechk,gen_header)
211 $(ARCH_DIR)/util/mk_task $(ARCH_DIR)/util/mk_constants : $(ARCH_DIR)/util \
214 $(ARCH_DIR)/util: FORCE
215 $(Q)$(MAKE) $(build)=$@
217 export SUBARCH USER_CFLAGS OS
222 echo '* linux - Binary kernel image (./linux)'