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 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 99 100 101 102 103 104 105 106 107

all: linux

linux: vmlinux
	ln -f $< $@

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

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

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

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

CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
CONFIG_KERNEL_STACK_ORDER ?= 2
STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )

ifndef START
125
  START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
L
Linus Torvalds 已提交
126 127
endif

128
CPPFLAGS_vmlinux.lds = -U$(SUBARCH) \
L
Linus Torvalds 已提交
129
	-DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
130 131
	-DELF_FORMAT="$(ELF_FORMAT)" $(CPP_MODE-y) \
	-DKERNEL_STACK_SIZE=$(STACK_SIZE) \
132
	-DUNMAP_PATH=arch/um/sys-$(SUBARCH)/unmap.o
L
Linus Torvalds 已提交
133 134 135 136

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

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

153
MRPROPER_FILES += $(ARCH_SYMLINKS)
L
Linus Torvalds 已提交
154 155 156 157 158 159 160

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

$(SYMLINK_HEADERS):
	@echo '  SYMLINK $@'
161
ifneq ($(KBUILD_SRC),)
162
	$(Q)ln -fsn $(srctree)/include/asm-um/$(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $@
163
else
L
Linus Torvalds 已提交
164 165
	$(Q)cd $(TOPDIR)/$(dir $@) ; \
	ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
166
endif
L
Linus Torvalds 已提交
167 168 169

include/asm-um/arch:
	@echo '  SYMLINK $@'
170 171 172 173
ifneq ($(KBUILD_SRC),)
	$(Q)mkdir -p include/asm-um
	$(Q)ln -fsn $(srctree)/include/asm-$(SUBARCH) include/asm-um/arch
else
L
Linus Torvalds 已提交
174
	$(Q)cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
175
endif
L
Linus Torvalds 已提交
176

J
Jeff Dike 已提交
177 178 179 180 181
$(objtree)/$(ARCH_DIR)/include:
	@echo '  MKDIR $@'
	$(Q)mkdir -p $@

$(ARCH_DIR)/include/sysdep: $(objtree)/$(ARCH_DIR)/include
L
Linus Torvalds 已提交
182
	@echo '  SYMLINK $@'
183
ifneq ($(KBUILD_SRC),)
A
Al Viro 已提交
184
	$(Q)ln -fsn $(srctree)/$(ARCH_DIR)/include/sysdep-$(SUBARCH) $(ARCH_DIR)/include/sysdep
185
else
L
Linus Torvalds 已提交
186
	$(Q)cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
187
endif
L
Linus Torvalds 已提交
188 189 190

$(ARCH_DIR)/os:
	@echo '  SYMLINK $@'
191 192 193
ifneq ($(KBUILD_SRC),)
	$(Q)ln -fsn $(srctree)/$(ARCH_DIR)/os-$(OS) $(ARCH_DIR)/os
else
L
Linus Torvalds 已提交
194
	$(Q)cd $(ARCH_DIR) && ln -sf os-$(OS) os
195
endif
L
Linus Torvalds 已提交
196 197 198 199 200 201

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

202 203 204 205 206 207
$(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
	$(call filechk,umlconfig)

$(ARCH_DIR)/user-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.c
	$(CC) $(USER_CFLAGS) -S -o $@ $<

208 209 210 211 212 213 214 215 216 217
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 已提交
218
         echo ""; )
219 220
endef

A
Al Viro 已提交
221
$(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/user-offsets.s
222 223
	$(call filechk,gen-asm-offsets)

A
Al Viro 已提交
224
CLEAN_FILES += $(ARCH_DIR)/user-offsets.s
225

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

export SUBARCH USER_CFLAGS OS