Makefile 7.2 KB
Newer Older
1 2 3 4
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies.
#
L
Linus Torvalds 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#

ARCH_DIR := arch/um
OS := $(shell uname -s)
# We require bash because the vmlinux link and loader script cpp use bash
# features.
SHELL := /bin/bash

filechk_gen_header = $<

core-y			+= $(ARCH_DIR)/kernel/		\
			   $(ARCH_DIR)/drivers/		\
			   $(ARCH_DIR)/os-$(OS)/

# Have to precede the include because the included Makefiles reference them.
SYMLINK_HEADERS := archparam.h system.h sigcontext.h processor.h ptrace.h \
23
	module.h vm-flags.h elf.h host_ldt.h
L
Linus Torvalds 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37
SYMLINK_HEADERS := $(foreach header,$(SYMLINK_HEADERS),include/asm-um/$(header))

# XXX: The "os" symlink is only used by arch/um/include/os.h, which includes
# ../os/include/file.h
#
# These are cleaned up during mrproper. Please DO NOT fix it again, this is
# the Correct Thing(tm) to do!
ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
	$(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h

um-modes-$(CONFIG_MODE_TT) += tt
um-modes-$(CONFIG_MODE_SKAS) += skas

MODE_INCLUDE	+= $(foreach mode,$(um-modes-y),\
38
		   -I$(srctree)/$(ARCH_DIR)/include/$(mode))
L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46 47

MAKEFILES-INCL	+= $(foreach mode,$(um-modes-y),\
		   $(srctree)/$(ARCH_DIR)/Makefile-$(mode))

ifneq ($(MAKEFILES-INCL),)
  include $(MAKEFILES-INCL)
endif

ARCH_INCLUDE	:= -I$(ARCH_DIR)/include
48 49 50
ifneq ($(KBUILD_SRC),)
ARCH_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/include
endif
L
Linus Torvalds 已提交
51 52
SYS_DIR		:= $(ARCH_DIR)/include/sysdep-$(SUBARCH)

53 54
# -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
# named - it's a common symbol in libpcap, so we get a binary which crashes.
55
#
56 57 58 59
# Same things for in6addr_loopback and mktime - found in libc. For these two we
# only get link-time error, luckily.
#
# These apply to USER_CFLAGS to.
L
Linus Torvalds 已提交
60

61 62
CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\"	\
	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
63 64
	-Din6addr_loopback=kernel_in6addr_loopback

A
Al Viro 已提交
65
AFLAGS += $(ARCH_INCLUDE)
L
Linus Torvalds 已提交
66

67 68 69 70 71 72 73 74
USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
	$(patsubst -I%,,$(CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
	-D_FILE_OFFSET_BITS=64

include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)

#This will adjust *FLAGS accordingly to the platform.
include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
75 76 77 78 79

# -Derrno=kernel_errno - This turns all kernel references to errno into
# kernel_errno to separate them from the libc errno.  This allows -fno-common
# in CFLAGS.  Otherwise, it would cause ld to complain about the two different
# errnos.
80
# These apply to kernelspace only.
81

82 83 84
KERNEL_DEFINES = -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
	-Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)
CFLAGS += $(KERNEL_DEFINES)
L
Linus Torvalds 已提交
85 86 87 88 89 90 91 92 93 94
CFLAGS += $(call cc-option,-fno-unit-at-a-time,)

# These are needed for clean and mrproper, since in that case .config is not
# included; the values here are meaningless

CONFIG_NEST_LEVEL ?= 0
CONFIG_KERNEL_HALF_GIGS ?= 0

SIZE = (($(CONFIG_NEST_LEVEL) + $(CONFIG_KERNEL_HALF_GIGS)) * 0x20000000)

95
PHONY += linux
L
Linus Torvalds 已提交
96 97 98 99

all: linux

linux: vmlinux
100
	@echo '  LINK $@'
101
	$(Q)ln -f $< $@
L
Linus Torvalds 已提交
102 103 104 105

define archhelp
  echo '* linux		- Binary kernel image (./linux) - for backward'
  echo '		   compatibility only, this creates a hard link to the'
M
Matt LaPlante 已提交
106
  echo '		   real kernel binary, the "vmlinux" binary you'
L
Linus Torvalds 已提交
107 108 109
  echo '		   find in the kernel root.'
endef

110
ifneq ($(KBUILD_SRC),)
111
$(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch)
112
else
113
$(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch)
114
endif
L
Linus Torvalds 已提交
115

A
Al Viro 已提交
116 117
archprepare: $(ARCH_SYMLINKS) $(ARCH_DIR)/include/user_constants.h
prepare: $(ARCH_DIR)/include/kern_constants.h
L
Linus Torvalds 已提交
118 119 120 121

LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib

122 123 124 125
CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
	$(call cc-option, -fno-stack-protector,) \
	$(call cc-option, -fno-stack-protector-all,)

L
Linus Torvalds 已提交
126 127 128 129 130
CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
CONFIG_KERNEL_STACK_ORDER ?= 2
STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )

ifndef START
131
  START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
L
Linus Torvalds 已提交
132 133
endif

134
CPPFLAGS_vmlinux.lds = -U$(SUBARCH) \
L
Linus Torvalds 已提交
135
	-DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
136 137
	-DELF_FORMAT="$(ELF_FORMAT)" $(CPP_MODE-y) \
	-DKERNEL_STACK_SIZE=$(STACK_SIZE) \
138
	-DUNMAP_PATH=arch/um/sys-$(SUBARCH)/unmap.o
L
Linus Torvalds 已提交
139 140 141 142

#The wrappers will select whether using "malloc" or the kernel allocator.
LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

143
CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS)
L
Linus Torvalds 已提交
144 145 146 147
define cmd_vmlinux__
	$(CC) $(CFLAGS_vmlinux) -o $@ \
	-Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
	-Wl,--start-group $(vmlinux-main) -Wl,--end-group \
148
	-lutil \
L
Linus Torvalds 已提交
149 150 151 152 153 154 155
	$(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) \
	FORCE ,$^) ; rm -f linux
endef

#When cleaning we don't include .config, so we don't include
#TT or skas makefiles and don't clean skas_ptregs.h.
CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
A
Al Viro 已提交
156 157
	$(ARCH_DIR)/include/user_constants.h \
	$(ARCH_DIR)/include/kern_constants.h $(ARCH_DIR)/Kconfig.arch
L
Linus Torvalds 已提交
158

159
MRPROPER_FILES += $(ARCH_SYMLINKS)
L
Linus Torvalds 已提交
160 161 162 163 164 165 166

archclean:
	@find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
		-o -name '*.gcov' \) -type f -print | xargs rm -f

$(SYMLINK_HEADERS):
	@echo '  SYMLINK $@'
167
ifneq ($(KBUILD_SRC),)
168
	$(Q)mkdir -p $(objtree)/include/asm-um
169
	$(Q)ln -fsn $(srctree)/include/asm-um/$(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $@
170
else
L
Linus Torvalds 已提交
171 172
	$(Q)cd $(TOPDIR)/$(dir $@) ; \
	ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
173
endif
L
Linus Torvalds 已提交
174 175 176

include/asm-um/arch:
	@echo '  SYMLINK $@'
177
ifneq ($(KBUILD_SRC),)
178
	$(Q)mkdir -p $(objtree)/include/asm-um
179 180
	$(Q)ln -fsn $(srctree)/include/asm-$(SUBARCH) include/asm-um/arch
else
L
Linus Torvalds 已提交
181
	$(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
182
endif
L
Linus Torvalds 已提交
183

J
Jeff Dike 已提交
184 185 186 187 188
$(objtree)/$(ARCH_DIR)/include:
	@echo '  MKDIR $@'
	$(Q)mkdir -p $@

$(ARCH_DIR)/include/sysdep: $(objtree)/$(ARCH_DIR)/include
L
Linus Torvalds 已提交
189
	@echo '  SYMLINK $@'
190
ifneq ($(KBUILD_SRC),)
A
Al Viro 已提交
191
	$(Q)ln -fsn $(srctree)/$(ARCH_DIR)/include/sysdep-$(SUBARCH) $(ARCH_DIR)/include/sysdep
192
else
L
Linus Torvalds 已提交
193
	$(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
194
endif
L
Linus Torvalds 已提交
195 196 197

$(ARCH_DIR)/os:
	@echo '  SYMLINK $@'
198 199 200
ifneq ($(KBUILD_SRC),)
	$(Q)ln -fsn $(srctree)/$(ARCH_DIR)/os-$(OS) $(ARCH_DIR)/os
else
L
Linus Torvalds 已提交
201
	$(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
202
endif
L
Linus Torvalds 已提交
203 204 205 206 207 208

# Generated files
define filechk_umlconfig
	sed 's/ CONFIG/ UML_CONFIG/'
endef

209 210 211
$(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
	$(call filechk,umlconfig)

212 213
$(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s: FORCE
	$(Q)$(MAKE) $(build)=$(ARCH_DIR)/sys-$(SUBARCH) $@
214

215 216 217 218 219 220 221 222 223 224
define filechk_gen-asm-offsets
        (set -e; \
         echo "/*"; \
         echo " * DO NOT MODIFY."; \
         echo " *"; \
         echo " * This file was generated by arch/$(ARCH)/Makefile"; \
         echo " *"; \
         echo " */"; \
         echo ""; \
         sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
A
Al Viro 已提交
225
         echo ""; )
226 227
endef

228
$(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s
229 230
	$(call filechk,gen-asm-offsets)

J
Jeff Dike 已提交
231
$(ARCH_DIR)/include/kern_constants.h: $(objtree)/$(ARCH_DIR)/include
232
	@echo '  SYMLINK $@'
233
	$(Q)ln -sf ../../../include/asm-um/asm-offsets.h $@
L
Linus Torvalds 已提交
234

235
export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS