Makefile 5.23 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.
#
Jeff Dike's avatar
Jeff Dike committed
5
# Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds's avatar
Linus Torvalds committed
6 7 8
# Licensed under the GPL
#

9 10 11 12 13 14 15 16 17 18 19
# select defconfig based on actual architecture
ifeq ($(SUBARCH),x86)
  ifeq ($(shell uname -m),x86_64)
        KBUILD_DEFCONFIG := x86_64_defconfig
  else
        KBUILD_DEFCONFIG := i386_defconfig
  endif
else
        KBUILD_DEFCONFIG := $(SUBARCH)_defconfig
endif

Linus Torvalds's avatar
Linus Torvalds committed
20 21 22 23 24 25 26 27 28 29 30 31
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)/

32
MODE_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)/include/shared/skas
Linus Torvalds's avatar
Linus Torvalds committed
33

Al Viro's avatar
Al Viro committed
34 35
HEADER_ARCH 	:= $(SUBARCH)

36 37
ifneq ($(filter $(SUBARCH),x86 x86_64 i386),)
	HEADER_ARCH := x86
Al Viro's avatar
Al Viro committed
38
endif
39 40

ifdef CONFIG_64BIT
41
	KBUILD_CFLAGS += -mcmodel=large
Al Viro's avatar
Al Viro committed
42 43
endif

44 45
HOST_DIR := arch/$(HEADER_ARCH)

46 47
include $(ARCH_DIR)/Makefile-skas
include $(HOST_DIR)/Makefile.um
48 49

core-y += $(HOST_DIR)/um/
Linus Torvalds's avatar
Linus Torvalds committed
50

51 52
SHARED_HEADERS	:= $(ARCH_DIR)/include/shared
ARCH_INCLUDE	:= -I$(srctree)/$(SHARED_HEADERS)
53 54
ARCH_INCLUDE	+= -I$(srctree)/$(HOST_DIR)/um/shared
KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
Linus Torvalds's avatar
Linus Torvalds committed
55

56 57
# -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.
58
#
59 60 61
# Same things for in6addr_loopback and mktime - found in libc. For these two we
# only get link-time error, luckily.
#
62 63 64
# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
# embedded copy of longjmp, same thing for setjmp.
#
65
# These apply to USER_CFLAGS to.
Linus Torvalds's avatar
Linus Torvalds committed
66

67
KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
68
	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
69
	-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
70
	-Din6addr_loopback=kernel_in6addr_loopback \
Al Viro's avatar
Al Viro committed
71
	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
72

73
KBUILD_AFLAGS += $(ARCH_INCLUDE)
Linus Torvalds's avatar
Linus Torvalds committed
74

75 76
USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
		$(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
77 78
		-D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
		-idirafter $(obj)/include -D__KERNEL__ -D__UM_HOST__
79 80

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

83
KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \
84
		   -I$(srctree)/$(HOST_DIR)/include/uapi \
85 86
		   -I$(objtree)/$(HOST_DIR)/include/generated \
		   -I$(objtree)/$(HOST_DIR)/include/generated/uapi
87

88 89
# -Derrno=kernel_errno - This turns all kernel references to errno into
# kernel_errno to separate them from the libc errno.  This allows -fno-common
90
# in KBUILD_CFLAGS.  Otherwise, it would cause ld to complain about the two different
91
# errnos.
92
# These apply to kernelspace only.
93 94 95
#
# strip leading and trailing whitespace to make the USER_CFLAGS removal of these
# defines more robust
96

97 98
KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
			 -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
99
KBUILD_CFLAGS += $(KERNEL_DEFINES)
Linus Torvalds's avatar
Linus Torvalds committed
100

101
PHONY += linux
Linus Torvalds's avatar
Linus Torvalds committed
102 103 104 105

all: linux

linux: vmlinux
106
	@echo '  LINK $@'
107
	$(Q)ln -f $< $@
Linus Torvalds's avatar
Linus Torvalds committed
108 109 110 111

define archhelp
  echo '* linux		- Binary kernel image (./linux) - for backward'
  echo '		   compatibility only, this creates a hard link to the'
Matt LaPlante's avatar
Matt LaPlante committed
112
  echo '		   real kernel binary, the "vmlinux" binary you'
Linus Torvalds's avatar
Linus Torvalds committed
113 114 115
  echo '		   find in the kernel root.'
endef

116
archheaders:
117
	$(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) asm-generic archheaders
118

119
archprepare: include/generated/user_constants.h
Linus Torvalds's avatar
Linus Torvalds committed
120 121

LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
122
LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
Linus Torvalds's avatar
Linus Torvalds committed
123

124 125 126 127
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,)

128 129 130 131
# Options used by linker script
export LDS_START      := $(START)
export LDS_ELF_ARCH   := $(ELF_ARCH)
export LDS_ELF_FORMAT := $(ELF_FORMAT)
Linus Torvalds's avatar
Linus Torvalds committed
132

Jeff Dike's avatar
Jeff Dike committed
133
# The wrappers will select whether using "malloc" or the kernel allocator.
Linus Torvalds's avatar
Linus Torvalds committed
134 135
LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

136
LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
137

138 139
# Used by link-vmlinux.sh which has special support for um link
export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
Linus Torvalds's avatar
Linus Torvalds committed
140

Jeff Dike's avatar
Jeff Dike committed
141 142
# When cleaning we don't include .config, so we don't include
# TT or skas makefiles and don't clean skas_ptregs.h.
Al Viro's avatar
Al Viro committed
143
CLEAN_FILES += linux x.i gmon.out
Linus Torvalds's avatar
Linus Torvalds committed
144 145 146 147 148 149

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

# Generated files
150

151
$(HOST_DIR)/um/user-offsets.s: __headers FORCE
152
	$(Q)$(MAKE) $(build)=$(HOST_DIR)/um $@
153

154 155 156 157 158 159 160 161 162
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 ""; \
163
         sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}" < $<; \
Al Viro's avatar
Al Viro committed
164
         echo ""; )
165 166
endef

167
include/generated/user_constants.h: $(HOST_DIR)/um/user-offsets.s
168 169
	$(call filechk,gen-asm-offsets)

170
export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS DEV_NULL_PATH