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

USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
J
Jeff Dike 已提交
69
	$(MODE_INCLUDE) -D_FILE_OFFSET_BITS=64
70 71 72 73 74

# -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.
75
# These apply to kernelspace only.
76

77 78
CFLAGS += -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
	-Dmktime=kernel_mktime
L
Linus Torvalds 已提交
79 80
CFLAGS += $(call cc-option,-fno-unit-at-a-time,)

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

L
Linus Torvalds 已提交
83 84 85 86 87 88 89 90 91 92 93
#This will adjust *FLAGS accordingly to the platform.
include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)

# 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)

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

all: linux

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

define archhelp
  echo '* linux		- Binary kernel image (./linux) - for backward'
  echo '		   compatibility only, this creates a hard link to the'
  echo '		   real kernel binary, the the "vmlinux" binary you'
  echo '		   find in the kernel root.'
endef

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

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

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

121 122 123 124
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 已提交
125 126 127 128 129
CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
CONFIG_KERNEL_STACK_ORDER ?= 2
STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )

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

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

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

142
CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS)
L
Linus Torvalds 已提交
143 144 145 146
define cmd_vmlinux__
	$(CC) $(CFLAGS_vmlinux) -o $@ \
	-Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
	-Wl,--start-group $(vmlinux-main) -Wl,--end-group \
147
	-lutil \
L
Linus Torvalds 已提交
148 149 150 151 152 153 154
	$(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 已提交
155 156
	$(ARCH_DIR)/include/user_constants.h \
	$(ARCH_DIR)/include/kern_constants.h $(ARCH_DIR)/Kconfig.arch
L
Linus Torvalds 已提交
157

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

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

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

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

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

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

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

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

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

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

214 215 216 217 218 219 220 221 222 223
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 已提交
224
         echo ""; )
225 226
endef

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

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

234
export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS