blob: 95bd047b97ac6c6a7cbb21f292083cafb0b32835 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001Get linux kernel version from Makefile of kernel source
2
3We get below messages while building iscsitarget,
4
5-- snip --
6x86_64-poky-linux-gcc: error:
7/CGE7_SHDD/project_yocto_1.8/poky/build/tmp/work-shared/qemux86-64/kernel-source/include/linux/version.h:
8No such file or directory
9x86_64-poky-linux-gcc: fatal error: no input files
10compilation terminated.
11/bin/sh: line 0: [: too many arguments
12/bin/sh: line 0: [: too many arguments
13/bin/sh: line 0: [: too many arguments
14/bin/sh: line 0: [: too many arguments
15/bin/sh: line 0: [: too many arguments
16/bin/sh: line 0: [: too many arguments
17/bin/sh: line 0: [: too many arguments
18/bin/sh: line 0: [: too many arguments
19/bin/sh: line 0: [: too many arguments
20/bin/sh: line 0: [: too many arguments
21/bin/sh: line 0: [: too many arguments
22/bin/sh: line 0: [: too many arguments
23-- CUT --
24
25These messages are due to absence of include/linux/version.h file in
26kernel source directory and failed to compute linux kernel version.
27So, use kernel source Makefile ( i.e $(KSRC)/Makefile) to find out
28actual kernel version.
29
30Upstream-Status: Pending
31
32Signed-off-by: Jagadeesh Krishnanjanappa <jkrishnanjanappa@mvista.com>
33
34--- iscsitarget-1.4.20.3+svn499_org/Makefile 2014-01-27 00:00:45.000000000 +0530
35+++ iscsitarget-1.4.20.3+svn499/Makefile 2015-07-23 10:44:47.013600285 +0530
36@@ -18,27 +18,11 @@ ifeq ($(KSRC),)
37 endif
38
39
40-ifneq ($(wildcard $(KSRC)/include/generated/utsrelease.h),)
41- VERSION_FILE := $(KSRC)/include/generated/utsrelease.h
42-else
43- ifneq ($(wildcard $(KSRC)/include/linux/utsrelease.h),)
44- VERSION_FILE := $(KSRC)/include/linux/utsrelease.h
45- else
46- VERSION_FILE := $(KSRC)/include/linux/version.h
47- endif
48-endif
49-
50-KVER := $(shell $(CC) $(CFLAGS) $(LDFLAGS) -E -dM $(VERSION_FILE) | \
51- grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
52-
53 KMOD := /lib/modules/$(KVER)/extra
54-
55-KMAJ := $(shell echo $(KVER) | \
56- sed -e 's/^\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/')
57-KMIN := $(shell echo $(KVER) | \
58- sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/')
59-KREV := $(shell echo $(KVER) | \
60- sed -e 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/')
61+KMAJ := $(shell cat $(KSRC)/Makefile | grep ^VERSION | gawk -F " " '{ print $$NF }')
62+KMIN := $(shell cat $(KSRC)/Makefile | grep ^PATCHLEVEL | gawk -F " " '{ print $$NF }')
63+KREV := $(shell cat $(KSRC)/Makefile | grep ^SUBLEVEL | gawk -F " " '{ print $$NF }')
64+KVER := ${KMAJ}.${KMIN}.${KREV}
65
66 kver_eq = $(shell [ $(KMAJ) -eq $(1) -a $(KMIN) -eq $(2) -a $(KREV) -eq $(3) ] && \
67 echo 1 || echo 0)