Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 454294 - linux-info.eclass: locate kernel source/build via /lib/modules/$(uname -r)/{source,build} symlinks
Summary: linux-info.eclass: locate kernel source/build via /lib/modules/$(uname -r)/{s...
Status: RESOLVED DUPLICATE of bug 87242
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal enhancement with 1 vote (vote)
Assignee: Gentoo Kernel Bug Wranglers and Kernel Maintainers
URL:
Whiteboard:
Keywords: PATCH
: 566496 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-01-27 12:28 UTC by Łukasz Stelmach
Modified: 2021-08-26 22:37 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Improve kernel source and object directory selection (linux-info.eclass.patch,529 bytes, patch)
2013-01-27 12:33 UTC, Łukasz Stelmach
Details | Diff
Above patch in git format-patch format (0001-locate-kernel-source-build-via-lib-modules-uname-r-s.patch,966 bytes, patch)
2016-03-18 15:41 UTC, Joe M
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Łukasz Stelmach 2013-01-27 12:28:18 UTC
I'd like to propose a small improvement for linux-info.eclass. It attempts KERNEL_DIR to set and KBUILD_OUTPUT to something sane, based on currently running kernel version or KERNEL_VER variable.

The attached patch is a proof of concept rather then a proper clean implementation. Please share your opinion.

Reproducible: Always
Comment 1 Łukasz Stelmach 2013-01-27 12:33:41 UTC
Created attachment 337006 [details, diff]
Improve kernel source and object directory selection

The patch makes linux-info.eclass depend on the /lib/modules/<VER>/{build,source} links rather than /usr/src/linux link. To build a package for a version of the kernel different then currently running one needs to set KERNEL_VER variable to a desired value.
Comment 3 Łukasz Stelmach 2013-03-05 00:32:57 UTC
This is not what I meant. As you write it in your comment for Bug #87242 you have /usr/src/linux link, which is exactly what I would like to avoid. The "source/" and "build/" links in the /lib/modules/<VER>/ directory are quite good at pointing at the right directories. Please do remember that they do not need to point to the same directory, although in the default Gentoo setup they do.


Could you please reconsider applying my patch or something similar?
Comment 4 Łukasz Stelmach 2013-03-05 00:37:05 UTC
Without my patch (as it is now), if there is no /usr/src/linux and/or I want to build for different kernel than I am running now. I need to specify 

KERNEL_DIR=/usr/src/linux-3.7.10-gentoo 
KBUILD_OUTPUT=/var/cache/linux-3.7.10-gentoo

With my patch nothing more than KERNEL_VER=3.7.10-gentoo is needed as an environment for emerge to build kernel dependent packages.
Comment 5 SpanKY gentoo-dev 2013-03-06 07:14:52 UTC
(In reply to comment #3)

the fact that /usr/src/linux is a symlink isn't terribly relevant.  it points to the kbuild output directly, and the eclass is capable of bootstrapping itself from there.  i have another system where i keep the source at /usr/src/linux-<ver> and use /usr/src/linux as my kbuild output, and the eclass has no problem locating paths.

bug 87242 already discusses locating paths via /lib/modules/.  the only reason i don't dupe this right away is that that bug is very long and a mess.  maybe i should just punt it.

(In reply to comment #4)

no, you don't.  you only have to set one var now -- point KERNEL_DIR to your kbuild output and the eclass will do the rest.
Comment 6 Łukasz Stelmach 2013-03-06 09:40:23 UTC
Re: part 1.

/usr/src/linux points to the sources. By default/accident this happens to be the same as KBUILD_OUTPUT. Recently I've implemented "--kernel-outputdir" option for genkernel (it's been upstream for some time already) because I think building out of source tree is the right way and linux-info.eclass should not assume that KERNEL_DIR == KBUILD_OUTPUT. (It doesn't, but the way it works isn't clear, see below).

Re: part 2.
Haven't you meant KBUILD_OUTPUT? linux-info.eclass says 

# @ECLASS-VARIABLE: KERNEL_DIR
# @DESCRIPTION:
# A string containing the directory of the target kernel sources. The default value is
# "/usr/src/linux"

It says *sources* here.

All right, I've just tested it and it works as you've said. Your patch enables linux-info.eclass to discover the setup basing on only one variable, however, it messes up with the semantics a bit. If this patch is going to stay I think you should alter that "docstring" too.

I still think, that detection via /lib/modules/<ver>/{source,build} is better.
Comment 7 Joe M 2015-11-23 03:17:34 UTC
This patch avoids other packages from failing when KBUILD_OUTPUT is set.

The solution of setting KBUILD_OUTPUT=<build dir> in /etc/portage/bashrc.d is causing linux-headers and busybox packages to fail. (https://bugs.gentoo.org/show_bug.cgi?id=566496 - linux-headers build fails.)

busybox build fails with the below:

>>> Configuring source in /var/tmp/portage/sys-apps/busybox-1.23.1-r1/work/busybox-1.23.1 ...
 * Could not locate user configfile, so we will save a default one
make --jobs=9 -j1 -s allyesconfig
/var/tmp/portage/sys-apps/busybox-1.23.1-r1/work/busybox-1.23.1/scripts/basic/fixdep.c:414:1: fatal error: opening dependency file scripts/basic/.fixdep.d: Permission denied
 }
 ^
compilation terminated.
make[2]: *** [scripts/basic/fixdep] Error 1
make[1]: *** [scripts_basic] Error 2
make: *** [allyesconfig] Error 2
 * ERROR: sys-apps/busybox-1.23.1-r1::gentoo failed (configure phase):
 *   emake failed
 *
 * If you need support, post the output of `emerge --info '=sys-apps/busybox-1.23.1-r1::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=sys-apps/busybox-1.23.1-r1::gentoo'`.
 * The complete build log is located at '/var/log/portage/sys-apps:busybox-1.23.1-r1:20151123-014530.log'.
 * For convenience, a symlink to the build log is located at '/var/tmp/portage/sys-apps/busybox-1.23.1-r1/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/sys-apps/busybox-1.23.1-r1/temp/environment'.
 * Working directory: '/var/tmp/portage/sys-apps/busybox-1.23.1-r1/work/busybox-1.23.1'
 * S: '/var/tmp/portage/sys-apps/busybox-1.23.1-r1/work/busybox-1.23.1'
 (null)*(null) --------------------------- ACCESS VIOLATION SUMMARY ---------------------------
 (null)*(null) LOG FILE: "/var/log/sandbox/sandbox-26199.log"
 (null)*(null)
VERSION 1.0
FORMAT: F - Function called
FORMAT: S - Access Status
FORMAT: P - Path as passed to function
FORMAT: A - Absolute Path (not canonical)
FORMAT: R - Canonical Path
FORMAT: C - Command Line

F: open_wr
S: deny
P: scripts/basic/.fixdep.d
A: /home/j/var/kernel/src/linux-builds/4.1.12-gentoo-20151122111531/scripts/basic/.fixdep.d
R: /home/j/var/kernel/src/linux-builds/4.1.12-gentoo-20151122111531/scripts/basic/.fixdep.d
C: /usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/cc1 -quiet -I scripts/basic -MD scripts/basic/.fixdep.d /var/tmp/portage/sys-apps/busybox-1.23.1-r1/work/busybox-1.23.1/scripts/basic/f
ixdep.c -quiet -dumpbase fixdep.c -mtune=generic -march=x86-64 -auxbase fixdep -O2 -Wall -Wstrict-prototypes -fomit-frame-pointer -fstack-protector-strong -o /var/tmp/portage/sys-ap
ps/busybox-1.23.1-r1/temp/cc61dPwo.s
 (null)*(null) --------------------------------------------------------------------------------

Can this patch be accepted?

It makes sense to have /usr/src/linux point to the source tree and using the /lib/modules/<ver>/build to figure out the build tree.
Comment 8 Joe M 2016-03-18 15:12:00 UTC
Is there any overlay that has this patch? I wish this could be merged into the official overlay.
Comment 9 Joe M 2016-03-18 15:41:46 UTC
Created attachment 428538 [details, diff]
Above patch in git format-patch format
Comment 10 Andreas K. Hüttel archtester gentoo-dev 2017-12-02 17:06:35 UTC
*** Bug 566496 has been marked as a duplicate of this bug. ***
Comment 11 Mike Pagano gentoo-dev 2021-08-26 22:37:16 UTC

*** This bug has been marked as a duplicate of bug 87242 ***