Makefile 6.9 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
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

J
Jeff Dike 已提交
34
MODE_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/include/skas
L
Linus Torvalds 已提交
35

J
Jeff Dike 已提交
36
include $(srctree)/$(ARCH_DIR)/Makefile-skas
L
Linus Torvalds 已提交
37 38

ARCH_INCLUDE	:= -I$(ARCH_DIR)/include
39 40 41
ifneq ($(KBUILD_SRC),)
ARCH_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/include
endif
L
Linus Torvalds 已提交
42 43
SYS_DIR		:= $(ARCH_DIR)/include/sysdep-$(SUBARCH)

44 45
# -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.
46
#
47 48 49 50
# 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 已提交
51

52 53
CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\"	\
	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
54 55
	-Din6addr_loopback=kernel_in6addr_loopback \
	-Din6addr_any=kernel_in6addr_any
56

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

59 60 61 62 63 64 65 66
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)
67 68 69 70 71

# -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.
72
# These apply to kernelspace only.
73

74 75 76
KERNEL_DEFINES = -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
	-Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)
CFLAGS += $(KERNEL_DEFINES)
L
Linus Torvalds 已提交
77 78 79 80 81 82 83
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

J
Jeff Dike 已提交
84
SIZE = ($(CONFIG_NEST_LEVEL) * 0x20000000)
L
Linus Torvalds 已提交
85

86
PHONY += linux
L
Linus Torvalds 已提交
87 88 89 90

all: linux

linux: vmlinux
91
	@echo '  LINK $@'
92
	$(Q)ln -f $< $@
L
Linus Torvalds 已提交
93 94 95 96

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

101
ifneq ($(KBUILD_SRC),)
102
$(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch)
103
else
104
$(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch)
105
endif
L
Linus Torvalds 已提交
106

A
Al Viro 已提交
107 108
archprepare: $(ARCH_SYMLINKS) $(ARCH_DIR)/include/user_constants.h
prepare: $(ARCH_DIR)/include/kern_constants.h
L
Linus Torvalds 已提交
109 110 111 112

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

113 114 115 116
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 已提交
117 118 119 120
CONFIG_KERNEL_STACK_ORDER ?= 2
STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )

ifndef START
121
  START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
L
Linus Torvalds 已提交
122 123
endif

J
Jeff Dike 已提交
124 125
CPPFLAGS_vmlinux.lds = -U$(SUBARCH) -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
	-DELF_FORMAT="$(ELF_FORMAT)" -DKERNEL_STACK_SIZE=$(STACK_SIZE)
L
Linus Torvalds 已提交
126 127 128 129

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

130
CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS)
L
Linus Torvalds 已提交
131 132 133 134
define cmd_vmlinux__
	$(CC) $(CFLAGS_vmlinux) -o $@ \
	-Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
	-Wl,--start-group $(vmlinux-main) -Wl,--end-group \
135
	-lutil \
A
Al Viro 已提交
136
	$(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o \
L
Linus Torvalds 已提交
137 138 139 140 141 142
	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 已提交
143 144
	$(ARCH_DIR)/include/user_constants.h \
	$(ARCH_DIR)/include/kern_constants.h $(ARCH_DIR)/Kconfig.arch
L
Linus Torvalds 已提交
145

146
MRPROPER_FILES += $(ARCH_SYMLINKS)
L
Linus Torvalds 已提交
147 148 149 150 151 152 153

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

$(SYMLINK_HEADERS):
	@echo '  SYMLINK $@'
154
ifneq ($(KBUILD_SRC),)
155
	$(Q)mkdir -p $(objtree)/include/asm-um
156
	$(Q)ln -fsn $(srctree)/include/asm-um/$(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $@
157
else
L
Linus Torvalds 已提交
158 159
	$(Q)cd $(TOPDIR)/$(dir $@) ; \
	ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
160
endif
L
Linus Torvalds 已提交
161 162 163

include/asm-um/arch:
	@echo '  SYMLINK $@'
164
ifneq ($(KBUILD_SRC),)
165
	$(Q)mkdir -p $(objtree)/include/asm-um
166
	$(Q)ln -fsn $(srctree)/include/asm-$(HEADER_ARCH) include/asm-um/arch
167
else
168
	$(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(HEADER_ARCH) arch
169
endif
L
Linus Torvalds 已提交
170

J
Jeff Dike 已提交
171 172 173 174 175
$(objtree)/$(ARCH_DIR)/include:
	@echo '  MKDIR $@'
	$(Q)mkdir -p $@

$(ARCH_DIR)/include/sysdep: $(objtree)/$(ARCH_DIR)/include
L
Linus Torvalds 已提交
176
	@echo '  SYMLINK $@'
177
ifneq ($(KBUILD_SRC),)
A
Al Viro 已提交
178
	$(Q)ln -fsn $(srctree)/$(ARCH_DIR)/include/sysdep-$(SUBARCH) $(ARCH_DIR)/include/sysdep
179
else
L
Linus Torvalds 已提交
180
	$(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
181
endif
L
Linus Torvalds 已提交
182 183 184

$(ARCH_DIR)/os:
	@echo '  SYMLINK $@'
185 186 187
ifneq ($(KBUILD_SRC),)
	$(Q)ln -fsn $(srctree)/$(ARCH_DIR)/os-$(OS) $(ARCH_DIR)/os
else
L
Linus Torvalds 已提交
188
	$(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
189
endif
L
Linus Torvalds 已提交
190 191 192 193 194 195

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

196 197 198
$(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
	$(call filechk,umlconfig)

199 200
$(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s: FORCE
	$(Q)$(MAKE) $(build)=$(ARCH_DIR)/sys-$(SUBARCH) $@
201

202 203 204 205 206 207 208 209 210 211
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 已提交
212
         echo ""; )
213 214
endef

215
$(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s
216 217
	$(call filechk,gen-asm-offsets)

J
Jeff Dike 已提交
218
$(ARCH_DIR)/include/kern_constants.h: $(objtree)/$(ARCH_DIR)/include
219
	@echo '  SYMLINK $@'
220
	$(Q)ln -sf ../../../include/asm-um/asm-offsets.h $@
L
Linus Torvalds 已提交
221

222
export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS HEADER_ARCH