Difference between revisions of "User:Invakid404/CLFS"

From Funtoo
Jump to navigation Jump to search
(Create CLFS directories)
 
(Build variables)
Line 26: Line 26:
mkdir: created directory '/home/invakid404/clfs/sources'
mkdir: created directory '/home/invakid404/clfs/sources'
}}
}}
Let's also define some build-related environment variables:
* '''CLFS_HOST''': the target triple of the host machine; modified to contain "cross" to handle the case where we're cross-compiling for the same target
* '''CLFS_TARGET''': the target triple of the target architecture
* '''CLFS_ARCH''': the name of the target architecture; used specifically when installing Linux kernel headers
* '''CLFS_CFLAGS''': extra flags we'll pass to the GCC cross compiler
* '''MAKEFLAGS''': flags we want to pass to GNU make by default
The host variable is straightforward:
{{console|body=
$##i## export CLFS_HOST=$(echo ${MACHTYPE} | sed -e 's/-[^-]*/-cross/')
$##i## echo "${CLFS_HOST}"
x86_64-cross-linux-gnu
}}
The target, arch, and CFLAGS depend on the target architecture you're going for. Here's a table of all currently tested architectures and their respective build variables:
{| class="wikitable"
|+ Build variables per architecture
|-
! Architecture !! CLFS_TARGET !! CLFS_ARCH !! CLFS_CFLAGS
|-
| x86_64 || x86_64-unknown-linux-musl || x86_64 || -m64
|-
| aarch64 || aarch64-unknown-linux-musl || arm64 ||
|}
The rest of this page will assume aarch64, but the steps should be analogous for all listed architectures:
{{console|body=
$##i## export CLFS_TARGET="aarch64-unknown-linux-musl"
$##i## export CLFS_ARCH="arm64"
$##i## export CLFS_CFLAGS=""
}}
For the makeflags, we'll tell GNU make to run as many jobs in parallel as we have threads to speed up the compilation:
{{console|body=
$##i## export MAKEFLAGS="-j$(nproc) -l$(nproc)"
}}
Note that one can put these exports in a file and source them every time one restarts their session to avoid having to setting them manually each and every time. The same applies for all convenience environment variables we'll define later on.

Revision as of 18:52, February 20, 2022

CLFS with musl

This page covers the steps of getting a working CLFS "temporary environment" with musl instead of glibc and latest everything.

Setting up the environment (Chapter 2)

Instead of creating a partition, we'll build everything in a directory in our home. Let's assign it to a variable called `CLFS` and create it:

user $ export CLFS=$HOME/clfs
user $ mkdir -v "${CLFS}"
mkdir: created directory '/home/invakid404/clfs'

We'll also need to create three subdirectories in our CLFS directory:

  • cross-tools: this is where the cross compiler will go
  • tools: this is where the so-called "temporary system" will go
  • sources: this is where we'll download and build all packages
user $ mkdir -v "${CLFS}"/cross-tools
mkdir: created directory '/home/invakid404/clfs/cross-tools'
user $ mkdir -v "${CLFS}"/tools
mkdir: created directory '/home/invakid404/clfs/tools'
user $ mkdir -v "${CLFS}"/sources
mkdir: created directory '/home/invakid404/clfs/sources'

Let's also define some build-related environment variables:

  • CLFS_HOST: the target triple of the host machine; modified to contain "cross" to handle the case where we're cross-compiling for the same target
  • CLFS_TARGET: the target triple of the target architecture
  • CLFS_ARCH: the name of the target architecture; used specifically when installing Linux kernel headers
  • CLFS_CFLAGS: extra flags we'll pass to the GCC cross compiler
  • MAKEFLAGS: flags we want to pass to GNU make by default

The host variable is straightforward:

user $ export CLFS_HOST=$(echo ${MACHTYPE}

The target, arch, and CFLAGS depend on the target architecture you're going for. Here's a table of all currently tested architectures and their respective build variables:

Build variables per architecture
Architecture CLFS_TARGET CLFS_ARCH CLFS_CFLAGS
x86_64 x86_64-unknown-linux-musl x86_64 -m64
aarch64 aarch64-unknown-linux-musl arm64

The rest of this page will assume aarch64, but the steps should be analogous for all listed architectures:

user $ export CLFS_TARGET="aarch64-unknown-linux-musl"
user $ export CLFS_ARCH="arm64"
user $ export CLFS_CFLAGS=""

For the makeflags, we'll tell GNU make to run as many jobs in parallel as we have threads to speed up the compilation:

user $ export MAKEFLAGS="-j$(nproc) -l$(nproc)"

Note that one can put these exports in a file and source them every time one restarts their session to avoid having to setting them manually each and every time. The same applies for all convenience environment variables we'll define later on.