Makefile 5.1 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.
#
J
Jeff Dike 已提交
5
# Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
L
Linus Torvalds 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# 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)/

21
MODE_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/include/shared/skas
L
Linus Torvalds 已提交
22

J
Jeff Dike 已提交
23
include $(srctree)/$(ARCH_DIR)/Makefile-skas
L
Linus Torvalds 已提交
24

A
Al Viro 已提交
25 26
ARCH_INCLUDE	:= -I$(srctree)/$(ARCH_DIR)/include/shared
ARCH_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/sys-$(SUBARCH)/shared
27
ifneq ($(KBUILD_SRC),)
A
Al Viro 已提交
28
ARCH_INCLUDE	+= -I$(ARCH_DIR)/include/shared # for two generated files
29
endif
A
Al Viro 已提交
30
KBUILD_CPPFLAGS += -I$(srctree)/$(ARCH_DIR)/sys-$(SUBARCH)
L
Linus Torvalds 已提交
31

32 33
# -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.
34
#
35 36 37 38
# 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 已提交
39

40
KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
41
	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
42 43
	-Din6addr_loopback=kernel_in6addr_loopback \
	-Din6addr_any=kernel_in6addr_any
44

45
KBUILD_AFLAGS += $(ARCH_INCLUDE)
L
Linus Torvalds 已提交
46

47
USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
48
	$(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
49
	$(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64
50 51 52 53 54

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

#This will adjust *FLAGS accordingly to the platform.
include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
55

56 57
KBUILD_CPPFLAGS += -I$(srctree)/arch/$(HEADER_ARCH)/include

58 59
# -Derrno=kernel_errno - This turns all kernel references to errno into
# kernel_errno to separate them from the libc errno.  This allows -fno-common
60
# in KBUILD_CFLAGS.  Otherwise, it would cause ld to complain about the two different
61
# errnos.
62
# These apply to kernelspace only.
63 64 65
#
# strip leading and trailing whitespace to make the USER_CFLAGS removal of these
# defines more robust
66

67 68
KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
			 -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
69
KBUILD_CFLAGS += $(KERNEL_DEFINES)
L
Linus Torvalds 已提交
70

71
PHONY += linux
L
Linus Torvalds 已提交
72 73 74 75

all: linux

linux: vmlinux
76
	@echo '  LINK $@'
77
	$(Q)ln -f $< $@
L
Linus Torvalds 已提交
78 79 80 81

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

A
Al Viro 已提交
86
KBUILD_KCONFIG := arch/um/Kconfig.$(HEADER_ARCH)
L
Linus Torvalds 已提交
87

A
Al Viro 已提交
88
archprepare: $(ARCH_DIR)/include/shared/user_constants.h
89
prepare: $(ARCH_DIR)/include/shared/kern_constants.h
L
Linus Torvalds 已提交
90 91 92 93

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

94 95 96 97
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 已提交
98 99 100
CONFIG_KERNEL_STACK_ORDER ?= 2
STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )

J
Jeff Dike 已提交
101 102
CPPFLAGS_vmlinux.lds = -U$(SUBARCH) -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
	-DELF_FORMAT="$(ELF_FORMAT)" -DKERNEL_STACK_SIZE=$(STACK_SIZE)
L
Linus Torvalds 已提交
103

J
Jeff Dike 已提交
104
# The wrappers will select whether using "malloc" or the kernel allocator.
L
Linus Torvalds 已提交
105 106
LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

107
LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
J
Jeff Dike 已提交
108 109

CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
L
Linus Torvalds 已提交
110 111 112 113
define cmd_vmlinux__
	$(CC) $(CFLAGS_vmlinux) -o $@ \
	-Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
	-Wl,--start-group $(vmlinux-main) -Wl,--end-group \
114
	-lutil \
A
Al Viro 已提交
115
	$(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o \
L
Linus Torvalds 已提交
116 117 118
	FORCE ,$^) ; rm -f linux
endef

J
Jeff Dike 已提交
119 120
# When cleaning we don't include .config, so we don't include
# TT or skas makefiles and don't clean skas_ptregs.h.
A
Al Viro 已提交
121
CLEAN_FILES += linux x.i gmon.out \
122
	$(ARCH_DIR)/include/shared/user_constants.h \
A
Al Viro 已提交
123
	$(ARCH_DIR)/include/shared/kern_constants.h
L
Linus Torvalds 已提交
124 125 126 127 128

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

129
$(objtree)/$(ARCH_DIR)/include/shared:
J
Jeff Dike 已提交
130 131 132
	@echo '  MKDIR $@'
	$(Q)mkdir -p $@

L
Linus Torvalds 已提交
133
# Generated files
134

135 136
$(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s: FORCE
	$(Q)$(MAKE) $(build)=$(ARCH_DIR)/sys-$(SUBARCH) $@
137

138 139 140 141 142 143 144 145 146 147
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 已提交
148
         echo ""; )
149 150
endef

151
$(ARCH_DIR)/include/shared/user_constants.h: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s
152 153
	$(call filechk,gen-asm-offsets)

154
$(ARCH_DIR)/include/shared/kern_constants.h: $(objtree)/$(ARCH_DIR)/include/shared
155
	@echo '  SYMLINK $@'
A
Al Viro 已提交
156
	$(Q)ln -sf ../../../../include/asm/asm-offsets.h $@
L
Linus Torvalds 已提交
157

A
Al Viro 已提交
158
export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS HEADER_ARCH DEV_NULL_PATH