-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
199 lines (169 loc) · 7.03 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# $Id: Makefile 9120 2006-08-28 13:01:07Z vlad $
PHONY += all kernel install_kernel install clean clean_kernel
all:
.PHONY: $(PHONY)
.DELETE_ON_ERROR:
include ./config.mk
export COMPAT_CONFIG=$(CWD)/compat.config
export COMPAT_AUTOCONF=$(CWD)/include/linux/compat_autoconf.h
export KLIB_BUILD
export KVERSION
export MAKE
-include $(COMPAT_CONFIG)
export CREL=$(shell cat $(CWD)/compat_version)
export CREL_PRE:=.compat_autoconf_
export CREL_CHECK:=$(CREL_PRE)$(CREL)
CFLAGS += \
-DCOMPAT_BASE="\"$(shell cat compat_base)\"" \
-DCOMPAT_BASE_TREE="\"$(shell cat compat_base_tree)\"" \
-DCOMPAT_BASE_TREE_VERSION="\"$(shell cat compat_base_tree_version)\"" \
-DCOMPAT_PROJECT="\"Compat-mlnx-ofed\"" \
-DCOMPAT_VERSION="\"$(shell cat compat_version)\"" \
DEPMOD = /sbin/depmod
INSTALL_MOD_DIR ?= $(shell test -f /etc/SuSE-release && echo updates || echo extra/mellanox-mlnx-en)
ifeq ($(CONFIG_MEMTRACK),m)
export KERNEL_MEMTRACK_CFLAGS = -include $(CWD)/drivers/net/ethernet/mellanox/debug/mtrack.h
else
export KERNEL_MEMTRACK_CFLAGS =
endif
# GCC earlier than 4.6.0 will build modules which require 'mcount',
# and this symbol will not be available in the kernel if the kernel was
# compiled with GCC 4.6.0 and above.
# therefore, to prevent unknown symbol issues we disable function tracing.
#
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
# try-run
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
# Exit code chooses option. "$$TMP" is can be used as temporary file and
# is automatically cleaned up.
TMPOUT := /tmp/
try-run = $(shell set -e; \
TMP="$(TMPOUT).$$$$.tmp"; \
TMPO="$(TMPOUT).$$$$.o"; \
if ($(1)) >/dev/null 2>&1; \
then echo "$(2)"; \
else echo "$(3)"; \
fi; \
rm -f "$$TMP" "$$TMPO")
# cc-option
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
cc-option = $(call try-run,\
$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
ifneq ($(call cc-option,-Werror=date-time),)
KCFLAGS += -Wno-date-time
export KCFLAGS
endif
CPP_MAJOR := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f1)
CPP_MINOR := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f2)
CPP_PATCH := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f3)
# Assumes that major, minor, and patch cannot exceed 999
CPP_VERS := $(shell expr 0$(CPP_MAJOR) \* 1000000 + 0$(CPP_MINOR) \* 1000 + 0$(CPP_PATCH))
compile_h=$(shell /bin/ls -1 $(KSRC)/include/*/compile.h 2> /dev/null | head -1)
ifneq ($(compile_h),)
KERNEL_GCC_MAJOR := $(shell grep LINUX_COMPILER $(compile_h) | sed -r -e 's/.*gcc version ([0-9\.\-]*) .*/\1/g' | cut -d'.' -f1)
KERNEL_GCC_MINOR := $(shell grep LINUX_COMPILER $(compile_h) | sed -r -e 's/.*gcc version ([0-9\.\-]*) .*/\1/g' | cut -d'.' -f2)
KERNEL_GCC_PATCH := $(shell grep LINUX_COMPILER $(compile_h) | sed -r -e 's/.*gcc version ([0-9\.\-]*) .*/\1/g' | cut -d'.' -f3)
KERNEL_GCC_VER := $(shell expr 0$(KERNEL_GCC_MAJOR) \* 1000000 + 0$(KERNEL_GCC_MINOR) \* 1000 + 0$(KERNEL_GCC_PATCH))
ifneq ($(shell if [ $(CPP_VERS) -lt 4006000 ] && [ $(KERNEL_GCC_VER) -ge 4006000 ]; then \
echo "YES"; else echo ""; fi),)
$(info Warning: The kernel was compiled with GCC newer than 4.6.0, while the current GCC is older than 4.6.0, Disabling function tracing to prevent unknown symbol issues...)
override WITH_MAKE_PARAMS += CONFIG_FUNCTION_TRACER= CONFIG_HAVE_FENTRY=
endif
endif
ifneq ($(shell if (echo $(KVERSION) | grep -qE 'uek.*debug'); then \
echo "YES"; else echo ""; fi),)
override WITH_MAKE_PARAMS += ctf-dir=$(CWD)/.ctf
endif
$(COMPAT_AUTOCONF): $(COMPAT_CONFIG)
+@$(CWD)/ofed_scripts/gen-compat-autoconf.sh $(COMPAT_CONFIG) > $(COMPAT_AUTOCONF)
$(COMPAT_CONFIG):
+@$(CWD)/ofed_scripts/gen-compat-config.sh > $(COMPAT_CONFIG)
all: kernel
install: install_kernel
install_kernel: install_modules
autoconf_h=$(shell /bin/ls -1 $(KSRC)/include/*/autoconf.h 2> /dev/null | head -1)
kconfig_h=$(shell /bin/ls -1 $(KSRC)/include/*/kconfig.h 2> /dev/null | head -1)
ifneq ($(kconfig_h),)
KCONFIG_H = -include $(kconfig_h)
endif
V ?= 0
#########################
# make kernel #
#########################
#NB: The LINUXINCLUDE value comes from main kernel Makefile
# with local directories prepended. This eventually affects
# CPPFLAGS in the kernel Makefile
kernel: $(COMPAT_CONFIG) $(COMPAT_AUTOCONF)
@echo "Building kernel modules"
@echo "Kernel version: $(KVERSION)"
@echo "Modules directory: $(INSTALL_MOD_PATH)/lib/modules/$(KVERSION)/$(INSTALL_MOD_DIR)"
@echo "Kernel sources: $(KSRC)"
env CWD=$(CWD) BACKPORT_INCLUDES=$(BACKPORT_INCLUDES) \
$(MAKE) -C $(KSRC) SUBDIRS="$(CWD)" \
V=$(V) KBUILD_NOCMDDEP=1 $(WITH_MAKE_PARAMS) \
CONFIG_COMPAT_VERSION=$(CONFIG_COMPAT_VERSION) \
CONFIG_COMPAT_KOBJECT_BACKPORT=$(CONFIG_COMPAT_KOBJECT_BACKPORT) \
CONFIG_MEMTRACK=$(CONFIG_MEMTRACK) \
CONFIG_MLX4_CORE=$(CONFIG_MLX4_CORE) \
CONFIG_MLX4_EN=$(CONFIG_MLX4_EN) \
CONFIG_MLX4_EN_DCB=$(CONFIG_MLX4_EN_DCB) \
CONFIG_MLX5_CORE=$(CONFIG_MLX5_CORE) \
CONFIG_DTRACE= \
LINUXINCLUDE=' \
$(CFLAGS) \
-include $(autoconf_h) \
$(KCONFIG_H) \
-include $(CWD)/include/linux/compat-2.6.h \
$(BACKPORT_INCLUDES) \
$(KERNEL_MEMTRACK_CFLAGS) \
$(SYSTUNE_INCLUDE) \
$(MLNX_EN_EXTRA_CFLAGS) \
-I$(CWD)/include \
$$(if $$(CONFIG_XEN),-D__XEN_INTERFACE_VERSION__=$$(CONFIG_XEN_INTERFACE_VERSION)) \
$$(if $$(CONFIG_XEN),-I$$(srctree)/arch/x86/include/mach-xen) \
-I$$(srctree)/arch/$$(SRCARCH)/include \
-Iarch/$$(SRCARCH)/include/generated \
-Iinclude \
-I$$(srctree)/arch/$$(SRCARCH)/include/uapi \
-Iarch/$$(SRCARCH)/include/generated/uapi \
-I$$(srctree)/include \
-I$$(srctree)/include/uapi \
-Iinclude/generated/uapi \
$$(if $$(KBUILD_SRC),-Iinclude2 -I$$(srctree)/include) \
-I$$(srctree)/arch/$$(SRCARCH)/include \
-Iarch/$$(SRCARCH)/include/generated \
' \
modules
#########################
# Install kernel #
#########################
install_modules:
@echo "Installing kernel modules"
ifeq ($(shell /usr/bin/lsb_release -s -i 2>/dev/null | grep -qiE "debian|ubuntu" 2>/dev/null && echo YES || echo ''),)
$(MAKE) -C $(KSRC) SUBDIRS="$(CWD)" \
INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) \
INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \
$(WITH_MAKE_PARAMS) modules_install;
else
install -d $(INSTALL_MOD_PATH)/lib/modules/$(KVERSION)/updates/dkms/
find $(CWD)/ -name "*.ko" -exec /bin/cp -f '{}' $(INSTALL_MOD_PATH)/lib/modules/$(KVERSION)/updates/dkms/ \;
endif
if [ ! -n "$(INSTALL_MOD_PATH)" ]; then $(DEPMOD) $(KVERSION);fi;
clean: clean_kernel
clean_kernel:
$(MAKE) -C $(KSRC) SUBDIRS="$(CWD)" $(WITH_MAKE_PARAMS) clean
@/bin/rm -f $(clean-files)
clean-files := Module.symvers modules.order Module.markers compat/modules.order
clean-files += $(COMPAT_CONFIG) $(COMPAT_AUTOCONF)
help:
@echo
@echo kernel: build kernel modules
@echo all: build kernel modules
@echo
@echo install_kernel: install kernel modules under $(INSTALL_MOD_PATH)/lib/modules/$(KVERSION)/$(INSTALL_MOD_DIR)
@echo install: run install_kernel
@echo
@echo clean: delete kernel modules binaries
@echo clean_kernel: delete kernel modules binaries
@echo