← Back to context

Comment by matheusmoreira

2 years ago

> However when you #include <linux/...>, you not only make your software non-portable, you also make it a PITA to cross-compile as you need the kernel headers on the host machine.

Yes, that is certainly a problem that I need to solve.

I added some support for cross compilation in the makefile. It currently requires clang for that.

  ifdef TARGET
    ifndef UAPI
      $(error UAPI must be defined when cross compiling)
    endif

    TARGET.triple := $(TARGET)-unknown-linux-elf
    override CC := clang -target $(TARGET.triple)
  else
    TARGET := $(shell uname -m)
  endif

With this, I was able to cross compile lone for x86_64 from within the Termux environment of my aarch64 smartphone. All I had to do was obtain the Linux user space API headers for x86_64. Getting those headers was somewhat annoying but doable, there are packages for them in many Linux distributions.

I made a Termux package request for multiplatform Linux UAPI headers specifically so I could cross compile lone but unfortunately it was rejected.

https://github.com/termux/termux-packages/issues/16069