Mac Compiling the Linux Kernel on OS X?

linuxftw

macrumors newbie
Original poster
Jun 25, 2007
10
0
I would like to compile the Linux kernel on OS X, as the thread title suggests.

Would XCode, be enough to do it? Or would the version of GCC it uses not work?

Any input would be useful, thanks :)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
24,638
61
Harrogate
To what end? It's not like you can replace Darwin with the Linux kernel and get OSX with a Linux core? Other than that, XCode uses gcc as it's compiler so I suppose it might well work...
 

linuxftw

macrumors newbie
Original poster
Jun 25, 2007
10
0
To what end? It's not like you can replace Darwin with the Linux kernel and get OSX with a Linux core?
No I know thats not possible. Just having to use linux to compile the linux kernel is a pain for me.

Anyway, I have had a go with the latest 2.6.5 kernel. The problem im facing is that the "-shared" option isn't available for GCC on OS X or something along those lines:

"i686-apple-darwin8-gcc-4.0.1: unrecognized option '-shared'
/usr/bin/ld: Undefined symbols:
_main"

ld returns 1 exit status, etc etc...

Anybody know a work around?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
24,638
61
Harrogate
I think the problem is that you are using the OSX linker so you will be building mach-o executables. You need to build in a different executable format (probably ELF?). Maybe then you'd gain access to the options you need. But that would prevent the OSX linker from being able to work.

Basically you need a cross compiler for x68-linux on x86-darwin...
 

antibact1

macrumors 6502
Jun 1, 2006
334
0
I've actually heard that the next iteration of iLife is going to include a graphical Linux kernel compiler, so if you wait for that, you may be in luck.

Really though, this is an absolutely ridiculous idea. It really begs the questions as to what you're even doing compiling a kernel, when you seem to be clueless about operating system internals. Best of luck to you.
 

iSee

macrumors 68040
Oct 25, 2004
3,525
253
Everyone's clueless about operating system internals until they start working with them.
 

antibact1

macrumors 6502
Jun 1, 2006
334
0
Everyone's clueless about operating system internals until they start working with them.
I agree. And to learn about the internals of a specific operating system, it's useful to look into them on that operating system.
 

ptomsich

macrumors newbie
Jul 16, 2007
1
0
Cross-compiling the Linux kernel on OS X

We regularily cross-compile Linux kernels on OS X to various target architectures (mainly MIPS and ARM, but also sometimes to embedded PowerPC targets) and it's perfectly possible but non-trivial to get working initially.

You will need an appropriate cross-toolchain (targeting <your-target-arch>-elf) and a number of userspace tools installed. From the top of my head, you will need ncurses for "make menuconfig", need to modify scripts/kconfig/lxdialog/check-lxdialog.sh to recognize .dylib files (again only, if you want to do a "make menuconfig"), and generally work around a lot of issues in the scripts subdirectory.

If you are only starting with Linux kernel development, native compiles will be a lot simpler than cross-compiles, though. And Linux-hosted cross-compiles will be simpler than OS X-hosted cross-compiled.
 

wmperry

macrumors newbie
Aug 5, 2007
1
0
ptomisch, could you provide details on how you get the cross-compilation to work? I have been using an i686-linux-gnu cross-compiling toolchain to build work-related software on my (macbook pro) laptop, and that works great until we get to compiling the kernel (mainly module related).

Setting ARCH and CROSS_COMPILE appropriate gets the build started, but it croaks when it tries to build scripts/mod/file2alias.c with HOSTCC. Have you just hacked your kernel source to let this build as a mach-o binary? It includes some linux kernel internal headers, which expect to have other linux-specific includes in the standard system include path.

Thanks

-Bill Perry

We regularily cross-compile Linux kernels on OS X to various target architectures (mainly MIPS and ARM, but also sometimes to embedded PowerPC targets) and it's perfectly possible but non-trivial to get working initially.

You will need an appropriate cross-toolchain (targeting <your-target-arch>-elf) and a number of userspace tools installed. From the top of my head, you will need ncurses for "make menuconfig", need to modify scripts/kconfig/lxdialog/check-lxdialog.sh to recognize .dylib files (again only, if you want to do a "make menuconfig"), and generally work around a lot of issues in the scripts subdirectory.

If you are only starting with Linux kernel development, native compiles will be a lot simpler than cross-compiles, though. And Linux-hosted cross-compiles will be simpler than OS X-hosted cross-compiled.