GNU/Linux-libre from source code for Pentium 4
**********************************************

This manual describes how to build a GNU/Linux-libre system from source for Pentium 4 processor.

This is edition 1.9.0 (last updated January 2026) of GNU/Linux-libre from source code for Pentium 4.

Copyright © 2026 Christophe Jarry.

This document was based on the Chinese page http://zdbr.net.cn/download/Loongson64-2.0.htm, which was copyright © 2009 Haiyong Sun (孙海勇). His blog is on http://blog.chinaunix.net/uid/436750.html.

Various formats of this manual as well as its texinfo source are available on http://cjarry.org/gnu-linux/gllfsc/pentium4/.

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''.

     Computer instructions in this manual are free software: you can redistribute them and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

     Those instructions are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

     You should have received a copy of the GNU General Public License along with this manual.  If not, see <http://www.gnu.org/licenses/>.

Introduction
************

GNU/Linux History
=================

GNU
---

GNU (GNU's Not Unix) is a project launched by Richard Stallman in 1984 with the goal of building an entirely free operating system compatible with Unix (See https://en.wikipedia.org/wiki/Unix). ``Free'' here means ``free as in freedom''. In this context, a free operating system is an operating system you can use and share in freedom. A core part of his motivation is given in the GNU Manifesto (http://www.gnu.org/gnu/manifesto.html):

     I consider that the Golden Rule requires that if I like a program I must share it with other people who like it. Software sellers want to divide the users and conquer them, making each user agree not to share with others. I refuse to break solidarity with other users in this way. I cannot in good conscience sign a nondisclosure agreement or a software license agreement. For years I worked within the Artificial Intelligence Lab to resist such tendencies and other inhospitalities, but eventually they had gone too far: I could not remain in an institution where such things are done for me against my will.

     So that I can continue to use computers without dishonor, I have decided to put together a sufficient body of free software so that I will be able to get along without any software that is not free. I have resigned from the AI Lab to deny MIT any legal excuse to prevent me from giving GNU away.

A program is free software if the program's user has the four essential freedoms:

  * The freedom to run the program, for any purpose (freedom 0).

  * The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.

  * The freedom to redistribute copies so you can help others (freedom 2).

  * The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.

One of the most popular free software license is the GNU General Public License (GNU GPL (http://www.gnu.org/licenses/gpl.html)).

The free software movement is supported by the Free Software Foundation (FSF (https://www.fsf.org)).

HURD
----

The HURD is an acronym for HIRD (HURD of interfaces representing depth) of Unix-replacing daemons. It is the GNU project's replacement for the Unix kernel. It is a collection of servers that run on the Mach microkernel to implement file systems, network protocols, file access control, and other features that are implemented by the Unix kernel or similar kernels (such as Linux).

The purpose of the GNU HURD is to improve your freedom on your operating system by allowing you to either add or remove a feature of the kernel on the fly.

From early on, the HURD was developed to use GNU Mach as the microkernel. This was a technical decision made by Richard Stallman, who thought it would speed up the work by saving a large part of it. He has admitted that he was wrong about that.

Nevertheless, development of the HURD is increasingly attracting developers and GNU/HURD systems exist and are usable.

Linux
-----

Linux is a monolithic kernel created by Linus Torvalds in 1991. Linus Torvalds initially wrote a terminal emulator, which he used to access the large UNIX servers of his university. He wrote the program specifically for the hardware he was using and independent of an operating system because he wanted to use the functions of his new PC with an 80386 processor. This later became the kernel Linux.

Initially, Torvalds first published the kernel Linux under its own licence, which had a restriction on commercial activity.

In the notes for the first release of the kernel Linux, Torvalds lists the GNU software that is required to run Linux:

     Sadly, a kernel by itself gets you nowhere. To get a working system you need a shell, compilers, a library etc. [...] Most of the tools used with linux are GNU software and are under the GNU copyleft.

In 1992, he suggested releasing the kernel under the GNU General Public License. He first announced this decision in the release notes of version 0.12. In the middle of December 1992 he published version 0.99 using the GNU GPL.

The kernel Linux is now a contribution of many professionals and volonteers around the world.

Linux-libre
-----------

Linux, the kernel developed and distributed by Linus Torvalds et al, contains non-Free Software (For more information about the presence of proprietary firmware in the kernel Linux, read http://www.fsfla.org/ikiwiki/anuncio/2010-03-Linux-2.6.33-libre.en and http://www.gnu.org/distros/free-system-distribution-guidelines.html#nonfree-firmware.), i.e., software that does not respect your essential freedoms, and it induces you to install additional non-Free Software that it doesn't contain.

GNU Linux-libre (http://www.fsfla.org/ikiwiki/selibre/linux-libre/index.en.html) is a project to maintain and publish 100% Free distributions of Linux, suitable for use in Free System Distributions (For a full list of free as in freedom GNU/Linux distributions, see http://www.gnu.org/distros/.), removing software that is included without source code, with obfuscated or obscured source code, under non-Free Software licenses, that do not permit you to change the software so that it does what you wish, and that induces or requires you to install additional pieces of non-Free Software.

You can visit http://h-node.org to see if your hardware works with Linux-libre: wireless card and graphics chip in particular.

References
----------

For more information on the GNU project and its relation with the kernel Linux, you can read http://www.gnu.org/gnu/thegnuproject.html and http://www.gnu.org/gnu/gnu-linux-faq.html.

For more information on the history of the HURD, I recommend you to read http://web.archive.org/web/20221122061739/http://www.h-online.com/open/features/GNU-HURD-Altered-visions-and-lost-promise-1030942.htm.

For more information on the HURD, read http://www.gnu.org/software/hurd/.

For more information on the early versions of the kernel Linux, read https://www.cs.cmu.edu/~awb/linux.history.html.

Purpose of this Document
========================

One day I found a Dell Optiplex 745 minitower with a Pentium 4 CPU in a municipal waste. I just replaced the button battery and the computer was able to boot. I decided to adapt the work I did for the Lemote Yeeloong 8133 (with a Loongson 3A CPU): GNU/Linux (Note: in this document, we use the term ``GNU/Linux'' to name the entire system and ``Linux'' to name the kernel.  For more information, read http://www.gnu.org/gnu/why-gnu-linux.html.) Libre from Source Code for Pentium 4 was born.

Prerequisites
*************

Definitions
===========

sysroot
-------

The traditional way of building a GNU/Linux operating system consists on building a (cross-) compilation toolchain to build a temporary operating system which in turn will be used to build the target system (see Further Readings for more details). This requires almost as much time to complete the temporary system as to build the target one. Using sysroot resolves this problem.

From GCC installation manual, under Cross-Compiler-Specific Options:

--with-sysroot
--with-sysroot=DIR
     Tells GCC to consider DIR as the root of a tree that contains (a subset of) the root filesystem of the target operating system.  Target system headers, libraries and run-time object files will be searched in there.  More specifically, this acts as if --sysroot=DIR was added to the default options of the built compiler.  The specified directory is not copied into the install tree, unlike the options --with-headers and --with-libs that this option obsoletes.  The default value, in case --with-sysroot is not given an argument, is ${gcc_tooldir}/sys-root.  If the specified directory is a subdirectory of ${exec_prefix}, then it will be found relative to the GCC binaries if the installation tree is moved.

     This option affects the system root for the compiler used to build target libraries (which runs on the build system) and the compiler newly installed with make install; it does not affect the compiler which is used to build GCC itself.

Toolchain
---------

According to Wikipedia (https://en.wikipedia.org/wiki/Toolchain):

     In software, a toolchain is the set of programming tools that are used to create a product (typically another computer program or system of programs). The tools may be used in a chain, so that the output of each tool becomes the input for the next, but the term is used widely to refer to any set of linked development tools.

     A simple software development toolchain consists of a text editor for editing source code, a compiler and linker to transform the source code into an executable program, libraries to provide interfaces to the operating system, and a debugger.

build, host and target
----------------------

During a cross-compilation, build host and target are among the most used options: understanding the precise meaning of those parameters is very important. We could define them thus:

  * --build=PLATFORM ON WHICH THE PROGRAM IS COMPILED,

  * --host=PLATFORM ON WHICH THE PROGRAM WILL RUN,

  * --target=PLATFORM FOR WHICH THE PROGRAM WILL CREATE OUTPUT.

Let's use GCC as an example to explain the role of those three parameters.

During GCC compilation, we use: ./configure --build=BUILD-PLATFORM --host=HOST-PLATFORM --target=TARGET-PLATFORM [various compilation parameters]

So in those configuration parameters:

  * --build provides the name of the platform currently running. If we were using an Intel Pentium processor to compile the system, our BUILD-PLATFORM would be something like i686-pc-linux-gnu.

     If this parameter is not specified, it will be guessed automatically.

  * --host represents the type of machine we are going to run GCC on after the compilation succeeds. During a cross-compilation this has to be specified, because the current machine can not know which architecture we wish to target. We want to produce executables to run on Pentium4, but there is currently no way we can specify Pentium4 directly; because of this we specify i386-unknown-linux-gnu.

     --host can also be left unspecified and, in that case, HOST-PLATFORM would automatically define itself as BUILD-PLATFORM, but this is not cross-compilation anymore.

          when --build and --host are different, configuration files will maintain the cross-compilation mode.

  * --target defines the system for which compiler tools will create output.

     TARGET-PLATFORM parameter is useful only for a limited number of programs. Although this parameter is often present when issuing ./configure --help, hardly any packages will need it.

     This parameter is only useful for performing tasks with different platforms; for instance, executable files compiled for different platforms can have a totally different code.

If we summarize, we have:

  * BUILD-PLATFORM: automatically guessed from platform in use; has to be specified if not guessed.

  * HOST-PLATFORM: if unspecified, automatically equals BUILD-PLATFORM. When BUILD-PLATFORM and HOST-PLATFORM values are identical, it is a local compilation; otherwise it is a cross-compilation.

  * TARGET-PLATFORM: defines the system for which compiler tools will create output; it equals HOST-PLATFORM if unspecified. GCC, binutils, and programs related to the platform's instructions have this parameter; most programs do not use this parameter.

FHS
---

The Filesystem Hierarchy Standard (FHS) has been created to specify the location and use of main directories on a GNU/Linux operating system. Common commands, user data, libraries have to be put inside a specific directory given in the standard. In this document, FHS is not respected: for instance, binaries are all located in /usr/bin, while bin, /sbin and /usr/sbin are symbolic links to it.

Commands
========

Because most commands are common for a regular Unix user, only uncommon commands are explained in this document. If you do not understand a command that is not explained, you can use the documentation available on your computer; in a terminal, typing man COMMAND should give you enough information. For GNU software, info PACKAGE can also give additional information.

To know more about command line, I suggest you read "Introduction to the Command Line" which is available on http://archive.flossmanuals.net/command-line/.

Preliminary Work
****************

     In order to complete the first steps of this chapter, you will need to have root permissions.

Package Users Introduction
==========================

Package Users is an interesting way of managing packages. Quotation from the project:

       * You want to know which packages your files belong to?

       * You want to deinstall software that doesn't have make uninstall?

       * You are bothered by programs installed setuid root behind your back?

       * You don't like packages quietly overwriting files from other packages?

       * You don't like package managers like RPM?

     YOU WANT TOTAL CONTROL USING ONLY UNIX BUILTINS?

The idea is to create one pair user:group per package to be installed: a Package User. Every Package User is part of an install group in order to be able to write in directories that are usually owned by the root user. In order to avoid that one package replaces a file or a directory installed by another one, the directories owned by the install group have the sticky attribute for users and groups other than the Package Users and the install group. For more details, read https://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt.

Package Installation
--------------------

To install a package with Package Users, you first have to type:

install_package foo

This will:

  * create the package user foo,

  * make package user foo a member of the install group,

  * create the directory /usr/src/foo,

  * copy the files from /etc/pkgusr/skel-package into /usr/src/foo,

  * log you in as foo.

After that, you have to get the source file of the program foo and install it as the user foo. Most of the time, the steps are simple:

su foo
wget http://path-to-source.org/foo-version.tar.gz
tar xf foo-version.tar.gz
cd foo-version
./configure --prefix=
make
make install
cd ..
rm -rf foo-version
rm foo-version.tar.gz
exit 0

Package Removal
---------------

To remove the files installed by a package:

find / -user foo | xargs rm

Then remove the package user:

userdel foo

Package Information
-------------------

To get information about files installed by package user FOO, do:

list_package foo

Be aware that this command may take some time to complete because the hard drive is scanned for files owned by Package User FOO.

Build OS
========

In the edition you are reading, GLLFSC 1.8 has been used to demonstrate that GLLFSC can build itself.

Because installing Package Users will modify the build OS, it is strongly recommended to have 3 partitions on your hard drive:

  * one partition for the current OS you are using, for instance /dev/sda1

  * one partition for the build OS, unmodified GLLFSC 1.8: for instance /dev/sda2

  * one partition for the OS we will build, GLLFSC 1.9: for instance /dev/sda3

You can create and modify partitions with a program like gparted.

Then, to mount the hard drive partition dedicated to the build OS, for instance /dev/sda2:

mkdir /mnt/sda2
mount /dev/sda2 /mnt/sda2

Then, extract GLLFSC 1.8 from gllfsc-pentium4-1.8-completed.tar.bz2 located at http://cjarry.org/gnu-linux/gllfsc/pentium4/gllfsc-pentium4-1.8-completed.tar.bz2:

cd /mnt/sda2
tar xf /path/to/gllfsc-pentium4-1.8-completed.tar.bz2
cd

Finally, edit /mnt/sda2/etc/fstab and /boot/grub/grub.cfg to your situation, so that you will be able to boot on GLLFSC 1.8.

A minimal /boot/grub/grub.cfg for classical hard disk could be:

insmod ext2
set default=0
set timeout=5

menuentry 'GLLFSC 1.8' {
    echo 'Loading linux-libre-3.10.108-gnu...'
    linux (hd0,2)/boot/vmlinuz-3.10.108-gnu root=/dev/sda2 quiet
}

A minimal /boot/grub/grub.cfg for hard disk supporting AHCI (Advanced Host Controller Interface) could be:

insmod part_msdos
insmod ext2
set default=0
set timeout=5

menuentry 'GLLFSC 1.8' {
    echo 'Loading linux-libre-3.10.108-gnu...'
    linux (ahci0,msdos2)/boot/vmlinuz-3.10.108-gnu root=/dev/sda2 quiet
}

Package Users Installation
==========================

Download Package Users archive at http://www.linuxfromscratch.org/hints/downloads/files/ATTACHMENTS/more_control_and_pkg_man/more_control_helpers.tar.bz2 inside /mnt/sda2/root. Then reboot on /dev/sda2, login as root and build:

tar xf more_control_helpers.tar.bz2
cd more_control_helpers
rm -v sbin/{groupadd,useradd}

mkdir -v /etc/pkgusr
rm -v etc/{build,skel-package/{build,build.conf,.project}}
cp -Rv etc/* /etc/pkgusr

mkdir -v /usr/lib/pkgusr
cp -Rv lib/* /usr/lib/pkgusr

cp -v bin/* /usr/bin

sed -i.orig 's/"\$1"$/"install"/' sbin/install_package

cp -v sbin/{add_package_user,install_package} /usr/sbin

groupadd -g 10000 install

sed -i.orig '/CREATE_MAIL_SPOOL/s/yes/no/' /etc/default/useradd

cd

Tmux Installation
=================

Tmux is a terminal multiplexer: it allows multiple terminal sessions to be accessed simultaneously in a single window. You can use it to read GLLFSC build instructions in a frame while building GLLFSC in another frame, both in the same window.

Connect to wired internet first with:

ifconfig eth0 up
dhcpcd eth0

Test the connection with:

# Bug in GLLFSC 1.8:
chmod u+x /sbin/ping

ping -c3 gnu.org

Then, build libevent (a tmux dependency) as root:

wget https://github.com/libevent/libevent/releases/download/release-2.0.22-\
stable/libevent-2.0.22-stable.tar.gz
tar xf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure \
    --prefix= \
    --disable-openssl
make
make install
cd ..
rm -rf libevent-2.0.22-stable*

Finally, build tmux as root:

wget https://github.com/tmux/tmux/releases/download/1.8/tmux-1.8.tar.gz
tar xf tmux-1.8.tar.gz
cd tmux-1.8
./configure \
    --prefix=
make
make install
cd ..
rm -rf tmux-1.8*

Work Directory Creation
=======================

To create the directory /gllfsc in which the system will be built:

mkdir -v /gllfsc

Setting up Required Environment Variables
=========================================

~/.bash_profile is a personal initialization file that is read when Bash is invoked as an interactive login shell (~ is the location of the user's home directory). To write the content of the default ~/.bash_profile of package users:

cat > /etc/pkgusr/bash_profile << 'EOF'
exec env -i HOME=${HOME} TERM=${TERM} PS1=${PS1} /bin/bash
EOF

The first line creates the file /etc/pkgusr/bash_profile and opens it for writing until EOF (End Of File) is written in it.

The second line tells Bash to execute /bin/bash with the option -i (or --ignore-environment) which will make Bash start with an empty environment. Variables HOME, TERM and PS1 define respectively the home directory of the current user, the terminal used and the primary prompt string displayed.

~/.bashrc is a personal initialization file that is read when Bash is invoked as an interactive shell but not a login one. To write the content of the file ~/.bashrc:

cat > /etc/pkgusr/bashrc << EOF
set +h
umask 022
alias less='less -ic'
#alias make='make -j4'
# Make prompt reflect that we are a package user.
export PROMPT_COMMAND='PS1="\[\e[35m\]\A-package \u:\W\[\e[00m\]> "'
#export PS1='\[\e[35m\]\A-\W\[\e[00m\]$ '
export LC_ALL=POSIX
export CROSS_HOST="$(echo $MACHTYPE |\
    sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
export CROSS_TARGET="i686-unknown-linux-gnu"
#export MABI=n32
#export MABI=64
export MARCH=pentium4
export PATH=/gllfsc/cross-tools/bin:/usr/lib/pkgusr:/bin:/usr/bin
# Go to the home directory whenever we su to a package user.
#cd

unset CFLAGS
unset CXXFLAGS
EOF
#source ~/.bash_profile

set +h tells Bash to not locate nor remember commands (hash) as they are looked up for execution.

umask 022 sets Bash process' file creation mask to 022. This results in permissions of `755' for those files.

PS1="\[\e[35m\]\A-package \u:\W\[\e[00m\]> " sets the primary prompt strings. The primary prompt strings are the strings you see before the commands you type in the terminal. The part \A-package \u:\W means that the time, in 24-hour HH:MM format will be displayed, then a `-', the package user, a `:' and finally the basename of $PWD, as in 19:33-package groff:bin. The part \$ adds a dollar sign at the end, \[\e[35m\] colors the strings in purple and \[\e[00m\] gets the original color back. For other colors, you can browse https://en.wikipedia.org/wiki/ANSI_escape_code.

LC_ALL is a macro used to define a single locale to overwrite other LC_* and LANG environment variables so that language, numeric values, time and other locale-dependant values have all the same value. It is set to the standard POSIX locale.

The value of variable CROSS_HOST equals the value of variable MACHTYPE of the current machine (for instance i686-pc-linux-gnu) modulo the second word, which is replaced by cross (i.e. i686-cross-linux-gnu).

The value of variable CROSS_TARGET equals the value of variable MACHTYPE of the machine for which the system is built (i.e. i686-unknown-linux-gnu).

The variable MABI defines the ABI (Application Binary Interface) for which the system will be built. -mabi is an option of GCC. n32/64 are for 64-bit CPUs only. 64 has 64-bit pointers and long integers, whereas n32 has 32-bit pointers and long integers. This does not apply to Pentium 4 machines.

The variable MARCH defines the architecture for which the system will be built. -march is an option of GCC (GNU Compiler Collection).

The variable PATH contains a colon-separated list of directories in which the shell looks for commands. The shell will first look for commands in /gllfsc/cross-tools/bin, then, if the command was not found, in /usr/lib/pkgusr, then in /bin and finally in /usr/bin. /usr/lib/pkgusr contains wrapper scripts to replace commands mkdir, chgrp, chown, chmod and install, so that permissions on files and folders are handled properly when using Package Users.

unset command removes the variable associated, here CFLAGS and CXXFLAGS. Those variables are used by GCC as extra flags given to the C compiler and the C++ compiler respectively.

Build Partition Creation
========================

     You can list existing partitions with fdisk -l.

     All data on the partition you chose in the next command will be deleted.

To dedicate the partition /dev/sda3 to the system build, and to define the filesystem to be used for it as ext3:

mke2fs -t ext3 /dev/sda3 -L gllfsc-1.9.0

Option -t is followed by the type of filesystem to be used. The filesystem ext3 is used as it is one of the most common filesystem used with the kernel Linux.

Mounting Partition
==================

To mount the hard drive partition used to build the system, for instance /dev/sda3:

mount /dev/sda3 /gllfsc

     You may wish to automatically mount /dev/sda3 under /gllfsc each time you boot from /dev/sda2. In this case, you can add the following line to your /etc/fstab:

     /dev/sda3   /   ext3   defaults   0   0

Creating Compilation and Download Directories
=============================================

mkdir -v /gllfsc/{build,download}

Downloads
=========

Downloading Packages
--------------------

If you have been disconnected from wired internet, reconnect with:

ifconfig eth0 up
dhcpcd eth0

The packages listed below are those used in this document.

Download those files under /gllfsc/download. You can use wget -nv URL to do this.

In order to download all the packages and patches automatically, you can create a download-packages-and-patches.sh file from gllfsc-pentium4-1.9.0.texi:

wget http://cjarry.org/gnu-linux/gllfsc/pentium4/gllfsc-pentium4-1.9.0.texi
sed -n '/^@node Packages Download/,/^@node Final Preparations/ p' \
        gllfsc-pentium4-1.9.0.texi \
    | sed -n '/^@itemize/,/^@end itemize/ p' \
    | grep '@uref' \
    | grep -v '^@c' \
    | grep -v 'ikiwiki' \
    | sed 's/.*@uref{//' \
    | sed 's/}.*//' \
    | sed 's,@/,,g' \
    | sed 's,^,wget --no-verbose --show-progress ,' \
    > download-packages-and-patches.sh

Then, make it executable with:

chmod u+x download-packages-and-patches.sh

And run it from inside /gllfsc/download:

cd /gllfsc/download
/root/download-packages-and-patches.sh

Check that all files have been downloaded with:

grep wget ~/download-packages-and-patches.sh | wc -l
ls -1 | wc -l

The two commands above should give the same result: 74.

     If you have trouble with a savannah mirror, you can have a full list of them at http://download.savannah.gnu.org/mirmon/savannah/. If you have trouble with a GNU mirror, you can have a full list of them at http://www.gnu.org/prep/ftp.html.

  * Autoconf: http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz.

  * Automake: http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz.

  * Bash: http://ftpmirror.gnu.org/bash/bash-4.2.tar.gz.

  * Bc: http://ftpmirror.gnu.org/bc/bc-1.07.1.tar.gz.

  * Binutils: http://ftpmirror.gnu.org/binutils/binutils-2.24.tar.bz2.

  * Bison: http://ftpmirror.gnu.org/bison/bison-2.7.tar.gz.

  * Bootscripts: http://ftp.clfs.org/pub/clfs/conglomeration/bootscripts-cross-lfs/bootscripts-cross-lfs-2.0.0.tar.xz.

  * Bzip2: ftp://sourceware.org/pub/bzip2/bzip2-1.0.6.tar.gz.

  * CA-Certificates: https://anduin.linuxfromscratch.org/sources/other/certdata.txt

  * Coreutils: http://ftpmirror.gnu.org/coreutils/coreutils-8.19.tar.xz.

  * DHCPCD: https://github.com/NetworkConfiguration/dhcpcd/archive/refs/tags/v6.1.0.tar.gz.

  * Diffutils: http://ftpmirror.gnu.org/diffutils/diffutils-3.3.tar.xz.

  * E2fsprogs: http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.42.8.tar.gz

  * Ed: http://ftpmirror.gnu.org/ed/ed-1.1.tar.bz2.

  * File: ftp://ftp.astron.com/pub/file/file-5.16.tar.gz.

  * Findutils: http://ftpmirror.gnu.org/findutils/findutils-4.4.2.tar.gz.

  * Flex: http://downloads.sourceforge.net/flex/flex-2.5.37.tar.bz2.

  * Gawk: http://ftpmirror.gnu.org/gawk/gawk-4.1.0.tar.gz.

  * GCC: http://ftpmirror.gnu.org/gcc/gcc-4.7.3/gcc-4.7.3.tar.bz2.

  * Gdbm: http://ftpmirror.gnu.org/gdbm/gdbm-1.11.tar.gz.

  * Gettext: http://ftpmirror.gnu.org/gettext/gettext-0.18.3.1.tar.gz.

  * Glibc: http://ftpmirror.gnu.org/glibc/glibc-2.18.tar.bz2.

  * Gmp: http://ftpmirror.gnu.org/gmp/gmp-5.1.3.tar.bz2.

  * Gperf: http://ftp.gnu.org/gnu/gperf/gperf-3.0.4.tar.gz.

  * Grep: http://ftpmirror.gnu.org/grep/grep-2.15.tar.xz.

  * Groff: http://ftpmirror.gnu.org/groff/groff-1.22.2.tar.gz.

  * GRUB: http://ftpmirror.gnu.org/grub/grub-2.00.tar.gz.

  * Gzip: http://ftpmirror.gnu.org/gzip/gzip-1.6.tar.gz.

  * Iana-Etc: http://sethwklein.net/iana-etc-2.30.tar.bz2.

  * Inetutils: http://ftpmirror.gnu.org/inetutils/inetutils-2.2.tar.gz.

  * Iproute2: https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.10.0.tar.bz2.

  * Kbd: https://www.kernel.org/pub/linux/utils/kbd/kbd-2.0.1.tar.gz.

  * Kmod: https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-15.tar.gz.

  * Less: http://www.greenwoodsoftware.com/less/less-458.tar.gz.

  * Libevent: https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz

  * Libpipeline: http://download.savannah.gnu.org/releases/libpipeline/libpipeline-1.3.0.tar.gz.

  * Libtasn1: http://ftpmirror.gnu.org/libtasn1/libtasn1-3.4.tar.gz.

  * Libtool: http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz.

  * Linux-Libre  (The kernel Linux is shipped with proprietary firmware. The version called Linux-Libre exists without them, recent versions are available for download at http://www.fsfla.org/ikiwiki/selibre/linux-libre/.). https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.108.tar.xz, http://linux-libre.fsfla.org/pub/linux-libre/releases/old/gen6/3.10.108-gnu/deblob-3.10 and http://linux-libre.fsfla.org/pub/linux-libre/releases/old/gen6/3.10.108-gnu/deblob-check.

  * Lynx: http://invisible-mirror.net/archives/lynx/tarballs/lynx2.8.9rel.1.tar.bz2.

  * M4: http://ftpmirror.gnu.org/m4/m4-1.4.17.tar.bz2.

  * Make: http://ftpmirror.gnu.org/make/make-4.0.tar.bz2.

  * Man-db: http://download.savannah.gnu.org/releases/man-db/man-db-2.6.7.1.tar.xz.

  * Man-Pages: https://www.kernel.org/pub/linux/docs/man-pages/Archive/man-pages-3.54.tar.bz2.

  * Mpc: http://ftpmirror.gnu.org/mpc/mpc-1.0.1.tar.gz.

  * Mpfr: http://ftpmirror.gnu.org/mpfr/mpfr-3.1.2.tar.bz2.

  * Nano: http://ftpmirror.gnu.org/nano/nano-2.3.2.tar.gz.

  * Ncurses: http://ftpmirror.gnu.org/ncurses/ncurses-5.9.tar.gz.

  * Openssl: https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1/openssl-1.1.1.tar.gz.

  * Patch: http://ftpmirror.gnu.org/patch/patch-2.7.1.tar.bz2.

  * Perl: http://www.cpan.org/src/5.0/perl-5.18.1.tar.gz.

  * Procps-ng: https://sourceforge.net/projects/procps-ng/files/Production/procps-ng-3.3.0.tar.gz.

  * Psmisc: https://sourceforge.net/projects/psmisc/files/psmisc/Archive/psmisc-22.20.tar.gz.

  * Readline: http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz.

  * Runit: https://smarden.org/runit/runit-2.1.2.tar.gz

  * Sed: http://ftpmirror.gnu.org/sed/sed-4.2.2.tar.bz2.

  * Shadow: https://github.com/shadow-maint/shadow/releases/download/4.6/shadow-4.6.tar.xz.

  * Sysvinit: http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf.tar.bz2.

  * Tar: http://ftpmirror.gnu.org/tar/tar-1.27.1.tar.bz2.

  * Texinfo: http://ftpmirror.gnu.org/texinfo/texinfo-4.13a.tar.gz.

  * Tmux: https://github.com/tmux/tmux/releases/download/1.8/tmux-1.8.tar.gz

  * Tzcode: http://www.iana.org/time-zones/repository/releases/tzcode2013h.tar.gz.

  * Tzdata: http://www.iana.org/time-zones/repository/releases/tzdata2013h.tar.gz.

  * Udev: https://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-175.tar.gz.

  * Util-Linux: https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.bz2.

  * Wireless_tools: https://hewlettpackard.github.io/wireless-tools/wireless_tools.29.tar.gz.

  * Wpa_supplicant: http://w1.fi/releases/wpa_supplicant-2.7.tar.gz.

  * Wget: http://ftpmirror.gnu.org/wget/wget-1.19.5.tar.gz.

  * XZ-Utils: https://tukaani.org/xz/xz-5.0.8.tar.bz2.

  * Zlib: http://www.zlib.net/fossils/zlib-1.2.8.tar.gz.

Downloading Patches
-------------------

Download those files under /gllfsc/download.

  * http://www.fsfla.org/svn/fsfla/software/linux-libre/lemote/gnewsense/tags/3.10.108-gnu_0freeloong/100gnu+freedo.patch this patch adds a picture of a GNU beside Freedo, Freedo being the mascot of Linux-Libre. The image can be seen on http://www.fsfla.org/ikiwiki/selibre/linux-libre/100gnu+freedo.

Final Preparations
==================

Target Filesystem Hierarchy Creation
------------------------------------

     You can automate the target filesystem creation with:

     csplit gllfsc-pentium4-1.9.0.texi '/subsection Target/' '{*}'

     # Remove useless stuff:
     nano xx01

     chmod u+x xx01
     ./xx01

cd /gllfsc

# /usr is required for cmake, python and ruby at least
mkdir -v usr
cd usr
mkdir -v bin include lib share src
ln -sv bin sbin
ln -sv lib lib32
ln -sv lib lib64
cd ..

mkdir -v boot dev etc home local mnt proc root run static sys
mkdir -v cross-tools libexec

ln -sv usr/bin bin
ln -sv usr/bin sbin
ln -sv usr/include include
ln -sv usr/lib lib
ln -sv usr/lib lib32
ln -sv usr/lib lib64
ln -sv usr/share share
ln -sv usr/src src

install -dv -m 0777 tmp
install -dv -m 1777 var

cd var
mkdir -v cache local lock log mail run spool
mkdir -pv lib/misc lib/locate
cd ..

install -dv -m 0750 root

cd local
mkdir -v bin include lib src
ln -sv bin sbin
ln -sv lib lib32
mkdir -v share
cd share
mkdir -v doc info locale man misc terminfo zoneinfo
mkdir -v man/man{1..8}
cd ../..
ln -sv share/man man
cd

The command install -dv -m 1777 var creates the directory var with the permissions to read, write and execute for everyone. The '1' in 1777 is the sticky bit which allows deletion of the file or directory having this attribute only for the owner of the file or directory.

Target Filesystem Hierarchy Ownership
-------------------------------------

To make Package Users work on the target filesystem hierarchy, we need to change its ownership:

chown -Rv 0:10000 /gllfsc
chmod -Rv g+w,o+t /gllfsc 2>/dev/null

chown -Rv 0:10000 /gllfsc changes the ownership of the files and folders under /gllfsc to user 0 (root) and group 10000 (install).

chmod -Rv g+w,o+t /gllfsc changes the file mode bits of the files and folders under /gllfsc to give write rights to the group (with g+w) and to add the sticky bit to others (with o+t) so that the files and folders installed by a Package User cannot be replaced by another one.

Creating needed user, groups and log files
------------------------------------------

     You can automate the creation of needed user, groups and log files with:

     csplit xx02 '/chapter Building/' '{*}'

     # Remove useless stuff:
     nano xx00

     chmod u+x xx00
     ./xx00

cat > /gllfsc/etc/passwd << EOF
root::0:0:root:/root:/bin/bash
EOF

The file /etc/passwd contains one line for each user account, with seven fields delimited by colons. These fields are:

  * login name;

  * optional encrypted password;

  * numerical user ID;

  * numerical group ID;

  * user name or comment field;

  * user home directory;

  * optional user command interpreter.

The first line creates the file /gllfsc/etc/passwd and opens it for writing until EOF (End Of File) is written in it.

cat > /gllfsc/etc/group << EOF
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
EOF

The file /etc/group is a text file which defines the groups on the system. There is one entry per line, with the following format: group_name:password:GID:user_list.

touch /gllfsc/var/run/utmp \
    /gllfsc/var/log/{btmp,lastlog,wtmp}
chmod -v 664 /gllfsc/var/run/utmp \
    /gllfsc/var/log/lastlog

cat > /root/.bash_profile << EOF
# Tab-complete package users when using su, finger or pinky
complete -o default -o nospace -A user su finger pinky
EOF

Building the Cross-Compilation Toolchain
****************************************

In this chapter, the cross-compilation toolchain is built as well as core components of the target system. Those will then be used to build the target system. The build process of the cross-compilation toolchain and tools takes about 2h30 on my Lenovo ThinkPad X200.

     You can automate parts of this chapter with:

     wget http://cjarry.org/gnu-linux/gllfsc/pentium4/automate-gllfsc.sh
     # Edit it to suit your needs:
     nano automate-gllfsc.sh
     chmod u+x automate-gllfsc.sh
     ./automate-gllfsc.sh

     Then you have to split the generated 1-build-cross.sh into instructions for each Package User:

     csplit 1-build-cross.sh '/install_package/' '{*}'
     rm xx00
     mv xx01 4.1-linux-headers
     mv xx02 4.2-binutils
     mv xx03 4.3-gcc-1

     csplit xx04 '/su - gcc/'
     mv xx00 4.4-glibc
     mv xx01 4.5-gcc-2

     mv xx05 5.1-file
     mv xx06 5.2-groff
     mv xx07 5.3-shadow
     mv xx08 5.4-m4
     mv xx09 5.5-ncurses

     chmod u+x 4.* 5.*

     Then, with nano, you can add the line set -e and the line set -v at the beginning of each script so that it will exit on error and print each instruction before executing it. Then, once inside the, for instance, linux-headers User personal directory:

     cp /root/4.1-linux-headers .
     ./4.1-linux-headers

Target Linux-Headers
====================

In this document, the kernel used is version 3.10.108 of Linux-libre.

Some changes made in the kernel since 3.14 require the non-free firmware of the radeon driver earlier at boot: without the firmware, the screen will remain blank on a machine that requires it, making the computer unusable. (See https://bugzilla.kernel.org/show_bug.cgi?id=77861 for details.)

You need Patch, Make and GCC on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install patch make gcc-4.4 and then sudo ln -sv gcc-4.4 /usr/bin/gcc.

install_package linux-headers
# 60 minutes mostly to deblob the kernel
cd /gllfsc/build

tar xf /gllfsc/download/linux-3.10.108.tar.xz
cd linux-3.10.108

cp /gllfsc/download/deblob-3.10 .
cp /gllfsc/download/deblob-check .

chmod u+x deblob*

# 47 minutes for the following command
./deblob-3.10 --force

rm deblob*
cd ..

# About 1 minute for the following command (491 MB)
tar -cf linux-libre-3.10.108-gnu.tar linux-3.10.108

# 12 minutes for the following command (69 MB)
# (requires ~840 MB of RAM)
xz -9 linux-libre-3.10.108-gnu.tar

#mv linux-libre-3.10.108-gnu.tar /gllfsc/download
mv linux-libre-3.10.108-gnu.tar.xz /gllfsc/download

cd linux-3.10.108

make mrproper
make ARCH=i386 headers_check
make ARCH=i386 INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /gllfsc/include
cd ..
rm -rf linux-3.10.108
cd

# Fix permissions for Package Users:
chmod g+w,o+t /gllfsc/include/scsi

exit 0

To login as user "linux-headers":

su - linux-headers

With the command su, it is possible to change the user ID. The option - provides an environment similar to what the user would expect had the user logged in directly.

60 minutes is the time it takes to build the package on Lenovo ThinkPad X200 with an Intel Core 2 Duo processor.

install_package linux-headers will:

  * create the package user linux-headers,

  * create the directory /usr/src/linux-headers,

  * copy the files from /etc/pkgusr/skel-package into /usr/src/linux-headers,

  * log you in as linux-headers.

The command make mrproper cleans the sources.

We need to specify ARCH=i386 as we are cross-compiling.

exit 0 exits the Package User environment.

Cross Binutils
==============

GNU Binutils (GNU binary utilities) is a collection of programs for manipulating binaries.

install_package binutils
# 5 minutes
tar xf /gllfsc/download/binutils-2.24.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/binutils-2.24
mkdir -pv ../binutils-build
cd ../binutils-build
CC="gcc" AR="ar" \
    ../binutils-2.24/configure \
    --prefix=/gllfsc/cross-tools \
    --build=${CROSS_HOST} \
    --host=${CROSS_HOST} \
    --target=${CROSS_TARGET} \
    --enable-64-bit-bfd \
    --with-sysroot=/gllfsc \
    --disable-nls \
    --enable-shared
make configure-host
make
make install
cp -v ../binutils-2.24/include/libiberty.h \
    /gllfsc/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.24
cd

# Fix permissions for Package Users:
cd /gllfsc/cross-tools
chmod g+w,o+t bin
chmod g+w,o+t i686-unknown-linux-gnu{,/lib}
chmod g+w,o+t share
chmod g+w,o+t share/man{,/man1}
chmod g+w,o+t share/info{,/dir}
cd

exit 0

CC="gcc" and AR="ar" are flags that tell the configure script to use the local commands gcc as the C compiler and ar as the program that handles archives.

--prefix=/gllfsc/cross-tools tells the configure script to install architecture-independant files in /gllfsc/cross-tools.

The option --enable-64-bit-bfd enables 64 bit for BFD (the Binary File Descriptor).

--with-sysroot=/gllfsc tells Binutils to consider /gllfsc as the root of a tree that contains (a subset of) the root filesystem of the target operating system. Target system headers, libraries and run-time object files will be searched in there.

The --enable-nls option enables Native Language Support (NLS), which lets Binutils output diagnostics in languages other than American English. Native Language Support is enabled by default if not doing a canadian cross build. The --disable-nls option disables NLS.

The option --enable-shared is used to build shared versions of libraries, if shared libraries are supported on the target platform. Use --disable-shared to build only static libraries.

Cross GCC (C support only)
==========================

GCC is the GNU Compiler Collection. It can compile many languages, of which only C and C++ will be enabled in this document.

In this section, we build a minimal GCC in order to build glibc.

     to build GMP (a GCC dependency), you need a version of GCC different from 4.3.2 on your system (https://gmplib.org/#STATUS):

     GCC 4.3.2 miscompiles GMP on 64-bit machines; please use a different gcc version (e.g., gcc 4.3.1 and gcc 4.3.3 both work properly). We have not been able to find any workaround for this gcc bug. Unfortunately, Debian 5.0 has decided to stay with this trouble gcc version, resulting in that many users strike this bug.

I recommend installing gcc-4.4 on gNewSense 4.0 to avoid this issue.

install_package gcc
# 20 minutes
tar xf /gllfsc/download/gcc-4.7.3.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/gcc-4.7.3
tar xf /gllfsc/download/gmp-5.1.3.tar.bz2
mv gmp-5.1.3 gmp
tar xf /gllfsc/download/mpc-1.0.1.tar.gz
mv mpc-1.0.1 mpc
tar xf /gllfsc/download/mpfr-3.1.2.tar.bz2
mv mpfr-3.1.2 mpfr
# Fix undefined reference to `__stack_check_guard' when compiling
# glibc:
sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
mkdir -pv ../gcc-build
cd ../gcc-build
../gcc-4.7.3/configure \
    --prefix=/gllfsc/cross-tools \
    --build=${CROSS_HOST} \
    --host=${CROSS_HOST} \
    --target=${CROSS_TARGET} \
    --with-sysroot=/gllfsc \
    --disable-multilib \
    --with-newlib \
    --disable-nls \
    --disable-shared \
    --disable-threads \
    --enable-languages=c \
    --with-mpfr-include="/gllfsc/build/gcc-4.7.3/mpfr/src" \
    --with-mpfr-lib="/gllfsc/build/gcc-build/mpfr/src/.libs" \
    --disable-decimal-float
# fixes bid_decimal_globals: fenv.h: No such file or directory

make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
cd ..
rm -r gcc-build
rm -r gcc-4.7.3
cd

# Fix permissions for Package Users:
chmod g+w,o+t /gllfsc/cross-tools/{include,lib}

exit 0

--disable-multilib specifies that multiple target libraries to support different target variants (Such as different ABI, for instance n32 and 64.), calling conventions, etc. should not be built. The default is to build a predefined set of them.

--with-newlib specifies that newlib is being used as the target C library.

--disable-threads specifies that threading support should be disabled.

--enable-languages=c specifies that only the C compiler and its runtime libraries should be built.

GCC provides a low-level runtime library, libgcc.a or libgcc_s.so.1 on some platforms. GCC generates calls to routines in this library automatically, whenever it needs to perform some operation that is too complicated to emit inline code for. This is built with make all-target-libgcc and installed with make install-target-libgcc

Target glibc
============

Glibc is the GNU C library. It provides macros, type definitions, and functions for tasks like string handling, mathematical computations, input/output processing, memory allocation and several other operating system services.

You need Gawk on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install gawk.

install_package glibc
# 20 minutes
tar xf /gllfsc/download/glibc-2.18.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/glibc-2.18
# Make 4.0 can be used to build glibc 2.18:
sed -i.orig '4775s/3.79\* | 3.\[89\]\*/& | 4.0/' configure
#sed -i.orig "s/ -lgcc_eh\| -lgcc_s//g" Makeconfig
#echo "" > ports/sysdeps/mips/mips64/n64/Makefile
#echo "" > ports/sysdeps/mips/mips64/n32/Makefile
#echo "" > ports/sysdeps/mips/mips32/Makefile
#sed -i "/default) machine=/s/n32/${MABI}/g" \
#    ports/sysdeps/mips/preconfigure
mkdir -pv ../glibc-build
cd ../glibc-build

cat > config.cache << EOF
libc_cv_c_cleanup=yes
libc_cv_slibdir=/lib
EOF

cat > configparms << EOF
install_root=/gllfsc
libdir=/lib
EOF

BUILD_CC="gcc" \
    CC="${CROSS_TARGET}-gcc -march=${MARCH}" \
    AR="${CROSS_TARGET}-ar" \
    RANLIB="${CROSS_TARGET}-ranlib" \
    ../glibc-2.18/configure \
    --prefix= \
    --libexecdir=/lib/glibc \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --disable-nls \
    --disable-profile \
    --enable-add-ons \
    --with-tls \
    --enable-kernel=3.10 \
    --with-__thread \
    --with-binutils=/gllfsc/cross-tools/bin \
    --with-headers=/gllfsc/include \
    --enable-obsolete-rpc \
    --cache-file=config.cache

make

make install

cd ..
rm -rf glibc-build
rm -rf glibc-2.18
cd

cat > /gllfsc/etc/nsswitch.conf << EOF
passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files
EOF

cat > /gllfsc/etc/ld.so.conf << EOF
/local/lib
EOF

# Make dir group-writable:
chmod g+w /gllfsc/share/info/dir
#mv /gllfsc/share/info/dir{,.glibc}

# Fix permissions for Package Users:
chmod g+w,o+t /gllfsc/include/sys
chmod g+w,o+t /gllfsc/share/info
chmod g+w,o+t /gllfsc/share/locale
chmod g+w,o+t /gllfsc/share/locale/*/LC_MESSAGES

exit 0

The file config.cache is used to attribute values to variables of the configure script.

libc_cv_forced_unwind=yes is used to avoid the error message error: forced unwind support is required.

libc_cv_c_cleanup=yes is used to avoid the error message error: the compiler must support C cleanup handling.

libc_cv_slibdir=/lib defines /lib as the directory in which the C library of the target system will be installed, instead of /lib64 or /lib32.

You can install glibc in a different location than where you configured it to go by setting the install_root variable on the command line for make install.  The value of this variable is prepended to all the paths for installation.  This is useful when setting up a chroot environment or preparing a binary distribution. The directory should be specified with an absolute file name.

Files listed in install-lib are installed in the directory specified by libdir in configparms or Makeconfig.

CC="${CROSS_TARGET}-gcc -march=${MARCH}" sets CC to the cross-compiler for the target's architecture, processor and ABI we configured the library for. AR and RANLIB are set to cross-compiling versions of ar and ranlib as the native tools are not configured to work with object files for the target we configured for.

--prefix= tells the configure script to install glibc in the root directory (/) of the target system.

Unlike previous builds, --host now equals ${CROSS_TARGET} instead of ${CROSS_HOST}. This is because we are building the glibc version that the target system will use. We won't have to build it later.

Profiling can be of help to optimize a program by analysing memory use, the usage of particular instructions, etc. Option --disable-profile is used to disable this.

Option --enable-add-ons is used to enable all the add-on packages in the main source directory, which includes the glibc-ports used to support the MIPS architecture.

The option --with-tls tells the configure script to use TLS (thread-local storage). Thread-local storage is a computer programming method that uses memory local to a thread.

The 3.10 parameter given to option --enable-kernel describes the earliest version of the Linux kernel the generated library is expected to support. The higher the version number is, the less compatibility code is added, and the faster the code gets.

Option --with-__thread enables threads in glibc.

The option --with-binutils=/gllfsc/cross-tools/bin tells the configure script to use the binutils (assembler and linker) built in the cross-compilation toolchain process.

--with-headers=/gllfsc/include indicates the location of the kernel Linux' headers.

--enable-obsolete-rpc tells the configure script to install remote procedure call (RPC) headers. Those may be required by some programs.

--cache-file=config.cache specifies the file in which cache variables are listed for configure.

The file /gllfsc/etc/nsswitch.conf contains the configuration of NSS (Name Service Switch). NSS is a facility in Unix-like operating systems that provides a variety of sources for common configuration databases and name resolution mechanisms. These sources include local operating system files (such as /etc/passwd, /etc/group, and /etc/hosts), the Domain Name System (DNS), the Network Information Service (NIS), and LDAP.

Cross GCC (C and C++ support)
=============================

In this section, we build a complete cross-compiler with support for C and C++ languages.

su - gcc
# 30 minutes
tar xf /gllfsc/download/gcc-4.7.3.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/gcc-4.7.3
tar xf /gllfsc/download/gmp-5.1.3.tar.bz2
mv gmp-5.1.3 gmp
tar xf /gllfsc/download/mpc-1.0.1.tar.gz
mv mpc-1.0.1 mpc
tar xf /gllfsc/download/mpfr-3.1.2.tar.bz2
mv mpfr-3.1.2 mpfr
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.7.3/configure \
    --prefix=/gllfsc/cross-tools \
    --build=${CROSS_HOST} \
    --host=${CROSS_HOST} \
    --target=${CROSS_TARGET} \
    --with-sysroot=/gllfsc \
    --disable-nls \
    --enable-shared \
    --enable-__cxa_atexit \
    --disable-multilib \
    --enable-c99 \
    --enable-long-long \
    --enable-threads=posix \
    --enable-languages=c,c++ \
    --with-mpfr-include="/gllfsc/build/gcc-4.7.3/mpfr/src" \
    --with-mpfr-lib="/gllfsc/build/gcc-build/mpfr/src/.libs"
make
make install
cd ..
rm -rf gcc-build
rm -rf gcc-4.7.3
cd
exit 0

--enable-__cxa_atexit enables __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects.  This is essential for fully standards-compliant handling of destructors, but requires __cxa_atexit in libc.

--enable-c99 enables support for the C99 standard.

--enable-long-long enables support for long long int types.

Building the Cross-Compilation Tools
************************************

File
====

The command file is used to determine the type of a file: text, executable or data.

install_package file
# 1 minute
tar xf /gllfsc/download/file-5.16.tar.gz -C /gllfsc/build
cd /gllfsc/build/file-5.16
./configure --prefix=/gllfsc/cross-tools
make
make install
cd ..
rm -rf file-5.16
cd

# Fix permissions for Package Users:
chmod g+w,o+t /gllfsc/cross-tools/share/man/man{3,4,5}

exit 0

Groff
=====

Groff is the GNU version of the roff document formatting system which is used to produce man pages.

You need G++ on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install g++-4.4 and then sudo ln -sv g++-4.4 /usr/bin/g++.

install_package groff
# 3 minutes
tar xf /gllfsc/download/groff-1.22.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/groff-1.22.2
PAGE=A4 \
    ./configure \
    --prefix=/gllfsc/cross-tools \
    --without-x
make
make install
cd ..
rm -rf groff-1.22.2
cd
exit 0

PAGE=A4 defines the default format of pages for printed output.

--without-x disables the dependency on the X window system.

Shadow
======

The package contains programs to handle users, groups and passwords in a secure way: passwords are encrypted.

install_package shadow
# 1 minute
tar xf /gllfsc/download/shadow-4.6.tar.xz -C /gllfsc/build
cd /gllfsc/build/shadow-4.6

cat > shadow-4.6.patch << 'EOF'
diff -Nur shadow-4.6.orig/lib/commonio.c shadow-4.6/lib/commonio.c
--- shadow-4.6.orig/lib/commonio.c	2025-10-09 16:53:30.514854530 +0200
+++ shadow-4.6/lib/commonio.c	2025-10-09 13:18:06.084698074 +0200
@@ -266,16 +266,6 @@
 		return NULL;
 	}

-#ifdef HAVE_FCHOWN
-	if (fchown (fileno (fp), sb->st_uid, sb->st_gid) != 0) {
-		goto fail;
-	}
-#else				/* !HAVE_FCHOWN */
-	if (chown (name, sb->st_mode) != 0) {
-		goto fail;
-	}
-#endif				/* !HAVE_FCHOWN */
-
 #ifdef HAVE_FCHMOD
 	if (fchmod (fileno (fp), sb->st_mode & 0664) != 0) {
 		goto fail;
diff -Nur shadow-4.6.orig/lib/Makefile.am shadow-4.6/lib/Makefile.am
--- shadow-4.6.orig/lib/Makefile.am	2018-04-29 18:42:37.000000000 +0200
+++ shadow-4.6/lib/Makefile.am	2025-10-12 08:09:14.903424913 +0200
@@ -2,6 +2,7 @@
 AUTOMAKE_OPTIONS = 1.0 foreign

 DEFS =
+AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"

 noinst_LTLIBRARIES = libshadow.la

--- shadow-4.6.orig/lib/Makefile.in	2018-04-29 18:45:50.000000000 +0200
+++ shadow-4.6/lib/Makefile.in	2025-10-12 08:09:37.866137840 +0200
@@ -340,6 +340,7 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
 AUTOMAKE_OPTIONS = 1.0 foreign
 noinst_LTLIBRARIES = libshadow.la
 libshadow_la_LDFLAGS = -version-info 0:0:0
diff -Nur shadow-4.6.orig/src/Makefile.am shadow-4.6/src/Makefile.am
--- shadow-4.6.orig/src/Makefile.am	2018-04-29 18:42:37.000000000 +0200
+++ shadow-4.6/src/Makefile.am	2025-10-11 22:30:08.389131714 +0200
@@ -3,11 +3,14 @@
 	.indent.pro

 ubindir = ${prefix}/bin
-usbindir = ${prefix}/sbin
+usbindir = ${prefix}/bin
 suidperms = 4755
 sgidperms = 2755

 AM_CPPFLAGS = \
+        -DSYSCONFDIR=\"$(sysconfdir)\" \
+        -DSG=\"`echo sg | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`\" \
+        -DVIGR=\"`echo vigr | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`\" \
 	-I${top_srcdir}/lib \
 	-I$(top_srcdir)/libmisc \
 	-DLOCALEDIR=\"$(datadir)/locale\"
@@ -124,13 +127,19 @@

 install-am: all-am
 	$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-	ln -sf newgrp	$(DESTDIR)$(ubindir)/sg
-	ln -sf vipw	$(DESTDIR)$(usbindir)/vigr
+	ln -sf `echo newgrp | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'` \
+                $(DESTDIR)$(ubindir)/`echo sg | \
+		sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`
+	ln -sf `echo vipw | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'` \
+                $(DESTDIR)$(usbindir)/`echo vigr | \
+		sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`
 	for i in $(suidbins); do \
-		chmod $(suidperms) $(DESTDIR)$(bindir)/$$i; \
+		chmod -f 4755 $(DESTDIR)$(bindir)/`echo $$i |\
+                sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
 	done
 	for i in $(suidubins); do \
-		chmod $(suidperms) $(DESTDIR)$(ubindir)/$$i; \
+		chmod -f 4755 $(DESTDIR)$(ubindir)/`echo $$i |\
+                sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
 	done
 if WITH_TCB
 	for i in $(shadowsgidubins); do \
diff -Nur shadow-4.6.orig/src/Makefile.in shadow-4.6/src/Makefile.in
--- shadow-4.6.orig/src/Makefile.in	2018-04-29 18:45:51.000000000 +0200
+++ shadow-4.6/src/Makefile.in	2025-10-11 22:26:21.423969169 +0200
@@ -509,10 +509,13 @@
 	.indent.pro

 ubindir = ${prefix}/bin
-usbindir = ${prefix}/sbin
+usbindir = ${prefix}/bin
 suidperms = 4755
 sgidperms = 2755
 AM_CPPFLAGS = \
+	-DSYSCONFDIR=\"$(sysconfdir)\" \
+	-DSG=\"`echo sg | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`\" \
+	-DVIGR=\"`echo vigr | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`\" \
 	-I${top_srcdir}/lib \
 	-I$(top_srcdir)/libmisc \
 	-DLOCALEDIR=\"$(datadir)/locale\"
@@ -1233,13 +1236,19 @@

 install-am: all-am
 	$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-	ln -sf newgrp	$(DESTDIR)$(ubindir)/sg
-	ln -sf vipw	$(DESTDIR)$(usbindir)/vigr
+	ln -sf `echo newgrp | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'` \
+		$(DESTDIR)$(ubindir)/`echo sg | \
+		sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`
+	ln -sf `echo vipw | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'` \
+		$(DESTDIR)$(usbindir)/`echo vigr | \
+		sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`
 	for i in $(suidbins); do \
-		chmod $(suidperms) $(DESTDIR)$(bindir)/$$i; \
+		chmod -f 4755 $(DESTDIR)$(bindir)/`echo $$i | \
+		sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
 	done
 	for i in $(suidubins); do \
-		chmod $(suidperms) $(DESTDIR)$(ubindir)/$$i; \
+		chmod -f 4755 $(DESTDIR)$(ubindir)/`echo $$i | \
+		sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
 	done
 @WITH_TCB_TRUE@	for i in $(shadowsgidubins); do \
 @WITH_TCB_TRUE@		chown root:shadow $(DESTDIR)$(ubindir)/$$i; \
EOF

patch -Np1 -i shadow-4.6.patch

sed -i.orig '/nscd_flush/s,^,//,' lib/commonio.c
cd src
sed -i.orig '/nscd_flush/s,^,//,' chfn.c chgpasswd.c chpasswd.c \
    chsh.c gpasswd.c groupadd.c groupdel.c groupmod.c grpck.c \
    grpconv.c grpunconv.c newusers.c passwd.c pwck.c pwconv.c \
    pwunconv.c useradd.c userdel.c usermod.c vipw.c
cd ..

sed -i.orig 's,"/etc,SYSCONFDIR",' lib/defines.h lib/getdef.c \
    lib/gshadow_.h lib/port.h libmisc/limits.c src/chsh.c \
    src/login_nopam.c src/logoutd.c src/suauth.c src/useradd.c

sed -i.orig '/amroot = .*uid/s,\((.*$\),1; /* \1 */,' src/chage.c \
    src/chsh.c src/passwd.c

sed -i.orig '/amroot.*bywho/s,\t(0 == bywho), 1 /* (0 == bywho) */,' \
    src/gpasswd.c
sed -i.orig 's,"sg",SG,' src/newgrp.c
sed -i.orig '/do_vipw = (/s,"vigr",VIGR,' src/vipw.c
sed -i.orig '/usbindir =/s,/sbin,/bin,' src/Makefile.{am,in}

sed -i.orig '/AM_CPPFLAGS =/s,=,= -DSYSCONFDIR=\\"$(sysconfdir)\\",' \
    libmisc/Makefile.{am,in}

#tar xf /gllfsc/download/gllfsc-pentium4-1.9.0-patches.tar.gz
#patch -Np1 -i shadow-4.6-sysroot_hacks-1.patch
#sed -i.orig \
#    's/bindir)\/\$\$i/bindir)\/mips64el-unknown-linux-gnu-\$\$i/' \
#    src/Makefile.am
#automake-1.11
#echo "shadow_cv_passwd_dir=/gllfsc/bin" > config.cache
#echo "ac_cv_func_lckpwdf=no" >> config.cache
./configure \
    --prefix=/gllfsc/cross-tools \
    --sbindir=/gllfsc/cross-tools/bin \
    --sysconfdir=/gllfsc/etc \
    --disable-shared \
    --without-audit \
    --without-libpam \
    --without-selinux \
    --program-prefix=${CROSS_TARGET}- \
    --cache-file=config.cache
sed -i.orig "/PASSWD_PROGRAM/s/passwd/${CROSS_TARGET}-&/" config.h
make
make install
cd ..
rm -rf shadow-4.6
cd
exit 0

Change ownership of group and passwd as root:

chown shadow:install /gllfsc/etc/group
chown shadow:install /gllfsc/etc/passwd

--without-audit, --without-libpam and --without-selinux disable support for auditing, PAM (Pluggable authentication modules) and SELinux (Security-Enhanced Linux). We do not need those extra features.

--program-prefix=${CROSS_TARGET}- prepends the value of CROSS_TARGET (that is i386-unknown-linux-gnu in this document) to installed program names for cross-compilation.

M4
==

Bison 2.5 requires M4 to be built.

GNU M4 is a package containing an implementation of the m4 macro language. GNU M4 is used in GNU Autoconf' configure files.

install_package m4
# 1 minute
tar xf /gllfsc/download/m4-1.4.17.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/m4-1.4.17
./configure --prefix=/gllfsc/cross-tools
make
make install
cd ..
rm -rf m4-1.4.17
cd
exit 0

Ncurses
=======

GNU ncurses contains a library used to write text-based user interfaces in a terminal-independent manner.

install_package ncurses
# 2 minutes
tar xf /gllfsc/download/ncurses-5.9.tar.gz -C /gllfsc/build
cd /gllfsc/build/ncurses-5.9
./configure \
    --prefix=/gllfsc/cross-tools \
    --without-shared \
    --disable-nls
make -C include
make -C progs tic
install -m755 progs/tic /gllfsc/cross-tools/bin
cd ..
rm -rf ncurses-5.9
cd
exit 0

--without-shared is used to avoid building the whole library as only tic is installed.

Cleaning up Cross-Compilation Toolchain
=======================================

In order to save some space, binaries and libraries of cross-compilation tools can be stripped out.

     incorrect cleaning arguments used against library files can lead to library files breaking. For this reason, be careful of the command arguments. If you are not comfortable with this, you can skip this section as it will have no effect on the process of building the target system.

cd /gllfsc/cross-tools
strip --strip-all bin/*
strip --strip-debug lib/*
cd

--strip-all removes all symbols. This command reduces the size of the bin directory's content from 34 MB to 10 MB.

--strip-debug removes debugging symbols only. This command reduces the size of the lib directory's content from 14 MB to 13 MB.

Building the Target System
**************************

After having set up the cross-compilation toolchain and tools, the operating system for the target machine is built in this chapter. This build process takes about 2 hours on my Lenovo ThinkPad X200.

Setting up the Environment
==========================

Because this chapter is about the build of the target system and not the build of the cross-compilation toolchain and tools anymore, we need to update some environment variables.

For more convenience, we can set environment variables up in the ~/.bashrc file, so that this setup is preserved when logging in:

export CROSS_TARGET="i686-unknown-linux-gnu"
export MARCH="pentium4"

cat >> /etc/pkgusr/bashrc << EOF
export CC="${CROSS_TARGET}-gcc -march=${MARCH}"
export CXX="${CROSS_TARGET}-g++ -march=${MARCH}"
export AR="${CROSS_TARGET}-ar"
export AS="${CROSS_TARGET}-as"
export RANLIB="${CROSS_TARGET}-ranlib"
export LD="${CROSS_TARGET}-ld"
export STRIP="${CROSS_TARGET}-strip"
EOF
#source /etc/pkgusr/bash_profile

CC is the flag that indicates the C compiler to be used, CXX the C++ compiler, AR the archiver, AS the assembler, RANLIB the archives' index generator, LD the linker and STRIP the program for stripping.

All the programs to be used are prefixed with ${CROSS_TARGET}- in order to use the cross-compilation toolchain instead of the toolchain of the host.

Automating the Build
====================

You can automate parts of this chapter by splitting the script 2-build-target-system.sh generated in see Building the Cross-Compilation Toolchain into instructions for each Package User:

csplit 2-build-target-system.sh '/install_package/' '{*}'
rm xx00
mv xx01 6.2-man-pages

csplit xx02 '/su - binutils/'
mv xx00 6.3-zlib
mv xx01 6.4-binutils
rm xx02

mv xx03 6.5-gmp
mv xx04 6.6-mpfr

csplit xx05 '/su - gcc/'
mv xx00 6.7-mpc
mv xx01 6.-8gcc
rm xx05

mv xx06 6.9-sed
mv xx07 6.10-e2fsprogs
mv xx08 6.11-coreutils
mv xx09 6.12-iana-etc
mv xx10 6.13-m4

csplit xx11 '/su -/'
mv xx00 6.14-bison
mv xx01 6.15-ncurses
rm xx11

mv xx12 6.16-procps-ng
mv xx13 6.17-libtool
mv xx14 6.18-readline
mv xx15 6.19-autoconf
mv xx16 6.20-automake
mv xx17 6.21-bash
mv xx18 6.22-bzip2
mv xx19 6.23-dhcpcd

csplit xx20 '/su -/'
mv xx00 6.24-diffutils
mv xx01 6.25-file
rm xx20

mv xx21 6.26-findutils
mv xx22 6.27-flex
mv xx23 6.28-gawk
mv xx24 6.29-gdbm
mv xx25 6.30-gettext

csplit xx26 '/su -/'
mv xx00 6.31-grep
mv xx01 6.32-groff
rm xx26

mv xx27 6.33-gzip
mv xx28 6.34-inetutils
mv xx29 6.35-iproute2
mv xx30 6.36-kbd
mv xx31 6.37-kmod
mv xx32 6.38-less
mv xx33 6.39-libpipeline
mv xx34 6.40-make
mv xx35 6.41-man-db
mv xx36 6.42-nano
mv xx37 6.43-patch

csplit xx38 '/su -/'
mv xx00 6.44-psmisc
mv xx01 6.45-shadow
rm xx38

mv xx39 6.46-sysvinit
mv xx40 6.47-tar
mv xx41 6.48-texinfo
mv xx42 6.49-udev
mv xx43 6.50-util-linux
mv xx44 6.51-xz-utils
mv xx45 6.52-bootscripts
mv xx46 6.53-linux-libre

# Edit 6.53-linux-libre and remove lines from ``Processor'' to
# ``Bootup logo''
nano 6.53-linux-libre

mv xx47 6.54-grub
chmod u+x 6.*

Then, with nano, you can remove lines beginning with install_package and su -, and add the line set -e and the line set -v at the beginning of each script so that it will exit on error and print each instruction before executing it. To automate this step:

sed -i 's,install_package.*,set -e\nset -v\n,' 6.*
sed -i 's,su -.*,set -e\nset -v\n,' 6.*

Then, once inside the, for instance, man-pages User personal directory:

cp /root/6.2-man-pages .
./6.2-man-pages

Man Pages
=========

The man-pages package documents the kernel Linux and C library's interfaces that are used by user-space programs.

install_package man-pages
# 1 minute
tar xf /gllfsc/download/man-pages-3.54.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/man-pages-3.54
make prefix=/gllfsc install
cd ..
rm -rf man-pages-3.54
cd
# shadow installs its own version of getspnam.3 and passwd.5:
mv -v /gllfsc/share/man/man3/getspnam.3{,.man-pages}
mv -v /gllfsc/share/man/man5/passwd.5{,.man-pages}

# Fix permissions for Package Users:
chmod g+w,o+t /gllfsc/share/man
chmod g+w,o+t /gllfsc/share/man/man*

exit 0

The option prefix=/gllfsc is used to install the man pages on the target directory instead of the /usr directory of the host.

Zlib
====

Zlib is a compression/decompression library.

install_package zlib
# 1 minute
tar xf /gllfsc/download/zlib-1.2.8.tar.gz -C /gllfsc/build
cd /gllfsc/build/zlib-1.2.8
./configure --prefix=
make AR="${AR}"
make prefix=/gllfsc install
cd ..
rm -rf zlib-1.2.8
cd

# Fix permissions for Package User e2fsprogs:
chmod g+w,o+t /gllfsc/lib/pkgconfig

exit 0

In order to build zlib by cross-compilation, the flag AR has to be equal to ${AR}.

Binutils
========

GNU Binutils (GNU binary utilities) is a collection of programs for manipulating binaries.

su - binutils
# 5 minutes
tar xf /gllfsc/download/binutils-2.24.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/binutils-2.24
mkdir -pv ../binutils-build
cd ../binutils-build
../binutils-2.24/configure \
    --prefix= \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --target=${CROSS_TARGET} \
    --enable-64-bit-bfd \
    --enable-shared \
    --disable-nls
make configure-host
make tooldir=
make DESTDIR=/gllfsc tooldir= install
cp -v ../binutils-2.24/include/libiberty.h /gllfsc/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.24
cd
# For autoconf:
mv /gllfsc/share/info/standards.info{,.binutils} -v
# For groff:
#mv /gllfsc/share/info/dir{,.binutils} -v
exit 0

The option --host is now set to CROSS_TARGET because the host that will run this build will be the target system.

GMP
===

GMP (GNU multiple precision arithmetic library) is required to build GCC.

install_package gmp
# 2 minutes
tar xf /gllfsc/download/gmp-5.1.3.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/gmp-5.1.3
./configure \
    --host=${CROSS_TARGET} \
    --prefix= \
    --enable-cxx
make
make DESTDIR=/gllfsc install
rm -v /gllfsc/lib/lib{gmp,gmpxx}.la
cd ..
rm -rf gmp-5.1.3
cd
exit 0

The option --enable-cxx enables support for the C++ language.

The files /gllfsc/lib/lib{gmp,gmpxx}.la are removed to avoid the following error when building MPFR: /lib/libgmp.so: could not read symbols: File in wrong format.

MPFR
====

GNU MPFR (Multiple Precision Floating-Point Reliably) is a portable C library for arbitrary-precision binary floating-point computation with correct rounding.

install_package mpfr
# 1 minute
tar xf /gllfsc/download/mpfr-3.1.2.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/mpfr-3.1.2
./configure \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
rm -v /gllfsc/lib/libmpfr.la
cd ..
rm -rf mpfr-3.1.2
cd

# Fix permissions for Package User procps-ng:
chmod g+w,o+t /gllfsc/share/doc

exit 0

The file /gllfsc/lib/libmpfr.la is removed to avoid the following error when building MPC: /lib/libmpfr.so: could not read symbols: File in wrong format.

MPC
===

GNU MPC (Multiple Precision Complex Library) is a C library for the arithmetic of complex numbers with arbitrarily high precision and correct rounding of the result.

install_package mpc
# 1 minute
tar xf /gllfsc/download/mpc-1.0.1.tar.gz -C /gllfsc/build
cd /gllfsc/build/mpc-1.0.1
./configure \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf mpc-1.0.1
cd
exit 0

GCC
===

GCC is the GNU Compiler Collection.

su - gcc
# 25 minutes
tar xf /gllfsc/download/gcc-4.7.3.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/gcc-4.7.3
sed -i.orig 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
sed -i.orig 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.7.3/configure \
    --prefix= \
    --libexecdir=/lib \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --target=${CROSS_TARGET} \
    --enable-shared \
    --enable-threads=posix \
    --enable-__cxa_atexit \
    --enable-c99 \
    --enable-long-long \
    --disable-multilib \
    --enable-clocale=gnu \
    --enable-languages=c,c++ \
    --disable-libstdcxx-pch \
    --disable-nls
make
make DESTDIR=/gllfsc install
ln -sv gcc /gllfsc/bin/cc
cd ..
rm -rf gcc-build
rm -rf gcc-4.7.3
cd
exit 0

sed -i.orig 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in is used as we already installed the library libiberty.a with Binutils.

Using --enable-clocale=gnu option ensures that the correct locale will automatically be chosen.

Option --disable-libstdcxx-pch disables support for precompiled headers (PCH).

The line ln -sv gcc /gllfsc/bin/cc creates a symbolic link cc that points to gcc.

Sed
===

GNU sed is a stream editor: it is used to perform basic text transformations on an input stream (a file or input from a pipeline).

install_package sed
# 1 minute
tar xf /gllfsc/download/sed-4.2.2.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/sed-4.2.2
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --bindir=/bin \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf sed-4.2.2
cd
exit 0

E2fsprogs
=========

E2fsprogs is a package that contains tools to handle the ext2, ext3 and ext4 filesystems.

install_package e2fsprogs
# 2 minutes
tar xf /gllfsc/download/e2fsprogs-1.42.8.tar.gz -C /gllfsc/build
cd /gllfsc/build/e2fsprogs-1.42.8
mkdir -v build
cd build
../configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --with-root-prefix="" \
    --enable-elf-shlibs \
    --disable-nls
make
make DESTDIR=/gllfsc install
make DESTDIR=/gllfsc install-libs
cd ../..
rm -rf e2fsprogs-1.42.8
cd
rm -v /gllfsc/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so
# util-linux installs its own versions:
mv -v /gllfsc/bin/blkid{,.e2fsprogs}
mv -v /gllfsc/bin/findfs{,.e2fsprogs}
mv -v /gllfsc/bin/fsck{,.e2fsprogs}
mv -v /gllfsc/bin/uuidgen{,.e2fsprogs}
mv -v /gllfsc/lib/libuuid.a{,.e2fsprogs}
mv -v /gllfsc/lib/libblkid.a{,.e2fsprogs}
mv -v /gllfsc/bin/uuidd{,.e2fsprogs}
mv -v /gllfsc/lib/libuuid.so.1{,.e2fsprogs}
mv -v /gllfsc/lib/libblkid.so.1{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man1/uuidgen.1{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_clear.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_compare.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_copy.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_generate.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_is_null.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_parse.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_time.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_unparse.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_generate_random.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/uuid_generate_time.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man3/libblkid.3{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man8/uuidd.8{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man8/blkid.8{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man8/findfs.8{,.e2fsprogs}
mv -v /gllfsc/usr/share/man/man8/fsck.8{,.e2fsprogs}

mv -v /gllfsc/usr/include/blkid/blkid.h{,.e2fsprogs}
mv -v /gllfsc/usr/lib/pkgconfig/uuid.pc{,.e2fsprogs}
mv -v /gllfsc/usr/lib/pkgconfig/blkid.pc{,.e2fsprogs}

mv -v /gllfsc/usr/include/uuid/uuid.h{,.e2fsprogs}

# Fix permissions for Package User util-linux:
chmod g+w,o+t /gllfsc/usr/include/blkid
chmod g+w,o+t /gllfsc/usr/include/uuid

exit 0

--with-root-prefix="" is used to put e2fsprogs binaries inside /sbin instead of PREFIX/sbin which would be /sbin.

Option --enable-elf-shlibs enables e2fsprogs shared libraries.

make DESTDIR=/gllfsc install-libs is used to install libraries, those are not installed with make DESTDIR=/gllfsc install.

The sequence of commands that follows first removes symbolic links /gllfsc/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so which point respectively to abolute paths /lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so. In order to use the libraries of the target operating system, we need to symlink /gllfsc/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so to their relative paths files.

Coreutils
=========

GNU coreutils (core utilities) includes the standard programs for text and file manipulation.

On gNewSense Parkes, you need to install xz-utils to extract the package.

install_package coreutils
# 3 minutes
tar xf /gllfsc/download/coreutils-8.19.tar.xz -C /gllfsc/build
cd /gllfsc/build/coreutils-8.19
cat > config.cache << EOF
fu_cv_sys_stat_statfs2_bsize=yes
gl_cv_func_mbrtowc_incomplete_state=yes
gl_cv_func_mbrtowc_nul_retval=yes
gl_cv_func_mbrtowc_null_arg=yes
gl_cv_func_mbrtowc_retval=yes
gl_cv_func_btowc_eof=yes
gl_cv_func_wcrtomb_retval=yes
gl_cv_func_wctob_works=yes
gl_cv_func_fstatat_zero_flag=yes
EOF
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --enable-install-program=hostname \
    --enable-no-install-program=kill,uptime \
    --cache-file=config.cache \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf coreutils-8.19
cd
# inetutils installs its own version of hostname:
mv -v /gllfsc/bin/hostname{,.coreutils}
mv -v /gllfsc/share/man/man1/hostname.1{,.coreutils}
# shadow installs its own version of groups:
mv -v /gllfsc/bin/groups{,.coreutils}
mv -v /gllfsc/share/man/man1/groups.1{,.coreutils}
exit 0

The variables listed in the file config.cache are used in order to avoid that the configure script evaluate their values: otherwise the build may fail when cross-compiling.

We use --enable-install-program=hostname to install the command hostname which is not built by default.

We use --enable-no-install-program=kill,uptime in order not to install commands kill and uptime. Those commands will be installed by the package procps.

iana-etc
========

The iana-etc package installs services and protocols using data from the Internet Assigned Numbers Authority (IANA).

install_package iana-etc
# 1 minute
tar xf /gllfsc/download/iana-etc-2.30.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/iana-etc-2.30
make
make DESTDIR=/gllfsc install
cd ..
rm -rf iana-etc-2.30
cd
exit 0

M4
==

GNU M4 is a package containing an implementation of the m4 macro language. GNU M4 is used in GNU Autoconf' configure files.

install_package m4
# 1 minute
tar xf /gllfsc/download/m4-1.4.17.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/m4-1.4.17
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf m4-1.4.17
cd
exit 0

Bison
=====

GNU bison parser generator.

install_package bison
# 1 minute
tar xf /gllfsc/download/bison-2.7.tar.gz -C /gllfsc/build
cd /gllfsc/build/bison-2.7
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
#echo '#define YYENABLE_NLS 1' >> config.h
make
make DESTDIR=/gllfsc install
cd ..
rm -rf bison-2.7
cd

# Fix permissions for Package User libtool:
chmod g+w,o+t /gllfsc/share/aclocal

exit 0

Ncurses
=======

su - ncurses
# 2 minutes
tar xf /gllfsc/download/ncurses-5.9.tar.gz -C /gllfsc/build
cd /gllfsc/build/ncurses-5.9
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --with-shared \
    --enable-widec \
    --without-debug \
    --without-ada \
    --with-build-cc="gcc -D_GNU_SOURCE" \
    --libdir=/lib \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf ncurses-5.9
cd
exit 0

Option --enable-widec enables wide characters support in ncurses.

Option --without-ada disables support for the Ada programming language inside ncurses.

Procps-ng
=========

The procps-ng package contains utilities that give information about processes using the /proc filesystem. The package includes the commands ps, top, vmstat, w, kill, free, slabtop, and skill.

install_package procps-ng
# 1 minute
ln -sv ncursesw/curses.h /gllfsc/include/curses.h
ln -sv ncursesw/ncurses.h /gllfsc/include/ncurses.h
ln -sv ncursesw/term.h /gllfsc/include/term.h
ln -sfv libncursesw.so /gllfsc/lib/libncurses.so
tar xf /gllfsc/download/procps-ng-3.3.0.tar.gz -C /gllfsc/build
cd /gllfsc/build/procps-ng-3.3.0

# From http://lists.gnu.org/archive/html/bug-make/2010-07/msg00153.html
# ps/proc.mk makefile uses LIBPROC, which is set in proc/module.mk:
#sed '177s,\*/module.mk,proc/module.mk ps/proc.mk,' -i.orig Makefile

./configure --prefix=
make
#make \
#    CPPFLAGS= \
#    lib64=lib
make DESTDIR=/gllfsc install
#make \
#    DESTDIR=/gllfsc \
#    lib64=lib \
#    ldconfig= \
#    install="install -D" \
#    install
cd ..
rm -rf procps-ng-3.3.0
cd
# util-linux installs its own version of kill:
mv -v /gllfsc/bin/kill{,.procps}
mv -v /gllfsc/usr/share/man/man1/kill.1{,.procps}
exit 0

Option lib64=lib makes the directory /lib the one where to put 64 bit libraries, default would be /lib64.

Option ldconfig= is used in order not to use current host's ldconfig.

Option install="install -D" is used so that all the files installed are owned by the current user. By default, all installed files are owned by root.

Libtool
=======

GNU libtool is a generic library support script. It hides the complexity of using shared libraries behind a consistent, portable interface.

install_package libtool
# 1 minute
tar xf /gllfsc/download/libtool-2.4.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/libtool-2.4.2
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf libtool-2.4.2
cd
exit 0

Readline
========

The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in.

install_package readline
# 1 minute
tar xf /gllfsc/download/readline-6.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/readline-6.2
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --libdir=/lib
make
make DESTDIR=/gllfsc install
make DESTDIR=/gllfsc install-doc
cd ..
rm -rf readline-6.2
cd
exit 0

Autoconf
========

GNU autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages. These scripts can adapt the packages to many kinds of UNIX-like systems without manual user intervention.

install_package autoconf
# 1 minute
tar xf /gllfsc/download/autoconf-2.69.tar.gz -C /gllfsc/build
cd /gllfsc/build/autoconf-2.69
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf autoconf-2.69
cd
exit 0

Automake
========

GNU automake is a tool for automatically generating Makefile.in files compliant with the GNU Coding Standards (http://www.gnu.org/prep/standards/).

You need Autoconf on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install autoconf (version 2.69 here).

install_package automake
# 1 minute
tar xf /gllfsc/download/automake-1.14.tar.gz -C /gllfsc/build
cd /gllfsc/build/automake-1.14
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf automake-1.14
cd
exit 0

Bash
====

GNU Bash (Bourne again shell) is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh).

install_package bash
# 2 minutes
tar xf /gllfsc/download/bash-4.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/bash-4.2
cat > config.cache << EOF
ac_cv_func_mmap_fixed_mapped=yes
ac_cv_func_strcoll_works=yes
ac_cv_func_working_mktime=yes
bash_cv_func_sigsetjmp=present
bash_cv_getcwd_malloc=yes
bash_cv_job_control_missing=present
bash_cv_printf_a_format=yes
bash_cv_sys_named_pipes=present
bash_cv_ulimit_maxfds=yes
bash_cv_under_sys_siglist=yes
bash_cv_unusable_rtsigs=no
gt_cv_int_divbyzero_sigfpe=yes
EOF
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --bindir=/bin \
    --cache-file=config.cache \
    --without-bash-malloc \
    --with-installed-readline \
    --disable-nls
make
make \
    DESTDIR=/gllfsc \
    htmldir=/share/doc/bash-4.2 \
    install
ln -sv bash /gllfsc/bin/sh
cd ..
rm -rf bash-4.2
cd
exit 0

The variables listed in the file config.cache are used in order to avoid that the configure script evaluate their values: otherwise the build may fail when cross-compiling.

Option --without-bash-malloc tells the configure script not to use the malloc function shipped with Bash. Glibc's version will be used instead.

Option --with-installed-readline tells the configure script to use the installed readline library instead of the one shipped with Bash.

ln -sv bash /gllfsc/bin/sh creates a symlink sh to bash.

Bzip2
=====

Bzip2 is a package that contains utilities to compress and decompress files with a better original size/compressed size ratio than gzip.

install_package bzip2
# 1 minute
tar xf /gllfsc/download/bzip2-1.0.6.tar.gz -C /gllfsc/build
cd /gllfsc/build/bzip2-1.0.6
sed -i.orig "/^all:/s/ test//" Makefile
sed -i.orig 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile
make \
    -f Makefile-libbz2_so \
    CC="${CC}" \
    AR="${AR}" \
    RANLIB="${RANLIB}"
make clean
make \
    CC="${CC}" \
    AR="${AR}" \
    RANLIB="${RANLIB}"
make \
    PREFIX=/gllfsc \
    install
cp -av libbz2.so* /gllfsc/lib
ln -sv ../../lib/libbz2.so.1.0 /gllfsc/lib/libbz2.so
rm -v /gllfsc/bin/{bunzip2,bzcat,bzip2}
cp -v bzip2-shared /gllfsc/bin/bzip2
ln -sv bzip2 /gllfsc/bin/bunzip2
ln -sv bzip2 /gllfsc/bin/bzcat
cd ..
rm -rf bzip2-1.0.6
cd
exit 0

sed -i.orig "/^all:/s/ test//" Makefile is used to skip tests when building.

sed -i.orig 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile is used in order to have relative path symlinks instead of absolute ones.

Option -f Makefile-libbz2_so is used to build shared libraries.

Flags CC, AR and RANLIB are used so that bzip2 is built using cross-compilation tools instead of the host's ones.

make clean is used to clean up temporary files.

The second build commands are used to build static libraries.

DHCPCD
======

DHCPCD is a wrapper for the DHCP (Dynamic Host Configuration Protocol) client daemon.

install_package dhcpcd
# 1 minute
tar xf /gllfsc/download/v6.1.0.tar.gz -C /gllfsc/build
cd /gllfsc/build/dhcpcd-6.1.0
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --bindir=/sbin \
    --sysconfdir=/etc \
    --dbdir=/var/lib/dhcpcd \
    --libexecdir=/lib/dhcpcd \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf dhcpcd-6.1.0
cd
exit 0

Diffutils
=========

GNU Diffutils is a package of several programs related to finding differences between files.

install_package diffutils
# 1 minute
tar xf /gllfsc/download/diffutils-3.3.tar.xz -C /gllfsc/build
cd /gllfsc/build/diffutils-3.3
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf diffutils-3.3
cd
exit 0

File
====

su - file
# 1 minute
tar xf /gllfsc/download/file-5.16.tar.gz -C /gllfsc/build
cd /gllfsc/build/file-5.16
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf file-5.16
cd
exit 0

Findutils
=========

The GNU Find Utilities are typically used to provide directory search and file locating capabilities.

install_package findutils
# 1 minute
tar xf /gllfsc/download/findutils-4.4.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/findutils-4.4.2
cat > config.cache << EOF
gl_cv_func_wcwidth_works=yes
gl_cv_header_working_fcntl_h=yes
ac_cv_func_fnmatch_gnu=yes
EOF
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --libexecdir=/lib/locate \
    --localstatedir=/var/lib/locate \
    --cache-file=config.cache \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf findutils-4.4.2
cd
exit 0

Flex
====

Flex is a tool for generating scanners. A scanner, sometimes called a tokenizer, is a program which recognizes lexical patterns in text.

install_package flex
# 1 minute
tar xf /gllfsc/download/flex-2.5.37.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/flex-2.5.37
# From http://sourceforge.net/p/flex/bugs/151/
sed -i.orig '1s/$/\n#undef malloc\n#undef realloc/' \
    lib/realloc.c
cat > config.cache << EOF
ac_cv_path_M4="/bin/m4"
EOF
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --cache-file=config.cache \
    --disable-nls
make
make DESTDIR=/gllfsc install
ln -sv libfl.a /gllfsc/lib/libl.a
cd ..
rm -r flex-2.5.37
cd

cat > /gllfsc/bin/lex << EOF
#!/bin/sh
exec /bin/flex -l \$@
EOF
chmod -v 755 /gllfsc/bin/lex
exit 0

config.cache forces flex to use /bin/m4 instead of /gllfsc/cross-tools/bin/m4 on the target machine.

For compatibility issues, we create the symlink libl.a.

We then create target system's /bin/lex that will execute flex with option -l in order to behave with maximal compatibility like lex.

Gawk
====

GNU awk (Gawk) is a program used to select particular records in a file and perform operations upon them.

install_package gawk
# 2 minutes
tar xf /gllfsc/download/gawk-4.1.0.tar.gz -C /gllfsc/build
cd /gllfsc/build/gawk-4.1.0
sed -i.orig \
    '/check-recursive all-recursive/s/ check-for-shared-lib-support//' \
    extension/Makefile.in
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --libexecdir=/lib \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -r gawk-4.1.0
cd
exit 0

The sed expression is used to avoid the error Building the extensions is not supported on this platform.

Gdbm
====

GNU dbm is a library of database functions.

install_package gdbm
# 1 minute
tar xf /gllfsc/download/gdbm-1.11.tar.gz -C /gllfsc/build
cd /gllfsc/build/gdbm-1.11
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -r gdbm-1.11
cd
# fix man-db's /lib/libpipeline.so: error adding symbols: File in
# wrong format
rm /gllfsc/lib/libgdbm.la
exit 0

Gettext
=======

GNU gettext utilities are a set of tools that provides a framework to help packages produce multi-lingual messages.

install_package gettext
# 7 minutes
tar xf /gllfsc/download/gettext-0.18.3.1.tar.gz -C /gllfsc/build
cd /gllfsc/build/gettext-0.18.3.1
cat > config.cache << EOF
am_cv_func_iconv_works=yes
gl_cv_func_wcwidth_works=yes
gt_cv_func_printf_posix=yes
gt_cv_int_divbyzero_sigfpe=yes
EOF
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --cache-file=config.cache \
    --disable-nls
make
#cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i}
#cp gettext-tools/src/.libs/libgettextsrc.la{,i}
make DESTDIR=/gllfsc install
cd ..
rm -rf gettext-0.18.3.1
cd
exit 0

Grep
====

GNU grep command searches one or more input files for lines containing a match to a specified pattern.

install_package grep
# 1 minute
tar xf /gllfsc/download/grep-2.15.tar.xz -C /gllfsc/build
cd /gllfsc/build/grep-2.15
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --bindir=/bin \
    --disable-perl-regexp \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf grep-2.15
cd
exit 0

Option --disable-perl-regexp disables support of Perl-style regular expressions (regexp).

Groff
=====

Groff is the GNU version of the roff document formatting system which is used to produce man pages.

su - groff
# 2 minutes
tar xf /gllfsc/download/groff-1.22.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/groff-1.22.2
PAGE=A4 \
    ./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make \
    TROFFBIN=troff \
    GROFFBIN=groff \
    GROFF_BIN_PATH=
make prefix=/gllfsc install
ln -sv soelim /gllfsc/bin/zsoelim
ln -sv eqn /gllfsc/bin/geqn
ln -sv tbl /gllfsc/bin/gtbl
cd ..
rm -rf groff-1.22.2
cd
# man-db installs its own version of zsoelim:
mv -v /gllfsc/bin/zsoelim{,.groff}
exit 0

The variables TROFFBIN=troff and GROFFBIN=groff tell make to use troff and groff commands installed in the Building the Cross-Compilation Tools to build documentation.

The variable GROFF_BIN_PATH before PATH is checked for programs groff is calling (preprocessors, troff, and output devices). If not set, it defaults to the directory where the groff binary is located.

The symlinks are used for compatibility.

Gzip
====

GNU Gzip is a data compression program.

install_package gzip
# 1 minute
tar xf /gllfsc/download/gzip-1.6.tar.gz -C /gllfsc/build
cd /gllfsc/build/gzip-1.6
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf gzip-1.6
cd
exit 0

Inetutils
=========

GNU Inetutils is a collection of common network programs.

install_package inetutils
# 1 minute
tar xf /gllfsc/download/inetutils-2.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/inetutils-2.2
#sed -i '/gets is a security hole/d' lib/stdio.in.h
sed -i '/PATH_PROCNET_DEV/s/\ no//' paths
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make DESTDIR=/gllfsc install
cd ..
rm -rf inetutils-2.2
cd
# util-linux installs its own verion of logger:
mv -v /gllfsc/bin/logger{,.inetutils}
mv -v /gllfsc/usr/share/man/man1/logger.1{,.inetutils}
exit 0

sed -i '/PATH_PROCNET_DEV/s/\ no//' paths is used to fix the following error when issuing make: 'PATH_PROCNET_DEV' undeclared (first use in this function).

Iproute2
========

Iproute2 is a collection of utilities for controlling TCP and UDP IP networking and traffic.

You need Bison and Flex on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install bison flex.

install_package iproute2
# 1 minute
tar xf /gllfsc/download/iproute2-3.10.0.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/iproute2-3.10.0
sed -i.orig '/^TARGETS/s@arpd@@g' misc/Makefile
make \
    DESTDIR=/gllfsc \
    CC="${CC}" \
    DOCDIR=/share/doc/iproute2 \
    MANDIR=/share/man
make \
    DESTDIR=/gllfsc \
    DOCDIR=/share/doc/iproute2 \
    MANDIR=/share/man \
    install
cd ..
rm -rf iproute2-3.10.0
cd
exit 0

sed -i.orig '/^TARGETS/s@arpd@@g' misc/Makefile is used to disable the build of arpd as it requires Berkeley DB to be installed.

DOCDIR and MANDIR indicate the location in which the documentation and the manual pages will be installed, respectively. Those are no absolute paths but use the value of DESTDIR as a prefix.

Kbd
===

Kbd contains keytable files and keyboard utilities.

You need Check on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install check.

install_package kbd
# 1 minute
tar xf /gllfsc/download/kbd-2.0.1.tar.gz -C /gllfsc/build
cd /gllfsc/build/kbd-2.0.1

# Do not check for CHECK:
sed -i.orig '14s/^/#/' configure.ac
autoconf configure.ac > configure

./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-vlock \
    --disable-nls
sed -i.orig '/^SUBDIRS/s/ tests//' Makefile.in
make
make DESTDIR=/gllfsc install
cd ..
rm -rf kbd-2.0.1
cd
exit 0

sed -i.orig '/SUBDIRS/s/ tests//' Makefile.am is used to prevent files in the tests directory to be built.

Option --disable-vlock disables the build of vlock. vlock needs PAM library headers to be present on the build system and is not necessary for us, so we do not build it.

Kmod
====

Kmod (previously known as module-init-tools) provides userspace-side assistance in loading kernel modules and their dependencies.

install_package kmod
# 1 minute
tar xf /gllfsc/download/kmod-15.tar.gz -C /gllfsc/build
cd /gllfsc/build/kmod-15
zlib_CFLAGS="-I/gllfsc/include" \
    zlib_LIBS="-L/gllfsc/lib -lz" \
    ./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --with-zlib \
    --disable-manpages
make
make \
    DESTDIR=/gllfsc \
    INSTALL=install \
    install
cd ..
rm -rf kmod-15
cd

# For bootscripts:
ln -sv kmod /gllfsc/bin/lsmod
ln -sv kmod /gllfsc/bin/depmod
ln -sv kmod /gllfsc/bin/insmod
ln -sv kmod /gllfsc/bin/modprobe
ln -sv kmod /gllfsc/bin/modinfo
ln -sv kmod /gllfsc/bin/rmmod

# Fix permissions for Package User util-linux:
chmod g+w,o+t /gllfsc/usr/share/bash-completion/completions

exit 0

zlib_CFLAGS and zlib_LIBS are defined to avoid the error message: The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. Alternatively, you may set the environment variables zlib_CFLAGS and zlib_LIBS to avoid the need to call pkg-config.

--with-zlib enables support for modules compressed with zlib.

By default, installation uses INSTALL=install-with-care which checks if old utilities have not been destroyed. To avoid this check, we use INSTALL=install.

Less
====

Less is a file pager: it is used to view the content of a text file.

install_package less
# 1 minute
tar xf /gllfsc/download/less-458.tar.gz -C /gllfsc/build
cd /gllfsc/build/less-458
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make prefix=/gllfsc install
cd ..
rm -rf less-458
cd
exit 0

Libpipeline
===========

GNU Libpipeline is a C library for manipulating pipelines of subprocesses in a flexible and convenient way.

install_package libpipeline
# 1 minute
tar xf /gllfsc/download/libpipeline-1.3.0.tar.gz -C /gllfsc/build
cd /gllfsc/build/libpipeline-1.3.0
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix=
make
make prefix=/gllfsc install
cd ..
rm -rf libpipeline-1.3.0
cd
# fix man-db's /lib/libpipeline.so: error adding symbols: File in
# wrong format
rm /gllfsc/lib/libpipeline.la
exit 0

Make
====

GNU make utility determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them.

install_package make
# 1 minute
tar xf /gllfsc/download/make-4.0.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/make-4.0
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf make-4.0
cd
exit 0

Man-db
======

Man-db is an implementation of the standard Unix documentation system accessed using the man command.  It uses a Berkeley DB database in place of the traditional flat-text whatis databases.

install_package man-db
# 1 minute
tar xf /gllfsc/download/man-db-2.6.7.1.tar.xz -C /gllfsc/build
cd /gllfsc/build/man-db-2.6.7.1
libpipeline_CFLAGS="-I/gllfsc/include" \
    libpipeline_LIBS="-L/gllfsc/lib -lpipeline" \
    ./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf man-db-2.6.7.1
cd

sed -i 's/#\(DEFINE.*pager.*\)less -s/\1 less -isRc/' \
    /gllfsc/etc/man_db.conf
exit 0

libpipeline_CFLAGS and libpipeline_LIBS are defined to avoid the error message: The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. Alternatively, you may set the environment variables libpipeline_CFLAGS and libpipeline_LIBS to avoid the need to call pkg-config.

The sed command is used to replace default pager with less. Option -c will cause less to display man pages faster as this option disables scrolling. Option -R will cause less to render colors in the man pages.

Nano
====

GNU nano is a lightweight text editor.

install_package nano
# 1 minute
tar xf /gllfsc/download/nano-2.3.2.tar.gz -C /gllfsc/build
cd /gllfsc/build/nano-2.3.2
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
sed -i.orig \
    '/CPPFLAGS/s@/usr/include/ncursesw@/gllfsc/include@' \
    `find . -iname 'Makefile'`
make
make DESTDIR=/gllfsc install
cd ..
rm -rf nano-2.3.2
cd
exit 0

The sed expression is used to replace /usr/include/ncursesw with /gllfsc/include in every file named Makefile in order to overcome the error /usr/include/ncursesw/ncurses.h:60:34: fatal error: ncursesw/ncurses_dll.h: No such file or directory.

     commands in nano are displayed as in `^X'. The `^' character means CTRL key, so `^X' means CTRL-X: press CTRL and X keys simultaneously on the keyboard.

Patch
=====

GNU patch takes a patch file containing a difference listing produced by the diff program and applies those differences to one or more original files, producing patched versions.

install_package patch
# 1 minute
tar xf /gllfsc/download/patch-2.7.1.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/patch-2.7.1
cat > config.cache << EOF
ac_cv_path_ed_PROGRAM=ed
ac_cv_func_strnlen_working=yes
EOF
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --cache-file=config.cache
make
make prefix=/gllfsc install
cd ..
rm -rf patch-2.7.1
cd
exit 0

Psmisc
======

This package contains utilities that use the proc filesystem.

install_package psmisc
# 1 minute
tar xf /gllfsc/download/psmisc-22.20.tar.gz -C /gllfsc/build
cd /gllfsc/build/psmisc-22.20
cat > config.cache << EOF
ac_cv_func_malloc_0_nonnull=yes
ac_cv_func_realloc_0_nonnull=yes
EOF
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --cache-file=config.cache \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf psmisc-22.20
cd
exit 0

Shadow
======

su - shadow
# 1 minute
tar xf /gllfsc/download/shadow-4.6.tar.xz -C /gllfsc/build
cd /gllfsc/build/shadow-4.6
#automake
echo "ac_cv_func_setpgrp_void=yes" > config.cache
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --libdir=/lib \
    --sysconfdir=/etc \
    --enable-shared \
    --without-audit \
    --without-libpam \
    --without-selinux \
    --cache-file=config.cache \
    --disable-nls
sed -i.orig '/man_MANS/s/$(man_nopam) //' man/ru/Makefile
#sed -i.orig 's/groups$(EXEEXT) //' src/Makefile
#for mkf in $(find man -name Makefile)
#    do
#    sed -i.orig -e '/groups.1.xml/d' -e 's/groups.1 //' ${mkf}
#    done
make
make DESTDIR=/gllfsc install
sed -i.orig -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \
    -e 's@/var/spool/mail@/var/mail@' \
    /gllfsc/etc/login.defs
#${CROSS_TARGET}-pwconv
#${CROSS_TARGET}-grpconv
cd ..
rm -rf shadow-4.6
cd
# util-linux installs its own version of nologin:
mv -v /gllfsc/bin/nologin{,.shadow}
mv -v /gllfsc/usr/share/man/man8/nologin.8{,.shadow}
# Adjusting PATH:
sed -i /PATH=/s,=.*$,=/local/bin:/bin, /gllfsc/etc/login.defs
exit 0

The option --enable-man is used to generate man pages.

The first call of sed removes $(MAN_NOPAM) on the line with man_MANS in man/ru/Makefile.am in order for make install to complete.

The second call of sed disables the build of command groups, as coreutils already installed it.

The last call of sed enables support for MD5 encrypted passwords and changes the mail default directory from /var/spool/mail to /var/mail.

Sysvinit
========

Sysvinit is the system-V style init process. Init is the first process started during booting. It is started by the kernel. Init continues running as a daemon until the system is shut down. It is the direct or indirect ancestor of all other processes and automatically adopts all orphaned processes.

install_package sysvinit
# 1 minute
tar xf /gllfsc/download/sysvinit-2.88dsf.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/sysvinit-2.88dsf
sed -i.orig -e 's@/dev/initctl@$(ROOT)&@g' \
    -e 's@\(mknod \)-m \([0-9]* \)\(.* \)p@\1\3p; chmod \2\3@g' \
    -e '/^ifeq/s/$(ROOT)//' \
    -e 's@/usr/lib@$(ROOT)/lib@' \
    src/Makefile
make -C src clobber
make -C src ROOT=/gllfsc CC="${CC}"
make -C src ROOT=/gllfsc INSTALL="install" install
cd ..
rm -rf sysvinit-2.88dsf
cd

cat > /gllfsc/etc/inittab << EOF
# Begin /etc/inittab

id:3:initdefault:

si::sysinit:/etc/rc.d/init.d/rc sysinit

l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

su:S016:once:/sbin/sulogin

1:2345:respawn:/sbin/agetty --noclear tty1 9600
2:2345:respawn:/sbin/agetty tty2 9600
#3:2345:respawn:/sbin/agetty tty3 9600
#4:2345:respawn:/sbin/agetty tty4 9600
#5:2345:respawn:/sbin/agetty tty5 9600
#6:2345:respawn:/sbin/agetty tty6 9600

#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100

# End /etc/inittab
EOF
# util-linux installs its own versions:
mv -v /gllfsc/bin/mountpoint{,.sysvinit}
mv -v /gllfsc/bin/sulogin{,.sysvinit}
mv -v /gllfsc/bin/mesg{,.sysvinit}
mv -v /gllfsc/bin/last{,.sysvinit}
mv -v /gllfsc/bin/utmpdump{,.sysvinit}
mv -v /gllfsc/bin/lastb{,.sysvinit}
mv -v /gllfsc/usr/share/man/man1/mesg.1{,.sysvinit}
mv -v /gllfsc/usr/share/man/man1/last.1{,.sysvinit}
mv -v /gllfsc/usr/share/man/man1/lastb.1{,.sysvinit}
mv -v /gllfsc/usr/share/man/man1/utmpdump.1{,.sysvinit}
mv -v /gllfsc/usr/share/man/man1/mountpoint.1{,.sysvinit}
mv -v /gllfsc/usr/share/man/man8/sulogin.8{,.sysvinit}
exit 0

The first call of sed replaces /dev/initctl with $(ROOT)/dev/initctl, and /usr/lib with $(ROOT)/lib among other things in order to install sysvinit on the target system.

make -C src clobber is used to clean up the src directory.

Then, we create the inittab file that describes which processes are started at bootup and during normal operation.

The line #c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100 is commented out (with #) in order to avoid the message: INIT: Id "c0" respawning too fast: disabled for 5 minutes on the target system.

Tar
===

GNU tar is an archiving utility: it stores and extracts files from a tape or disk archive.

install_package tar
# 1 minute
tar xf /gllfsc/download/tar-1.27.1.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/tar-1.27.1
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf tar-1.27.1
cd
exit 0

Texinfo
=======

GNU Texinfo is a documentation system that can produce both online information and a printed manual from a single source.

You need Ncurses headers on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install libncurses5-dev.

install_package texinfo
# 1 minute
tar xf /gllfsc/download/texinfo-4.13a.tar.gz -C /gllfsc/build
cd /gllfsc/build/texinfo-4.13
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
make -C tools/gnulib/lib
make -C tools
make
make DESTDIR=/gllfsc install
cd ..
rm -rf texinfo-4.13
cd

cd /gllfsc/share/info
#rm dir
for f in *
    do install-info $f dir 2>/dev/null
done
cd
exit 0

The first three calls of make make it possible to build Texinfo by cross-compilation.

For Info to work, the info directory must contain a file that serves as a top level directory for the Info system. By convention, this file is called dir. We update this file for the target system.

Udev
====

Udev is the dynamic device management of the kernel Linux.

You need Gperf on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install gperf. Under GLLFSC 1.8, try, as root:

tar xf /gllfsc/download/gperf-3.0.4.tar.gz
cd gperf-3.0.4
./configure --prefix=
make install
cd ..
rm -rf gperf-3.0.4

Then:

install_package udev
# 1 minute
tar xf /gllfsc/download/udev-175.tar.gz -C /gllfsc/build
cd /gllfsc/build/udev-175
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --with-rootlibdir=/lib \
    --libexecdir=/lib/udev \
    --docdir=/share/doc/udev-175 \
    --disable-introspection \
    --with-pci-ids-path=no \
    --with-usb-ids-path=no \
    --disable-gudev
make
make DESTDIR=/gllfsc install
install -dv /gllfsc/lib/firmware
ln -sv ../lib/udev/udevd /gllfsc/sbin/udevd
cd ..
rm -rf udev-175
cd

# fix /lib/libudev.so: error adding symbols: File in wrong format
rm /gllfsc/lib/libudev.la

# Fix /bin/install: cannot change permissions of
# '/gllfsc/lib/udev/devices/pts': No such file or directory
chmod g+w,o+t /gllfsc/lib/udev/devices

# Fix permissions for Package Users:
chmod g+w,o+t /gllfsc/lib/udev/rules.d
chmod g+w,o+t /gllfsc/share/gtk-doc
chmod g+w,o+t /gllfsc/share/gtk-doc/html
chmod g+w,o+t /gllfsc/share/pkgconfig

exit 0

Util-Linux
==========

util-linux is a random collection of utilities for use with the kernel Linux.

     If you have trouble building util-linux from a distribution using .deb packages, try to uninstall the package named libtinfo-dev. Then remove /gllfsc/build/util-linux-2.24 and build it again.

install_package util-linux
# 3 minutes
tar xf /gllfsc/download/util-linux-2.24.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/util-linux-2.24
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --enable-partx \
    --disable-wall \
    --enable-write \
    --disable-makeinstall-chown \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -r util-linux-2.24
cd
exit 0

Option --enable-partx enables the build and installation of the addpart, delpart and partx commands.

Option --disable-wall disables the build of the wall command which is already provided by sysvinit.

Option --enable-write enables the build and installation of the write command.

Option --disable-makeinstall-chown disables the change of owner to root for installed programs.

XZ-Utils
========

XZ Utils is a general-purpose data compression software with high compression ratio.

install_package xz-utils
# 1 minute
tar xf /gllfsc/download/xz-5.0.8.tar.bz2 -C /gllfsc/build
cd /gllfsc/build/xz-5.0.8
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
make
make DESTDIR=/gllfsc install
cd ..
rm -rf xz-5.0.8
cd
exit 0

Bootscripts
===========

The bootscript archive contains scripts that manage services during system's bootup and shutdown.

install_package bootscripts
# 1 minute
tar xf /gllfsc/download/bootscripts-cross-lfs-2.0.0.tar.xz \
    -C /gllfsc/build
cd /gllfsc/build/bootscripts-cross-lfs-2.0-pre2
make DESTDIR=/gllfsc install-bootscripts
make DESTDIR=/gllfsc install-network
cd ..
rm -rf bootscripts-cross-lfs-2.0-pre2
cd

# We do not use a system log daemon:
rm /gllfsc/etc/rc.d/rc3.d/S10rsyslog

# Bringing up network interfaces fails:
rm /gllfsc/etc/rc.d/rc3.d/S20network

# Fix permissions for Package Users:
chmod g+w,o+t /gllfsc/etc/sysconfig

exit 0

This installs basic bootscripts required for bootup and shutdown, and network-related bootscripts.

     To modify the keyboard layout at boot, for instance fr' azerty:

     sed -i.orig '/^KEYMAP/s/us/fr/' /gllfsc/etc/sysconfig/i18n

The Kernel
==========

Linux is a kernel aimed towards POSIX and Single UNIX Specification compliance.

You need Bc and Lzma on your system to compile this program from source. Under gNewSense 4.0, try sudo apt-get install bc lzma.

Under GLLFSC, install ed, which is a bc dependency then bc:

tar xf /gllfsc/download/ed-1.1.tar.bz2
cd ed-1.1
./configure --prefix=
make install
cd ..
rm -rf ed-1.1

tar xf /gllfsc/download/bc-1.07.1.tar.gz
cd bc-1.07.1
./configure --prefix=
make install
cd ..
rm -rf bc-1.07.1

install_package linux-libre
# 25 minutes
tar xf /gllfsc/download/linux-libre-3.10.108-gnu.tar.xz \
    -C /gllfsc/build
cd /gllfsc/build/linux-3.10.108
make mrproper

Then:

cp arch/x86/configs/i386_defconfig .config
#patch -Np1 -i /gllfsc/download/100gnu+freedo.patch

Then, if you want to change the configuration:

make ARCH=i386 CROSS_COMPILE=${CROSS_TARGET}- menuconfig

     If you have more than 3GB of RAM installed on a 32 bit CPU, you can use all of it by selecting the following option:

     Processor type and features
     > High Memory Support
       (X) 64GB

     In order to avoid the error message "cannot create directory '/dev/pts': read only filesystem" at boot, you have to activate the two options below:

     Device Drivers
     > Generic Driver Options
       > [*] Maintain a devtmpfs fs to mount on /dev
       > [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs

     Also ensure you have CONFIG_DRM_I915_KMS=y in your .config after the configuration step, working under tty is more pleasant with a nice resolution:

     Device Drivers
     > Graphics support
       > <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)
       > <*> Intel 8xx/9xx/G3x/G4x/HD Graphics
       > [*] Enable modesetting on intel by default

     Disable the Tux/Freedo logo with:

     Device Drivers
     > Graphics support
       > [ ] Bootup logo

Then:

make \
    ARCH=i386 \
    CROSS_COMPILE=${CROSS_TARGET}-
make \
    ARCH=i386 \
    CROSS_COMPILE=${CROSS_TARGET}- \
    INSTALL_MOD_PATH=/gllfsc \
    modules_install
cp arch/x86/boot/bzImage /gllfsc/boot/vmlinuz-3.10.108-gnu
cp System.map /gllfsc/boot/System.map-3.10.108-gnu
cp .config /gllfsc/boot/config-3.10.108-gnu
cd ..
cd
exit 0

     because future compilation may need kernel sources, the compilation directory of the kernel should be preserved.

GRUB
====

GNU GRUB is a Multiboot boot loader.

A bootloader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel software (such as Linux). The kernel, in turn, initializes the rest of the system (e.g. GNU).

install_package grub
# 3 minutes
tar xf /gllfsc/download/grub-2.00.tar.gz \
    -C /gllfsc/build
cd /gllfsc/build/grub-2.00
sed -i '/gets is a security hole/d' grub-core/gnulib/stdio.in.h
./configure \
    --build=${CROSS_HOST} \
    --host=${CROSS_TARGET} \
    --prefix= \
    --disable-nls
cd grub-core/script
EXP1='\n#pragma GCC diagnostic ignored \"-Wunused-function\"'
sed -i.1 '/Wunsafe-loop-optimizations\"/s,$,'"$EXP1"',' yylex.l
EXP2='\n#pragma GCC diagnostic ignored \"-Wsign-compare\"'
sed -i.2 '/Wunused-function\"/s,$,'"$EXP2"',' yylex.l
cd ../..
make
make DESTDIR=/gllfsc install
cd ..
rm -rf grub-2.00
cd

mkdir /gllfsc/boot/grub
exit 0

sed -i '/gets is a security hole/d' grub-core/gnulib/stdio.in.h is used to fix the following error when issuing make:

./stdio.h:456:1: error: 'gets' undeclared here (not in a function)
make[4]: Leaving directory '/gllfsc/build/grub-2.00/grub-core/gnulib'

The sed expressions applied to yylex.l fixes:
grub_script.yy.c:2296:17: error: comparison between signed and
unsigned integer expressions [-Werror=sign-compare]
./grub-core/script/yylex.l

Creating Required Configuration Files for the New System
********************************************************

File for Time Setup
===================

su - bootscripts
cat > /gllfsc/etc/sysconfig/clock << EOF
UTC=1
EOF

# If you have trouble with the clock behaviour, do:

mv -v /gllfsc/etc/rc.d/rcsysinit.d/{S15setclock,K15setclock}
exit 0

Setting up Keyboard Function keys for the Shell
===============================================

     You can automate this section by splitting the file gllfsc-pentium4-1.9.0.texi into instructions:

     csplit gllfsc-pentium4-1.9.0.texi '/su -/' '{*}'
     mv xx11 7.2
     rm xx*
     chmod u+x 7.2

     Then, with nano, you can remove the line beginning with su -, and add the line set -e and the line set -v at the beginning of the script so that it will exit on error and print each instruction before executing it:

     nano 7.2

     Then, once inside the readline User personal directory:

     cp /root/7.2 .
     ./7.2

Readline default configuration file is set:

su - readline
cat > /gllfsc/etc/inputrc << EOF
set bell-style none
set convert-meta Off
set horizontal-scroll-mode Off
set input-meta On
set output-meta On
"\eOd": backward-word
"\eOc": forward-word
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
"\eOH": beginning-of-line
"\eOF": end-of-line
"\e[H": beginning-of-line
"\e[F": end-of-line
EOF
exit 0

If convert-meta is set to On, Readline will convert characters with the eighth bit set to an ASCII key sequence by stripping the eighth bit and prefixing an ESC character, converting them to a meta-prefixed key sequence.

horizontal-scroll-mode set to Off means that the text of the lines being edited will be wrapped onto a new screen line when they are longer than the width of the screen, instead of being scrolled horizontally on a single screen line.

If input-meta is set to On, Readline will enable eight-bit input (it will not clear the eighth bit in the characters it reads), regardless of what the terminal claims it can support.

If output-meta is set to On, Readline will display characters with the eighth bit set directly rather than as a meta-prefixed escape sequence.

Setting up Bash Shell Startup Files
===================================

su - bash
cat > /gllfsc/etc/profile << 'EOF'
export LANG=en_US.UTF-8
export INPUTRC=/etc/inputrc
export PS1='\[\e[31m\]\A-\W\[\e[00m\]# '
EOF
exit 0

The environment variable LANG defines the default language that should be used on the system. en_US.UTF-8 means ``english'' language, country ``US'' and UTF-8 (UCS Transformation Format—8-bit) encoding (Unicode).

For explanations on PS1, see Environment Variables Setup.

Localhost Setup
===============

su - bootscripts
echo "HOSTNAME=gllfsc" > /gllfsc/etc/sysconfig/network
exit 0

Setting up hosts File
=====================

cat > /gllfsc/etc/hosts << EOF
127.0.0.1 gllfsc localhost
EOF

Setting up Network Address
==========================

You can choose to have a network static or dynamic address.

Setting up Network Static Address
---------------------------------

su - bootscripts
cd /gllfsc/etc/sysconfig/network-devices
mkdir -v ifconfig.eth0
cat > ifconfig.eth0/ipv4 << EOF
ONBOOT=yes
SERVICE=ipv4-static
IP=192.168.1.1
GATEWAY=192.168.1.2
PREFIX=24
BROADCAST=192.168.1.255
EOF
cd
exit 0

     IP, GATEWAY, BROADCAST addresses are set up according to one's situation.

Setting up Network Dynamic Address
----------------------------------

su - bootscripts
cd /gllfsc/etc/sysconfig/network-devices
mkdir -v ifconfig.eth0
cat > ifconfig.eth0/dhcpcd << EOF
ONBOOT=yes
SERVICE=dhcpcd
DHCP_START="-q"
DHCP_STOP="-k"
EOF
cd
exit 0

Setting up DNS
==============

cat > /gllfsc/etc/resolv.conf << EOF
nameserver your-main-DNS-address
nameserver your-secondary-DNS-address
EOF

fstab File Creation
===================

The file /etc/fstab is used at boot to mount partitions under the requested directories.

su - util-linux
cat > /gllfsc/etc/fstab << EOF
# file system    mount-point  type     options        dump  fsck order

/dev/sda3        /            ext3     defaults        0    0
#/dev/sda7        /home        ext3     defaults        0    0
/dev/sda5        swap         swap     pri=1           0    0
devtmpfs         /dev         dev      defaults        0    0
proc             /proc        proc     defaults        0    0
tmpfs            /run         run      defaults        0    0
sysfs            /sys         sysfs    defaults        0    0
devpts           /dev/pts     devpts   gid=4,mode=620  0    0
shm              /dev/shm     tmpfs    defaults        0    0
EOF
exit 0

     the name of the hard drive and the filesystems used here have to be modified to reflect your real situation.

Before Booting GLLFSC
*********************

Enabling Package Users on the target GLLFSC
===========================================

In order to enable Package Users under GLLFSC, we need to copy the package users and groups to the new system:

su - shadow
grep ':100' /etc/passwd >> /gllfsc/etc/passwd
grep ':100' /etc/group >> /gllfsc/etc/group
exit 0

Then, as root:

cp -av /usr/src/* /gllfsc/usr/src

cd /tmp
tar xf /root/more_control_helpers.tar.bz2
cd more_control_helpers
rm sbin/{groupadd,useradd}

mkdir -v /gllfsc/etc/pkgusr
rm -v etc/{build,skel-package/{build,build.conf,.project}}
cp -Rv etc/* /gllfsc/etc/pkgusr

mkdir -v /gllfsc/usr/lib/pkgusr
cp -Rv lib/* /gllfsc/usr/lib/pkgusr

cp -v bin/* /gllfsc/usr/bin

sed -i.orig 's/"\$1"$/"install"/' sbin/install_package

cp -v sbin/{add_package_user,install_package} /gllfsc/usr/sbin
sed -i.orig '/CREATE_MAIL_SPOOL/s/yes/no/' /gllfsc/etc/default/useradd

Then:

cat > /gllfsc/etc/pkgusr/bash_profile << 'EOF'
export PATH=/usr/lib/pkgusr:/bin:/local/bin

# Make prompt reflect that we are a package user.
export PROMPT_COMMAND='PS1="\[\e[35m\]\A-package \u:\W\[\e[00m\]> "'

# Go to the home directory whenever we su to a package user.
cd

alias less='less -ic'
EOF

Finally:

cat > /gllfsc/root/.bash_profile << EOF
# Tab-complete package users when using su, finger or pinky
complete -o default -o nospace -A user su finger pinky
EOF

Archiving the System
====================

Create required files:

cd /gllfsc
mknod -m 600 dev/console c 5 1
mknod -m 666 dev/null c 1 3
cp -av dev/{console,null} lib/udev/devices/

We archive the entire system by using the following command:

# 3 minutes
tar -cjf gllfsc-pentium4-1.9.0.tar.bz2 \
    bin boot dev etc home include lib* local man mnt proc root run \
    sbin share src static sys tmp usr var download
cd

It is then simple to copy gllfsc-pentium4-1.9.0.tar.bz2 to the target machine and extract it.

     If you use another GLLFSC system when you extract gllfsc-pentium4-1.9.0.tar.bz2 to its dedicated partition, you should use option --numeric-owner to avoid conflicts with Package User names.

Some Recommendations
====================

We recommend extracting the system to an empty partition. Moreover, the filesystem of the chosen partition has to be a filesystem supported by the kernel you compiled. Finally, this partition has to be consistent with the system description in the file /etc/fstab you created during setup (see fstab File Creation).

Then, you will have to edit the GRUB configuration file of the target machine: /boot/grub/grub.cfg. You can do it with nano.

A minimal /boot/grub/grub.cfg for classical hard disk could be:

insmod ext2
set default=0
set timeout=5

menuentry 'GLLFSC 1.9.0' {
    echo 'Loading linux-libre-3.10.108-gnu...'
    linux (hd0,3)/boot/vmlinuz-3.10.108-gnu root=/dev/sda3 quiet
}

A minimal /boot/grub/grub.cfg for hard disk supporting AHCI (Advanced Host Controller Interface) could be:

insmod part_msdos
insmod ext2
set default=0
set timeout=5

menuentry 'GLLFSC 1.9.0' {
    echo 'Loading linux-libre-3.10.108-gnu...'
    linux (ahci0,msdos3)/boot/vmlinuz-3.10.108-gnu root=/dev/sda3 quiet
}

Halting the Computer
====================

In order to halt the computer, type:

init 0

If you prefer to reboot instead type:

init 6

After Booting GLLFSC
********************

Some system configuration and package installation can only be made after booting onto the new system. The build process of this chapter takes about 25 minutes on my Lenovo ThinkPad X200.

Boot Process
============

Once the computer starts, the BIOS makes GRUB responsible for loading and transferring control to the operating system kernel (Linux-libre here). The kernel, in turn, initializes the rest of the operating system, beginning with init (runit at the end of this chapter).

If, for some reason, GRUB fails to launch linux-libre, you may be presented a grub rescue > prompt. In this case, you may launch GRUB by issuing the following commands:

set
ls
# If you want to boot the kernel on partition 1 of a classical drive:
set prefix=(hd0,1)/grub
set root=(hd0,1)
insmod normal
normal

Login
=====

To login as root, just type root when the system asks for your login:.

Then, if you want to use the french keyboard layout, type loadkeys -q fr.

     To modify the keyboard layout at boot, for instance fr' azerty:

     sed -i.orig '/^KEYMAP/s/us/fr/' /gllfsc/etc/sysconfig/i18n

Locales
=======

You may want to have your new system display messages in your native language. If you desire to have a system supporting US english (german, french and China mainland's chinese are commented):

su - glibc
mkdir /lib/locale

#localedef -i de_DE -f UTF-8 de_DE
localedef -i en_US -f UTF-8 en_US
#localedef -i fr_FR -f UTF-8 fr_FR
#localedef -i zh_CN -f UTF-8 zh_CN
exit 0

Other locales are available:

  * For available charmaps, see the content of /share/i18n/charmaps.

  * For available locales, see the content of /share/i18n/locales.

Timezone
========

     You can automate parts of this chapter by splitting the script 3-build-post-boot.sh generated in see Building the Cross-Compilation Toolchain into instructions for each Package User:

     csplit 3-build-post-boot.sh '/install_package/' '{*}'
     rm xx00
     mv xx01 9.4-tz
     mv xx02 9.5-runit
     mv xx03 9.6-perl
     mv xx04 9.7-openssl
     mv xx05 9.8-wpa-supplicant
     mv xx06 9.9-wireless-tools
     mv xx07 9.10-wget
     mv xx08 9.11-libtasn1
     mv xx09 9.12-lynx
     mv xx10 9.13-ca-certificates
     mv xx11 9.14-libevent

     csplit xx12 '/inetutils/'
     mv xx00 9.15-tmux
     rmxx12

     mv xx01 xx99
     csplit xx99 '/cat/'
     rm xx99

     mv xx01 xx99
     csplit xx99 '/Clean up/'
     mv xx00 9.16-pkgusr
     mv xx01 9.17-archiving
     rm xx99

     chmod u+x 9.*

     Then, with nano, you can remove lines beginning with install_package and add the line set -e and the line set -v at the beginning of each script so that it will exit on error and print each instruction before executing it. To automate this step:

     sed -i 's,install_package.*,set -e\nset -v\n,' 6.*

     Then, once inside the, for instance, tz User personal directory:

     cp /root/9.4-tz .
     ./9.4-tz

In order to have the time and date corresponding to the area where you live, you should build tzcode, tzdata and define your timezone.

install_package tz
# 1 minute
mkdir /build/tz
tar xf /download/tzcode2013h.tar.gz -C /build/tz
tar xf /download/tzdata2013h.tar.gz -C /build/tz
cd /build/tz

make \
    TOPDIR=/ \
    TZDIR=/share/zoneinfo \
    ETCDIR=/bin

for TZ in africa antarctica asia australasia europe northamerica \
          southamerica pacificnew etcetera backward systemv factory \
          solar87 solar88 solar89; do
    zic -y "sh yearistype.sh" \
        -d /share/zoneinfo \
        -L /dev/null $TZ
done

zic -y "bash yearistype.sh" \
    -d /share/zoneinfo \
    -l GMT \
    -p America/New_York

cp iso3166.tab zone.tab /share/zoneinfo
cd ..
rm -rf tz
cd

Then, we define our timezone, in my case Europe/Paris:

cp -v --remove-destination \
    /share/zoneinfo/Europe/Paris \
    /etc/localtime
exit

Runit
=====

runit is a cross-platform Unix init scheme with service supervision, a replacement for sysvinit, and other init schemes.

install_package runit
# 1 minute
tar xf /download/runit-2.1.2.tar.gz -C /build
cd /build/admin/runit-2.1.2
cd src
make
make check

install -s -m0755 \
    chpst runit runit-init runsv runsvchdir runsvdir sv svlogd utmpset \
    /sbin

install -m0644 ../man/* \
    /share/man/man8

cd ..

mkdir /etc/runit

mkdir /service

cp etc/debian/ctrlaltdel /etc/runit/

cd ../..
rm -rf admin
cd

The init-related programs have been installed. We need to create the boot scripts too: /etc/runit/1 to boot the system, /etc/runit/2 to launch 2 ttys and the service logging daemon and /etc/runit/3 to halt or reboot the system.

cat > /etc/runit/1 << 'EOF'
#!/bin/sh
# system one time tasks

# Exit on error:
set -e

PATH=/bin

echo -n '16. Mounting kernel-based file systems:'
echo -n ' /proc'
mount -n -o nosuid,noexec,nodev -t proc proc /proc
echo -n ' /sys'
mount -n -o nosuid,noexec,nodev -t sysfs sys /sys
echo ' /run'
mount -n -o mode=0755,nosuid,nodev -t tmpfs run /run

echo -n '15. Creating directories:'
echo -n ' /run/lock'
mkdir -m 1777 /run/lock
echo -n ' /dev/pts'
mkdir -p /dev/pts
echo ' /dev/shm'
mkdir -p /dev/shm

echo '14. Mounting root file system in read-write mode.'
mount -n -o remount,rw / >/dev/null

# Remove fsck-related system watermarks.
rm -f /fastboot /forcefsck

echo '13. Recording existing mounts in /etc/mtab.'
> /etc/mtab
mount -f /
mount -f /proc
mount -f /sys
mount -f /run
mount -f /dev

echo '12. Mounting remaining file systems.'
mount -a -r >/dev/null

echo '11. Cleaning file system /tmp.'
cd /tmp && find . -xdev -mindepth 1 ! -name lost+found -delete

echo '10. Creating /var/run/utmp.'
if grep -q '^utmp:' /etc/group; then
    chmod 664 /var/run/utmp
    chgrp utmp /var/run/utmp
fi

echo '9. Starting udevd...'
echo '' > /sys/kernel/uevent_helper

/lib/udev/udevd --daemon

echo '8. Performing Coldplugging...'
/sbin/udevadm trigger --action=add --type=subsystems
/sbin/udevadm trigger --action=add --type=devices

/sbin/udevadm settle

# Uncomment the following lines if you use a swap partition:
#echo '7. Activating all swap files/partitions...'
#swapon -a

echo '6. Setting Font...'
setfont LatArCyrHeb-16 -C /dev/tty1
setfont LatArCyrHeb-16 -C /dev/tty2

echo '5. Setting keymap to UTF-8...'
dumpkeys | loadkeys --unicode

echo '4. Enabling Multibyte input...'
kbd_mode -u

echo '3. Setting up US Keymap...'
loadkeys -q us

echo '2. Setting encoding to UTF-8...'
echo -ne $'\033%G' > /dev/tty1
echo -ne $'\033%G' > /dev/tty2

echo '1. Bringing up the loopback interface...'
ip addr add 127.0.0.1/8 label lo dev lo
ip link set lo up

echo '0. Setting hostname to gllfsc...'
hostname gllfsc

echo
echo To login, remember:
echo your login is root
echo with no password
echo
echo You can now login here.
echo
echo If needed, you can use tty2 by pressing simultaneously Ctrl, Alt
echo and F2 keys. You can then come back to this screen \(tty1\) by
echo pressing simultaneously Ctrl, Alt and F1 keys.
echo
echo Edit /etc/runit/1 if you want to remove this message.
echo

touch /etc/runit/stopit
chmod 0 /etc/runit/stopit

exit 0
EOF

chmod +x /etc/runit/1

cat > /etc/runit/2 << EOF
#!/bin/sh

PATH=/bin

exec env -i PATH=/bin \
runsvdir -P /service 'log: ..........................................'
EOF

chmod +x /etc/runit/2

cat > /etc/runit/3 << EOF
#!/bin/sh

# Exit on error:
set -e

exec 2>&1

PATH=/bin

echo '4. Waiting for services to stop...'
sv down /service/*

echo '3. Exiting services...'
sv exit /service/*

echo '2. Deactivating all swap files/partitions...'
swapoff -a

# Unmount everything but /:
echo -n '1. Unmounting filesystems: /home'
umount -r /home
echo -n ' /proc'
umount -r /proc
echo -n ' /sys'
umount -r /sys
echo -n ' /dev/pts'
umount -r /dev/pts
echo ' /dev/shm'
umount -r /dev/shm

echo '0. Shutdown...'

exit 0
EOF

chmod +x /etc/runit/3

We now create useful services:

mkdir /etc/sv
mkdir /etc/sv/getty-1

cat > /etc/sv/getty-1/run << EOF
#!/bin/sh
exec /sbin/agetty --noclear tty1 9600
EOF
chmod +x /etc/sv/getty-1/run

cat > /etc/sv/getty-1/finish << EOF
#!/bin/sh
exec utmpset -w tty1
EOF
chmod +x /etc/sv/getty-1/finish

ln -sv /etc/sv/getty-1 /service/getty-1

mkdir -p /etc/sv/getty-2

cat > /etc/sv/getty-2/run << EOF
#!/bin/sh
exec /sbin/agetty tty2 9600
EOF
chmod +x /etc/sv/getty-2/run

cat > /etc/sv/getty-2/finish << EOF
#!/bin/sh
exec utmpset -w tty2
EOF
chmod +x /etc/sv/getty-2/finish

ln -sv /etc/sv/getty-2 /service/getty-2

mkdir /etc/sv/svlogd

cat > /etc/sv/svlogd/run << EOF
#!/bin/sh
exec svlogd
EOF
chmod +x /etc/sv/svlogd/run

ln -sv /etc/sv/svlogd /service/svlogd
exit 0

Finally, as root, make runit the default init:

mv /sbin/init /sbin/init.sysv
ln -sv runit-init /sbin/init

Perl
====

Perl is a high-level programming language.

     You may have to type exit twice during the configure phase of the Perl installation.

install_package perl
# 10 minutes
tar xf /download/perl-5.18.1.tar.gz -C /build
cd /build/perl-5.18.1
sh Configure -ds -e -Dprefix=
make
make install
cd ..
rm -rf perl-5.18.1
cd

# Fix permissions for Package Users:
chmod g+w,o+t /local/lib/perl5/site_perl/5.18.1/i686-linux
chmod g+w,o+t /local/lib/perl5/5.18.1/i686-linux

exit 0

OpenSSL
=======

OpenSSL is a toolkit implementing the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols as well as a cryptography library.

install_package openssl
# 5 minutes
tar xf /download/openssl-1.1.1.tar.gz -C /build
cd /build/openssl-1.1.1
./config \
    --prefix=/usr \
    --openssldir=/etc/ssl \
    shared
make -j1
# Install without the documentation:
make install_sw
cd ..
rm -rf openssl-1.1.1
cd
exit 0

Wpa_supplicant
==============

Wpa_supplicant is a user space IEEE 802.1X/WPA supplicant (wireless client) for many wireless drivers.

install_package wpa-supplicant
# 1 minute
tar xf /download/wpa_supplicant-2.7.tar.gz -C /build
cd /build/wpa_supplicant-2.7/wpa_supplicant

cat > .config << EOF
CONFIG_DRIVER_HOSTAP=y
CONFIG_DRIVER_WEXT=y
#CONFIG_DRIVER_NL80211=y
#CONFIG_DRIVER_WIRED=y

#CONFIG_PKCS12=y
#CONFIG_SMARTCARD=y

CONFIG_CTRL_IFACE=y

CONFIG_BACKEND=file
CONFIG_PEERKEY=y
#CONFIG_IEEE80211W=y

CONFIG_TLS=openssl

#CONFIG_IEEE80211N=y
EOF

sed -i.orig 's@local/@@g' Makefile
make
make install
cd ../..
rm -rf wpa_supplicant-2.7
cd

cat > /etc/wpa_supplicant.conf << EOF
network={
    ssid="MYESSID"
    key_mgmt=WPA-PSK
    pairwise=TKIP
    group=TKIP
    psk="MYPASSWORD"
}
EOF
chmod 600 /etc/wpa_supplicant.conf
exit 0

Wireless_tools
==============

The Wireless Tools is a set of tools allowing to manipulate the Wireless Extensions.

install_package wireless-tools
# 1 minute
tar xf /download/wireless_tools.29.tar.gz -C /build
cd /build/wireless_tools.29
make
make PREFIX= install
cd ..
rm -rf wireless_tools.29
cd
exit 0

Wget
====

GNU wget is an utility for downloading network data.

install_package wget
# 1 minute
tar xf /download/wget-1.19.5.tar.gz -C /build
cd /build/wget-1.19.5
#sed -i.orig 's/item $thing/item C<$thing>/' doc/texi2pod.pl
OPENSSL_CFLAGS='-I/include/openssl' \
    OPENSSL_LIBS='-L/lib -lssl -lcrypto' \
    ./configure \
    --prefix= \
    --with-ssl=openssl \
    --disable-nls
make
make install
cd ..
rm -rf wget-1.19.5
cd
exit 0

OPENSSL_CFLAGS and OPENSSL_LIBS are defined to avoid the error message:

The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config. Alternatively, you may set the environment
variables OPENSSL_CFLAGS and OPENSSL_LIBS to avoid the need to call
pkg-config.

Libtasn1
========

GNU libtasn1 is a ASN.1 library.

install_package libtasn1
# 1 minute
tar xf /download/libtasn1-3.4.tar.gz -C /build
cd /build/libtasn1-3.4
./configure --prefix=
make
make install
cd ..
rm -rf libtasn1-3.4
cd
exit 0

Lynx
====

Lynx is a text web browser.

install_package lynx
# 2 minutes
tar xf /download/lynx2.8.9rel.1.tar.bz2 -C /build
cd /build/lynx2.8.9rel.1
./configure \
    --prefix= \
    --with-ssl=/lib \
    --enable-nls \
    --with-screen=ncursesw
make
make install
cd ..
rm -rf lynx2.8.9rel.1

# Stop asking questions about certificates:
sed -i s/#FORCE_SSL_PROMPT:PROMPT/FORCE_SSL_PROMPT:yes/ \
    /etc/lynx.cfg

# Display non-ascii characters:
sed -i s/#CHARACTER_SET:iso-8859-1/CHARACTER_SET:utf-8/  \
    /etc/lynx.cfg

# I don't want cookies:
sed -i 's/#SET_COOKIES:TRUE/SET_COOKIES:FALSE/'  \
    /etc/lynx.cfg
sed -i 's/#ACCEPT_ALL_COOKIES:FALSE/ACCEPT_ALL_COOKIES:FALSE/'  \
    /etc/lynx.cfg
sed -i 's/#PERSISTENT_COOKIES:FALSE/PERSISTENT_COOKIES:FALSE/'  \
    /etc/lynx.cfg
cd
exit 0

CA-Certificates
===============

CA-Certificates are used for https web pages.

install_package ca-certificates
# 1 minute
# Inspired from
# http://linuxfromscratch.org/blfs/view/stable/postlfs/cacerts.html

cp /download/certdata.txt /build
cd /build

cat > /bin/make-cert.pl << 'EOF'
#!/bin/perl -w

# Used to generate PEM encoded files from Mozilla certdata.txt.
# Run as ./make-cert.pl > certificate.crt
#
# Parts of this script courtesy of RedHat (mkcabundle.pl)
#
# This script modified for use with single file data (tempfile.cer)
# extracted from certdata.txt, taken from the latest version in the
# Mozilla NSS source.
# mozilla/security/nss/lib/ckfw/builtins/certdata.txt
#
# Authors: DJ Lucas
#          Bruce Dubbs
#
# Version 20120211

my $certdata = './tempfile.cer';

open( IN, "cat $certdata|" )
    || die "could not open $certdata";

my $incert = 0;

while ( <IN> )
{
    if ( /^CKA_VALUE MULTILINE_OCTAL/ )
    {
        $incert = 1;
        open( OUT, "|openssl x509 -text -inform DER -fingerprint" )
            || die "could not pipe to openssl x509";
    }

    elsif ( /^END/ && $incert )
    {
        close( OUT );
        $incert = 0;
        print "\n\n";
    }

    elsif ($incert)
    {
        my @bs = split( /\\/ );
        foreach my $b (@bs)
        {
            chomp $b;
            printf( OUT "%c", oct($b) ) unless $b eq '';
        }
    }
}
EOF

chmod +x /bin/make-cert.pl

cat > /bin/make-ca.sh << 'EOF'
#!/bin/sh
# Begin make-ca.sh
# Script to populate OpenSSL's CApath from a bundle of PEM formatted
# CAs
#
# The file certdata.txt must exist in the local directory
# Version number is obtained from the version of the data.
#
# Authors: DJ Lucas
#          Bruce Dubbs
#
# Version 20120211

certdata="certdata.txt"

if [ ! -r $certdata ]; then
  echo "$certdata must be in the local directory"
  exit 1
fi

REVISION=$(grep CVS_ID $certdata | cut -f4 -d'$')

if [ -z "${REVISION}" ]; then
  echo "$certfile has no 'Revision' in CVS_ID"
  exit 1
fi

VERSION=$(echo $REVISION | cut -f2 -d" ")

TEMPDIR=$(mktemp -d)
TRUSTATTRIBUTES="CKA_TRUST_SERVER_AUTH"
BUNDLE="BLFS-ca-bundle-${VERSION}.crt"
CONVERTSCRIPT="/bin/make-cert.pl"
SSLDIR="/etc/ssl"

mkdir "${TEMPDIR}/certs"

# Get a list of starting lines for each cert
CERTBEGINLIST=$(grep -n "^# Certificate" "${certdata}" | cut -d ":" -f1)

# Get a list of ending lines for each cert
CERTENDLIST=$(grep -n "^CKA_TRUST_STEP_UP_APPROVED" "${certdata}" \
    | cut -d ":" -f 1)

# Start a loop
for certbegin in ${CERTBEGINLIST}; do
  for certend in ${CERTENDLIST}; do
    if test "${certend}" -gt "${certbegin}"; then
      break
    fi
  done

  # Dump to a temp file with the name of the file as the beginning
  # line number
  sed -n "${certbegin},${certend}p" "${certdata}" \
      > "${TEMPDIR}/certs/${certbegin}.tmp"
done

unset CERTBEGINLIST CERTDATA CERTENDLIST certbegin certend

mkdir -p certs
rm -f certs/*      # Make sure the directory is clean

for tempfile in ${TEMPDIR}/certs/*.tmp; do
  # Make sure that the cert is trusted...
  grep "CKA_TRUST_SERVER_AUTH" "${tempfile}" | \
    egrep "TRUST_UNKNOWN|NOT_TRUSTED" > /dev/null

  if test "${?}" = "0"; then
    # Throw a meaningful error and remove the file
    cp "${tempfile}" tempfile.cer
    perl ${CONVERTSCRIPT} > tempfile.crt
    keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
    echo "Certificate ${keyhash} is not trusted!  Removing..."
    rm -f tempfile.cer tempfile.crt "${tempfile}"
    continue
  fi

  # If execution made it to here in the loop, the temp cert is trusted
  # Find the cert data and generate a cert file for it

  cp "${tempfile}" tempfile.cer
  perl ${CONVERTSCRIPT} > tempfile.crt
  keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
  mv tempfile.crt "certs/${keyhash}.pem"
  rm -f tempfile.cer "${tempfile}"
  echo "Created ${keyhash}.pem"
done

# Remove blacklisted files
# MD5 Collision Proof of Concept CA
if test -f certs/8f111d69.pem; then
  echo "Certificate 8f111d69 is not trusted!  Removing..."
  rm -f certs/8f111d69.pem
fi

# Finally, generate the bundle and clean up.
cat certs/*.pem >  ${BUNDLE}
rm -r "${TEMPDIR}"
EOF

chmod +x /bin/make-ca.sh

cat > /bin/remove-expired-certs.sh << 'EOF'
#!/bin/sh
# Begin /bin/remove-expired-certs.sh
#
# Version 20120211

# Make sure the date is parsed correctly on all systems
mydate()
{
  local y=$( echo $1 | cut -d" " -f4 )
  local M=$( echo $1 | cut -d" " -f1 )
  local d=$( echo $1 | cut -d" " -f2 )
  local m

  if [ ${d} -lt 10 ]; then d="0${d}"; fi

  case $M in
    Jan) m="01";;
    Feb) m="02";;
    Mar) m="03";;
    Apr) m="04";;
    May) m="05";;
    Jun) m="06";;
    Jul) m="07";;
    Aug) m="08";;
    Sep) m="09";;
    Oct) m="10";;
    Nov) m="11";;
    Dec) m="12";;
  esac

  certdate="${y}${m}${d}"
}

OPENSSL=/bin/openssl
DIR=/etc/ssl/certs

if [ $# -gt 0 ]; then
  DIR="$1"
fi

certs=$( find ${DIR} -type f -name "*.pem" -o -name "*.crt" )
today=$( date +%Y%m%d )

for cert in $certs; do
  notafter=$( $OPENSSL x509 -enddate -in "${cert}" -noout )
  date=$( echo ${notafter} |  sed 's/^notAfter=//' )
  mydate "$date"

  if [ ${certdate} -lt ${today} ]; then
     echo "${cert} expired on ${certdate}! Removing..."
     rm -f "${cert}"
  fi
done
EOF

chmod +x /bin/remove-expired-certs.sh

make-ca.sh
remove-expired-certs.sh certs

install -d /etc/ssl/certs
cp -v certs/*.pem /etc/ssl/certs
c_rehash
install BLFS-ca-bundle*.crt /etc/ssl/ca-bundle.crt
ln -sfv ../ca-bundle.crt /etc/ssl/certs/ca-certificates.crt

rm BLFS-ca-bundle*.crt
rm certdata.txt
rm -rf certs

cd
exit 0

Libevent
========

Libevent is a dependency of Tmux.

install_package libevent
# 1 minute
tar xf /download/libevent-2.0.22-stable.tar.gz -C /build
cd /build/libevent-2.0.22-stable
./configure \
    --prefix= \
    --disable-openssl
make
make DESTDIR= install
cd ..
rm -rf libevent-2.0.22-stable
cd
exit 0

Tmux
====

Tmux is a terminal multiplexer: it allows multiple terminal sessions to be accessed simultaneously in a single window.

install_package tmux
# 1 minute
tar xf /download/tmux-1.8.tar.gz -C /build
cd /build/tmux-1.8
./configure --prefix=
make
make DESTDIR= install
cd ..
rm -rf tmux-1.8
cd
exit 0

Package Users Final Tweaks
==========================

In order to simplify the build of future packages, create the following file:

cat > /etc/pkgusr/skel-package/build-me.sh << EOF
# Exit on error:
set -e

wget
tar xf
cd
./configure --prefix=
make install
cd ..
rm -rf
rm

exit 0
EOF

chmod u+x /etc/pkgusr/skel-package/build-me.sh

Then:

cat >> /etc/pkgusr/bash_profile << 'EOF'
if [[ -f build-me.sh ]]
    then mv build-me.sh build-`whoami`.sh
    if [[ -f /src/recipes-1.9.0/`whoami` ]]
        then cp /src/recipes-1.9.0/`whoami` build-`whoami`.sh
    elif [[ -f /src/recipes-1.8/`whoami` ]]
        then cp /src/recipes-1.8/`whoami` build-`whoami`.sh
    elif [[ -f /src/recipes-1.7/`whoami` ]]
        then cp /src/recipes-1.7/`whoami` build-`whoami`.sh
    elif [[ -f /src/recipes-1.6/`whoami` ]]
        then cp /src/recipes-1.6/`whoami` build-`whoami`.sh
    elif [[ -f /src/recipes-1.5/`whoami` ]]
        then cp /src/recipes-1.5/`whoami` build-`whoami`.sh
    fi
fi
EOF

Because i wrote many recipes in the past, you can use them when possible. Connect to the wired internet first:

ifconfig eth0 up
dhcpcd eth0

Now download my recipes:

mkdir -v /src/recipes-1.{5,6,7,8,9.0}

cd /src/recipes-1.5
wget http://cjarry.org/gnu-linux/gllfsc/recipes/gllfsc-1.0-to-1.5/0-recipes-1.5
chmod u+x 0-recipes-1.5
sed -i 's/wget/wget -nv/' 0-recipes-1.5
./0-recipes-1.5

cd /src/recipes-1.6
wget http://cjarry.org/gnu-linux/gllfsc/recipes/gllfsc-1.6/0-recipes-1.6
chmod u+x 0-recipes-1.6
sed -i 's/wget/wget -nv/' 0-recipes-1.6
./0-recipes-1.6

cd /src/recipes-1.7
wget http://cjarry.org/gnu-linux/gllfsc/recipes/gllfsc-1.7/0-recipes-1.7
chmod u+x 0-recipes-1.7
sed -i 's/wget/wget -nv/' 0-recipes-1.7
./0-recipes-1.7

cd /src/recipes-1.8
wget http://cjarry.org/gnu-linux/gllfsc/recipes/gllfsc-1.8/0-recipes-1.8
chmod u+x 0-recipes-1.8
sed -i 's/wget/wget -nv/' 0-recipes-1.8
./0-recipes-1.8

cd /src/recipes-1.9.0
wget http://cjarry.org/gnu-linux/gllfsc/recipes/gllfsc-1.9.0/0-recipes-1.9.0
chmod u+x 0-recipes-1.9.0
sed -i 's/wget/wget -nv/' 0-recipes-1.9.0
./0-recipes-1.9.0
cd

Archiving the Complete System
=============================

# Clean up:
#rm /src/*
rm /root/*
rm /root/.bash_history
rm -rf /share/doc
#mv /share/man/man* /share
#rm -rf /share/man/*
#mv /share/man[1-8] /share/man

# Strip binaries
# 116 MB before, 41 MB after
strip --strip-all /bin/*

Switch to another operating system on the same machine, for instance GLLFSC 1.8. Then issue the following command:

# To be done outside GLLFSC:
# 4 minutes
cd /gllfsc
tar -cjf gllfsc-pentium4-1.9.0-completed.tar.bz2 \
    bin boot dev etc home include lib* local man mnt proc root run \
    sbin service share src static sys tmp usr var

Add User
========

To create a new user, without root rights:

useradd -m USER

This will create a new user named USER with group USER and user's home at /home/USER.

To give a password to this user:

passwd USER

You may want to change the color of this user's prompt:

cat > /home/USER/.bash_profile << EOF
export PS1='\[\e[32m\]\A-\W\[\e[00m\]$ '
EOF
chown USER:USER /home/USER/.bash_profile

Halting the Computer
====================

In order to halt the computer after this build process, type:

init.sysv 0

If you prefer to reboot instead type:

init.sysv 6

The next time you use GLLFSC, runit will be the default init system and you will have to type init 0 to halt the operating system and init 6 to reboot.

Further Readings
****************

On my personal website at http://cjarry.org/gnu-linux/gllfsc/gllfsc.en.html, there is some information on how to connect to the internet with wifi, and how to extend GLLFSC, for instance instructions on how to build Xorg, chose a font and a web browser, text-based or graphical.

Haiyong Sun's website (in Chinese): http://blog.chinaunix.net/uid/436750.html. It includes documents on building a GNU/Linux system for Loongson and a GNU/Hurd system for x86. He also owns repositories on https://github.com/sunhaiyong1978/, some of which concern the LoongArch architecture.

The suckless team (http://suckless.org) is a group of programmers that share the following philosophy (http://suckless.org/philosophy/):

     Focus on simplicity, clarity and frugality. Our philosophy is about keeping things simple, minimal and usable. We believe this should become the mainstream philosophy in the IT sector. Unfortunately, the tendency for complex, error-prone and slow software seems to be prevalent in the present-day software industry. We intend to prove the opposite with our software projects.

The simple and lightweight programs released by this team are interesting for everyone who like small, reactive and reliable programs.

Musl (http://musl.libc.org/) is a free software C library for the kernel Linux. It is simple and suitable for both static and dynamic linking of binaries.

Thanks
******

I am particularily grateful to Haiyong Sun for having shared his knowledge on building a free operating system for Loongson 2F machines, this document was heavily based on his work.

GNU Free Documentation License
******************************

     [file fdl-1.3.texi not included]

GNU General Public License
**************************

     [file gpl-3.0.texi not included]