Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Kernel & Hardware
  • Search

When is the kernel "source" symlink created?

Kernel not recognizing your hardware? Problems with power management or PCMCIA? What hardware is compatible with Gentoo? See here. (Only for kernels supported by Gentoo.)
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
Goverp
Advocate
Advocate
User avatar
Posts: 2402
Joined: Wed Mar 07, 2007 6:41 pm

When is the kernel "source" symlink created?

  • Quote

Post by Goverp » Mon May 10, 2021 12:29 pm

I'm trying to document the "right way" to build kernels from a normal user rather than root. The basic command is

Code: Select all

cd builddir
make -C /usr/src/linux O=$PWD <target>
which at some point creates a "builddir/source" symlink pointing at the source tree (ie, the target of the /usr/src/linux symlink).

I can't find any documentation as to when said source symlink is created, nor indeed overwritten. Tests show that "make clean" doesn't create it (which was a surprise). "make defconfig" does, so I suspect it's anything that creates something. Which is actually rather annoying.

The trouble is, having created the symlink, it's then permissible to just use "make <target>" without the "-C" parameter; make follows the symlink to the kernel source - note, the versioned /usr/src/linux-5.12.1-gentoo or whatever /usr/src/linux pointed at when the symlink was created. Which may be the right thing to do; it means you can download a new kernel and update the symlink, but make will still address the old version until you do something to update the source symlink.

I can see a couple of use cases:
a) normal kernel building: update gentoo-sources with USE="symlink", and issue "make -C /usr/src/linux -O=builddir clean oldconfig" to start building a new kernel with the latest sources.
b) external kernel building: in this case I'm thinking of cross-compiling a kernel for a Raspberry Pi or some other host. For whatever reason, I may not wish to update to the latest sources, so I'd want to simply "cd builddir; make <target>"

I'm trying to write a single shell script to simplify this, as it's far too easy to make a mess instead of a kernel. Perhaps a new Makefile target "newsource" that takes an optional directory defaulting to /usr/src/linux (or more likely a fake target handled in the script rather than dare to touch a Makefile). Which brings me to the title of this post: when/how should the script cause the "source" symlink to be set? I thought it might be enough to "make -C ... kernelversion", but that reports the version from the "-C" source, while leaving the source symlink pointing where it was, which is useless!

MY gut feel is that this is just a shambles, rather than a documented and well-considered API :-(

(For anyone interested, my documentation thus far is in my user page in the wiki.)
Greybeard
Top
Naib
Watchman
Watchman
User avatar
Posts: 6101
Joined: Fri May 21, 2004 9:42 pm
Location: Removed by Neddy
Contact:
Contact Naib
Website

  • Quote

Post by Naib » Mon May 10, 2021 1:04 pm

its either made if you have the symlink USE flag (and thus made at emerge) or when the user sets this (via eselect kernel). NOTE this symlink is needed for external modules or for end-user convenience .
#define HelloWorld int
#define Int main()
#define Return printf
#define Print return
#include <stdio>
HelloWorld Int {
Return("Hello, world!\n");
Print 0;
Top
trilithium
n00b
n00b
Posts: 43
Joined: Mon Nov 18, 2019 7:22 pm

  • Quote

Post by trilithium » Mon May 10, 2021 1:08 pm

This seems to be the relevant part of /usr/src/linux-5.12.2-gentoo/Makefile:

Code: Select all

PHONY += outputmakefile
# Before starting out-of-tree build, make sure the source tree is clean.
# outputmakefile generates a Makefile in the output directory, if using a
# separate output directory. This allows convenient use of make in the
# output directory.
# At the same time when output Makefile generated, generate .gitignore to
# ignore whole output directory
outputmakefile:
ifdef building_out_of_srctree
	$(Q)if [ -f $(srctree)/.config -o \
		 -d $(srctree)/include/config -o \
		 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
		echo >&2 "***"; \
		echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
		echo >&2 "*** in $(abs_srctree)";\
		echo >&2 "***"; \
		false; \
	fi
	$(Q)ln -fsn $(srctree) source
	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
	$(Q)test -e .gitignore || \
	{ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
endif
The outputmakefile target might be useful for what you are trying to do?
Top
Goverp
Advocate
Advocate
User avatar
Posts: 2402
Joined: Wed Mar 07, 2007 6:41 pm

  • Quote

Post by Goverp » Mon May 10, 2021 3:16 pm

trilitium, thanks! I'd seen that lurking in the Makefile, but hadn't realised I could simply "make -C foo outputmakefile"; that does exactly what I wanted.
Greybeard
Top
Post Reply

4 posts • Page 1 of 1

Return to “Kernel & Hardware”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic