1

I have been trying for hours to recompile Linux kernel of https://github.com/torvalds/linux from my MacBook Pro and at the end, still stuck. Hard to find a tutorial to understand how to recompile it, headers missing, bla bla bla.

PS: I tried first adding a syscall website because that's what I'm trying to do at first.

At the begining, I got a .config not found.

*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
make[3]: *** [silentoldconfig] Error 1
make[2]: *** [silentoldconfig] Error 2
make[1]: *** No rule to make target `include/config/auto.conf', needed by`include/config/kernel.release'.  Stop.

Unlike in some web-links, the conf used doesn't exist or something else is wrong, so I'm creating a new .config from "make menuconfig" (as some answers on the web).

Then, I try to compile again. There is some command I tried:

- make

emixam23@Maximes-MBP:~/Workspace/linux-kernel$ make
getconf: no such configuration parameter `LFS_CFLAGS'
getconf: no such configuration parameter `LFS_LDFLAGS'
getconf: no such configuration parameter `LFS_LIBS'
/bin/sh: scripts/basic/modules.order: Permission denied
make[1]: *** [scripts/basic/modules.order] Error 1
make: *** [scripts_basic] Error 2

- sudo make

emixam23@Maximes-MBP:~/Workspace/linux-kernel$ sudo make
Password:
getconf: no such configuration parameter `LFS_CFLAGS'
getconf: no such configuration parameter `LFS_LDFLAGS'
getconf: no such configuration parameter `LFS_LIBS'
    HOSTCC  arch/x86/tools/relocs_32.o
In file included from arch/x86/tools/relocs_32.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
         ^~~~~~~
1 error generated.
make[1]: *** [arch/x86/tools/relocs_32.o] Error 1
make: *** [archscripts] Error 2

After that, I begin to search if the mistake was coming from my make command and I found this:

- sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4

emixam23@Maximes-MBP:~/Workspace/linux-kernel$ sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4
getconf: no such configuration parameter `LFS_CFLAGS'
getconf: no such configuration parameter `LFS_LDFLAGS'
getconf: no such configuration parameter `LFS_LIBS'
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  HOSTCC  arch/x86/tools/relocs_32.o
  HOSTCC  arch/x86/tools/relocs_64.o
  HOSTCC  arch/x86/tools/relocs_common.o
In file included from arch/x86/tools/relocs_common.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
         ^~~~~~~
In file included from arch/x86/tools/relocs_32.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
         ^~~~~~~
In file included from arch/x86/tools/relocs_64.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
         ^~~~~~~
1 error generated.
make[1]: *** [arch/x86/tools/relocs_common.o] Error 1
make[1]: *** Waiting for unfinished jobs....
1 error generated.
1 error generated.
make[1]: *** [arch/x86/tools/relocs_32.o] Error 1
make[1]: *** [arch/x86/tools/relocs_64.o] Error 1
make: *** [archscripts] Error 2
make: INTERNAL: Exiting with 5 jobserver tokens available; should be 4!

So, based on the errors I got, I searched about <elf.h> and it seems to be something about Android. To me, it doesn't have any links, I mean, I feel like this.

The thing is, I just downloaded a Linux kernel (Torvalds), I added my syscall, now I'm trying to recompile it and use it with vagrant. That's it. Why does it seem so complicated? I will be honest, I feel completely lost... Do you have any idea if I'm right but I just missunderstood something, or I'm totally out of the good way?

I am working from a MacBook Pro:

MacBook Pro (Retina, 15-inch, Mid 2015)

  • macOS High Sierra
  • Version 10.13.1

Thanks for any hints/help

Max

PS: Edit 1: Add of my edits: https://github.com/Emixam23/linux-kernel/commit/d7d7b66cc6513e7b69fd2122b880c259628c438a


Vagrant

I found a workaround which is vagrant :) With vragrant you can recompile the kernel from a Mac OS. You just have to vagrant init then you connect yourself to the vagrant VM vagrant ssh. Once your inside the vagrant VM, run cd / and you will arrive to the root of your machin, which is also where you created the VM, so you can do whatever you want from Mac OS and compile from the terminal make -j 4 :)

Emixam23
  • 3,854
  • 8
  • 50
  • 107
  • Why are you trying to compile Linux from macOS? That sounds like it would be very complicated (see [here](https://stackoverflow.com/q/10018764/182402), for example). Why not spin up a Linux VM using Vagrant, and work from there? – Wander Nauta Nov 18 '17 at 14:54
  • That could be an idea but I'm not sure to know how to do? I already read this answer also – Emixam23 Nov 18 '17 at 15:06
  • I dunno if Buildroot can be built using MacOS native SDK (also you may try one from homebrew in case it differs), but it worth to try. Buildroot is a Linux distribution which has it's own SDK, so, it would build SDK first and then use it to build everything else including Linux kernel. No virtual environment needed. – 0andriy Nov 18 '17 at 19:01
  • Alright, so I tried with `vagrant trusty64` and it works partially, `` not found however – Emixam23 Nov 21 '17 at 08:16

1 Answers1

0

Check your tool-chain. It is not just android thing. https://linux.die.net/man/5/elf. Please go ahead if you like being challenged. cause this will not be straight forward. If your task is just compiling code use virtual machine / other linux machine it will be quicker. But if you are curious to check how things work and getting them work on mac for future compilations without vm. then continue.try adding those header files. in /usr/include as per this

Devidas
  • 2,479
  • 9
  • 24
  • I want to because I'll have to create some kernel module, and some others things, for school's projects. So thank you :) – Emixam23 Nov 20 '17 at 13:03