Exclude undesired files from git archive
[gllfsc.git] / gllfsc-pentium4-1.7.texi
1 \input texinfo
2 @c -*-texinfo-*-
3 @c %**start of header
4 @setfilename gllfsc-pentium4-1.7.info
5 @settitle GNU/Linux-libre from source code for Pentium 4
6 @c Comment the following if you want Letter format instead of A4 for
7 @c PDF output
8 @afourpaper
9 @c %**end of header
10 @c Book headers for PDF version
11 @setchapternewpage odd
12 @documentencoding UTF-8
13
14 @copying
15 This is edition 1.7 (last updated April 2020) of
16 @cite{GNU/Linux-libre from source code for Pentium 4}.
17
18 Copyright @copyright{} 2020 Christophe Jarry.
19
20 @ignore
21 This document is based on the Chinese page
22 @url{http://zdbr.net.cn/download/Loongson64-@/2.0.htm}, which is
23 copyright @copyright{} 2009
24 @c Because TeX does not handle Chinese fonts automatically, we need to
25 @c do the following:
26 @ifnottex
27 Haiyong Sun (孙海勇).
28 @end ifnottex
29 @iftex
30 Haiyong Sun.
31 @end iftex
32 His blog is on @url{http://blog.chinaunix.net/uid/436750.html}.
33 @end ignore
34
35 Various formats of this manual as well as its texinfo source are
36 available on
37 @uref{http://cjarry.org/gnu-linux/gllfsc/pentium4/}.
38
39 @quotation
40 Permission is granted to copy, distribute and/or modify this document
41 under the terms of the GNU Free Documentation License, Version 1.3
42 or any later version published by the Free Software Foundation;
43 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
44 Texts. A copy of the license is included in the section entitled ``GNU
45 Free Documentation License''.
46 @end quotation
47
48 @quotation
49 Computer instructions in this manual are free software: you can
50 redistribute them and/or modify them under the terms of the GNU
51 General Public License as published by the Free Software Foundation,
52 either version 3 of the License, or (at your option) any later
53 version.
54
55 Those instructions are distributed in the hope that they will be
56 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
57 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58 GNU General Public License for more details.
59
60 You should have received a copy of the GNU General Public License
61 along with this manual.  If not, see <http://www.gnu.org/licenses/>.
62 @end quotation
63
64 @end copying
65
66 @c   @setchapternewpage odd
67
68 @titlepage
69 @title GNU/Linux-libre from source code
70 @subtitle for Pentium 4
71 @c @subtitle SUBTITLE-IF-ANY
72 @c @subtitle SECOND-SUBTITLE
73 @author Christophe Jarry
74
75 @c  The following two commands
76 @c  start the copyright page.
77 @page
78 @vskip 0pt plus 1filll
79 @insertcopying
80
81 @c Published by ...
82 @end titlepage
83
84 @c Short table of contents
85 @shortcontents
86
87 @c So the toc is printed at the start.
88 @contents
89
90 @ifnottex
91 @node Top
92 @top GNU/Linux-libre from source code for Pentium 4
93
94 This manual describes how to build a GNU/Linux-libre system from
95 source for Pentium 4 processor.
96
97 @insertcopying
98 @end ifnottex
99
100 @menu
101 * Introduction::     What this document is all about.
102 * Prerequisites::    Useful knowledge before proceeding.
103 * Preliminary Work:: Preparing the build.
104 * Building the Cross-Compilation Toolchain:: Building the cross-
105                                               compilation Toolchain.
106 * Building the Cross-Compilation Tools:: Building the
107                                           cross-compilation Tools.
108 * Building the Target System::       How to build the target system.
109 * Configuration Files::              Creating configuration files
110                                       needed by the new system.
111 * Before Booting GLLFSC::            Final things to do before booting
112                                       into the new system.
113 * After Booting GLLFSC::             Some packages to install and
114                                       configuration to tweek in order
115                                       to extend the system.
116 * Further Readings::                 Websites useful to know more.
117 @c * Thanks::                           Thanks.
118 * GNU Free Documentation License::   Your rights and freedoms with the
119                                      text.
120 * GNU General Public License::       Your rights and freedoms with the
121                                      commands.
122 @end menu
123
124
125 @node Introduction
126 @chapter Introduction
127
128 @menu
129 * GNU/Linux History::           A brief history of GNU/Linux.
130 * Purpose of this Document::    What this document is all about.
131 @end menu
132
133
134 @node GNU/Linux History
135 @section GNU/Linux History
136
137 @menu
138 * GNU::          Presentation of the GNU project
139 * HURD::         Presentation of the HURD
140 * Linux::        Presentation of the kernel Linux
141 * Linux-libre::  Presentation of the kernel Linux-libre
142 * References::   Where to get more information
143 @end menu
144
145 @node GNU
146 @subsection GNU
147
148 @acronym{GNU} (GNU's Not Unix) is a project launched by Richard
149 Stallman in 1984 with the goal of building an entirely free operating
150 system compatible with Unix@footnote{See
151 @uref{http://en.wikipedia.org/wiki/Unix}}. ``Free'' here means ``free
152 as in freedom''. In this context, a free operating system is an
153 operating system you can use and share in freedom. A core part of his
154 motivation is given in the GNU
155 Manifesto@footnote{@uref{http://www.gnu.org/gnu/manifesto.html}}:
156
157 @quotation
158 I consider that the Golden Rule requires that if I like a program I
159 must share it with other people who like it. Software sellers want to
160 divide the users and conquer them, making each user agree not to share
161 with others. I refuse to break solidarity with other users in this
162 way. I cannot in good conscience sign a nondisclosure agreement or a
163 software license agreement. For years I worked within the Artificial
164 Intelligence Lab to resist such tendencies and other inhospitalities,
165 but eventually they had gone too far: I could not remain in an
166 institution where such things are done for me against my will.
167
168 So that I can continue to use computers without dishonor, I have
169 decided to put together a sufficient body of free software so that I
170 will be able to get along without any software that is not free. I
171 have resigned from the AI Lab to deny MIT any legal excuse to prevent
172 me from giving GNU away.
173 @end quotation
174
175 A program is free software if the program's user has the four
176 essential freedoms:
177
178 @itemize
179 @item
180 The freedom to run the program, for any purpose (freedom 0).
181
182 @item
183 The freedom to study how the program works, and change it so it does
184 her computing as she wishes (freedom 1). Access to the source code is
185 a precondition for this.
186
187 @item
188 The freedom to redistribute copies so she can help her neighbor
189 (freedom 2).
190
191 @item
192 The freedom to distribute copies of her modified versions to others
193 (freedom 3). By doing this she can give the whole community a chance
194 to benefit from her changes. Access to the source code is a
195 precondition for this.
196 @end itemize
197
198 One of the most popular free software license is the GNU General
199 Public License (GNU
200 GPL@footnote{@uref{http://www.gnu.org/licenses/gpl.html}}).
201
202 The free software movement is supported by the Free Software
203 Foundation (FSF@footnote{@uref{http://www.fsf.org}}).
204
205
206 @node HURD
207 @subsection HURD
208
209 The @acronym{HURD} is an acronym for @acronym{HIRD} (HURD of
210 interfaces representing depth) of Unix-replacing daemons. It is the
211 GNU project's replacement for the Unix kernel. It is a collection of
212 servers that run on the Mach microkernel to implement file systems,
213 network protocols, file access control, and other features that are
214 implemented by the Unix kernel or similar kernels (such as Linux).
215
216 The purpose of the GNU HURD is to improve the user's freedom on her
217 operating system by allowing her to either add or remove a feature of
218 the kernel on the fly.
219
220 From early on, the HURD was developed to use GNU Mach as the
221 microkernel. This was a technical decision made by Richard Stallman,
222 who thought it would speed up the work by saving a large part of
223 it. He has admitted that he was wrong about that.
224
225 Nevertheless, development of the HURD is increasingly attracting
226 developers and GNU/HURD systems exist and are usable.
227
228
229 @node Linux
230 @subsection Linux
231
232 Linux is a monolithic kernel created by Linus Torvalds in 1991. Linus
233 Torvalds initially wrote a terminal emulator, which he used to access
234 the large UNIX servers of his university. He wrote the program
235 specifically for the hardware he was using and independent of an
236 operating system because he wanted to use the functions of his new PC
237 with an 80386 processor. This later became the kernel Linux.
238
239 Initially, Torvalds first published the kernel Linux under its own
240 licence, which had a restriction on commercial activity.
241
242 In the notes for the first release of the kernel Linux, Torvalds lists
243 the GNU software that is required to run Linux:
244
245 @quotation
246 Sadly, a kernel by itself gets you nowhere. To get a working system
247 you need a shell, compilers, a library etc. [...] Most of the tools
248 used with linux are GNU software and are under the GNU copyleft.
249 @end quotation
250
251 In 1992, he suggested releasing the kernel under the GNU General
252 Public License. He first announced this decision in the release notes
253 of version 0.12. In the middle of December 1992 he published version
254 0.99 using the GNU GPL.
255
256 The kernel Linux is now a contribution of many professionals and
257 volonteers around the world.
258
259
260 @node Linux-libre
261 @subsection Linux-libre
262
263 Linux, the kernel developed and distributed by Linus Torvalds et al,
264 contains non-Free Software@footnote{For more information about the
265 presence of proprietary firmware in the kernel Linux, read
266 @uref{http://www.fsfla.org/ikiwiki/anuncio/2010-03-Linux-2.6.33-libre.en}
267 and
268 @uref{http://www.gnu.org/@/distros/free-system-distribution-guidelines.html#nonfree-firmware}.},
269 i.e., software that does not respect your essential freedoms, and it
270 induces you to install additional non-Free Software that it doesn't
271 contain.
272
273 GNU
274 Linux-libre@footnote{@uref{http://www.fsfla.org/ikiwiki/selibre/linux-libre/index.en.html}}
275 is a project to maintain and publish 100% Free distributions of Linux,
276 suitable for use in Free System Distributions@footnote{For a full list
277 of free as in freedom GNU/Linux distributions, see
278 @uref{http://www.gnu.org/distros/}.}, removing software that is
279 included without source code, with obfuscated or obscured source code,
280 under non-Free Software licenses, that do not permit you to change the
281 software so that it does what you wish, and that induces or requires
282 you to install additional pieces of non-Free Software.
283
284
285 @node References
286 @subsection References
287
288 For more information on the GNU project and its relation with the
289 kernel Linux, you can read @uref{http://www.gnu.org/gnu/thegnuproject.html}
290 and @uref{http://www.gnu.org/gnu/gnu-linux-faq.html}.
291
292 For more information on the history of the HURD, I recommend you to
293 read @uref{http://www.h-online.com/open/features/GNU-HURD-Altered-visions-and-lost-promise@/-1030942.html}.
294
295 For more information on the HURD, read @uref{http://www.gnu.org/software/hurd/}.
296
297 For more information on the early versions of the kernel Linux, read
298 @uref{https://www.cs.cmu.edu/~awb/linux.history.html}.
299
300
301 @node Purpose of this Document
302 @section Purpose of this Document
303
304 One day I found a Dell Optiplex 745 minitower with a Pentium 4 CPU in
305 a municipal waste. I just replaced the button battery and the computer
306 was able to boot. I decided to adapt the work I did for the Lemote
307 Yeeloong 8133: GNU/Linux@footnote{Note: in this document, we use the
308 term ``GNU/Linux'' to name the entire system and ``Linux'' to name the
309 kernel. For more information, read
310 @uref{http://www.gnu.org/gnu/why-gnu-linux.html}.} Libre from Source
311 Code for Pentium 4 was born.
312
313
314 @node Prerequisites
315 @chapter Prerequisites
316
317 @menu
318 * Definitions::  Definitions of important notions used to build the
319                  system
320 * Commands::     Help on commands
321 @end menu
322
323
324 @node Definitions
325 @section Definitions
326
327 @menu
328 * sysroot::              @option{sysroot}
329 * Toolchain::            What a Toolchain is.
330 * build host target::    Understanding the meaning of the
331                          @option{build}-@option{host}-@option{target}
332                          triplet.
333 * FHS::                  The Filesystem Hierarchy Standard.
334 @end menu
335
336
337 @node sysroot
338 @subsection @option{sysroot}
339
340 The traditional way of building a GNU/Linux operating system consists
341 on building a (cross-) compilation toolchain to build a temporary
342 operating system which in turn will be used to build the target
343 system@footnote{@pxref{Further Readings} for more details}. This
344 requires almost as much time to complete the temporary system as to
345 build the target one. Using sysroot resolves this problem.
346
347 From GCC installation manual, under Cross-Compiler-Specific Options:
348
349 @table @code
350 @item --with-sysroot
351 @itemx --with-sysroot=@var{dir}
352 Tells GCC to consider @var{dir} as the root of a tree that contains (a
353 subset of) the root filesystem of the target operating system.  Target
354 system headers, libraries and run-time object files will be searched
355 in there.  More specifically, this acts as if
356 @option{--sysroot=@var{dir}} was added to the default options of the
357 built compiler.  The specified directory is not copied into the
358 install tree, unlike the options @option{--with-headers} and
359 @option{--with-libs} that this option obsoletes.  The default value,
360 in case @option{--with-sysroot} is not given an argument, is
361 @option{$@{gcc_tooldir@}/sys-root}.  If the specified directory is a
362 subdirectory of @option{$@{exec_prefix@}}, then it will be found
363 relative to the GCC binaries if the installation tree is moved.
364
365 This option affects the system root for the compiler used to build
366 target libraries (which runs on the build system) and the compiler
367 newly installed with @code{make install}; it does not affect the
368 compiler which is used to build GCC itself.
369 @end table
370
371
372 @node Toolchain
373 @subsection Toolchain
374
375 According to
376 Wikipedia@footnote{@uref{http://en.wikipedia.org/wiki/Toolchain}}:
377
378 @quotation
379 In software, a toolchain is the set of programming tools that are used
380 to create a product (typically another computer program or system of
381 programs). The tools may be used in a chain, so that the output of
382 each tool becomes the input for the next, but the term is used widely
383 to refer to any set of linked development tools.
384
385 A simple software development toolchain consists of a text editor for
386 editing source code, a compiler and linker to transform the source
387 code into an executable program, libraries to provide interfaces to
388 the operating system, and a debugger.
389 @end quotation
390
391
392 @node build host target
393 @subsection @option{build}, @option{host} and @option{target}
394
395 During a cross-compilation, @option{build} @option{host} and
396 @option{target} are among the most used options: understanding the
397 precise meaning of those parameters is very important. We could define
398 them thus:
399
400 @itemize
401 @item @option{--build=@var{platform on which the program is
402 compiled}},
403 @item @option{--host=@var{platform on which the program will run}},
404 @item @option{--target=@var{platform for which the program will create
405 output}}.
406 @end itemize
407
408 Let's use GCC as an example to explain the role of those three
409 parameters.
410
411 During GCC compilation, we use:
412
413 @samp{./configure --build=@var{build-platform}
414 --host=@var{host-platform} --target=@var{target-platform} [various
415 compilation parameters]}
416
417 So in those configuration parameters:
418
419 @itemize
420 @item
421 @option{--build} provides the name of the platform currently running.
422 If we were using an Intel Pentium processor to compile the system, our
423 @var{build-platform} would be something like @samp{i686-pc-linux-gnu}.
424
425 If this parameter is not specified, it will be guessed automatically.
426
427 @item
428 @option{--host} represents the type of machine we are going to run GCC
429 on after the compilation succeeds. During a cross-compilation this has
430 to be specified, because the current machine can not know which
431 architecture we wish to target. We want to produce executables to run
432 on @emph{Pentium4}, but there is currently no way we can specify
433 @samp{Pentium4} directly; because of this we specify
434 @samp{i386-unknown-linux-gnu}.
435
436 @option{--host} can also be left unspecified, in that case,
437 @var{host-platform} would automatically define itself as
438 @var{build-platform}, but this is not cross-compilation anymore.
439
440 @quotation Note
441 when @option{--build} and @option{--host} are different, configuration
442 files will maintain the cross-compilation mode.
443 @end quotation
444
445 @item
446 @option{--target} defines the system for which compiler tools will
447 create output.
448
449 @var{target-platform} parameter is useful only for a limited number of
450 programs. Although this parameter is often present when issuing
451 @samp{./configure --help}, hardly any packages will need it.
452
453 This parameter is only useful for performing tasks with different
454 platforms; for instance, executable files compiled for different
455 platforms can have a totally different code.
456 @end itemize
457
458 If we summarize, we have:
459
460 @itemize
461 @item @var{build-platform}: automatically guessed from platform in
462 use; has to be specified if not guessed.
463
464 @item @var{host-platform}: if unspecified, automatically equals
465 @var{build-platform}. When @var{build-platform} and
466 @var{host-platform} values are identical, it is a local compilation;
467 otherwise it is a cross-compilation.
468
469 @item @var{target-platform}: defines the system for which compiler
470 tools will create output; it equals @var{host-platform} if
471 unspecified. GCC, binutils, and programs related to the platform's
472 instructions have this parameter; most programs do not use this
473 parameter.
474 @end itemize
475
476
477 @node FHS
478 @subsection FHS
479
480 The Filesystem Hierarchy Standard (FHS) has been created to specify
481 the location and use of main directories on a GNU/Linux operating
482 system. Common commands, user data, libraries have to be put inside a
483 specific directory given in the standard. During the build process,
484 some commands are used to comply with FHS.
485
486
487 @node Commands
488 @section Commands
489
490 Because most commands are common for a regular Unix user, only
491 uncommon commands are explained in this document. If you do not
492 understand a command that is not explained, you can use the
493 documentation available on your computer; in a terminal, typing
494 @samp{man @var{command}} should give you enough information. For GNU
495 software, @samp{info @var{package}} can also give additional
496 information.
497
498 To know more about command line, I suggest you read "Introduction to
499 the Command Line" which is available on
500 @uref{http://flossmanuals.net/command-line/}.
501
502
503 @node Preliminary Work
504 @chapter Preliminary Work
505
506 @quotation Important
507 In order to complete the first steps of this chapter, you will need to
508 have root permissions.
509 @end quotation
510
511 @menu
512 * Build Partition Creation::   Creating a partition for the build.
513 * Build User Creation::        Creating a user account dedicated to
514                                the build.
515 * Work Directory Creation::    Creating the parent directory for the
516                                build.
517 * Partition Mount::            Mounting the partition dedicated to the
518                                build.
519 * Useful Directories Creation:: Creating the directories for downloads
520                                and compilations.
521 * User Switch::                Switching to the user dedicated to the
522                                build.
523 * Environment Variables Setup:: Setting up the environment variables
524                                of the target system.
525 * Downloads::                  Downloading needed packages and
526                                patches.
527 * Final Preparations::         Preparing the system for the build.
528 @end menu
529
530
531 @node Build Partition Creation
532 @section Build Partition Creation
533
534 To dedicate the partition @file{/dev/sda1} to the system build, and to
535 define the filesystem to be used for it as @samp{ext3}:
536
537 @verbatim
538 mke2fs -t ext3 /dev/sda1
539 @end verbatim
540
541 Option @option{-t} is followed by the type of filesystem to be
542 used. The filesystem @samp{ext3} is used as it is one of the most
543 common filesystem used with the kernel Linux.
544
545
546 @node Build User Creation
547 @section Build User Creation
548
549 To create the builder group, user and password:
550
551 @verbatim
552 groupadd gllfsc
553 useradd -s /bin/bash -g gllfsc -m -k /dev/null gllfsc
554 passwd gllfsc
555 @end verbatim
556
557 @itemize
558 @item
559 Option @option{-s} (or @option{--shell}) is used to define the created
560 user's default shell, here @file{/bin/bash}.
561
562 @item
563 Option @option{-g} (or @option{--gid}) is used to define the group
564 name or number of the created user's initial login group, here
565 @samp{gllfsc}.
566
567 @item
568 Option @option{-m} (or @option{--create-home}) does create the user's
569 home directory if it does not exist (@file{/home/@var{username}}).
570
571 @item
572 Option @option{-k} (or @option{--skel}) is used to define the skeleton
573 directory to be copied in the user's home directory, here
574 @file{/dev/null}. @file{/dev/null} is a special file which, in this
575 case, will give no skeleton at all to @command{useradd}.
576 @end itemize
577
578
579 @node Work Directory Creation
580 @section Work Directory Creation
581
582 To create the directory @file{/gllfsc} in which the system will be
583 built:
584
585 @verbatim
586 export TARGET_DIR="/gllfsc"
587 mkdir -pv ${TARGET_DIR}
588 @end verbatim
589
590 @samp{export TARGET_DIR="/gllfsc"} sets the value of the variable
591 @env{TARGET_DIR} to @file{/gllfsc}, the directory in which the system
592 will be built.
593
594
595 @node Partition Mount
596 @section Mounting Partition
597
598 To mount the hard drive partition, for instance @file{/dev/sda1}, used
599 to build the system:
600
601 @verbatim
602 mount /dev/sda1 ${TARGET_DIR}
603 @end verbatim
604
605
606 @node Useful Directories Creation
607 @section Creating Compilation and Download Directories
608
609 @verbatim
610 mkdir -pv ${TARGET_DIR}/{build,download}
611 chown -Rv gllfsc ${TARGET_DIR}
612 @end verbatim
613
614
615 @node User Switch
616 @section Switching to the Build User
617
618 To login as the user that will build the system:
619
620 @verbatim
621 su - gllfsc
622 @end verbatim
623
624 With the command @command{su}, it is possible to change the user
625 ID. The option @option{-} provides an environment similar to what the
626 user would expect had the user logged in directly.
627
628
629 @node Environment Variables Setup
630 @section Setting up Required Environment Variables
631
632 @file{~/.bash_profile} is a personal initialization file that is read
633 when Bash is invoked as an interactive login shell (@file{~} is the
634 location of the user's home directory). To write the content of the
635 file @file{~/.bash_profile}:
636
637 @verbatim
638 cat > ~/.bash_profile << 'EOF'
639 exec env -i HOME=${HOME} TERM=${TERM} PS1=${PS1} /bin/bash
640 EOF
641 @end verbatim
642
643 The first line creates the file @file{~/.bash_profile} and opens it
644 for writing until @samp{@acronym{EOF}} (End Of File) is written in it.
645
646 The second line tells Bash to execute @file{/bin/bash} with the option
647 @option{-i} (or @option{--ignore-environment}) which will make Bash
648 start with an empty environment. Variables @env{HOME}, @env{TERM} and
649 @env{PS1} define respectively the home directory of the current user,
650 the terminal used and the primary prompt string displayed.
651
652 @file{~/.bashrc} is a personal initialization file that is read when
653 Bash is invoked as an interactive shell but not a login one. To write
654 the content of the file @file{~/.bashrc}:
655
656 @verbatim
657 export TARGET_DIR=/gllfsc
658 cat > ~/.bashrc << EOF
659 set +h
660 umask 022
661 #alias make='make -j5'
662 export PS1='\[\e[35m\]\A-\W\[\e[00m\]$ '
663 export LC_ALL=POSIX
664 export TARGET_DIR=/gllfsc
665 export BUILD_DIR="${TARGET_DIR}/build"
666 export DOWNLOAD_DIR="${TARGET_DIR}/download"
667 export CROSS_HOST="$(echo $MACHTYPE |\
668     sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
669 export CROSS_TARGET="i686-unknown-linux-gnu"
670 #export MABI="n32"
671 #export MABI="64"
672 export MARCH="pentium4"
673 export PATH=${TARGET_DIR}/cross-tools/bin:/bin:/usr/bin
674 unset CFLAGS
675 unset CXXFLAGS
676 EOF
677 source ~/.bash_profile
678 @end verbatim
679
680 @samp{set +h} tells Bash to not locate nor remember commands (hash) as
681 they are looked up for execution.
682
683 @samp{umask 022} sets Bash process' file creation mask to
684 @samp{022}. This results in permissions of `755' for those files.
685
686 @samp{alias make='make -j5'} tells Bash to replace every call of
687 @samp{make} by @samp{make -j5}. This is useful for multiple-cores CPUs
688 as it parallelizes tasks.
689
690 @samp{export PS1='\[\e[35m\]\A-\W\[\e[00m\]$ '} sets the primary
691 prompt strings. The primary prompt strings are the strings you see
692 before the commands you type in the terminal. The part @samp{\A-\W}
693 means that the time, in 24-hour HH:MM format and the basename of
694 @env{$PWD} will be displayed separated by a `-', as in
695 @samp{19:33-bin}. The part @samp{\$} adds a dollar sign at the end,
696 @samp{\[\e[35m\]} colors the strings in purple and @samp{\[\e[00m\]}
697 gets the original color back. For other colors, you can browse
698 @uref{http://en.wikipedia.org/wiki/ANSI_escape_code}.
699
700 @env{LC_ALL} is a macro used to define a single locale to overwrite
701 other @env{LC_*} and @env{LANG} environment variables so that
702 language, numeric values, time and other locale-dependant values have
703 all the same value. It is set to the standard POSIX locale.
704
705 @samp{export BUILD_DIR="$@{TARGET_DIR@}/build"} sets the environment
706 variable @env{BUILD_DIR} to the value of @samp{$@{TARGET_DIR@}/build}
707 which is @samp{/gllfsc/build} in this document.
708
709 The value of variable @env{CROSS_HOST} equals the value of variable
710 @env{MACHTYPE} of the current machine (for instance
711 @samp{i686-pc-linux-gnu}) modulo the second word, which is replaced by
712 @samp{cross} (i.e. @samp{i486-cross-linux-gnu}).
713
714 The value of variable @env{CROSS_TARGET} equals the value of variable
715 @env{MACHTYPE} of the machine for which the system is built (i.e.
716 @samp{i686-unknown-linux-gnu}).
717
718 The variable @env{MABI} defines the @acronym{ABI} (Application Binary
719 Interface) for which the system will be built. @option{-mabi} is an
720 option of GCC. n32/64 are for 64-bit CPUs only. 64 has 64-bit pointers
721 and long integers, whereas n32 has 32-bit pointers and long integers.
722 This does not apply to pentium 4 machines.
723
724 The variable @env{MARCH} defines the architecture for which the system
725 will be built. @option{-march} is an option of @acronym{GCC} (GNU
726 Compiler Collection).
727
728 The variable @env{PATH} contains a colon-separated list of directories
729 in which the shell looks for commands. The shell will first look for
730 commands in @file{$@{TARGET_DIR@}/cross-tools/bin}, then, if the
731 command was not found, in @file{/bin} and finally in @file{/usr/bin}.
732
733 @command{unset} command removes the variable associated, here
734 @env{CFLAGS} and @env{CXXFLAGS}. Those variables are used by GCC as
735 extra flags given to the C compiler and the C++ compiler
736 respectively.
737
738 Finally @samp{source ~/.bash_profile} reads and executes the content
739 of the file @file{~/.bash_profile}.
740
741
742 @node Downloads
743 @section Downloads
744
745 @menu
746 * Packages Download::  List of packages to be downloaded.
747 * Patches Download::   List of patches to be downloaded.
748 @end menu
749
750
751 @node Packages Download
752 @subsection Downloading Packages
753
754 The packages listed below are those used in this document. You can try
755 other versions but you will need a recent version of Binutils, GCC and
756 the kernel Linux in order to build GLLFSC.
757
758 Download those files under @env{$@{DOWNLOAD_DIR@}} (which is
759 @file{/gllfsc/download} in this document).
760
761 @quotation Note
762 If you have trouble with a savannah mirror, you can have a full list
763 of them at @uref{http://download.savannah.gnu.org/mirmon/savannah/}.
764 If you have trouble with a GNU mirror, you can have a full list
765 of them at @uref{http://www.gnu.org/prep/ftp.html}.
766 @end quotation
767
768 @itemize
769 @item
770 Autoconf: @uref{http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz}.
771
772 @item
773 Automake: @uref{http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz}.
774
775 @item
776 Bash: @uref{http://ftpmirror.gnu.org/bash/bash-4.2.tar.gz}.
777
778 @item
779 Binutils: @uref{http://ftpmirror.gnu.org/binutils/binutils-2.24.tar.bz2}.
780
781 @item
782 Bison: @uref{http://ftpmirror.gnu.org/bison/bison-2.7.tar.gz}.
783
784 @item
785 Bootscripts: @uref{http://ftp.clfs.org/pub/clfs/conglomeration/bootscripts@/-cross@/-lfs/@/bootscripts-cross-lfs-2.0.0.tar.xz}.
786
787 @item
788 Bzip2: @uref{http://downloads.sourceforge.net/bzip2/bzip2-1.0.6.tar.gz}.
789
790 @item
791 CA-Certificates: @uref{http://anduin.linuxfromscratch.org/sources/other/certdata.txt}.
792
793 @item
794 Coreutils: @uref{http://ftpmirror.gnu.org/coreutils/coreutils-8.19.tar.xz}.
795
796 @item
797 DHCPCD: @uref{https://roy.marples.name/downloads/dhcpcd/dhcpcd-6.1.0.tar.bz2}.
798
799 @item
800 Diffutils: @uref{http://ftpmirror.gnu.org/diffutils/diffutils-3.3.tar.xz}.
801
802 @item
803 E2fsprogs: @uref{http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.42.8.tar@/.gz}.
804
805 @item
806 File: @uref{ftp://ftp.astron.com/pub/file/file-5.16.tar.gz}.
807
808 @item
809 Findutils: @uref{http://ftpmirror.gnu.org/findutils/findutils-4.4.2.tar.gz}.
810
811 @item
812 Flex: @uref{http://downloads.sourceforge.net/flex/flex-2.5.37.tar.bz2}.
813
814 @item
815 Gawk: @uref{http://ftpmirror.gnu.org/gawk/gawk-4.1.0.tar.gz}.
816
817 @item
818 GCC: @uref{http://ftpmirror.gnu.org/gcc/gcc-4.7.3/gcc-4.7.3.tar.bz2}.
819
820 @item
821 Gdbm: @uref{http://ftp.gnu.org/gnu/gdbm/gdbm-1.11.tar.gz}.
822
823 @item
824 Gettext: @uref{http://ftpmirror.gnu.org/gettext/gettext-0.18.3.1.tar.gz}.
825
826 @item
827 Glibc: @uref{http://ftpmirror.gnu.org/glibc/glibc-2.18.tar.bz2}.
828
829 @item
830 Gmp: @uref{http://ftpmirror.gnu.org/gmp/gmp-5.1.3.tar.bz2}.
831
832 @item
833 Grep: @uref{http://ftpmirror.gnu.org/grep/grep-2.15.tar.xz}.
834
835 @item
836 Groff: @uref{http://ftpmirror.gnu.org/groff/groff-1.22.2.tar.gz}.
837
838 @item
839 GRUB: @uref{http://ftpmirror.gnu.org/grub/grub-2.00.tar.gz}.
840
841 @item
842 Gzip: @uref{http://ftpmirror.gnu.org/gzip/gzip-1.6.tar.gz}.
843
844 @item
845 Iana-Etc: @uref{http://sethwklein.net/iana-etc-2.30.tar.bz2}.
846
847 @item
848 Inetutils: @uref{http://ftpmirror.gnu.org/inetutils/inetutils-1.9.1.tar.gz}.
849
850 @item
851 Iproute2: @uref{https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.10.0@/.tar.bz2}.
852
853 @item
854 Kbd: @uref{http://ftp.altlinux.org/pub/people/legion/kbd/kbd-2.0.1.tar.gz}.
855
856 @item
857 Kmod: @uref{https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-15.tar.gz}.
858
859 @item
860 Less: @uref{http://www.greenwoodsoftware.com/less/less-458.tar.gz}.
861
862 @item
863 Libpipeline: @uref{http://download.savannah.gnu.org/releases/libpipeline/@/libpipeline-1.3.0.tar.gz}.
864
865 @item
866 Libtasn1: @uref{http://ftpmirror.gnu.org/libtasn1/libtasn1-3.4.tar.gz}.
867
868 @item
869 Libtool: @uref{http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz}.
870
871 @item
872 Linux-Libre @footnote{The kernel Linux is shipped with proprietary
873 firmware. The version called Linux-Libre exists without them, it is
874 available for download at
875 @uref{http://www.fsfla.org/ikiwiki/selibre/linux-libre/}.}.
876 @uref{http://linux-libre.fsfla.org/pub/linux-libre/releases/3.10-gnu/@/linux-libre-3.10-gnu.tar.xz}.
877
878 @item
879 Lynx: @uref{http://invisible-mirror.net/archives/lynx/tarballs/lynx2.8.8dev.16.tar@/.bz2}.
880
881 @item
882 M4: @uref{http://ftpmirror.gnu.org/m4/m4-1.4.17.tar.bz2}.
883
884 @item
885 Make: @uref{http://ftpmirror.gnu.org/make/make-4.0.tar.bz2}.
886
887 @item
888 Man-db: @uref{http://download.savannah.gnu.org/releases/man-db/man-db-2.6.7.1.tar@/.xz}.
889
890 @item
891 Man-Pages: @uref{https://www.kernel.org/pub/linux/docs/man-pages/Archive/man-pages-@/3.54.tar.bz2}.
892
893 @item
894 Mpc: @uref{http://ftpmirror.gnu.org/mpc/mpc-1.0.1.tar.gz}.
895
896 @item
897 Mpfr: @uref{http://ftpmirror.gnu.org/mpfr/mpfr-3.1.2.tar.bz2}.
898
899 @item
900 Nano: @uref{http://ftpmirror.gnu.org/nano/nano-2.3.2.tar.gz}.
901
902 @item
903 Ncurses: @uref{http://ftpmirror.gnu.org/ncurses/ncurses-5.9.tar.gz}.
904
905 @item
906 Openssl: @uref{ftp://ftp.openssl.org/source/old/1.0.1/openssl-1.0.1i.tar.gz}.
907
908 @item
909 Patch: @uref{http://ftpmirror.gnu.org/patch/patch-2.7.1.tar.bz2}.
910
911 @item
912 Perl: @uref{http://www.cpan.org/src/5.0/perl-5.18.1.tar.gz}.
913
914 @item
915 Procps: @uref{http://procps.sourceforge.net/procps-3.2.8.tar.gz}.
916
917 @item
918 Psmisc: @uref{https://sourceforge.net/projects/psmisc/files/psmisc/psmisc-22.20.tar@/.gz}.
919
920 @item
921 Readline: @uref{http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz}.
922
923 @item
924 Runit: @uref{http://smarden.org/runit/runit-2.1.2.tar.gz}
925
926 @item
927 Sed: @uref{http://ftpmirror.gnu.org/sed/sed-4.2.2.tar.bz2}.
928
929 @item
930 Shadow: @uref{https://src.fedoraproject.org/repo/pkgs/shadow-utils/shadow-4.1.4.3@/.tar.bz2/b8608d8294ac88974f27b20f991c0e79/shadow-4.1.4.3.tar.bz2}.
931
932 @item
933 Sysvinit: @uref{http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf@/.tar.bz2}.
934
935 @item
936 Tar: @uref{http://ftpmirror.gnu.org/tar/tar-1.27.1.tar.bz2}.
937
938 @item
939 Texinfo: @uref{http://ftpmirror.gnu.org/texinfo/texinfo-4.13a.tar.gz}.
940
941 @item
942 Tzcode: @uref{http://www.iana.org/time-zones/repository/releases/tzcode2013h.tar@/.gz}.
943
944 @item
945 Tzdata: @uref{http://www.iana.org/time-zones/repository/releases/tzdata2013h.tar@/.gz}.
946
947 @item
948 Udev: @uref{https://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-175.tar.gz}.
949
950 @item
951 Util-Linux: @uref{https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-@/linux-2.24.tar.bz2}.
952
953 @item
954 Wireless_tools: @uref{http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz}.
955
956 @item
957 Wpa_supplicant: @uref{http://w1.fi/releases/wpa_supplicant-2.0.tar.gz}.
958
959 @item
960 Wget: @uref{http://ftpmirror.gnu.org/wget/wget-1.14.tar.gz}.
961
962 @item
963 XZ-Utils: @uref{https://tukaani.org/xz/xz-5.0.8.tar.bz2}.
964
965 @item
966 Zlib: @uref{http://www.zlib.net/fossils/zlib-1.2.8.tar.gz}.
967 @end itemize
968
969
970 @node Patches Download
971 @subsection Downloading Patches
972
973 Patches and configuration files location:
974
975 @itemize
976 @item
977 @uref{http://cjarry.org/gnu-linux/gllfsc/pentium4/gllfsc-pentium4-1.7-patches@/.tar.gz}. After
978 having downloaded this file under @env{$@{DOWNLOAD_DIR@}}, execute
979 the following commands to extract its content:
980
981 @verbatim
982 cd ${DOWNLOAD_DIR}
983 tar xvf gllfsc-pentium4-1.7-patches.tar.gz
984 cd
985 @end verbatim
986
987 @ignore
988 @item
989 The page
990 @uref{http://dev.lemote.com/cgit/linux-official.git/commit/?h=linux-3.6@/&id=94fe1f0a7d2e3042fa7fadfd15da71b9d0c11809}
991 describes the changes to be made to the kernel in order to add support
992 for Chinese fonts in console. The patch applies to Linux 3.6.
993 Be aware though that applying this patch to the kernel may make
994 characters that are both non-@acronym{CJK} (Chinese Japanese Korean)
995 and non-ASCII unreadable (accented letters, cyrillic, etc.).
996
997 @item
998 The page
999 @uref{http://microcai.gsalex.net/old/archives/2011/01/fbcon_UNICODE_font_support.html}
1000 is useful for users who want support for @acronym{CJK} (Chinese
1001 Japanese Korean) characters under the (non-graphical) terminal. It
1002 gives access to a git@footnote{@uref{http://git-scm.com/}} repository
1003 with kernel patches@footnote{The patches to use with version 3.5 of
1004 the kernel are the first four on
1005 @uref{http://repo.or.cz/w/linux-2.6/cjktty.git/shortlog/refs/heads/3.5-utf8}.}
1006 that permit direct rendering of UTF-8 characters under the framebuffer
1007 environment. Be aware though that applying those CJK patches to the
1008 kernel may make characters that are both non-CJK and non-ASCII
1009 unreadable (accented letters, cyrillic, etc.).
1010 @end ignore
1011
1012 @item
1013 @uref{http://www.fsfla.org/svn/fsfla/software/linux-libre/lemote/gnewsense/tags/@/2.6.36-libre-lemote_0lxo/100gnu+freedo.patch}
1014 this patch adds a picture of a GNU beside Freedo, Freedo being the
1015 mascot of Linux-Libre. The image can be seen on
1016 @uref{http://www.fsfla.org/ikiwiki/selibre/linux-libre/100gnu+freedo}.
1017
1018 @item
1019 @uref{http://linux-libre.fsfla.org/pub/linux-libre/releases/3.10.7-gnu/patch-3.10-@/gnu-3.10.7-gnu.xz}
1020 this patch updates linux-libre-3.10 to linux-libre-3.10.7.
1021 @end itemize
1022
1023
1024 @node Final Preparations
1025 @section Final Preparations
1026
1027 @menu
1028 * Target Filesystem Hierarchy Creation:: Creating the directories of
1029                                          the target system.
1030 * Needed Files Creation::                Creating files for needed
1031                                          user, groups and log.
1032 @end menu
1033
1034
1035 @node Target Filesystem Hierarchy Creation
1036 @subsection Target Filesystem Hierarchy Creation
1037
1038 @verbatim
1039 cd ${TARGET_DIR}
1040
1041 # /usr is required for cmake, python and ruby at least
1042 mkdir -v usr
1043 cd usr
1044 mkdir -v bin include lib share src
1045 ln -sv bin sbin
1046 ln -sv lib lib32
1047 ln -sv lib lib64
1048 cd ..
1049
1050 mkdir -v boot dev etc home local mnt proc root run static sys var
1051 mkdir -v cross-tools libexec
1052
1053 ln -sv usr/bin bin
1054 ln -sv usr/bin sbin
1055 ln -sv usr/include include
1056 ln -sv usr/lib lib
1057 ln -sv usr/lib lib32
1058 ln -sv usr/lib lib64
1059 ln -sv usr/share share
1060 ln -sv usr/src src
1061 install -dv -m 0777 tmp
1062
1063 install -dv -m 1777 var
1064 cd var
1065 mkdir -v cache local lock log mail run spool
1066 mkdir -pv lib/misc lib/locate
1067 cd ..
1068
1069 install -dv -m 0750 root
1070
1071 cd local
1072 mkdir -v bin include lib src
1073 ln -sv bin sbin
1074 ln -sv lib lib32
1075 mkdir -v share
1076 cd share
1077 mkdir -v doc info locale man misc terminfo zoneinfo
1078 mkdir -v man/man{1..8}
1079 cd ../..
1080 ln -sv share/man man
1081 cd
1082 @end verbatim
1083
1084 The command @samp{install -dv -m 1777 var} creates the directory
1085 @file{var} with the permissions to read, write and execute for
1086 everyone. The '1' in @samp{1777} is the sticky bit which allows
1087 deletion of the file or directory having this attribute only for the
1088 owner of the file or directory.
1089
1090 The command @samp{ln -svf lib lib64} creates a symbolic link (option
1091 @option{-s}) with the name @file{lib64} which will point to
1092 @file{lib}.
1093
1094
1095 @node Needed Files Creation
1096 @subsection Creating needed user, groups and log files
1097
1098 @verbatim
1099 cat > ${TARGET_DIR}/etc/passwd << EOF
1100 root::0:0:root:/root:/bin/bash
1101 EOF
1102 @end verbatim
1103
1104 The file @file{/etc/passwd} contains one line for each user account,
1105 with seven fields delimited by colons. These fields are:
1106
1107 @itemize
1108 @item
1109 login name;
1110
1111 @item
1112 optional encrypted password;
1113
1114 @item
1115 numerical user ID;
1116
1117 @item
1118 numerical group ID;
1119
1120 @item
1121 user name or comment field;
1122
1123 @item
1124 user home directory;
1125
1126 @item
1127 optional user command interpreter.
1128 @end itemize
1129
1130
1131 @verbatim
1132 cat > ${TARGET_DIR}/etc/group << EOF
1133 root:x:0:
1134 bin:x:1:
1135 sys:x:2:
1136 kmem:x:3:
1137 tty:x:4:
1138 tape:x:5:
1139 daemon:x:6:
1140 floppy:x:7:
1141 disk:x:8:
1142 lp:x:9:
1143 dialout:x:10:
1144 audio:x:11:
1145 video:x:12:
1146 utmp:x:13:
1147 usb:x:14:
1148 cdrom:x:15:
1149 EOF
1150 @end verbatim
1151
1152 The file @file{/etc/group} is a text file which defines the groups on
1153 the system. There is one entry per line, with the following format:
1154 @samp{group_name:password:GID:user_list}.
1155
1156
1157 @verbatim
1158 touch ${TARGET_DIR}/var/run/utmp \
1159     ${TARGET_DIR}/var/log/{btmp,lastlog,wtmp}
1160 chmod -v 664 ${TARGET_DIR}/var/run/utmp \
1161     ${TARGET_DIR}/var/log/lastlog
1162 @end verbatim
1163
1164
1165 @node Building the Cross-Compilation Toolchain
1166 @chapter Building the Cross-Compilation Toolchain
1167
1168 In this chapter, the cross-compilation toolchain is built as well as
1169 core components of the target system. Those will then be used to build
1170 the target system.
1171
1172 @menu
1173 * Target Linux-Header::  Linux-Header for target system.
1174 * Cross Binutils::       Binutils for cross-compilation.
1175 * Cross GCC::        GCC for cross-compilation (C support only).
1176 * Target glibc::     glibc for target system.
1177 * Cross GCC CXX::    GCC for cross-compilation (C and C++ support).
1178 @end menu
1179
1180
1181 @node Target Linux-Header
1182 @section Target Linux-Header
1183
1184 In this document, the kernel used is version 3.10.7 of Linux-libre. I
1185 stick to this version because some changes made in the kernel since
1186 3.14 require the non-free firmware of the radeon driver earlier at
1187 boot: without the firmware, the screen will remain blank on a machine
1188 that requires it, making the computer unusable.@footnote{See
1189 @uref{https://bugzilla.kernel.org/show_bug.cgi?id=77861} for details.}
1190 I think version 3.10.7 of Linux-libre is usable on such a machine
1191 without the non-free firmware of the radeon driver.
1192
1193 You need Patch, Make and GCC on your system to compile this program
1194 from source. Under gNewSense 4.0, try @samp{sudo apt-get install patch
1195 make gcc-4.4} and then @samp{sudo ln -sv gcc-4.4 /usr/bin/gcc}.
1196
1197 @verbatim
1198 # 14 minutes mostly to compress the kernel with xz
1199 cd ${BUILD_DIR}
1200
1201 tar xf ${DOWNLOAD_DIR}/linux-libre-3.10-gnu.tar.xz \
1202     -C ${BUILD_DIR}
1203 cd ${BUILD_DIR}/linux-3.10
1204 unxz ${DOWNLOAD_DIR}/patch-3.10-gnu-3.10.7-gnu.xz
1205 patch -Np1 -i ${DOWNLOAD_DIR}/patch-3.10-gnu-3.10.7-gnu
1206 cd ..
1207
1208 # About 2 minutes for the following command (490 MB)
1209 tar -cf linux-libre-3.10.7-gnu.tar linux-3.10
1210
1211 # About 12 minutes for the following command (68 MB)
1212 # (requires ~800 MB of RAM)
1213 xz -9 linux-libre-3.10.7-gnu.tar
1214
1215 mv linux-libre-3.10.7-gnu.tar.xz ${DOWNLOAD_DIR}
1216
1217 cd linux-3.10
1218
1219 make mrproper
1220 make ARCH=i386 headers_check
1221 make ARCH=i386 INSTALL_HDR_PATH=dest headers_install
1222 cp -rv dest/include/* ${TARGET_DIR}/include
1223 cd ..
1224 rm -rf linux-3.10
1225 cd
1226 @end verbatim
1227
1228 @samp{14 minutes} is the time it takes to build the package on Dell
1229 Optiplex 745 with a Pentium 4 processor.
1230
1231 The command @samp{make mrproper} cleans the sources.
1232
1233 We need to specify @samp{ARCH=i386} as we are cross-compiling.
1234
1235
1236 @node Cross Binutils
1237 @section Cross Binutils
1238
1239 GNU Binutils (GNU binary utilities) is a collection of programs for
1240 manipulating binaries.
1241
1242 @verbatim
1243 # 4 minutes
1244 tar xf ${DOWNLOAD_DIR}/binutils-2.24.tar.bz2 -C ${BUILD_DIR}
1245 cd $BUILD_DIR/binutils-2.24
1246 mkdir -pv ../binutils-build
1247 cd ../binutils-build
1248 CC="gcc" AR="ar" \
1249     ../binutils-2.24/configure \
1250     --prefix=${TARGET_DIR}/cross-tools \
1251     --build=${CROSS_HOST} \
1252     --host=${CROSS_HOST} \
1253     --target=${CROSS_TARGET} \
1254     --enable-64-bit-bfd \
1255     --with-sysroot=${TARGET_DIR} \
1256     --disable-nls \
1257     --enable-shared
1258 make configure-host
1259 make
1260 make install
1261 cp -v ../binutils-2.24/include/libiberty.h \
1262     ${TARGET_DIR}/include
1263 cd ..
1264 rm -rf binutils-build
1265 rm -rf binutils-2.24
1266 cd
1267 @end verbatim
1268
1269 @samp{CC="gcc"} and @samp{AR="ar"} are flags that tell the
1270 @file{configure} script to use the local commands @command{gcc} as the
1271 C compiler and @command{ar} as the program that handles archives.
1272
1273 @option{--prefix=$@{TARGET_DIR@}/cross-tools} tells the configure
1274 script to install architecture-independant files in
1275 @file{$@{TARGET_DIR@}/cross-tools}.
1276
1277 The option @option{--enable-64-bit-bfd} enables 64 bit for
1278 @acronym{BFD} (the Binary File Descriptor).
1279
1280 @option{--with-sysroot=@env{$@{TARGET_DIR@}}} tells Binutils to
1281 consider @env{$@{TARGET_DIR@}} as the root of a tree that contains (a
1282 subset of) the root filesystem of the target operating system. Target
1283 system headers, libraries and run-time object files will be searched
1284 in there.
1285
1286 The @option{--enable-nls} option enables Native Language Support
1287 (NLS), which lets Binutils output diagnostics in languages other than
1288 American English. Native Language Support is enabled by default if not
1289 doing a canadian cross build. The @option{--disable-nls} option
1290 disables NLS.
1291
1292 The option @option{--enable-shared} is used to build shared versions
1293 of libraries, if shared libraries are supported on the target
1294 platform. Use @option{--disable-shared} to build only static
1295 libraries.
1296
1297 @c cp -v ../binutils-2.22/include/libiberty.h \
1298 @c    ${TARGET_DIR}/include
1299
1300
1301 @node Cross GCC
1302 @section Cross GCC (C support only)
1303
1304 GCC is the GNU compiler collection. It can compile many languages, of
1305 which only C and C++ will be enabled in this document.
1306
1307 In this section, we build a minimal GCC in order to build glibc.
1308
1309 @quotation Warning
1310 to build GMP (a GCC dependency), you need a version of GCC different
1311 from 4.3.2 on your system@footnote{@uref{https://gmplib.org/#STATUS}}:
1312 @end quotation
1313
1314 @quotation
1315 GCC 4.3.2 miscompiles GMP on 64-bit machines; please use a different
1316 gcc version (e.g., gcc 4.3.1 and gcc 4.3.3 both work properly). We
1317 have not been able to find any workaround for this gcc bug.
1318 Unfortunately, Debian 5.0 has decided to stay with this trouble gcc
1319 version, resulting in that many users strike this bug.
1320 @end quotation
1321
1322 I recommend installing @samp{gcc-4.4} on gNewSense 4.0 to avoid this
1323 issue.
1324
1325 @verbatim
1326 # 20 minutes
1327 tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR}
1328 cd ${BUILD_DIR}/gcc-4.7.3
1329 tar xf ${DOWNLOAD_DIR}/gmp-5.1.3.tar.bz2
1330 mv gmp-5.1.3 gmp
1331 tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz
1332 mv mpc-1.0.1 mpc
1333 tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2
1334 mv mpfr-3.1.2 mpfr
1335 # Fix undefined reference to `__stack_check_guard' when compiling glibc:
1336 sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
1337 mkdir -pv ../gcc-build
1338 cd ../gcc-build
1339 ../gcc-4.7.3/configure \
1340     --prefix=${TARGET_DIR}/cross-tools \
1341     --build=${CROSS_HOST} \
1342     --host=${CROSS_HOST} \
1343     --target=${CROSS_TARGET} \
1344     --with-sysroot=${TARGET_DIR} \
1345     --disable-multilib \
1346     --with-newlib \
1347     --disable-nls \
1348     --disable-shared \
1349     --disable-threads \
1350     --enable-languages=c \
1351     --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \
1352     --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs" \
1353     --disable-decimal-float
1354 # fixes bid_decimal_globals: fenv.h: No such file or directory
1355
1356 make all-gcc
1357 make all-target-libgcc
1358 make install-gcc
1359 make install-target-libgcc
1360 cd ..
1361 rm -r gcc-build
1362 rm -r gcc-4.7.3
1363 cd
1364 @end verbatim
1365
1366 @option{--disable-multilib} specifies that multiple target libraries
1367 to support different target variants@footnote{Such as different ABI,
1368 for instance n32 and 64.}, calling conventions, etc@:. should not be
1369 built. The default is to build a predefined set of them.
1370
1371 @option{--with-newlib} specifies that @samp{newlib} is being used as
1372 the target C library.
1373
1374 @option{--disable-threads} specifies that threading support should be
1375 disabled.
1376
1377 @option{--enable-languages=c} specifies that only the C compiler and
1378 its runtime libraries should be built.
1379
1380 @c --with-abi=${MABI}
1381
1382 @c --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \
1383 @c --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs"
1384 @c to avoid error: libmpfr not found or uses a different ABI (including static vs shared).
1385
1386 GCC provides a low-level runtime library, @file{libgcc.a} or
1387 @file{libgcc_s.so.1} on some platforms. GCC generates calls to
1388 routines in this library automatically, whenever it needs to perform
1389 some operation that is too complicated to emit inline code for. This
1390 is built with @samp{make all-target-libgcc} and installed with
1391 @samp{make install-target-libgcc}
1392
1393
1394 @node Target glibc
1395 @section Target glibc
1396
1397 Glibc is the GNU C library. It provides macros, type definitions, and
1398 functions for tasks like string handling, mathematical computations,
1399 input/output processing, memory allocation and several other operating
1400 system services.
1401
1402 You need Gawk on your system to compile this program from
1403 source. Under gNewSense 4.0, try @samp{sudo apt-get install gawk}.
1404
1405 @verbatim
1406 # 20 minutes
1407 tar xf ${DOWNLOAD_DIR}/glibc-2.18.tar.bz2 -C ${BUILD_DIR}
1408 cd ${BUILD_DIR}/glibc-2.18
1409 sed -i.orig '4775s/3.79\* | 3.\[89\]\*/& | 4.0/' configure
1410 sed -i.orig "s/ -lgcc_eh\| -lgcc_s//g" Makeconfig
1411 #echo "" > ports/sysdeps/mips/mips64/n64/Makefile
1412 #echo "" > ports/sysdeps/mips/mips64/n32/Makefile
1413 #echo "" > ports/sysdeps/mips/mips32/Makefile
1414 #sed -i "/default) machine=/s/n32/${MABI}/g" \
1415 #    ports/sysdeps/mips/preconfigure
1416 mkdir -pv ../glibc-build
1417 cd ../glibc-build
1418
1419 cat > config.cache << EOF
1420 libc_cv_c_cleanup=yes
1421 libc_cv_slibdir=/lib
1422 EOF
1423
1424 cat > configparms << EOF
1425 install_root=${TARGET_DIR}
1426 libdir=/lib
1427 EOF
1428
1429 BUILD_CC="gcc" \
1430     CC="${CROSS_TARGET}-gcc -march=${MARCH}" \
1431     AR="${CROSS_TARGET}-ar" \
1432     RANLIB="${CROSS_TARGET}-ranlib" \
1433     ../glibc-2.18/configure \
1434     --prefix= \
1435     --libexecdir=/lib/glibc \
1436     --build=${CROSS_HOST} \
1437     --host=${CROSS_TARGET} \
1438     --disable-profile \
1439     --enable-add-ons \
1440     --with-tls \
1441     --enable-kernel=3.10 \
1442     --with-__thread \
1443     --with-binutils=${TARGET_DIR}/cross-tools/bin \
1444     --with-headers=${TARGET_DIR}/include \
1445     --enable-obsolete-rpc \
1446     --cache-file=config.cache
1447
1448 make
1449
1450 make install
1451
1452 cd ..
1453 rm -rf glibc-build
1454 rm -rf glibc-2.18
1455 cd
1456
1457 cat > ${TARGET_DIR}/etc/nsswitch.conf << EOF
1458 # Begin /etc/nsswitch.conf
1459
1460 passwd: files
1461 group: files
1462 shadow: files
1463
1464 hosts: files dns
1465 networks: files
1466
1467 protocols: files
1468 services: files
1469 ethers: files
1470 rpc: files
1471
1472 # End /etc/nsswitch.conf
1473 EOF
1474
1475 cat > ${TARGET_DIR}/etc/ld.so.conf << EOF
1476 # Begin /etc/ld.so.conf
1477
1478 /local/lib
1479
1480 # End /etc/ld.so.conf
1481 EOF
1482 @end verbatim
1483
1484 @c @samp{sed -i.orig "s/\ -lgcc_eh\|\ -lgcc_s//g" Makeconfig}
1485
1486 @c Glibc uses @samp{n32} ABI by default with MIPS. To use @env{MABI}
1487 @c instead, we do the following:
1488 @c
1489 @c @verbatim
1490 @c echo "" > ports/sysdeps/mips/mips64/n64/Makefile
1491 @c echo "" > ports/sysdeps/mips/mips64/n32/Makefile
1492 @c echo "" > ports/sysdeps/mips/mips32/Makefile
1493 @c sed -i "/default) machine=/s/n32/${MABI}/g" \
1494 @c     ports/sysdeps/mips/preconfigure
1495 @c @end verbatim
1496
1497 @ignore
1498 Contents of the files above.
1499
1500 cat mips64/n64/Makefile
1501 # `long double' is a distinct type we support.
1502 long-double-fcts = yes
1503
1504 ifeq ($(filter -mabi=64,$(CC)),)
1505 CC += -mabi=64
1506 endif
1507
1508 cat mips64/n32/Makefile
1509 # `long double' is a distinct type we support.
1510 long-double-fcts = yes
1511
1512 ifeq ($(filter -mabi=n32,$(CC)),)
1513 CC += -mabi=n32
1514 endif
1515
1516 cat mips32/Makefile
1517 ifeq ($(filter -mabi=32,$(CC)),)
1518 CC += -mabi=32
1519 endif
1520
1521 grep 'default)' preconfigure
1522
1523     default) machine=mips/mips64/n32 mips_config_abi=n32 ;;
1524
1525 @end ignore
1526
1527 The file @file{config.cache} is used to attribute values to variables
1528 of the configure script.
1529
1530 @samp{libc_cv_forced_unwind=yes} is used to avoid the error message
1531 @samp{error: forced unwind support is required}.
1532
1533 @samp{libc_cv_c_cleanup=yes} is used to avoid the error message
1534 @samp{error: the compiler must support C cleanup handling}.
1535
1536 @samp{libc_cv_slibdir=/lib} defines @file{/lib} as the directory in
1537 which the C library of the target system will be installed, instead of
1538 @file{/lib64} or @file{/lib32}.
1539
1540 You can install glibc somewhere other than where you configured it to
1541 go by setting the @code{install_root} variable on the command line for
1542 @samp{make install}. The value of this variable is prepended to all
1543 the paths for installation. This is useful when setting up a chroot
1544 environment or preparing a binary distribution. The directory should
1545 be specified with an absolute file name.
1546
1547 Files listed in @samp{install-lib} are installed in the directory
1548 specified by @samp{libdir} in @file{configparms} or @file{Makeconfig}.
1549
1550 @verbatim
1551 BUILD_CC="gcc" \
1552     CC="${CROSS_TARGET}-gcc -march=${MARCH}" \
1553     AR="${CROSS_TARGET}-ar" \
1554     RANLIB="${CROSS_TARGET}-ranlib"
1555 @end verbatim
1556
1557 @samp{CC="$@{CROSS_TARGET@}-gcc -march=$@{MARCH@}"}
1558 sets @code{CC} to the cross-compiler for the target's architecture,
1559 processor and ABI we configured the library for. @code{AR} and
1560 @code{RANLIB} are set to cross-compiling versions of @code{ar} and
1561 @code{ranlib} as the native tools are not configured to work with
1562 object files for the target we configured for.
1563
1564 @option{--prefix=} tells the @file{configure} script to install
1565 glibc in the root directory (@file{/}) of the target system.
1566
1567 @c @option{--libexecdir=/lib/glibc} tells the configure script to
1568 @c install glibc executables inside @file{/lib/glibc}.
1569
1570 Unlike previous builds, @option{--host} now equals
1571 @env{$@{CROSS_TARGET@}} instead of @env{$@{CROSS_HOST@}}. This is
1572 because we are building the glibc version that the target system will
1573 use. We won't have to build it later.
1574
1575 Profiling can be of help to optimize a program by analysing memory
1576 use, the usage of particular instructions, etc. Option
1577 @option{--disable-profile} is used to disable this.
1578
1579 Option @option{--enable-add-ons} is used to enable all the add-on
1580 packages in the main source directory, which includes the glibc-ports
1581 used to support the MIPS architecture.
1582
1583 The option @option{--with-tls} tells the configure script to use
1584 @acronym{TLS} (thread-local storage). Thread-local storage is a
1585 computer programming method that uses memory local to a thread.
1586
1587 The @samp{3.10} parameter given to option @option{--enable-kernel}
1588 describes the smallest version of the Linux kernel the generated
1589 library is expected to support. The higher the version number is, the
1590 less compatibility code is added, and the faster the code gets.
1591
1592 Option @option{--with-__thread} enables threads in glibc.
1593
1594 The option @option{--with-binutils=$@{TARGET_DIR@}/cross-tools/bin}
1595 tells the @file{configure} script to use the binutils (assembler and
1596 linker) built in the cross-compilation toolchain process.
1597
1598 @option{--with-headers=$@{TARGET_DIR@}/include} indicates the
1599 location of the kernel Linux' headers.
1600
1601 @option{--enable-obsolete-rpc} tells the @file{configure} script to
1602 install remote procedure call (RPC) headers. Those may be required by
1603 some programs.
1604
1605 @option{--cache-file=config.cache} specifies the file in which cache
1606 variables are listed for @file{configure}.
1607
1608 The file @file{$@{TARGET_DIR@}/etc/nsswitch.conf} contains the
1609 configuration of @acronym{NSS} (Name Service Switch). NSS is a facility
1610 in Unix-like operating systems that provides a variety of sources for
1611 common configuration databases and name resolution mechanisms. These
1612 sources include local operating system files (such as
1613 @file{/etc/passwd}, @file{/etc/group}, and @file{/etc/hosts}), the
1614 Domain Name System (DNS), the Network Information Service (NIS), and
1615 LDAP.
1616
1617 @c Purpose of the file @file{$@{TARGET_DIR@}/etc/ld.so.conf}
1618
1619
1620 @node Cross GCC CXX
1621 @section Cross GCC (C and C++ support)
1622
1623 In this section, we build a complete cross-compiler with support for C
1624 and C++ languages.
1625
1626 @verbatim
1627 # 35 minutes
1628 tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR}
1629 cd ${BUILD_DIR}/gcc-4.7.3
1630 tar xf ${DOWNLOAD_DIR}/gmp-5.1.3.tar.bz2
1631 mv gmp-5.1.3 gmp
1632 tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz
1633 mv mpc-1.0.1 mpc
1634 tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2
1635 mv mpfr-3.1.2 mpfr
1636 mkdir -v ../gcc-build
1637 cd ../gcc-build
1638 ../gcc-4.7.3/configure \
1639     --prefix=${TARGET_DIR}/cross-tools \
1640     --build=${CROSS_HOST} \
1641     --host=${CROSS_HOST} \
1642     --target=${CROSS_TARGET} \
1643     --with-sysroot=${TARGET_DIR} \
1644     --disable-nls \
1645     --enable-shared \
1646     --enable-__cxa_atexit \
1647     --disable-multilib \
1648     --enable-c99 \
1649     --enable-long-long \
1650     --enable-threads=posix \
1651     --enable-languages=c,c++ \
1652     --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \
1653     --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs"
1654 make
1655 make install
1656 cd ..
1657 rm -rf gcc-build
1658 rm -rf gcc-4.7.3
1659 cd
1660 @end verbatim
1661
1662 @option{--enable-__cxa_atexit} enables @code{__cxa_atexit}, rather
1663 than @code{atexit}, to register C++ destructors for local statics and
1664 global objects.  This is essential for fully standards-compliant
1665 handling of destructors, but requires @code{__cxa_atexit} in libc.
1666
1667 @option{--enable-c99} enables support for the C99 standard.
1668
1669 @option{--enable-long-long} enables support for @code{long long int}
1670 types.
1671
1672 @c @option{--enable-threads=posix}
1673
1674
1675 @node Building the Cross-Compilation Tools
1676 @chapter Building the Cross-Compilation Tools
1677
1678 @menu
1679 * Cross File::         File for cross-compilation.
1680 * Cross Groff::        Groff for cross-compilation.
1681 * Cross Shadow::       Shadow for cross-compilation.
1682 * Cross M4::           M4 for cross-compilation.
1683 * Cross Ncurses::      Ncurses for cross-compilation.
1684 * Cross Cleaning::     Cleaning up the cross-compilation toolchain.
1685 @end menu
1686
1687
1688 @node Cross File
1689 @section File
1690
1691 The command @command{file} is used to determine the type of a file:
1692 text, executable or data.
1693
1694 @verbatim
1695 # 1 minute
1696 tar xf ${DOWNLOAD_DIR}/file-5.16.tar.gz -C ${BUILD_DIR}
1697 cd ${BUILD_DIR}/file-5.16
1698 ./configure \
1699     --prefix=${TARGET_DIR}/cross-tools
1700 make
1701 make install
1702 cd ..
1703 rm -rf file-5.16
1704 cd
1705 @end verbatim
1706
1707
1708 @node Cross Groff
1709 @section Groff
1710
1711 Groff is the GNU version of the roff document formatting system which
1712 is used to produce man pages.
1713
1714 You need G++ on your system to compile this program from source. Under
1715 gNewSense 4.0, try @samp{sudo apt-get install g++-4.4} and then
1716 @samp{sudo ln -sv g++-4.4 /usr/bin/g++}.
1717
1718
1719 @verbatim
1720 # 2 minutes
1721 tar xf ${DOWNLOAD_DIR}/groff-1.22.2.tar.gz -C ${BUILD_DIR}
1722 cd ${BUILD_DIR}/groff-1.22.2
1723 PAGE=A4 \
1724     ./configure \
1725     --prefix=${TARGET_DIR}/cross-tools \
1726     --without-x
1727 make
1728 make install
1729 cd ..
1730 rm -rf groff-1.22.2
1731 cd
1732 @end verbatim
1733
1734 @samp{PAGE=A4} defines the default format of pages for printed output.
1735
1736 @option{--without-x} disables the dependancy on the X window system.
1737
1738
1739 @node Cross Shadow
1740 @section Shadow
1741
1742 The package contains programs to handle users, groups and passwords in
1743 a secure way: passwords are encrypted.
1744
1745 @verbatim
1746 # 1 minute
1747 tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR}
1748 cd ${BUILD_DIR}/shadow-4.1.4.3
1749 patch -Np1 -i ${DOWNLOAD_DIR}/shadow-4.1.4.3-sysroot_hacks-1.patch
1750 #sed -i.orig \
1751 #    's/bindir)\/\$\$i/bindir)\/mips64el-unknown-linux-gnu-\$\$i/' \
1752 #    src/Makefile.am
1753 #automake-1.11
1754 echo "shadow_cv_passwd_dir=${TARGET_DIR}/bin" > config.cache
1755 echo "ac_cv_func_lckpwdf=no" >> config.cache
1756 ./configure \
1757     --prefix=${TARGET_DIR}/cross-tools \
1758     --sbindir=${TARGET_DIR}/cross-tools/bin \
1759     --sysconfdir=${TARGET_DIR}/etc \
1760     --disable-shared \
1761     --without-audit \
1762     --without-libpam \
1763     --without-selinux \
1764     --program-prefix=${CROSS_TARGET}- \
1765     --cache-file=config.cache
1766 sed -i.orig "/PASSWD_PROGRAM/s/passwd/${CROSS_TARGET}-&/" config.h
1767 make
1768 make install
1769 cd ..
1770 rm -rf shadow-4.1.4.3
1771 cd
1772 @end verbatim
1773
1774 @c @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin}
1775 @c @samp{ac_cv_func_lckpwdf=no}
1776
1777 The patch @file{shadow-4.1.4.3-sysroot_hacks-1.patch} is used so that
1778 shadow can be built with the sysroot method. Because we use this
1779 patch, @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin} and
1780 @samp{ac_cv_func_lckpwdf=no} have to be added in @file{config.cache}
1781 in order for the @file{configure} script not to test the
1782 functionalities associated.
1783
1784 @c @option{--sbindir=$@{TARGET_DIR@}/cross-tools/bin}
1785
1786 @c @option{--sysconfdir=$@{TARGET_DIR@}/etc}
1787
1788 @option{--without-audit}, @option{--without-libpam} and
1789 @option{--without-selinux} disable support for auditing, @acronym{PAM}
1790 (Pluggable authentication modules) and @acronym{SELinux}
1791 (Security-Enhanced Linux). We do not need those extra features.
1792
1793 @option{--program-prefix=$@{CROSS_TARGET@}-} prepends the value of
1794 @env{CROSS_TARGET} (that is @samp{i386-unknown-linux-gnu} in this
1795 document) to installed program names for cross-compilation.
1796
1797 @c @samp{sed -i.orig "/PASSWD_PROGRAM/s/passwd/$@{CROSS_TARGET@}-&/"
1798 @c config.h} is used to avoid the error message
1799
1800
1801 @node Cross M4
1802 @section M4
1803
1804 Bison 2.5 requires M4 to be built.
1805
1806 GNU M4 is a package containing an implementation of the m4 macro
1807 language. GNU M4 is used in GNU Autoconf' @file{configure} files.
1808
1809 @verbatim
1810 # 1 minute
1811 tar xf ${DOWNLOAD_DIR}/m4-1.4.17.tar.bz2 -C ${BUILD_DIR}
1812 cd ${BUILD_DIR}/m4-1.4.17
1813 ./configure \
1814     --prefix=${TARGET_DIR}/cross-tools
1815 make
1816 make install
1817 cd ..
1818 rm -rf m4-1.4.17
1819 cd
1820 @end verbatim
1821
1822
1823 @node Cross Ncurses
1824 @section Ncurses
1825
1826 GNU ncurses contains a library used to write text-based user
1827 interfaces in a terminal-independent manner.
1828
1829 @verbatim
1830 # 1 minute
1831 tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR}
1832 cd ${BUILD_DIR}/ncurses-5.9
1833 ./configure \
1834     --prefix=${TARGET_DIR}/cross-tools \
1835     --without-shared
1836 make -C include
1837 make -C progs tic
1838 install -m755 progs/tic ${TARGET_DIR}/cross-tools/bin
1839 cd ..
1840 rm -rf ncurses-5.9
1841 cd
1842 @end verbatim
1843
1844 @option{--without-shared} is used to avoid building the whole library
1845 as only @command{tic} is installed.
1846
1847
1848 @node Cross Cleaning
1849 @section Cleaning up Cross-Compilation Toolchain
1850
1851 In order to save some space, binaries and libraries of
1852 cross-compilation tools can be stripped out.
1853
1854 @quotation Warning
1855 incorrect cleaning arguments used against library files can lead to
1856 library files breaking. For this reason, be careful of the command
1857 arguments. If you are not comfortable with this, you can skip this
1858 section as it will have no effect on the process of building the
1859 target system.
1860 @end quotation
1861
1862
1863 @verbatim
1864 cd ${TARGET_DIR}/cross-tools
1865 strip --strip-all bin/*
1866 strip --strip-debug lib/*
1867 cd
1868 @end verbatim
1869
1870 @option{--strip-all} removes all symbols. This command reduces the
1871 size of the @file{bin} directory's content from 26 MB to 9 MB.
1872
1873 @option{--strip-debug} removes debugging symbols only. This command
1874 reduces the size of the @file{lib} directory's content from 13 MB to
1875 13 MB.
1876
1877
1878 @node Building the Target System
1879 @chapter Building the Target System
1880
1881 After having set up the cross-compilation toolchain and tools, the
1882 operating system for the target machine is built in this chapter.
1883
1884 @menu
1885 * Environment Setup:: Setting up the environment.
1886 * Man Pages::         Building Man Pages.
1887 * Zlib::              Building Zlib.
1888 * Binutils::          Building Binutils.
1889 * GMP::               Building GMP.
1890 * MPFR::              Building MPFR.
1891 * MPC::               Building MPC.
1892 * GCC::               Building GCC.
1893 * Sed::               Building Sed.
1894 * E2fsprogs::         Building E2fsprogs.
1895 * Coreutils::         Building Coreutils.
1896 * iana-etc::          Building iana-etc.
1897 * M4::                Building M4.
1898 * Bison::             Building Bison.
1899 * Ncurses::           Building Ncurses.
1900 * Procps::            Building Procps.
1901 * Libtool::           Building Libtool.
1902 * Readline::          Building Readline.
1903 * Autoconf::          Building Autoconf.
1904 * Automake::          Building Automake.
1905 * Bash::              Building Bash.
1906 * Bzip2::             Building Bzip2.
1907 * DHCPCD::            Building DHCPCD.
1908 * Diffutils::         Building Diffutils.
1909 * File::              Building File.
1910 * Findutils::         Building Findutils.
1911 * Flex::              Building Flex.
1912 * Gawk::              Building Gawk.
1913 * Gdbm::              Building Gdbm.
1914 * Gettext::           Building Gettext.
1915 * Grep::              Building Grep.
1916 * Groff::             Building Groff.
1917 * Gzip::              Building Gzip.
1918 * Inetutils::         Building Inetutils.
1919 * Iproute2::          Building Iproute2.
1920 * Kbd::               Building Kbd.
1921 * Kmod::              Building Kmod.
1922 * Less::              Building Less.
1923 * Libpipeline::       Building Libpipeline.
1924 * Make::              Building Make.
1925 * Man-db::            Building Man-db.
1926 * Nano::              Building Nano.
1927 * Patch::             Building Patch.
1928 * Psmisc::            Building Psmisc.
1929 * Shadow::            Building Shadow.
1930 * Sysvinit::          Building Sysvinit.
1931 * Tar::               Building Tar.
1932 * Texinfo::           Building Texinfo.
1933 * Udev::              Building Udev.
1934 * Util-Linux::        Building Util-Linux.
1935 * XZ-Utils::          Building XZ-Utils.
1936 * Bootscripts::       Building Bootscripts.
1937 * Kernel::            Building the Kernel.
1938 @end menu
1939
1940
1941 @node Environment Setup
1942 @section Setting up the Environment
1943
1944 Because this chapter is about the build of the target system and not
1945 the build of the cross-compilation toolchain and tools anymore, we
1946 need to update some environment  variables.
1947
1948 For more convenience, we can set environment variables up in the
1949 @file{~/.bashrc} file, so that this setup is preserved when logging
1950 in:
1951
1952
1953 @verbatim
1954 cat >> ~/.bashrc << EOF
1955 export CC="${CROSS_TARGET}-gcc -march=${MARCH}"
1956 export CXX="${CROSS_TARGET}-g++ -march=${MARCH}"
1957 export AR="${CROSS_TARGET}-ar"
1958 export AS="${CROSS_TARGET}-as"
1959 export RANLIB="${CROSS_TARGET}-ranlib"
1960 export LD="${CROSS_TARGET}-ld"
1961 export STRIP="${CROSS_TARGET}-strip"
1962 EOF
1963 source ~/.bash_profile
1964 @end verbatim
1965
1966 @env{CC} is the flag that indicates the C compiler to be used,
1967 @env{CXX} the C++ compiler, @env{AR} the archiver, @env{AS} the
1968 assembler, @env{RANLIB} the archives' index generator, @env{LD} the
1969 linker and @env{STRIP} the program for stripping.
1970
1971 All the programs to be used are prefixed with
1972 @samp{$@{CROSS_TARGET@}-} in order to use the cross-compilation
1973 toolchain instead of the toolchain of the host.
1974
1975
1976 @node Man Pages
1977 @section Man Pages
1978
1979 The man-pages package documents the kernel Linux and C library's
1980 interfaces that are used by user-space programs.
1981
1982 @verbatim
1983 # 1 minute
1984 tar xf ${DOWNLOAD_DIR}/man-pages-3.54.tar.bz2 -C ${BUILD_DIR}
1985 cd ${BUILD_DIR}/man-pages-3.54
1986 make prefix=${TARGET_DIR} install
1987 cd ..
1988 rm -rf man-pages-3.54
1989 cd
1990 @end verbatim
1991
1992 The option @option{prefix=$@{TARGET_DIR@}} is used to install the man
1993 pages on the target directory instead of the @file{/usr} directory of
1994 the host.
1995
1996
1997 @node Zlib
1998 @section Zlib
1999
2000 Zlib is a compression/decompression library.
2001
2002 @verbatim
2003 # 1 minute
2004 tar xf ${DOWNLOAD_DIR}/zlib-1.2.8.tar.gz -C ${BUILD_DIR}
2005 cd ${BUILD_DIR}/zlib-1.2.8
2006 ./configure \
2007     --prefix=
2008 make AR="${AR}"
2009 make prefix=${TARGET_DIR} install
2010 cd ..
2011 rm -rf zlib-1.2.8
2012 cd
2013 @end verbatim
2014
2015 In order to build zlib by cross-compilation, the flag @env{AR} has to
2016 be equal to @samp{$@{AR@}}.
2017
2018
2019 @node Binutils
2020 @section Binutils
2021
2022 GNU Binutils (GNU binary utilities) is a collection of programs for
2023 manipulating binaries.
2024
2025 @verbatim
2026 # 5 minutes
2027 tar xf ${DOWNLOAD_DIR}/binutils-2.24.tar.bz2 -C ${BUILD_DIR}
2028 cd ${BUILD_DIR}/binutils-2.24
2029 mkdir -pv ../binutils-build
2030 cd ../binutils-build
2031 ../binutils-2.24/configure \
2032     --prefix= \
2033     --build=${CROSS_HOST} \
2034     --host=${CROSS_TARGET} \
2035     --target=${CROSS_TARGET} \
2036     --enable-64-bit-bfd \
2037     --enable-shared
2038 make configure-host
2039 make tooldir=
2040 make DESTDIR=${TARGET_DIR} tooldir= install
2041 cp -v ../binutils-2.24/include/libiberty.h ${TARGET_DIR}/include
2042 cd ..
2043 rm -rf binutils-build
2044 rm -rf binutils-2.24
2045 cd
2046 @end verbatim
2047
2048 The option @option{--host} is now set to @env{CROSS_TARGET} because
2049 the host that will run this build will be the target system.
2050
2051 @c @samp{make tooldir=}
2052 @c @samp{make DESTDIR=$@{TARGET_DIR@} tooldir= install}
2053
2054
2055 @node GMP
2056 @section GMP
2057
2058 @acronym{GMP} (GNU multiple precision arithmetic library) is required
2059 to build GCC.
2060
2061 @verbatim
2062 # 2 minutes
2063 tar xf ${DOWNLOAD_DIR}/gmp-5.1.3.tar.bz2 -C ${BUILD_DIR}
2064 cd ${BUILD_DIR}/gmp-5.1.3
2065 ./configure \
2066     --host=${CROSS_TARGET} \
2067     --prefix= \
2068     --enable-cxx
2069 make
2070 make DESTDIR=${TARGET_DIR} install
2071 rm -v ${TARGET_DIR}/lib/lib{gmp,gmpxx}.la
2072 cd ..
2073 rm -rf gmp-5.1.3
2074 cd
2075 @end verbatim
2076
2077 The option @option{--enable-cxx} enables support for the C++ language.
2078
2079 The files @file{$@{TARGET_DIR@}/lib/lib@{gmp,gmpxx@}.la} are removed
2080 to avoid the following error when building MPFR:
2081 @samp{/lib/libgmp.so: could not read symbols: File in wrong format}.
2082
2083
2084 @node MPFR
2085 @section MPFR
2086
2087 GNU @acronym{MPFR} (Multiple Precision Floating-Point Reliably) is a
2088 portable C library for arbitrary-precision binary floating-point
2089 computation with correct rounding.
2090
2091 @verbatim
2092 # 1 minute
2093 tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2 -C ${BUILD_DIR}
2094 cd ${BUILD_DIR}/mpfr-3.1.2
2095 ./configure \
2096     --host=${CROSS_TARGET} \
2097     --prefix=
2098 make
2099 make DESTDIR=${TARGET_DIR} install
2100 rm -v ${TARGET_DIR}/lib/libmpfr.la
2101 cd ..
2102 rm -rf mpfr-3.1.2
2103 cd
2104 @end verbatim
2105
2106 The file @file{$@{TARGET_DIR@}/lib/libmpfr.la} is removed to avoid the
2107 following error when building MPC:
2108 @samp{/lib/libmpfr.so: could not read symbols: File in wrong format}.
2109
2110
2111 @node MPC
2112 @section MPC
2113
2114 GNU @acronym{MPC} (Multiple Precision Complex Library) is a C library
2115 for the arithmetic of complex numbers with arbitrarily high precision
2116 and correct rounding of the result.
2117
2118 @verbatim
2119 # 1 minute
2120 tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz -C ${BUILD_DIR}
2121 cd ${BUILD_DIR}/mpc-1.0.1
2122 ./configure \
2123     --host=${CROSS_TARGET} \
2124     --prefix=
2125 make
2126 make DESTDIR=${TARGET_DIR} install
2127 cd ..
2128 rm -rf mpc-1.0.1
2129 cd
2130 @end verbatim
2131
2132
2133 @node GCC
2134 @section GCC
2135
2136 GCC is the GNU Compiler Collection.
2137
2138 @verbatim
2139 # 25 minutes
2140 tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR}
2141 cd ${BUILD_DIR}/gcc-4.7.3
2142 sed -i.orig 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
2143 sed -i.orig 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
2144 mkdir -v ../gcc-build
2145 cd ../gcc-build
2146 ../gcc-4.7.3/configure \
2147     --prefix= \
2148     --libexecdir=/lib \
2149     --build=${CROSS_HOST} \
2150     --host=${CROSS_TARGET} \
2151     --target=${CROSS_TARGET} \
2152     --enable-shared \
2153     --enable-threads=posix \
2154     --enable-__cxa_atexit \
2155     --enable-c99 \
2156     --enable-long-long \
2157     --disable-multilib \
2158     --enable-clocale=gnu \
2159     --enable-languages=c,c++ \
2160     --disable-libstdcxx-pch
2161 make
2162 make DESTDIR=${TARGET_DIR} install
2163 ln -sv gcc ${TARGET_DIR}/bin/cc
2164 cd ..
2165 rm -rf gcc-build
2166 rm -rf gcc-4.7.3
2167 cd
2168 @end verbatim
2169
2170 @samp{sed -i.orig 's/install_to_$(INSTALL_DEST) //'
2171 libiberty/Makefile.in} is used as we already installed the library
2172 @file{libiberty.a} with Binutils.
2173
2174 @c We use @samp{sed -i.orig 's@@\./fixinc\.sh@@-c true@@'
2175 @c gcc/Makefile.in} to avoid using fixincludes that may output errors if
2176 @c headers have been modified.
2177
2178 Using @option{--enable-clocale=gnu} option ensures that the correct
2179 locale will automatically be chosen.
2180
2181 Option @option{--disable-libstdcxx-pch} disables support for
2182 precompiled headers (PCH).
2183
2184 The line @samp{ln -sv gcc $@{TARGET_DIR@}/bin/cc} creates a
2185 symbolic link @file{cc} that points on @file{gcc}.
2186
2187
2188 @node Sed
2189 @section Sed
2190
2191 GNU sed is a stream editor: it is used to perform basic text
2192 transformations on an input stream (a file or input from a pipeline).
2193
2194 @verbatim
2195 # 1 minute
2196 tar xf ${DOWNLOAD_DIR}/sed-4.2.2.tar.bz2 -C ${BUILD_DIR}
2197 cd ${BUILD_DIR}/sed-4.2.2
2198 ./configure \
2199     --build=${CROSS_HOST} \
2200     --host=${CROSS_TARGET} \
2201     --prefix= \
2202     --bindir=/bin
2203 make
2204 make DESTDIR=${TARGET_DIR} install
2205 cd ..
2206 rm -rf sed-4.2.2
2207 cd
2208 @end verbatim
2209
2210 @c @option{--bindir=/bin} FHS?
2211
2212
2213 @node E2fsprogs
2214 @section E2fsprogs
2215
2216 E2fsprogs is a package that contains tools to handle the ext2, ext3
2217 and ext4 filesystems.
2218
2219 @verbatim
2220 # 2 minutes
2221 tar xf ${DOWNLOAD_DIR}/e2fsprogs-1.42.8.tar.gz -C ${BUILD_DIR}
2222 cd ${BUILD_DIR}/e2fsprogs-1.42.8
2223 mkdir -v build
2224 cd build
2225 ../configure \
2226     --build=${CROSS_HOST} \
2227     --host=${CROSS_TARGET} \
2228     --prefix= \
2229     --with-root-prefix="" \
2230     --enable-elf-shlibs
2231 make
2232 make DESTDIR=${TARGET_DIR} install
2233 make DESTDIR=${TARGET_DIR} install-libs
2234 rm -v ${TARGET_DIR}/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so
2235 cd ../..
2236 rm -rf e2fsprogs-1.42.8
2237 cd
2238 @end verbatim
2239
2240 @option{--with-root-prefix=""} is used to put e2fsprogs binaries
2241 inside @file{/sbin} instead of @file{@var{PREFIX}/sbin} which would be
2242 @file{/sbin}.
2243
2244 Option @option{--enable-elf-shlibs} enables e2fsprogs shared
2245 libraries.
2246
2247 @samp{make DESTDIR=$@{TARGET_DIR@} install-libs} is used to install
2248 libraries, those are not installed with @samp{make
2249 DESTDIR=$@{TARGET_DIR@} install}.
2250
2251 The sequence of commands that follows first removes symbolic links
2252 @file{$@{TARGET_DIR@}/lib/lib@{@/blkid,com_err,e2p,ext2fs,ss,uuid@}.so}
2253 which point on abolute paths
2254 @file{/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so}. In order to
2255 use the libraries of the target operating system, we need to symlink
2256 @file{$@{TARGET_DIR@}/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so}
2257 to their relative paths files.
2258
2259
2260 @node Coreutils
2261 @section Coreutils
2262
2263 GNU coreutils (core utilities) includes the standard programs for text
2264 and file manipulation.
2265
2266 On gNewSense Parkes, you need to install @file{xz-utils} to extract
2267 the package.
2268
2269 @verbatim
2270 # 3 minutes
2271 tar xf ${DOWNLOAD_DIR}/coreutils-8.19.tar.xz -C ${BUILD_DIR}
2272 cd ${BUILD_DIR}/coreutils-8.19
2273 cat > config.cache << EOF
2274 fu_cv_sys_stat_statfs2_bsize=yes
2275 gl_cv_func_mbrtowc_incomplete_state=yes
2276 gl_cv_func_mbrtowc_nul_retval=yes
2277 gl_cv_func_mbrtowc_null_arg=yes
2278 gl_cv_func_mbrtowc_retval=yes
2279 gl_cv_func_btowc_eof=yes
2280 gl_cv_func_wcrtomb_retval=yes
2281 gl_cv_func_wctob_works=yes
2282 gl_cv_func_fstatat_zero_flag=yes
2283 EOF
2284 ./configure \
2285     --build=${CROSS_HOST} \
2286     --host=${CROSS_TARGET} \
2287     --prefix= \
2288     --enable-install-program=hostname \
2289     --enable-no-install-program=kill,uptime \
2290     --cache-file=config.cache
2291 make
2292 make DESTDIR=${TARGET_DIR} install
2293 cd ..
2294 rm -rf coreutils-8.19
2295 cd
2296 @end verbatim
2297
2298 @c @samp{sed -i.orig '/strftime/s/\ LC_ALL//' man/help2man}
2299
2300 The variables listed in the file @file{config.cache} are used in order
2301 to avoid that the @file{configure} script evaluate their values:
2302 otherwise the build may fail when cross-compiling.
2303
2304 We use @option{--enable-install-program=hostname} to install the
2305 command @command{hostname} which is not built by default.
2306
2307 We use @option{--enable-no-install-program=kill,uptime} in order not
2308 to install commands @command{kill} and @command{uptime}. Those
2309 commands will be installed by the package procps.
2310
2311
2312 @node iana-etc
2313 @section iana-etc
2314
2315 The iana-etc package installs services and protocols using data from
2316 the Internet Assigned Numbers Authority (IANA).
2317
2318 @verbatim
2319 # 1 minute
2320 tar xf ${DOWNLOAD_DIR}/iana-etc-2.30.tar.bz2 -C ${BUILD_DIR}
2321 cd ${BUILD_DIR}/iana-etc-2.30
2322 make
2323 make DESTDIR=${TARGET_DIR} install
2324 cd ..
2325 rm -rf iana-etc-2.30
2326 cd
2327 @end verbatim
2328
2329
2330 @node M4
2331 @section M4
2332
2333 GNU M4 is a package containing an implementation of the m4 macro
2334 language. GNU M4 is used in GNU Autoconf' @file{configure} files.
2335
2336 @verbatim
2337 # 1 minute
2338 tar xf ${DOWNLOAD_DIR}/m4-1.4.17.tar.bz2 -C ${BUILD_DIR}
2339 cd ${BUILD_DIR}/m4-1.4.17
2340 ./configure \
2341     --build=${CROSS_HOST} \
2342     --host=${CROSS_TARGET} \
2343     --prefix=
2344 make
2345 make DESTDIR=${TARGET_DIR} install
2346 cd ..
2347 rm -rf m4-1.4.17
2348 cd
2349 @end verbatim
2350
2351
2352 @node Bison
2353 @section Bison
2354
2355 GNU bison parser generator.
2356
2357 @verbatim
2358 # 2 minutes
2359 tar xf ${DOWNLOAD_DIR}/bison-2.7.tar.gz -C ${BUILD_DIR}
2360 cd ${BUILD_DIR}/bison-2.7
2361 ./configure \
2362     --build=${CROSS_HOST} \
2363     --host=${CROSS_TARGET} \
2364     --prefix=
2365 echo '#define YYENABLE_NLS 1' >> config.h
2366 make
2367 make DESTDIR=${TARGET_DIR} install
2368 cd ..
2369 rm -rf bison-2.7
2370 cd
2371 @end verbatim
2372
2373 @samp{echo '#define YYENABLE_NLS 1' >> config.h} is used to build
2374 @acronym{NLS} (native language support) inside bison.
2375
2376
2377 @node Ncurses
2378 @section Ncurses
2379
2380 @verbatim
2381 # 4 minutes
2382 tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR}
2383 cd ${BUILD_DIR}/ncurses-5.9
2384 ./configure \
2385     --build=${CROSS_HOST} \
2386     --host=${CROSS_TARGET} \
2387     --prefix= \
2388     --with-shared \
2389     --enable-widec \
2390     --without-debug \
2391     --without-ada \
2392     --with-build-cc="gcc -D_GNU_SOURCE" \
2393     --libdir=/lib
2394 make
2395 make DESTDIR=${TARGET_DIR} install
2396 cd ..
2397 rm -rf ncurses-5.9
2398 cd
2399 @end verbatim
2400
2401 Option @option{--enable-widec} enables wide characters support in
2402 ncurses.
2403
2404 @c Option @option{--without-debug}
2405
2406 Option @option{--without-ada} disables support for the Ada programming
2407 language inside ncurses.
2408
2409 @c Option @option{--with-build-cc="gcc -D_GNU_SOURCE"}
2410
2411 @c Option @option{--libdir=/lib}
2412
2413 @ignore
2414 @c PROCPS issue:
2415 The command @samp{ln -sfv libncursesw.so $@{TARGET_DIR@}/lib/libncurses.so}
2416 creates the symlink @file{libcurses.so} so that programs that do not
2417 know @file{libncursesw.so} can be linked against it.
2418 @end ignore
2419
2420 @c ln -sfv ../../share/terminfo ${TARGET_DIR}/lib/terminfo
2421
2422
2423 @node Procps
2424 @section Procps
2425
2426 The procps package contains utilities that give information about
2427 processes using the @file{/proc} filesystem. The package includes the
2428 commands @command{ps}, @command{top}, @command{vmstat}, @command{w},
2429 @command{kill}, @command{free}, @command{slabtop}, and
2430 @command{skill}.
2431
2432 @verbatim
2433 # 1 minute
2434 ln -sv ncursesw/curses.h ${TARGET_DIR}/include/curses.h
2435 ln -sv ncursesw/ncurses.h ${TARGET_DIR}/include/ncurses.h
2436 ln -sv ncursesw/term.h ${TARGET_DIR}/include/term.h
2437 ln -sfv libncursesw.so ${TARGET_DIR}/lib/libncurses.so
2438 tar xf ${DOWNLOAD_DIR}/procps-3.2.8.tar.gz -C ${BUILD_DIR}
2439 cd ${BUILD_DIR}/procps-3.2.8
2440
2441 # From http://lists.gnu.org/archive/html/bug-make/2010-07/msg00153.html
2442 sed '177s,\*/module.mk,proc/module.mk ps/proc.mk,' -i.orig Makefile
2443
2444 make \
2445     CPPFLAGS= \
2446     lib64=lib
2447 make \
2448     DESTDIR=${TARGET_DIR} \
2449     lib64=lib \
2450     ldconfig= \
2451     install="install -D" \
2452     install
2453 cd ..
2454 rm -rf procps-3.2.8
2455 cd
2456 @end verbatim
2457
2458 @ignore
2459 Option @option{CPPFLAGS= } is used so that the target system's ncurses
2460 library will be used, default value would have been
2461 @option{-I/include/ncurses}.
2462 @end ignore
2463
2464 Option @option{lib64=lib} makes the directory @file{/lib} the one
2465 where to put 64 bit libraries, default would be @file{/lib64}.
2466
2467 Option @option{ldconfig= } is used in order not to use current host's
2468 @command{ldconfig}.
2469
2470 Option @option{install="install -D"} is used so that all the files
2471 installed are owned by the current user. By default, all installed
2472 files are owned by root.
2473
2474
2475 @node Libtool
2476 @section Libtool
2477
2478 GNU libtool is a generic library support script. It hides the
2479 complexity of using shared libraries behind a consistent, portable
2480 interface.
2481
2482 @verbatim
2483 # 1 minute
2484 tar xf ${DOWNLOAD_DIR}/libtool-2.4.2.tar.gz -C ${BUILD_DIR}
2485 cd ${BUILD_DIR}/libtool-2.4.2
2486 ./configure \
2487     --build=${CROSS_HOST} \
2488     --host=${CROSS_TARGET} \
2489     --prefix=
2490 make
2491 make DESTDIR=${TARGET_DIR} install
2492 cd ..
2493 rm -rf libtool-2.4.2
2494 cd
2495 @end verbatim
2496
2497
2498 @node Readline
2499 @section Readline
2500
2501 The GNU Readline library provides a set of functions for use by
2502 applications that allow users to edit command lines as they are typed
2503 in.
2504
2505 @verbatim
2506 # 1 minute
2507 tar xf ${DOWNLOAD_DIR}/readline-6.2.tar.gz -C ${BUILD_DIR}
2508 cd ${BUILD_DIR}/readline-6.2
2509 ./configure \
2510     --build=${CROSS_HOST} \
2511     --host=${CROSS_TARGET} \
2512     --prefix= \
2513     --libdir=/lib
2514 make
2515 make DESTDIR=${TARGET_DIR} install
2516 make DESTDIR=${TARGET_DIR} install-doc
2517 cd ..
2518 rm -rf readline-6.2
2519 cd
2520 @end verbatim
2521
2522 @c sed -i 's:^SHLIB_LIBS=:SHLIB_LIBS=-lncursesw:' support/shobj-conf
2523
2524
2525 @node Autoconf
2526 @section Autoconf
2527
2528 GNU autoconf is an extensible package of M4 macros that produce shell
2529 scripts to automatically configure software source code
2530 packages. These scripts can adapt the packages to many kinds of
2531 UNIX-like systems without manual user intervention.
2532
2533 @verbatim
2534 # 1 minute
2535 tar xf ${DOWNLOAD_DIR}/autoconf-2.69.tar.gz -C ${BUILD_DIR}
2536 cd ${BUILD_DIR}/autoconf-2.69
2537 ./configure \
2538     --build=${CROSS_HOST} \
2539     --host=${CROSS_TARGET} \
2540     --prefix=
2541 make
2542 make DESTDIR=${TARGET_DIR} install
2543 cd ..
2544 rm -rf autoconf-2.69
2545 cd
2546 @end verbatim
2547
2548
2549 @node Automake
2550 @section Automake
2551
2552 GNU automake is a tool for automatically generating @file{Makefile.in}
2553 files compliant with the GNU Coding
2554 Standards@footnote{@uref{http://www.gnu.org/prep/standards/}}.
2555
2556 You need Autoconf on your system to compile this program from
2557 source. Under gNewSense 4.0, try @samp{sudo apt-get install autoconf}
2558 (version 2.69 here).
2559
2560 @verbatim
2561 # 1 minute
2562 tar xf ${DOWNLOAD_DIR}/automake-1.14.tar.gz -C ${BUILD_DIR}
2563 cd ${BUILD_DIR}/automake-1.14
2564 ./configure \
2565     --build=${CROSS_HOST} \
2566     --host=${CROSS_TARGET} \
2567     --prefix=
2568 make
2569 make DESTDIR=${TARGET_DIR} install
2570 cd ..
2571 rm -rf automake-1.14
2572 cd
2573 @end verbatim
2574
2575
2576 @node Bash
2577 @section Bash
2578
2579 GNU @acronym{Bash} (Bourne again shell) is an sh-compatible shell that
2580 incorporates useful features from the Korn shell (ksh) and C shell
2581 (csh).
2582
2583 @verbatim
2584 # 2 minutes
2585 tar xf ${DOWNLOAD_DIR}/bash-4.2.tar.gz -C ${BUILD_DIR}
2586 cd ${BUILD_DIR}/bash-4.2
2587 cat > config.cache << EOF
2588 ac_cv_func_mmap_fixed_mapped=yes
2589 ac_cv_func_strcoll_works=yes
2590 ac_cv_func_working_mktime=yes
2591 bash_cv_func_sigsetjmp=present
2592 bash_cv_getcwd_malloc=yes
2593 bash_cv_job_control_missing=present
2594 bash_cv_printf_a_format=yes
2595 bash_cv_sys_named_pipes=present
2596 bash_cv_ulimit_maxfds=yes
2597 bash_cv_under_sys_siglist=yes
2598 bash_cv_unusable_rtsigs=no
2599 gt_cv_int_divbyzero_sigfpe=yes
2600 EOF
2601 ./configure \
2602     --build=${CROSS_HOST} \
2603     --host=${CROSS_TARGET} \
2604     --prefix= \
2605     --bindir=/bin \
2606     --cache-file=config.cache \
2607     --without-bash-malloc \
2608     --with-installed-readline
2609 make
2610 make \
2611     DESTDIR=${TARGET_DIR} \
2612     htmldir=/share/doc/bash-4.2 \
2613     install
2614 ln -sv bash ${TARGET_DIR}/bin/sh
2615 cd ..
2616 rm -rf bash-4.2
2617 cd
2618 @end verbatim
2619
2620 The variables listed in the file @file{config.cache} are used in order
2621 to avoid that the @file{configure} script evaluate their values:
2622 otherwise the build may fail when cross-compiling.
2623
2624 Option @option{--without-bash-malloc} tells the @file{configure}
2625 script not to use the @code{malloc} function shipped with
2626 Bash. Glibc's version will be used instead.
2627
2628 Option @option{--with-installed-readline} tells the configure script
2629 to use the installed readline library instead of the one shipped with
2630 Bash.
2631
2632 @samp{ln -sv bash $@{TARGET_DIR@}/bin/sh} creates a symlink @file{sh}
2633 to @file{bash}.
2634
2635
2636 @node Bzip2
2637 @section Bzip2
2638
2639 Bzip2 is a package that contains utilities to compress and decompress
2640 files with a better original size/compressed size ratio than gzip.
2641
2642 @verbatim
2643 # 1 minute
2644 tar xf ${DOWNLOAD_DIR}/bzip2-1.0.6.tar.gz -C ${BUILD_DIR}
2645 cd ${BUILD_DIR}/bzip2-1.0.6
2646 sed -i -e "/^all:/s/ test//" Makefile
2647 sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile
2648 make \
2649     -f Makefile-libbz2_so \
2650     CC="${CC}" \
2651     AR="${AR}" \
2652     RANLIB="${RANLIB}"
2653 make clean
2654 make \
2655     CC="${CC}" \
2656     AR="${AR}" \
2657     RANLIB="${RANLIB}"
2658 make \
2659     PREFIX=${TARGET_DIR} \
2660     install
2661 cp -av libbz2.so* ${TARGET_DIR}/lib
2662 ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/lib/libbz2.so
2663 rm -v ${TARGET_DIR}/bin/{bunzip2,bzcat,bzip2}
2664 cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2
2665 ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2
2666 ln -sv bzip2 ${TARGET_DIR}/bin/bzcat
2667 cd ..
2668 rm -rf bzip2-1.0.6
2669 cd
2670 @end verbatim
2671
2672 @samp{sed -i.orig -e "/^all:/s/ test//" Makefile} is used to skip
2673 tests when building.
2674
2675 @samp{sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile} is used
2676 in order to have relative path symlinks instead of absolute ones.
2677
2678 Option @option{-f Makefile-libbz2_so} is used to build shared
2679 libraries.
2680
2681 Flags @env{CC}, @env{AR} and @env{RANLIB} are used so that bzip2 is
2682 built using cross-compilation tools instead of the host's ones.
2683
2684 @samp{make clean} is used to clean up temporary files.
2685
2686 The second build commands are used to build static libraries.
2687
2688 @ignore
2689 cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2
2690 cp -av libbz2.so* ${TARGET_DIR}/lib
2691 ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/lib/libbz2.so
2692 rm -v ${TARGET_DIR}/bin/{bunzip2,bzcat,bzip2}
2693 ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2
2694 ln -sv bzip2 ${TARGET_DIR}/bin/bzcat
2695 @end ignore
2696
2697
2698 @node DHCPCD
2699 @section DHCPCD
2700
2701 DHCPCD is a wrapper for the @acronym{DHCP} (Dynamic Host Configuration
2702 Protocol) client daemon.
2703
2704 @verbatim
2705 # 1 minute
2706 tar xf ${DOWNLOAD_DIR}/dhcpcd-6.1.0.tar.bz2 -C ${BUILD_DIR}
2707 cd ${BUILD_DIR}/dhcpcd-6.1.0
2708 ./configure \
2709     --build=${CROSS_HOST} \
2710     --host=${CROSS_TARGET} \
2711     --prefix= \
2712     --bindir=/sbin \
2713     --sysconfdir=/etc \
2714     --dbdir=/var/lib/dhcpcd \
2715     --libexecdir=/lib/dhcpcd
2716 make
2717 make DESTDIR=${TARGET_DIR} install
2718 cd ..
2719 rm -rf dhcpcd-6.1.0
2720 cd
2721 @end verbatim
2722
2723 @c Option @option{--bindir=/sbin} is used to comply with FHS?
2724 @c @option{--sysconfdir=/etc} @file{/etc} instead of ?
2725 @c @option{--dbdir=/var/lib/dhcpcd} @file{/var/lib/dhcpcd} instead of?
2726 @c @option{--libexecdir=/lib/dhcpcd} @file{/lib/dhcpcd} instead of ?
2727
2728
2729 @node Diffutils
2730 @section Diffutils
2731
2732 GNU Diffutils is a package of several programs related to finding
2733 differences between files.
2734
2735 @verbatim
2736 # 1 minute
2737 tar xf ${DOWNLOAD_DIR}/diffutils-3.3.tar.xz -C ${BUILD_DIR}
2738 cd ${BUILD_DIR}/diffutils-3.3
2739 ./configure \
2740     --build=${CROSS_HOST} \
2741     --host=${CROSS_TARGET} \
2742     --prefix=
2743 make
2744 make DESTDIR=${TARGET_DIR} install
2745 cd ..
2746 rm -rf diffutils-3.3
2747 cd
2748 @end verbatim
2749
2750
2751 @node File
2752 @section File
2753
2754 @verbatim
2755 # 1 minute
2756 tar xf ${DOWNLOAD_DIR}/file-5.16.tar.gz -C ${BUILD_DIR}
2757 cd ${BUILD_DIR}/file-5.16
2758 ./configure \
2759     --build=${CROSS_HOST} \
2760     --host=${CROSS_TARGET} \
2761     --prefix=
2762 make
2763 make DESTDIR=${TARGET_DIR} install
2764 cd ..
2765 rm -rf file-5.16
2766 cd
2767 @end verbatim
2768
2769
2770 @node Findutils
2771 @section Findutils
2772
2773 The GNU Find Utilities are typically used to provide directory search
2774 and file locating capabilities.
2775
2776 @verbatim
2777 # 1 minute
2778 tar xf ${DOWNLOAD_DIR}/findutils-4.4.2.tar.gz -C ${BUILD_DIR}
2779 cd ${BUILD_DIR}/findutils-4.4.2
2780 cat > config.cache << EOF
2781 gl_cv_func_wcwidth_works=yes
2782 gl_cv_header_working_fcntl_h=yes
2783 ac_cv_func_fnmatch_gnu=yes
2784 EOF
2785 ./configure \
2786     --build=${CROSS_HOST} \
2787     --host=${CROSS_TARGET} \
2788     --prefix= \
2789     --libexecdir=/lib/locate \
2790     --localstatedir=/var/lib/locate \
2791     --cache-file=config.cache
2792 make
2793 make DESTDIR=${TARGET_DIR} install
2794 cd ..
2795 rm -rf findutils-4.4.2
2796 cd
2797 @end verbatim
2798
2799 @c --libexecdir=/lib/locate
2800 @c --localstatedir=/var/lib/locate
2801
2802
2803 @node Flex
2804 @section Flex
2805
2806 Flex is a tool for generating scanners. A scanner, sometimes called a
2807 tokenizer, is a program which recognizes lexical patterns in text.
2808
2809 @verbatim
2810 # 1 minute
2811 tar xf ${DOWNLOAD_DIR}/flex-2.5.37.tar.bz2 -C ${BUILD_DIR}
2812 cd ${BUILD_DIR}/flex-2.5.37
2813 # From http://sourceforge.net/p/flex/bugs/151/
2814 sed '1s/$/\n#undef malloc\n#undef realloc/' \
2815     -i.orig lib/realloc.c
2816 cat > config.cache << EOF
2817 ac_cv_path_M4="/bin/m4"
2818 EOF
2819 ./configure \
2820     --build=${CROSS_HOST} \
2821     --host=${CROSS_TARGET} \
2822     --prefix= \
2823     --cache-file=config.cache
2824 make
2825 make DESTDIR=${TARGET_DIR} install
2826 ln -sv libfl.a ${TARGET_DIR}/lib/libl.a
2827 cd ..
2828 rm -r flex-2.5.37
2829 cd
2830
2831 cat > ${TARGET_DIR}/bin/lex << EOF
2832 #!/bin/sh
2833 exec /bin/flex -l \$@
2834 EOF
2835 chmod -v 755 ${TARGET_DIR}/bin/lex
2836 @end verbatim
2837
2838 @file{config.cache} forces flex to use @file{/bin/m4} instead of
2839 @file{/gllfsc/cross-tools/bin/m4} on the target machine.
2840
2841 For compatibility issues, we create the symlink @file{libl.a}.
2842
2843 We then create target system's @file{/bin/lex} that will execute
2844 @command{flex} with option @option{-l} in order to behave with maximal
2845 compatibility like @command{lex}.
2846
2847 @ignore
2848 @samp{sed -i.orig "s/-I@@includedir@@//g" Makefile.in} is used in
2849 order not to use host's headers in @file{/include} during
2850 cross-compilation.
2851 @end ignore
2852
2853 @c Variables @samp{ac_cv_func_malloc_0_nonnull=yes} and
2854 @c @samp{ac_cv_func_realloc_0_nonnull=yes} are used to get rid of
2855 @c error message: @samp{}.
2856
2857 @c We use option @option{-fPIC} passed to the cross-compiler in order to
2858 @c generate position-independent code (PIC).
2859
2860
2861 @node Gawk
2862 @section Gawk
2863
2864 GNU awk (Gawk) is a program used to select particular records in a
2865 file and perform operations upon them.
2866
2867 @verbatim
2868 # 1 minute
2869 tar xf ${DOWNLOAD_DIR}/gawk-4.1.0.tar.gz -C ${BUILD_DIR}
2870 cd ${BUILD_DIR}/gawk-4.1.0
2871 sed -i.orig \
2872     '/check-recursive all-recursive/s/ check-for-shared-lib-support//' \
2873     extension/Makefile.in
2874 ./configure \
2875     --build=${CROSS_HOST} \
2876     --host=${CROSS_TARGET} \
2877     --prefix= \
2878     --libexecdir=/lib
2879 make
2880 make DESTDIR=${TARGET_DIR} install
2881 cd ..
2882 rm -r gawk-4.1.0
2883 cd
2884 @end verbatim
2885
2886 The sed expression is used to avoid the error @samp{Building the
2887 extensions is not supported on this platform}.
2888
2889
2890 @node Gdbm
2891 @section Gdbm
2892
2893 GNU dbm is a library of database functions.
2894
2895 @verbatim
2896 # 1 minute
2897 tar xf ${DOWNLOAD_DIR}/gdbm-1.11.tar.gz -C ${BUILD_DIR}
2898 cd ${BUILD_DIR}/gdbm-1.11
2899 ./configure \
2900     --build=${CROSS_HOST} \
2901     --host=${CROSS_TARGET} \
2902     --prefix=
2903 make
2904 make DESTDIR=${TARGET_DIR} install
2905 cd ..
2906 rm -r gdbm-1.11
2907 cd
2908 @end verbatim
2909
2910
2911 @node Gettext
2912 @section Gettext
2913
2914 GNU gettext utilities are a set of tools that provides a framework to
2915 help packages produce multi-lingual messages.
2916
2917 @verbatim
2918 # 7 minutes
2919 tar xf ${DOWNLOAD_DIR}/gettext-0.18.3.1.tar.gz -C ${BUILD_DIR}
2920 cd ${BUILD_DIR}/gettext-0.18.3.1
2921 cat > config.cache << EOF
2922 am_cv_func_iconv_works=yes
2923 gl_cv_func_wcwidth_works=yes
2924 gt_cv_func_printf_posix=yes
2925 gt_cv_int_divbyzero_sigfpe=yes
2926 EOF
2927 ./configure \
2928     --build=${CROSS_HOST} \
2929     --host=${CROSS_TARGET} \
2930     --prefix= \
2931     --cache-file=config.cache
2932 make
2933 #cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i}
2934 #cp gettext-tools/src/.libs/libgettextsrc.la{,i}
2935 make DESTDIR=${TARGET_DIR} install
2936 cd ..
2937 rm -rf gettext-0.18.3.1
2938 cd
2939 @end verbatim
2940
2941 @c cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i} ?
2942 @c cp gettext-tools/src/.libs/libgettextsrc.la{,i} ?
2943
2944
2945 @node Grep
2946 @section Grep
2947
2948 GNU @command{grep} command searches one or more input files for lines
2949 containing a match to a specified pattern.
2950
2951 @verbatim
2952 # 1 minute
2953 tar xf ${DOWNLOAD_DIR}/grep-2.15.tar.xz -C ${BUILD_DIR}
2954 cd ${BUILD_DIR}/grep-2.15
2955 ./configure \
2956     --build=${CROSS_HOST} \
2957     --host=${CROSS_TARGET} \
2958     --prefix= \
2959     --bindir=/bin \
2960     --disable-perl-regexp
2961 make
2962 make DESTDIR=${TARGET_DIR} install
2963 cd ..
2964 rm -rf grep-2.15
2965 cd
2966 @end verbatim
2967
2968 Option @option{--disable-perl-regexp} disables support of Perl-style
2969 regular expressions (regexp).
2970
2971
2972 @node Groff
2973 @section Groff
2974
2975 Groff is the GNU version of the roff document formatting system which
2976 is used to produce man pages.
2977
2978 @verbatim
2979 # 2 minutes
2980 tar xf ${DOWNLOAD_DIR}/groff-1.22.2.tar.gz -C ${BUILD_DIR}
2981 cd ${BUILD_DIR}/groff-1.22.2
2982 PAGE=A4 \
2983     ./configure \
2984     --build=${CROSS_HOST} \
2985     --host=${CROSS_TARGET} \
2986     --prefix=
2987 make \
2988     TROFFBIN=troff \
2989     GROFFBIN=groff \
2990     GROFF_BIN_PATH=
2991 make prefix=${TARGET_DIR} install
2992 ln -sv soelim ${TARGET_DIR}/bin/zsoelim
2993 ln -sv eqn ${TARGET_DIR}/bin/geqn
2994 ln -sv tbl ${TARGET_DIR}/bin/gtbl
2995 cd ..
2996 rm -rf groff-1.22.2
2997 cd
2998 @end verbatim
2999
3000 The variables @env{TROFFBIN=troff} and @env{GROFFBIN=groff} tell
3001 @command{make} to use @command{troff} and @command{groff} commands
3002 installed in the @ref{Building the Cross-Compilation Tools} to build
3003 documentation.
3004
3005 The variable @env{GROFF_BIN_PATH} before @env{PATH} is checked for
3006 programs @command{groff} is calling (preprocessors, @command{troff},
3007 and output devices). If not set, it defaults to the directory where
3008 the @file{groff} binary is located.
3009
3010 The symlinks are used for compatibility.
3011
3012
3013 @node Gzip
3014 @section Gzip
3015
3016 GNU Gzip is a data compression program.
3017
3018 @verbatim
3019 # 2 minutes
3020 tar xf ${DOWNLOAD_DIR}/gzip-1.6.tar.gz -C ${BUILD_DIR}
3021 cd ${BUILD_DIR}/gzip-1.6
3022 ./configure \
3023     --build=${CROSS_HOST} \
3024     --host=${CROSS_TARGET} \
3025     --prefix=
3026 make
3027 make DESTDIR=${TARGET_DIR} install
3028 cd ..
3029 rm -rf gzip-1.6
3030 cd
3031 @end verbatim
3032
3033
3034 @node Inetutils
3035 @section Inetutils
3036
3037 Inetutils is a collection of common network programs.
3038
3039 @verbatim
3040 # 2 minutes
3041 tar xf ${DOWNLOAD_DIR}/inetutils-1.9.1.tar.gz -C ${BUILD_DIR}
3042 cd ${BUILD_DIR}/inetutils-1.9.1
3043 sed -i '/gets is a security hole/d' lib/stdio.in.h
3044 sed -i -e '/PATH_PROCNET_DEV/s/\ no//' paths
3045 ./configure \
3046     --build=${CROSS_HOST} \
3047     --host=${CROSS_TARGET} \
3048     --prefix=
3049 make
3050 make DESTDIR=${TARGET_DIR} install
3051 cd ..
3052 rm -rf inetutils-1.9.1
3053 cd
3054 @end verbatim
3055
3056 @samp{sed -i.orig '/gets is a security hole/d' lib/stdio.in.h} is used
3057 to fix the following error when issuing @samp{make}:
3058 @samp{./stdio.h:1030:1: error: 'gets' undeclared here (not in a
3059 function)}.
3060
3061 @c It deletes the following line in lib/stdio.in.h:
3062 @c _GL_WARN_ON_USE (gets, ``gets is a security hole - use fgets instead'');
3063
3064 @samp{sed -i.orig -e '/PATH_PROCNET_DEV/s/\ no//' paths} is used to
3065 fix the following error when issuing @samp{make}:
3066 @samp{'PATH_PROCNET_DEV' undeclared (first use in this function)}.
3067
3068
3069 @node Iproute2
3070 @section Iproute2
3071
3072 Iproute2 is a collection of utilities for controlling TCP and UDP IP
3073 networking and traffic.
3074
3075 You need Bison and Flex on your system to compile this program from
3076 source. Under gNewSense 4.0, try @samp{sudo apt-get install bison flex}.
3077
3078 @verbatim
3079 # 2 minutes
3080 tar xf ${DOWNLOAD_DIR}/iproute2-3.10.0.tar.bz2 -C ${BUILD_DIR}
3081 cd ${BUILD_DIR}/iproute2-3.10.0
3082 sed -i.orig '/^TARGETS/s@arpd@@g' misc/Makefile
3083 make \
3084     DESTDIR=${TARGET_DIR} \
3085     CC="${CC}" \
3086     DOCDIR=/share/doc/iproute2 \
3087     MANDIR=/share/man
3088 make \
3089     DESTDIR=${TARGET_DIR} \
3090     DOCDIR=/share/doc/iproute2 \
3091     MANDIR=/share/man \
3092     install
3093 cd ..
3094 rm -rf iproute2-3.10.0
3095 cd
3096 @end verbatim
3097
3098 @samp{sed -i.orig '/^TARGETS/s@@arpd@@@@g' misc/Makefile} is used to
3099 disable the build of @command{arpd} as it requires Berkeley DB to be
3100 installed.
3101
3102 @env{DOCDIR} and @env{MANDIR} indicate the location in which the
3103 documentation and the manual pages will be installed,
3104 respectively. Those are no absolute paths but use the value of
3105 @env{DESTDIR} as a prefix.
3106
3107
3108 @node Kbd
3109 @section Kbd
3110
3111 Kbd contains keytable files and keyboard utilities.
3112
3113 You need Check on your system to compile this program from
3114 source. Under gNewSense 4.0, try @samp{sudo apt-get install check}.
3115
3116 @verbatim
3117 # 3 minutes
3118 tar xf ${DOWNLOAD_DIR}/kbd-2.0.1.tar.gz -C ${BUILD_DIR}
3119 cd ${BUILD_DIR}/kbd-2.0.1
3120
3121 # Do not check for CHECK:
3122 sed '14s/^/#/' -i.orig configure.ac
3123 autoconf configure.ac > configure
3124
3125 sed -i.orig '/^SUBDIRS/s/ tests//' Makefile.am
3126 ./configure \
3127     --build=${CROSS_HOST} \
3128     --host=${CROSS_TARGET} \
3129     --prefix= \
3130     --disable-vlock
3131 make
3132 make DESTDIR=${TARGET_DIR} install
3133 cd ..
3134 rm -rf kbd-2.0.1
3135 cd
3136 @end verbatim
3137
3138 @samp{sed -i.orig '/SUBDIRS/s/ tests//' Makefile.in} is used to
3139 prevent files in the @file{tests} directory to be built.
3140
3141 Option @option{--disable-vlock} disables the build of vlock. vlock
3142 needs PAM library headers to be present on the build system and is not
3143 necessary for us, so we do not build it.
3144
3145
3146 @node Kmod
3147 @section Kmod
3148
3149 Kmod (previously known as module-init-tools) provide userspace-side
3150 assistance in loading kernel modules and their dependencies.
3151
3152 You need Xsltproc on your system to compile this program from
3153 source. Under gNewSense 4.0, try @samp{sudo apt-get install xsltproc}.
3154
3155 @verbatim
3156 # 2 minutes
3157 tar xf ${DOWNLOAD_DIR}/kmod-15.tar.gz -C ${BUILD_DIR}
3158 cd ${BUILD_DIR}/kmod-15
3159 zlib_CFLAGS="-I${TARGET_DIR}/include" \
3160     zlib_LIBS="-L${TARGET_DIR}/lib -lz" \
3161     ./configure \
3162     --build=${CROSS_HOST} \
3163     --host=${CROSS_TARGET} \
3164     --prefix= \
3165     --with-zlib
3166 make
3167 make \
3168     DESTDIR=${TARGET_DIR} \
3169     INSTALL=install \
3170     install
3171 cd ..
3172 rm -rf kmod-15
3173 cd
3174
3175 # For bootscripts:
3176 ln -sv kmod ${TARGET_DIR}/bin/lsmod
3177 ln -sv kmod ${TARGET_DIR}/bin/depmod
3178 ln -sv kmod ${TARGET_DIR}/bin/insmod
3179 ln -sv kmod ${TARGET_DIR}/bin/modprobe
3180 ln -sv kmod ${TARGET_DIR}/bin/modinfo
3181 ln -sv kmod ${TARGET_DIR}/bin/rmmod
3182 @end verbatim
3183
3184 @samp{zlib_CFLAGS} and @samp{zlib_LIBS} are defined to avoid the error
3185 message: @samp{The pkg-config script could not be found or is too
3186 old. Make sure it is in your PATH or set the PKG_CONFIG environment
3187 variable to the full path to pkg-config. Alternatively, you may set
3188 the environment variables zlib_CFLAGS and zlib_LIBS to avoid the need
3189 to call pkg-config.}
3190
3191 @option{--with-zlib} enables support for modules compressed with
3192 zlib.
3193
3194 By default, installation uses @env{INSTALL=install-with-care} which
3195 checks if old utilities have not been destroyed. To avoid this check,
3196 we use @env{INSTALL=install}.
3197
3198
3199 @node Less
3200 @section Less
3201
3202 Less is a file pager: it is used to view the content of a text file.
3203
3204 @verbatim
3205 # 2 minutes
3206 tar xf ${DOWNLOAD_DIR}/less-458.tar.gz -C ${BUILD_DIR}
3207 cd ${BUILD_DIR}/less-458
3208 ./configure \
3209     --build=${CROSS_HOST} \
3210     --host=${CROSS_TARGET} \
3211     --prefix=
3212 make
3213 make prefix=${TARGET_DIR} install
3214 cd ..
3215 rm -rf less-458
3216 cd
3217 @end verbatim
3218
3219
3220 @node Libpipeline
3221 @section Libpipeline
3222
3223 Libpipeline is a C library for manipulating pipelines of subprocesses
3224 in a flexible and convenient way.
3225
3226 @verbatim
3227 tar xf ${DOWNLOAD_DIR}/libpipeline-1.3.0.tar.gz -C ${BUILD_DIR}
3228 cd ${BUILD_DIR}/libpipeline-1.3.0
3229 ./configure \
3230     --build=${CROSS_HOST} \
3231     --host=${CROSS_TARGET} \
3232     --prefix=
3233 make
3234 make prefix=${TARGET_DIR} install
3235 cd ..
3236 rm -rf libpipeline-1.3.0
3237 cd
3238 @end verbatim
3239
3240
3241 @node Make
3242 @section Make
3243
3244 GNU @command{make} utility determines automatically which pieces of a
3245 large program need to be recompiled, and issues the commands to
3246 recompile them.
3247
3248 @verbatim
3249 # 5 minutes
3250 tar xf ${DOWNLOAD_DIR}/make-4.0.tar.bz2 -C ${BUILD_DIR}
3251 cd ${BUILD_DIR}/make-4.0
3252 ./configure \
3253     --build=${CROSS_HOST} \
3254     --host=${CROSS_TARGET} \
3255     --prefix=
3256 make
3257 make DESTDIR=${TARGET_DIR} install
3258 cd ..
3259 rm -rf make-4.0
3260 cd
3261 @end verbatim
3262
3263
3264 @node Man-db
3265 @section Man-db
3266
3267 Man-db is an implementation of the standard Unix documentation system
3268 accessed using the man command.  It uses a Berkeley DB database in
3269 place of the traditional flat-text whatis databases.
3270
3271 @verbatim
3272 # fix /lib/libpipeline.so: error adding symbols: File in wrong format
3273 rm ${TARGET_DIR}/lib/libgdbm.la
3274 rm ${TARGET_DIR}/lib/libpipeline.la
3275
3276 tar xf ${DOWNLOAD_DIR}/man-db-2.6.7.1.tar.xz -C ${BUILD_DIR}
3277 cd ${BUILD_DIR}/man-db-2.6.7.1
3278 libpipeline_CFLAGS="-I${TARGET_DIR}/include" \
3279     libpipeline_LIBS="-L${TARGET_DIR}/lib -lpipeline" \
3280     ./configure \
3281     --build=${CROSS_HOST} \
3282     --host=${CROSS_TARGET} \
3283     --prefix=
3284 make
3285 make DESTDIR=${TARGET_DIR} install
3286 cd ..
3287 rm -rf man-db-2.6.7.1
3288 cd
3289
3290 sed -i 's/#\(DEFINE.*pager.*\)less -s/\1 less -isRc/' \
3291     ${TARGET_DIR}/etc/man_db.conf
3292 @end verbatim
3293
3294 @samp{libpipeline_CFLAGS} and @samp{libpipeline_LIBS} are defined to
3295 avoid the error message: @samp{The pkg-config script could not be
3296 found or is too old. Make sure it is in your PATH or set the
3297 PKG_CONFIG environment variable to the full path to
3298 pkg-config. Alternatively, you may set the environment variables
3299 libpipeline_CFLAGS and libpipeline_LIBS to avoid the need to call
3300 pkg-config.}
3301
3302 The @command{sed} command is used to replace default pager with
3303 @command{less}. Option @option{-c} will cause @command{less} to
3304 display man pages faster as this option disables scrolling. Option
3305 @option{-R} will cause @command{less} to render colors in the man
3306 pages.
3307
3308
3309 @node Nano
3310 @section Nano
3311
3312 GNU nano is a lightweight text editor.
3313
3314 @verbatim
3315 # 2 minutes
3316 tar xf ${DOWNLOAD_DIR}/nano-2.3.2.tar.gz -C ${BUILD_DIR}
3317 cd ${BUILD_DIR}/nano-2.3.2
3318 ./configure \
3319     --build=${CROSS_HOST} \
3320     --host=${CROSS_TARGET} \
3321     --prefix=
3322 sed -i.orig -e \
3323     '/CPPFLAGS/s@/usr/include/ncursesw@${TARGET_DIR}/include@' \
3324     `find . -iname 'Makefile'`
3325 make
3326 make DESTDIR=${TARGET_DIR} install
3327 cd ..
3328 rm -rf nano-2.3.2
3329 cd
3330 @end verbatim
3331
3332 The sed expression is used to replace @file{/usr/include/ncursesw}
3333 with @file{$@{TARGET_DIR@}/include} in every file named
3334 @file{Makefile} in order to overcome the error
3335 @samp{/usr/include/ncursesw/ncurses.h:60:34: fatal error:
3336 ncursesw/ncurses_dll.h: No such file or directory}.
3337
3338 @quotation Note
3339 commands in nano are displayed as in `^X'. The `^' character means
3340 @key{CTRL} key, so `^X' means @kbd{CTRL-X}.
3341 @end quotation
3342
3343
3344 @node Patch
3345 @section Patch
3346
3347 GNU patch takes a patch file containing a difference listing produced
3348 by the @command{diff} program and applies those differences to one or
3349 more original files, producing patched versions.
3350
3351 @verbatim
3352 # 2 minutes
3353 tar xf ${DOWNLOAD_DIR}/patch-2.7.1.tar.bz2 -C ${BUILD_DIR}
3354 cd ${BUILD_DIR}/patch-2.7.1
3355 cat > config.cache << EOF
3356 ac_cv_path_ed_PROGRAM=ed
3357 ac_cv_func_strnlen_working=yes
3358 EOF
3359 ./configure \
3360     --build=${CROSS_HOST} \
3361     --host=${CROSS_TARGET} \
3362     --prefix= \
3363     --cache-file=config.cache
3364 make
3365 make prefix=${TARGET_DIR} install
3366 cd ..
3367 rm -rf patch-2.7.1
3368 cd
3369 @end verbatim
3370
3371
3372 @node Psmisc
3373 @section Psmisc
3374
3375 This package contains utilities that use the proc filesystem.
3376
3377 @verbatim
3378 # 2 minutes
3379 tar xf ${DOWNLOAD_DIR}/psmisc-22.20.tar.gz -C ${BUILD_DIR}
3380 cd ${BUILD_DIR}/psmisc-22.20
3381 cat > config.cache << EOF
3382 ac_cv_func_malloc_0_nonnull=yes
3383 ac_cv_func_realloc_0_nonnull=yes
3384 EOF
3385 ./configure \
3386     --build=${CROSS_HOST} \
3387     --host=${CROSS_TARGET} \
3388     --prefix= \
3389     --cache-file=config.cache
3390 make
3391 make DESTDIR=${TARGET_DIR} install
3392 cd ..
3393 rm -rf psmisc-22.20
3394 cd
3395 @end verbatim
3396
3397
3398 @node Shadow
3399 @section Shadow
3400
3401 @verbatim
3402 # 4 minutes
3403 tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR}
3404 cd ${BUILD_DIR}/shadow-4.1.4.3
3405 #automake
3406 echo "ac_cv_func_setpgrp_void=yes" > config.cache
3407 ./configure \
3408     --build=${CROSS_HOST} \
3409     --host=${CROSS_TARGET} \
3410     --libdir=/lib \
3411     --sysconfdir=/etc \
3412     --enable-shared \
3413     --without-audit \
3414     --without-libpam \
3415     --without-selinux \
3416     --cache-file=config.cache \
3417     --enable-man
3418 sed -i.orig '/man_MANS/s/$(man_nopam) //' man/ru/Makefile
3419 sed -i.orig 's/groups$(EXEEXT) //' src/Makefile
3420 for mkf in $(find man -name Makefile)
3421     do
3422     sed -i.orig -e '/groups.1.xml/d' -e 's/groups.1 //' ${mkf}
3423     done
3424 make
3425 make DESTDIR=${TARGET_DIR} install
3426 sed -i.orig -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \
3427     -e 's@/var/spool/mail@/var/mail@' \
3428     ${TARGET_DIR}/etc/login.defs
3429 ${CROSS_TARGET}-pwconv
3430 ${CROSS_TARGET}-grpconv
3431 cd ..
3432 rm -rf shadow-4.1.4.3
3433 cd
3434 @end verbatim
3435
3436 @c echo "ac_cv_func_setpgrp_void=yes" > config.cache
3437
3438 The option @option{--enable-man} is used to generate man pages.
3439
3440 The first call of @command{sed} removes @var{$(man_nopam)} on the line
3441 with man_MANS in @file{man/ru/Makefile.am} in order for @samp{make
3442 install} to complete.
3443
3444 The second call of @command{sed} disables the build of command
3445 @command{groups}, as coreutils already installed it.
3446
3447 The last call of @command{sed} enables support for MD5 encrypted
3448 passwords and changes the mail default directory from
3449 @file{/var/spool/mail} to @file{/var/mail}.
3450
3451 The @command{pwconv} command creates @file{shadow} file from file
3452 @file{passwd} and an optionally existing @file{shadow} file.
3453
3454 The @command{grpconv} command creates @file{gshadow} file from file
3455 @file{group} and an optionally existing @file{gshadow} file.
3456
3457
3458 @node Sysvinit
3459 @section Sysvinit
3460
3461 Sysvinit is the system-V style init process. Init is the first process
3462 started during booting. It is started by the kernel. Init continues
3463 running as a daemon until the system is shut down. It is the direct or
3464 indirect ancestor of all other processes and automatically adopts all
3465 orphaned processes.
3466
3467
3468 @verbatim
3469 # 1 minute
3470 tar xf ${DOWNLOAD_DIR}/sysvinit-2.88dsf.tar.bz2 -C ${BUILD_DIR}
3471 cd ${BUILD_DIR}/sysvinit-2.88dsf
3472 sed -i.orig -e 's@/dev/initctl@$(ROOT)&@g' \
3473     -e 's@\(mknod \)-m \([0-9]* \)\(.* \)p@\1\3p; chmod \2\3@g' \
3474     -e '/^ifeq/s/$(ROOT)//' \
3475     -e 's@/usr/lib@$(ROOT)/lib@' \
3476     src/Makefile
3477 make -C src clobber
3478 make -C src ROOT=${TARGET_DIR} CC="${CC}"
3479 make -C src ROOT=${TARGET_DIR} INSTALL="install" install
3480 cd ..
3481 rm -rf sysvinit-2.88dsf
3482 cd
3483
3484 cat > ${TARGET_DIR}/etc/inittab << EOF
3485 # Begin /etc/inittab
3486
3487 id:3:initdefault:
3488
3489 si::sysinit:/etc/rc.d/init.d/rc sysinit
3490
3491 l0:0:wait:/etc/rc.d/init.d/rc 0
3492 l1:S1:wait:/etc/rc.d/init.d/rc 1
3493 l2:2:wait:/etc/rc.d/init.d/rc 2
3494 l3:3:wait:/etc/rc.d/init.d/rc 3
3495 l4:4:wait:/etc/rc.d/init.d/rc 4
3496 l5:5:wait:/etc/rc.d/init.d/rc 5
3497 l6:6:wait:/etc/rc.d/init.d/rc 6
3498
3499 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
3500
3501 su:S016:once:/sbin/sulogin
3502
3503 1:2345:respawn:/sbin/agetty --noclear tty1 9600
3504 2:2345:respawn:/sbin/agetty tty2 9600
3505 #3:2345:respawn:/sbin/agetty tty3 9600
3506 #4:2345:respawn:/sbin/agetty tty4 9600
3507 #5:2345:respawn:/sbin/agetty tty5 9600
3508 #6:2345:respawn:/sbin/agetty tty6 9600
3509
3510 #c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100
3511
3512 # End /etc/inittab
3513 EOF
3514 @end verbatim
3515
3516 The first call of @command{sed} replaces @file{/dev/initctl} with
3517 @file{$(ROOT)/dev/initctl}, and @file{/usr/lib} with
3518 @file{$(ROOT)/lib} among other things in order to install sysvinit
3519 on the target system.
3520
3521 @samp{make -C src clobber} is used to clean up the @file{src}
3522 directory.
3523
3524 Then, we create the @file{inittab} file that describes which processes
3525 are started at bootup and during normal operation.
3526
3527 The line @samp{#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100} is
3528 commented out (with @code{#}) in order to avoid the message:
3529 @samp{INIT: Id "c0" respawning too fast: disabled for 5 minutes} on
3530 the target system.
3531
3532
3533 @node Tar
3534 @section Tar
3535
3536 GNU tar is an archiving utility: it stores and extracts files from a
3537 tape or disk archive.
3538
3539 @verbatim
3540 # 5 minutes
3541 tar xf ${DOWNLOAD_DIR}/tar-1.27.1.tar.bz2 -C ${BUILD_DIR}
3542 cd ${BUILD_DIR}/tar-1.27.1
3543 ./configure \
3544     --build=${CROSS_HOST} \
3545     --host=${CROSS_TARGET} \
3546     --prefix=
3547 make
3548 make DESTDIR=${TARGET_DIR} install
3549 cd ..
3550 rm -rf tar-1.27.1
3551 cd
3552 @end verbatim
3553
3554
3555 @node Texinfo
3556 @section Texinfo
3557
3558 GNU Texinfo is a documentation system that can produce both online
3559 information and a printed manual from a single source.
3560
3561 You need Ncurses headers on your system to compile this program from
3562 source. Under gNewSense 4.0, try @samp{sudo apt-get install
3563 libncurses5-dev}.
3564
3565 @verbatim
3566 # 10 minutes
3567 tar xf ${DOWNLOAD_DIR}/texinfo-4.13a.tar.gz -C ${BUILD_DIR}
3568 cd ${BUILD_DIR}/texinfo-4.13
3569 ./configure \
3570     --build=${CROSS_HOST} \
3571     --host=${CROSS_TARGET} \
3572     --prefix=
3573 make -C tools/gnulib/lib
3574 make -C tools
3575 make
3576 make DESTDIR=${TARGET_DIR} install
3577 cd ..
3578 rm -rf texinfo-4.13
3579 cd
3580
3581 cd ${TARGET_DIR}/share/info
3582 rm dir
3583 for f in *
3584     do install-info $f dir 2>/dev/null
3585 done
3586 cd
3587 @end verbatim
3588
3589 The first three calls of @command{make} make it possible to build
3590 Texinfo by cross-compilation.
3591
3592 For Info to work, the @file{info} directory must contain a file that
3593 serves as a top level directory for the Info system. By convention,
3594 this file is called @file{dir}. We update this file for the target
3595 system.
3596
3597
3598 @node Udev
3599 @section Udev
3600
3601 Udev is the dynamic device management of the kernel Linux.
3602
3603 You need Gperf on your system to compile this program from
3604 source. Under gNewSense 4.0, try @samp{sudo apt-get install gperf}.
3605
3606 @verbatim
3607 # 2 minutes
3608 tar xf ${DOWNLOAD_DIR}/udev-175.tar.gz -C ${BUILD_DIR}
3609 cd ${BUILD_DIR}/udev-175
3610 ./configure \
3611     --build=${CROSS_HOST} \
3612     --host=${CROSS_TARGET} \
3613     --prefix= \
3614     --with-rootlibdir=/lib \
3615     --libexecdir=/lib/udev \
3616     --docdir=/share/doc/udev-175 \
3617     --disable-introspection \
3618     --with-pci-ids-path=no \
3619     --with-usb-ids-path=no \
3620     --disable-gudev
3621 make
3622 make DESTDIR=${TARGET_DIR} install
3623 install -dv ${TARGET_DIR}/lib/firmware
3624 ln -sv ../lib/udev/udevd ${TARGET_DIR}/sbin/udevd
3625 cd ..
3626 rm -rf udev-175
3627 cd
3628 @end verbatim
3629
3630
3631 @node Util-Linux
3632 @section Util-Linux
3633
3634 util-linux is a random collection of utilities for use with the kernel
3635 Linux.
3636
3637 @quotation Warning
3638 If you have trouble building util-linux, try to uninstall the package
3639 named libtinfo-dev. Then remove @file{$@{BUILD_DIR@}/util-linux-2.24}
3640 and build it again.
3641 @end quotation
3642
3643 @verbatim
3644 # 5 minutes
3645 # fix /lib/libudev.so: error adding symbols: File in wrong format
3646 rm ${TARGET_DIR}/lib/libudev.la
3647
3648 tar xf ${DOWNLOAD_DIR}/util-linux-2.24.tar.bz2 -C ${BUILD_DIR}
3649 cd ${BUILD_DIR}/util-linux-2.24
3650 ./configure \
3651     --build=${CROSS_HOST} \
3652     --host=${CROSS_TARGET} \
3653     --enable-partx \
3654     --disable-wall \
3655     --enable-write \
3656     --disable-makeinstall-chown
3657 make
3658 make DESTDIR=${TARGET_DIR} install
3659 cd ..
3660 rm -r util-linux-2.24
3661 cd
3662 @end verbatim
3663
3664 Option @option{--enable-partx} enables the build and installation of
3665 the @command{addpart}, @command{delpart} and @command{partx} commands.
3666
3667 Option @option{--disable-wall} disables the build of the
3668 @command{wall} command which is already provided by sysvinit.
3669
3670 Option @option{--enable-write} enables the build and installation of
3671 the @command{write} command.
3672
3673 Option @option{--disable-makeinstall-chown} disables the change of
3674 owner to root for installed programs.
3675
3676
3677 @node XZ-Utils
3678 @section XZ-Utils
3679
3680 XZ Utils is a general-purpose data compression software with high
3681 compression ratio.
3682
3683 @verbatim
3684 # 2 minutes
3685 tar xf ${DOWNLOAD_DIR}/xz-5.0.8.tar.bz2 -C ${BUILD_DIR}
3686 cd ${BUILD_DIR}/xz-5.0.8
3687 ./configure \
3688     --build=${CROSS_HOST} \
3689     --host=${CROSS_TARGET} \
3690     --prefix=
3691 make
3692 make DESTDIR=${TARGET_DIR} install
3693 cd ..
3694 rm -rf xz-5.0.8
3695 cd
3696 @end verbatim
3697
3698
3699 @node Bootscripts
3700 @section Bootscripts
3701
3702 The bootscript archive contains scripts that manage services during
3703 system's bootup and shutdown.
3704
3705 @verbatim
3706 # 1 minute
3707 tar xf ${DOWNLOAD_DIR}/bootscripts-cross-lfs-2.0.0.tar.xz \
3708     -C ${BUILD_DIR}
3709 cd ${BUILD_DIR}/bootscripts-cross-lfs-2.0-pre2
3710 make DESTDIR=${TARGET_DIR} install-bootscripts
3711 make DESTDIR=${TARGET_DIR} install-network
3712 cd ..
3713 rm -rf bootscripts-cross-lfs-2.0-pre2
3714 cd
3715 @end verbatim
3716
3717 This installs basic bootscripts required for bootup and shutdown, and
3718 network-related bootscripts.
3719
3720
3721 @node Kernel
3722 @section The Kernel
3723
3724 Linux is a kernel aimed towards POSIX and Single UNIX Specification
3725 compliance.
3726
3727 You need Bc and Lzma on your system to compile this program from
3728 source. Under gNewSense 4.0, try @samp{sudo apt-get install bc lzma}.
3729
3730 @ignore
3731 @quotation Warning
3732 You may need to install the package libncurses5-dev to build the
3733 Kernel.
3734 @end quotation
3735 @end ignore
3736
3737 @verbatim
3738 # 35 minutes
3739 tar xf ${DOWNLOAD_DIR}/linux-libre-3.10.7-gnu.tar.xz \
3740     -C ${BUILD_DIR}
3741 cd ${BUILD_DIR}/linux-3.10
3742 make mrproper
3743 @end verbatim
3744
3745 The @command{sed} expression is used to avoid waiting 60 seconds for
3746 the binary-blob firmware to load at boot time, as those have been
3747 removed by the @file{deblob} script.
3748
3749 Then:
3750
3751 @verbatim
3752 cp arch/x86/configs/i386_defconfig .config
3753 #patch -Np1 -i ${DOWNLOAD_DIR}/100gnu+freedo.patch
3754 @end verbatim
3755
3756 Then, if you want to change the configuration:
3757
3758 @verbatim
3759 make ARCH=i386 CROSS_COMPILE=${CROSS_TARGET}- menuconfig
3760 @end verbatim
3761
3762 @quotation Note
3763 In order for GLLFSC to boot properly, you have to activate the two options
3764 below:
3765
3766 @verbatim
3767 Device Drivers
3768   > Generic Driver Options
3769     > [*] Maintain a devtmpfs fs to mount on /dev
3770     > [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs.
3771 @end verbatim
3772
3773 @ignore
3774 The second option is for runit
3775
3776 You can also disable bootup logos in
3777 _D_evice drivers > _G_raphics support > _B_ootup logo.
3778
3779 # _F_ile systems : stay with ext4 even with an ext3 partition
3780 @end ignore
3781 @end quotation
3782
3783 Then:
3784
3785 @verbatim
3786 make \
3787     ARCH=i386 \
3788     CROSS_COMPILE=${CROSS_TARGET}-
3789 make \
3790     ARCH=i386 \
3791     CROSS_COMPILE=${CROSS_TARGET}- \
3792     INSTALL_MOD_PATH=${TARGET_DIR} \
3793     modules_install
3794 cp arch/x86/boot/bzImage ${TARGET_DIR}/boot/vmlinuz-3.10.7-gnu
3795 cp System.map ${TARGET_DIR}/boot/System.map
3796 cp .config ${TARGET_DIR}/boot/config
3797 cd ..
3798 cd
3799 @end verbatim
3800
3801 @quotation Tip
3802 because future compilation may need kernel sources, the compilation
3803 directory of the kernel should be preserved.
3804 @end quotation
3805
3806
3807 @node Configuration Files
3808 @chapter Creating Required Configuration Files for the New System
3809
3810 @menu
3811 * Time Setup File::              File for time setup.
3812 * Bash Keyboard Setup::          Setting up keyboard function keys
3813                                    for the Shell.
3814 * Bash Startup Files::           Setting up Bash shell startup files.
3815 * Localhost Setup::              Setting up localhost.
3816 * hosts Setup::                  Setting up @file{hosts} file.
3817 * Network Address Setup::        Setting up network address.
3818 * DNS Setup::                    Setting up DNS.
3819 * fstab File Creation::          Creating @file{fstab} file.
3820 @end menu
3821
3822
3823 @node Time Setup File
3824 @section File for Time Setup
3825
3826 @verbatim
3827 #mkdir ${TARGET_DIR}/etc/sysconfig
3828 cat > ${TARGET_DIR}/etc/sysconfig/clock << EOF
3829 # Begin /etc/sysconfig/clock
3830
3831 UTC=1
3832
3833 # End /etc/sysconfig/clock
3834 EOF
3835 @end verbatim
3836
3837 If you have trouble with the clock behaviour, do:
3838
3839 @verbatim
3840 mv ${TARGET_DIR}/etc/rc.d/rcsysinit.d/S15setclock \
3841    ${TARGET_DIR}/etc/rc.d/rcsysinit.d/K15setclock
3842 @end verbatim
3843
3844
3845 @node Bash Keyboard Setup
3846 @section Setting up Keyboard Function keys for the Shell
3847
3848 Readline default configuration file is set:
3849
3850 @verbatim
3851 cat > ${TARGET_DIR}/etc/inputrc << EOF
3852 set bell-style none
3853 set convert-meta Off
3854 set horizontal-scroll-mode Off
3855 set input-meta On
3856 set output-meta On
3857 "\eOd": backward-word
3858 "\eOc": forward-word
3859 "\e[1~": beginning-of-line
3860 "\e[4~": end-of-line
3861 "\e[5~": beginning-of-history
3862 "\e[6~": end-of-history
3863 "\e[3~": delete-char
3864 "\e[2~": quoted-insert
3865 "\eOH": beginning-of-line
3866 "\eOF": end-of-line
3867 "\e[H": beginning-of-line
3868 "\e[F": end-of-line
3869 EOF
3870 @end verbatim
3871
3872 If @option{convert-meta} is set to @samp{on}, Readline will convert
3873 characters with the eighth bit set to an @sc{ascii} key sequence by
3874 stripping the eighth bit and prefixing an @key{ESC} character,
3875 converting them to a meta-prefixed key sequence.
3876
3877 @option{horizontal-scroll-mode} set to @samp{off} means that the text
3878 of the lines being edited will be wrapped onto a new screen line when
3879 they are longer than the width of the screen, instead of being
3880 scrolled horizontally on a single screen line.
3881
3882 @c set meta-flag On
3883
3884 @option{input-meta} If set to @samp{on}, Readline will enable
3885 eight-bit input (it will not clear the eighth bit in the characters it
3886 reads), regardless of what the terminal claims it can support.
3887
3888 If @option{output-meta} is set to @samp{on}, Readline will display
3889 characters with the eighth bit set directly rather than as a
3890 meta-prefixed escape sequence.
3891
3892 @ignore
3893 "\eOd": backward-word
3894 "\eOc": forward-word
3895 "\e[1~": beginning-of-line
3896 "\e[4~": end-of-line
3897 "\e[5~": beginning-of-history
3898 "\e[6~": end-of-history
3899 "\e[3~": delete-char
3900 "\e[2~": quoted-insert
3901 "\eOH": beginning-of-line
3902 "\eOF": end-of-line
3903 "\e[H": beginning-of-line
3904 "\e[F": end-of-line
3905 @end ignore
3906
3907
3908 @node Bash Startup Files
3909 @section Setting up Bash Shell Startup Files
3910
3911 @verbatim
3912 cat > ${TARGET_DIR}/etc/profile << 'EOF'
3913 # Begin /etc/profile
3914
3915 export LANG=en_US.UTF-8
3916 export INPUTRC=/etc/inputrc
3917 export PS1='\[\e[31m\]\A-\W\[\e[00m\]# '
3918
3919 # End /etc/profile
3920 EOF
3921 @end verbatim
3922
3923 The environment variable @env{LANG} defines the default language that
3924 should be used on the system. @samp{en_US.UTF-8} means ``english''
3925 language, country ``US'' and @acronym{UTF-8} (UCS Transformation
3926 Format—8-bit) encoding (Unicode).
3927
3928 @c For a full list, see???
3929
3930 For explanations on @env{PS1}, @pxref{Environment Variables Setup}.
3931
3932
3933 @node Localhost Setup
3934 @section Localhost Setup
3935
3936 @verbatim
3937 echo "HOSTNAME=gllfsc" > ${TARGET_DIR}/etc/sysconfig/network
3938 @end verbatim
3939
3940
3941 @node hosts Setup
3942 @section Setting up @file{hosts} File
3943
3944 @verbatim
3945 cat > ${TARGET_DIR}/etc/hosts << EOF
3946 # Begin /etc/hosts
3947
3948 127.0.0.1 gllfsc localhost
3949
3950 # End /etc/hosts
3951 EOF
3952 @end verbatim
3953
3954
3955 @node Network Address Setup
3956 @section Setting up Network Address
3957
3958 You can choose to have a network static or dynamic address.
3959
3960 @menu
3961 * Network Static Address Setup::    Setting up Network Static Address.
3962 * Network Dynamic Address Setup::   Setting up Network Dynamic
3963                                       Address.
3964 @end menu
3965
3966
3967 @node Network Static Address Setup
3968 @subsection Setting up Network Static Address
3969
3970 @verbatim
3971 cd ${TARGET_DIR}/etc/sysconfig/network-devices
3972 mkdir -v ifconfig.eth0
3973 cat > ifconfig.eth0/ipv4 << EOF
3974 ONBOOT=yes
3975 SERVICE=ipv4-static
3976 IP=192.168.1.1
3977 GATEWAY=192.168.1.2
3978 PREFIX=24
3979 BROADCAST=192.168.1.255
3980 EOF
3981 cd
3982 @end verbatim
3983
3984 @quotation Warning
3985 @code{IP}, @code{GATEWAY}, @code{BROADCAST} addresses are set up
3986 according to one's situation.
3987 @end quotation
3988
3989
3990 @node Network Dynamic Address Setup
3991 @subsection Setting up Network Dynamic Address
3992
3993 @verbatim
3994 cd ${TARGET_DIR}/etc/sysconfig/network-devices
3995 mkdir -v ifconfig.eth0
3996 cat > ifconfig.eth0/dhcpcd << EOF
3997 ONBOOT=yes
3998 SERVICE=dhcpcd
3999 DHCP_START="-q"
4000 DHCP_STOP="-k"
4001 EOF
4002 cd
4003 @end verbatim
4004
4005
4006 @node DNS Setup
4007 @section Setting up DNS
4008
4009 @verbatim
4010 cat > ${TARGET_DIR}/etc/resolv.conf << EOF
4011 # Begin /etc/resolv.conf
4012
4013 nameserver your-main-DNS-address
4014 nameserver your-secondary-DNS-address
4015
4016 # End /etc/resolv.conf
4017 EOF
4018 @end verbatim
4019
4020
4021 @node fstab File Creation
4022 @section @file{fstab} File Creation
4023
4024 The file @file{/etc/fstab} is used at boot to mount partitions under
4025 the requested directories.
4026
4027 @verbatim
4028 cat > ${TARGET_DIR}/etc/fstab << EOF
4029 # Begin /etc/fstab
4030
4031 # file system    mount-point  type     options        dump  fsck order
4032
4033 /dev/sda1        /            ext3     defaults        0    0
4034 #/dev/sda7        /home        ext3     defaults        0    0
4035 /dev/sda5        swap         swap     pri=1           0    0
4036 devtmpfs         /dev         dev      defaults        0    0
4037 proc             /proc        proc     defaults        0    0
4038 tmpfs            /run         run      defaults        0    0
4039 sysfs            /sys         sysfs    defaults        0    0
4040 devpts           /dev/pts     devpts   gid=4,mode=620  0    0
4041 shm              /dev/shm     tmpfs    defaults        0    0
4042
4043 # End /etc/fstab
4044 EOF
4045 @end verbatim
4046
4047 @quotation Warning
4048 the name of the hard drive and the name of filesystem used here have
4049 to be modified to reflect @emph{your} real situation.
4050 @end quotation
4051
4052
4053 @node Before Booting GLLFSC
4054 @chapter Before Booting GLLFSC
4055
4056 @menu
4057 * Archiving::                        All the system archived in one
4058                                      package.
4059 * Recommendations::                  Some tips.
4060 @end menu
4061
4062
4063 @node Archiving
4064 @section Archiving the System
4065
4066 After the system has been completed, we use the command @command{exit}
4067 to logout as the @emph{gllfsc} user.
4068
4069 Now, login as the @emph{root} user.
4070
4071 Then fix the permissions on the new system:
4072
4073 @verbatim
4074 export TARGET_DIR=/gllfsc
4075 cd ${TARGET_DIR}
4076 mknod -m 600 dev/console c 5 1
4077 mknod -m 666 dev/null c 1 3
4078 cp -a dev/{console,null} lib/udev/devices/
4079 #chown -R root:root *
4080 chown -R root:root \
4081     bin boot dev etc home include lib* local man mnt proc root run \
4082     sbin share src static sys tmp usr var
4083 @end verbatim
4084
4085 Also copy packages to be built after reboot:
4086
4087 @verbatim
4088 export DOWNLOAD_DIR="${TARGET_DIR}/download"
4089 for FILE in \
4090     tzcode2013h.tar.gz \
4091     tzdata2013h.tar.gz \
4092     runit-2.1.2.tar.gz \
4093     openssl-1.0.1i.tar.gz \
4094     wpa_supplicant-2.0.tar.gz \
4095     wireless_tools.29.tar.gz \
4096     wget-1.14.tar.gz \
4097     perl-5.18.1.tar.gz \
4098     libtasn1-3.4.tar.gz \
4099     lynx2.8.8dev.16.tar.bz2 \
4100     certdata.txt \
4101     inetutils-1.9.1.tar.gz \
4102     man-db-2.6.7.1.tar.xz; do
4103 cp -v ${DOWNLOAD_DIR}/$FILE ${TARGET_DIR}/src
4104 done
4105 @end verbatim
4106
4107 We archive the entire system by using the following command:
4108
4109 @verbatim
4110 # 8 minutes
4111 tar -cjf gllfsc-pentium4-1.7.tar.bz2 \
4112     bin boot dev etc home include lib* local man mnt proc root run \
4113     sbin share src static sys tmp usr var
4114 @end verbatim
4115
4116 It is then simple to copy the archive to the target machine and extract
4117 it.
4118
4119
4120 @node Recommendations
4121 @section Some Recommendations
4122
4123 We recommend extracting the system to an empty partition. Moreover,
4124 the filesystem of the chosen partition has to be a filesystem
4125 supported by the kernel you compiled. Finally, this partition has to
4126 be consistent with the system description in the file
4127 @file{/etc/fstab} you created during setup (@pxref{fstab File
4128 Creation}).
4129
4130 @ignore
4131
4132 extlinux
4133 lilo
4134
4135 @verbatim
4136 # ? minute
4137 tar xf ${DOWNLOAD_DIR}/grub-2.00.tar.gz \
4138     -C ${BUILD_DIR}
4139 cd ${BUILD_DIR}/grub-2.00
4140 sed -i '/gets is a security hole/d' grub-core/gnulib/stdio.in.h
4141 ./configure \
4142     --build=${CROSS_HOST} \
4143     --host=${CROSS_TARGET} \
4144     --prefix=
4145 make
4146 make DESTDIR=${TARGET_DIR} install
4147 cd ..
4148 rm -rf grub-2.00
4149 cd
4150
4151 mkdir ${TARGET_DIR}/boot/grub
4152 @end verbatim
4153 @end ignore
4154
4155 Then, you will have to edit the GRUB configuration file of the target
4156 machine: @file{/boot/grub/grub.cfg}.
4157
4158 @c ?This file has to be put on the first partition of the hard drive.
4159
4160 @c GRUB sur /dev/sda1 >= 1MB
4161 @c mount ... /mnt/boot && grub-install --boot-directory=/mnt/boot /dev/sda
4162 @c grub-script-check
4163
4164 @ignore
4165 @quotation Note
4166 ?On the Yeeloong 8133, vmlinuz @emph{must} be on the first primary
4167 partition to be able to boot.
4168 @end quotation
4169
4170 # Install in the MBR
4171 #grub-install /dev/sda
4172 # Install in the OS partition
4173 grub-install /dev/sda1
4174 @end ignore
4175
4176 A minimal @file{/boot/grub/grub.cfg} could be:
4177
4178 @verbatim
4179 insmod ext2
4180 set default=0
4181 set root=(hd0,1)
4182 set timeout=5
4183
4184 menuentry 'GLLFSC 1.7' {
4185     echo 'Loading linux-libre-3.10.7-gnu...'
4186     linux (hd0,1)/boot/vmlinuz-3.10.7-gnu root=/dev/sda1 quiet
4187 }
4188 @end verbatim
4189
4190 @c Or use grub-mkconfig -o /boot/grub/grub.cfg
4191
4192
4193 @node After Booting GLLFSC
4194 @chapter After Booting GLLFSC
4195
4196 Some system configuration and package installation can only be made
4197 after booting onto the new system.
4198
4199 @menu
4200 * Login::             Login onto GLLFSC.
4201 * Locales::           Configure the language of GLLFSC.
4202 * Timezone::          Building Tzcode, Tzdata and choosing timezone.
4203 * Runit::             Building Runit.
4204 * Perl::              Building Perl.
4205 * OpenSSL::           Building OpenSSL.
4206 * Wpa_supplicant::    Building Wpa_supplicant.
4207 * Wireless_tools::    Building Wireless_tools.
4208 * Wget::              Building Wget.
4209 * Libtasn1::          Building Libtasn1.
4210 * Lynx::              Building Lynx.
4211 * CA-Certificates::   Building CA-Certificates.
4212 * Inetutils 2::       Building Inetutils under GLLFSC.
4213 * Man-db 2::          Building Man-db under GLLFSC.
4214 * Archiving Complete System:: Archiving the Complete System.
4215 * Add User::          Creating a New User Account.
4216 * Halting Computer::  Halting the Computer
4217 @end menu
4218
4219
4220 @node Login
4221 @section Login
4222
4223 To login as @emph{root}, just type @samp{root} when the system asks
4224 for your @samp{login:}. Then, update your bash profile:
4225
4226 @quotation Note
4227 To use the french keyboard layout, type @samp{loadkeys -q fr}.
4228 @end quotation
4229
4230 @verbatim
4231 cat > ~/.bash_profile << EOF
4232 export BUILD_DIR=/tmp
4233 export DOWNLOAD_DIR=/src
4234 EOF
4235
4236 source ~/.bash_profile
4237 @end verbatim
4238
4239
4240 @node Locales
4241 @section Locales
4242
4243 You may want to have your new system display messages in your native
4244 language. If you desire to have a system supporting german, US
4245 english, french and China mainland's chinese:
4246
4247 @verbatim
4248 mkdir /lib/locale
4249
4250 #localedef -i de_DE -f UTF-8 de_DE
4251 localedef -i en_US -f UTF-8 en_US
4252 #localedef -i fr_FR -f UTF-8 fr_FR
4253 #localedef -i zh_CN -f UTF-8 zh_CN
4254 @end verbatim
4255
4256 Other locales are available:
4257
4258 @itemize
4259 @item
4260 For available charmaps, see the content of @file{/share/i18n/charmaps}.
4261
4262 @item
4263 For available locales, see the content of @file{/share/i18n/locales}.
4264
4265 @end itemize
4266
4267
4268 @node Timezone
4269 @section Timezone
4270
4271 In order to have the time and date corresponding to the area where you
4272 live, you should build tzcode, tzdata and define your timezone.
4273
4274 @verbatim
4275 mkdir ${BUILD_DIR}/tz
4276 tar xf ${DOWNLOAD_DIR}/tzcode2013h.tar.gz -C ${BUILD_DIR}/tz
4277 tar xf ${DOWNLOAD_DIR}/tzdata2013h.tar.gz -C ${BUILD_DIR}/tz
4278 cd ${BUILD_DIR}/tz
4279
4280 make \
4281     TOPDIR=/ \
4282     TZDIR=/share/zoneinfo \
4283     ETCDIR=/bin
4284
4285 for TZ in africa antarctica asia australasia europe northamerica \
4286           southamerica pacificnew etcetera backward systemv factory \
4287           solar87 solar88 solar89; do
4288     zic -y "sh yearistype.sh" \
4289         -d /share/zoneinfo \
4290         -L /dev/null $TZ
4291 done
4292
4293 zic -y "bash yearistype.sh" \
4294     -d /share/zoneinfo \
4295     -l GMT \
4296     -p America/New_York
4297
4298 cp iso3166.tab zone.tab /share/zoneinfo
4299 cd ..
4300 rm -rf tz
4301 cd
4302 @end verbatim
4303
4304 Then, we define our timezone, in this case @file{Europe/Paris}:
4305
4306 @verbatim
4307 cp -v --remove-destination \
4308     /share/zoneinfo/Europe/Paris \
4309     /etc/localtime
4310 @end verbatim
4311
4312
4313 @node Runit
4314 @section Runit
4315
4316 runit is a cross-platform Unix init scheme with service supervision, a
4317 replacement for sysvinit, and other init schemes.
4318
4319
4320 @verbatim
4321 tar xf ${DOWNLOAD_DIR}/runit-2.1.2.tar.gz -C ${BUILD_DIR}
4322 cd ${BUILD_DIR}/admin/runit-2.1.2
4323
4324 # On GLLFSC, sleep is not under /bin:
4325 sed -i 's,/bin/sleep,sleep,' etc/debian/ctrlaltdel
4326
4327 cd src
4328
4329 make
4330 make check
4331
4332 install -s -m0755 \
4333     chpst runit runit-init runsv runsvchdir runsvdir sv svlogd utmpset \
4334     /sbin
4335
4336 install -m0644 ../man/* \
4337     /share/man/man8
4338
4339 cd ..
4340
4341 mkdir /etc/runit
4342
4343 mkdir /service
4344
4345 cp etc/debian/ctrlaltdel /etc/runit/
4346
4347 mv /sbin/init /sbin/init.sysv
4348 ln -sv runit-init /sbin/init
4349
4350 cd ../..
4351 rm -rf admin
4352 cd
4353 @end verbatim
4354
4355 The init-related programs have been installed. We need to create the
4356 boot scripts too: @file{/etc/runit/1} to boot the system,
4357 @file{/etc/runit/2} to launch 2 ttys and the service logging daemon
4358 and @file{/etc/runit/3} to halt or reboot the system.
4359
4360 @verbatim
4361 cat > /etc/runit/1 << 'EOF'
4362 #!/bin/sh
4363 # system one time tasks
4364
4365 # Exit on error:
4366 set -e
4367
4368 PATH=/bin
4369
4370 echo -n '16. Mounting kernel-based file systems:'
4371 echo -n ' /proc'
4372 mount -n -o nosuid,noexec,nodev -t proc proc /proc
4373 echo -n ' /sys'
4374 mount -n -o nosuid,noexec,nodev -t sysfs sys /sys
4375 echo ' /run'
4376 mount -n -o mode=0755,nosuid,nodev -t tmpfs run /run
4377
4378 echo -n '15. Creating directories:'
4379 echo -n ' /run/lock'
4380 mkdir -m 1777 /run/lock
4381 echo -n ' /dev/pts'
4382 mkdir -p /dev/pts
4383 echo ' /dev/shm'
4384 mkdir -p /dev/shm
4385
4386 echo '14. Mounting root file system in read-write mode.'
4387 mount -n -o remount,rw / >/dev/null
4388
4389 # Remove fsck-related system watermarks.
4390 rm -f /fastboot /forcefsck
4391
4392 echo '13. Recording existing mounts in /etc/mtab.'
4393 > /etc/mtab
4394 mount -f /
4395 mount -f /proc
4396 mount -f /sys
4397 mount -f /run
4398 mount -f /dev
4399
4400 echo '12. Mounting remaining file systems.'
4401 mount -a -r >/dev/null
4402
4403 echo '11. Cleaning file system /tmp.'
4404 cd /tmp && find . -xdev -mindepth 1 ! -name lost+found -delete
4405
4406 echo '10. Creating /var/run/utmp.'
4407 if grep -q '^utmp:' /etc/group; then
4408     chmod 664 /var/run/utmp
4409     chgrp utmp /var/run/utmp
4410 fi
4411
4412 echo '9. Starting udevd...'
4413 echo '' > /sys/kernel/uevent_helper
4414
4415 /lib/udev/udevd --daemon
4416
4417 echo '8. Performing Coldplugging...'
4418 /sbin/udevadm trigger --action=add --type=subsystems
4419 /sbin/udevadm trigger --action=add --type=devices
4420
4421 /sbin/udevadm settle
4422
4423 echo '7. Activating all swap files/partitions...'
4424 swapon -a
4425
4426 echo '6. Setting Font...'
4427 setfont LatArCyrHeb-16 -C /dev/tty2
4428 setfont LatArCyrHeb-16 -C /dev/tty3
4429
4430 echo '5. Setting keymap to UTF-8...'
4431 dumpkeys | loadkeys --unicode
4432
4433 echo '4. Enabling Multibyte input...'
4434 kbd_mode -u
4435
4436 echo '3. Setting up US Keymap...'
4437 loadkeys -q us
4438
4439 echo '2. Setting encoding to UTF-8...'
4440 echo -ne $'\033%G' > /dev/tty2
4441 echo -ne $'\033%G' > /dev/tty3
4442
4443 echo '1. Bringing up the loopback interface...'
4444 ip addr add 127.0.0.1/8 label lo dev lo
4445 ip link set lo up
4446
4447 echo '0. Setting hostname to gllfsc...'
4448 hostname gllfsc
4449
4450 echo
4451 echo To login, remember:
4452 echo your login is root
4453 echo with no password
4454 echo
4455 echo You can now login through tty2 by pressing simultaneously
4456 echo Ctrl, Alt and F2 keys
4457 echo
4458 echo You can then come back to this screen \(tty1\) by pressing
4459 echo simultaneously Ctrl, Alt and F1 keys
4460 echo
4461 echo Edit /etc/runit/1 if you want to remove this message
4462 echo
4463
4464 touch /etc/runit/stopit
4465 chmod 0 /etc/runit/stopit
4466
4467 exit 0
4468 EOF
4469
4470 chmod +x /etc/runit/1
4471 @end verbatim
4472
4473 @verbatim
4474 cat > /etc/runit/2 << EOF
4475 #!/bin/sh
4476
4477 PATH=/bin
4478
4479 exec env -i PATH=/bin \
4480 runsvdir -P /service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'
4481 EOF
4482
4483 chmod +x /etc/runit/2
4484 @end verbatim
4485
4486 @verbatim
4487 cat > /etc/runit/3 << EOF
4488 #!/bin/sh
4489
4490 # Exit on error:
4491 set -e
4492
4493 exec 2>&1
4494
4495 PATH=/bin
4496
4497 echo '4. Waiting for services to stop...'
4498 sv down /service/*
4499
4500 echo '3. Exiting services...'
4501 sv exit /service/*
4502
4503 echo '2. Deactivating all swap files/partitions...'
4504 swapoff -a
4505
4506 # Unmount everything but /:
4507 echo -n '1. Unmounting filesystems: /home'
4508 umount -r /home
4509 echo -n ' /proc'
4510 umount -r /proc
4511 echo -n ' /sys'
4512 umount -r /sys
4513 echo -n ' /dev/pts'
4514 umount -r /dev/pts
4515 echo ' /dev/shm'
4516 umount -r /dev/shm
4517
4518 echo '0. Shutdown...'
4519
4520 exit 0
4521 EOF
4522
4523 chmod +x /etc/runit/3
4524 @end verbatim
4525
4526 We now create useful services:
4527
4528 @verbatim
4529 mkdir /etc/sv
4530 mkdir /etc/sv/getty-2
4531
4532 cat > /etc/sv/getty-2/run << EOF
4533 #!/bin/sh
4534 exec /sbin/agetty tty2 9600
4535 EOF
4536 chmod +x /etc/sv/getty-2/run
4537
4538 cat > /etc/sv/getty-2/finish << EOF
4539 #!/bin/sh
4540 exec utmpset -w tty2
4541 EOF
4542 chmod +x /etc/sv/getty-2/finish
4543
4544 ln -sv /etc/sv/getty-2 /service/getty-2
4545
4546
4547 mkdir -p /etc/sv/getty-3
4548
4549 cat > /etc/sv/getty-3/run << EOF
4550 #!/bin/sh
4551 exec /sbin/agetty tty3 9600
4552 EOF
4553 chmod +x /etc/sv/getty-3/run
4554
4555 cat > /etc/sv/getty-3/finish << EOF
4556 #!/bin/sh
4557 exec utmpset -w tty3
4558 EOF
4559 chmod +x /etc/sv/getty-3/finish
4560
4561 ln -sv /etc/sv/getty-3 /service/getty-3
4562
4563
4564 mkdir /etc/sv/svlogd
4565
4566 cat > /etc/sv/svlogd/run << EOF
4567 #!/bin/sh
4568 exec svlogd
4569 EOF
4570 chmod +x /etc/sv/svlogd/run
4571
4572 ln -sv /etc/sv/svlogd /service/svlogd
4573 @end verbatim
4574
4575
4576 @node Perl
4577 @section Perl
4578
4579 Perl is a high-level programming language.
4580
4581 @quotation Note
4582 You may have to type @samp{exit} twice during the configure phase of
4583 the Perl installation.
4584 @end quotation
4585
4586 @verbatim
4587 tar xf ${DOWNLOAD_DIR}/perl-5.18.1.tar.gz -C ${BUILD_DIR}
4588 cd ${BUILD_DIR}/perl-5.18.1
4589 sh Configure -ds -e -Dprefix=
4590 make
4591 make install
4592 cd ..
4593 rm -rf perl-5.18.1
4594 cd
4595 @end verbatim
4596
4597
4598 @node OpenSSL
4599 @section OpenSSL
4600
4601 OpenSSL is a toolkit implementing the Transport Layer Security (TLS)
4602 and Secure Sockets Layer (SSL) protocols as well as a cryptography
4603 library.
4604
4605 @verbatim
4606 tar xf ${DOWNLOAD_DIR}/openssl-1.0.1i.tar.gz -C ${BUILD_DIR}
4607 cd ${BUILD_DIR}/openssl-1.0.1i
4608 ./config \
4609     --prefix=/usr \
4610     --openssldir=/etc/ssl \
4611     shared
4612 make -j1
4613 # Install without the documentation:
4614 make install_sw
4615 cd ..
4616 rm -rf openssl-1.0.1i
4617 cd
4618 @end verbatim
4619
4620
4621 @node Wpa_supplicant
4622 @section Wpa_supplicant
4623
4624 Wpa_supplicant is a user space IEEE 802.1X/WPA supplicant (wireless
4625 client) for many wireless drivers.
4626
4627 @verbatim
4628 # 2 minutes
4629 tar xf ${DOWNLOAD_DIR}/wpa_supplicant-2.0.tar.gz -C ${BUILD_DIR}
4630 cd ${BUILD_DIR}/wpa_supplicant-2.0/wpa_supplicant
4631
4632 cat > .config << EOF
4633 CONFIG_DRIVER_HOSTAP=y
4634 CONFIG_DRIVER_WEXT=y
4635 #CONFIG_DRIVER_NL80211=y
4636 #CONFIG_DRIVER_WIRED=y
4637
4638 #CONFIG_PKCS12=y
4639 #CONFIG_SMARTCARD=y
4640
4641 CONFIG_CTRL_IFACE=y
4642
4643 CONFIG_BACKEND=file
4644 CONFIG_PEERKEY=y
4645 #CONFIG_IEEE80211W=y
4646
4647 CONFIG_TLS=openssl
4648
4649 #CONFIG_IEEE80211N=y
4650 EOF
4651
4652 sed -i.orig 's@local/@@g' Makefile
4653 make
4654 make install
4655 cd ../..
4656 rm -rf wpa_supplicant-2.0
4657 cd
4658
4659 cat > /etc/wpa_supplicant.conf << EOF
4660 network={
4661     ssid="MYESSID"
4662     key_mgmt=WPA-PSK
4663     pairwise=TKIP
4664     group=TKIP
4665     psk="MYPASSWORD"
4666 }
4667 EOF
4668 chmod 600 /etc/wpa_supplicant.conf
4669 @end verbatim
4670
4671
4672 @node Wireless_tools
4673 @section Wireless_tools
4674
4675 The Wireless Tools is a set of tools allowing to manipulate the
4676 Wireless Extensions.
4677
4678 @verbatim
4679 # 1 minute
4680 tar xf ${DOWNLOAD_DIR}/wireless_tools.29.tar.gz -C ${BUILD_DIR}
4681 cd ${BUILD_DIR}/wireless_tools.29
4682 make
4683 make PREFIX= install
4684 cd ..
4685 rm -rf wireless_tools.29
4686 cd
4687 @end verbatim
4688
4689
4690 @ignore
4691 Launch wireless connection:
4692
4693 ifconfig wlan0 up
4694 iwconfig wlan0 essid MYESSID
4695 sleep 10s
4696 dhcpcd wlan0
4697 @end ignore
4698
4699
4700 @node Wget
4701 @section Wget
4702
4703 GNU wget is an utility for downloading network data.
4704
4705 @verbatim
4706 # 5 minutes
4707 tar xf ${DOWNLOAD_DIR}/wget-1.14.tar.gz -C ${BUILD_DIR}
4708 cd ${BUILD_DIR}/wget-1.14
4709 sed -i.orig 's/item $thing/item C<$thing>/' doc/texi2pod.pl
4710 ./configure \
4711     --prefix= \
4712     --with-ssl=openssl
4713 make
4714 make install
4715 cd ..
4716 rm -rf wget-1.14
4717 cd
4718 @end verbatim
4719
4720
4721 @node Libtasn1
4722 @section Libtasn1
4723
4724 GNU libtasn1 is a ASN.1 library.
4725
4726 @verbatim
4727 tar xf ${DOWNLOAD_DIR}/libtasn1-3.4.tar.gz -C ${BUILD_DIR}
4728 cd ${BUILD_DIR}/libtasn1-3.4
4729 ./configure \
4730     --prefix=
4731 make
4732 make install
4733 cd ..
4734 rm -rf libtasn1-3.4
4735 cd
4736 @end verbatim
4737
4738
4739 @node Lynx
4740 @section Lynx
4741
4742 Lynx is a text web browser.
4743
4744 @verbatim
4745 tar xf ${DOWNLOAD_DIR}/lynx2.8.8dev.16.tar.bz2 -C ${BUILD_DIR}
4746 cd ${BUILD_DIR}/lynx2-8-8
4747 ./configure \
4748     --prefix= \
4749     --with-ssl=/lib \
4750     --enable-nls \
4751     --with-screen=ncursesw
4752 make
4753 make install
4754 cd ..
4755 rm -rf lynx2-8-8
4756
4757 # Stop asking questions about certificates:
4758 sed -i s/#FORCE_SSL_PROMPT:PROMPT/FORCE_SSL_PROMPT:yes/ \
4759     /etc/lynx.cfg
4760
4761 # Display non-ascii characters:
4762 sed -i s/#CHARACTER_SET:iso-8859-1/CHARACTER_SET:utf-8/  \
4763     /etc/lynx.cfg
4764
4765 # I don't want cookies:
4766 sed -i 's/#SET_COOKIES:TRUE/SET_COOKIES:FALSE/'  \
4767     /etc/lynx.cfg
4768 sed -i 's/#ACCEPT_ALL_COOKIES:FALSE/ACCEPT_ALL_COOKIES:FALSE/'  \
4769     /etc/lynx.cfg
4770 sed -i 's/#PERSISTENT_COOKIES:FALSE/PERSISTENT_COOKIES:FALSE/'  \
4771     /etc/lynx.cfg
4772 cd
4773 @end verbatim
4774
4775
4776 @node CA-Certificates
4777 @section CA-Certificates
4778
4779 CA-Certificates are used for https web pages.
4780
4781 @verbatim
4782 # Inspired from
4783 # http://linuxfromscratch.org/blfs/view/stable/postlfs/cacerts.html
4784
4785 cp ${DOWNLOAD_DIR}/certdata.txt ${BUILD_DIR}
4786 cd ${BUILD_DIR}
4787
4788 cat > /bin/make-cert.pl << 'EOF'
4789 #!/bin/perl -w
4790
4791 # Used to generate PEM encoded files from Mozilla certdata.txt.
4792 # Run as ./make-cert.pl > certificate.crt
4793 #
4794 # Parts of this script courtesy of RedHat (mkcabundle.pl)
4795 #
4796 # This script modified for use with single file data (tempfile.cer)
4797 # extracted from certdata.txt, taken from the latest version in the
4798 # Mozilla NSS source.
4799 # mozilla/security/nss/lib/ckfw/builtins/certdata.txt
4800 #
4801 # Authors: DJ Lucas
4802 #          Bruce Dubbs
4803 #
4804 # Version 20120211
4805
4806 my $certdata = './tempfile.cer';
4807
4808 open( IN, "cat $certdata|" )
4809     || die "could not open $certdata";
4810
4811 my $incert = 0;
4812
4813 while ( <IN> )
4814 {
4815     if ( /^CKA_VALUE MULTILINE_OCTAL/ )
4816     {
4817         $incert = 1;
4818         open( OUT, "|openssl x509 -text -inform DER -fingerprint" )
4819             || die "could not pipe to openssl x509";
4820     }
4821
4822     elsif ( /^END/ && $incert )
4823     {
4824         close( OUT );
4825         $incert = 0;
4826         print "\n\n";
4827     }
4828
4829     elsif ($incert)
4830     {
4831         my @bs = split( /\\/ );
4832         foreach my $b (@bs)
4833         {
4834             chomp $b;
4835             printf( OUT "%c", oct($b) ) unless $b eq '';
4836         }
4837     }
4838 }
4839 EOF
4840
4841 chmod +x /bin/make-cert.pl
4842
4843
4844
4845 cat > /bin/make-ca.sh << 'EOF'
4846 #!/bin/sh
4847 # Begin make-ca.sh
4848 # Script to populate OpenSSL's CApath from a bundle of PEM formatted
4849 # CAs
4850 #
4851 # The file certdata.txt must exist in the local directory
4852 # Version number is obtained from the version of the data.
4853 #
4854 # Authors: DJ Lucas
4855 #          Bruce Dubbs
4856 #
4857 # Version 20120211
4858
4859 certdata="certdata.txt"
4860
4861 if [ ! -r $certdata ]; then
4862   echo "$certdata must be in the local directory"
4863   exit 1
4864 fi
4865
4866 REVISION=$(grep CVS_ID $certdata | cut -f4 -d'$')
4867
4868 if [ -z "${REVISION}" ]; then
4869   echo "$certfile has no 'Revision' in CVS_ID"
4870   exit 1
4871 fi
4872
4873 VERSION=$(echo $REVISION | cut -f2 -d" ")
4874
4875 TEMPDIR=$(mktemp -d)
4876 TRUSTATTRIBUTES="CKA_TRUST_SERVER_AUTH"
4877 BUNDLE="BLFS-ca-bundle-${VERSION}.crt"
4878 CONVERTSCRIPT="/bin/make-cert.pl"
4879 SSLDIR="/etc/ssl"
4880
4881 mkdir "${TEMPDIR}/certs"
4882
4883 # Get a list of starting lines for each cert
4884 CERTBEGINLIST=$(grep -n "^# Certificate" "${certdata}" | cut -d ":" -f1)
4885
4886 # Get a list of ending lines for each cert
4887 CERTENDLIST=$(grep -n "^CKA_TRUST_STEP_UP_APPROVED" "${certdata}" \
4888     | cut -d ":" -f 1)
4889
4890 # Start a loop
4891 for certbegin in ${CERTBEGINLIST}; do
4892   for certend in ${CERTENDLIST}; do
4893     if test "${certend}" -gt "${certbegin}"; then
4894       break
4895     fi
4896   done
4897
4898   # Dump to a temp file with the name of the file as the beginning
4899   # line number
4900   sed -n "${certbegin},${certend}p" "${certdata}" \
4901       > "${TEMPDIR}/certs/${certbegin}.tmp"
4902 done
4903
4904 unset CERTBEGINLIST CERTDATA CERTENDLIST certbegin certend
4905
4906 mkdir -p certs
4907 rm -f certs/*      # Make sure the directory is clean
4908
4909 for tempfile in ${TEMPDIR}/certs/*.tmp; do
4910   # Make sure that the cert is trusted...
4911   grep "CKA_TRUST_SERVER_AUTH" "${tempfile}" | \
4912     egrep "TRUST_UNKNOWN|NOT_TRUSTED" > /dev/null
4913
4914   if test "${?}" = "0"; then
4915     # Throw a meaningful error and remove the file
4916     cp "${tempfile}" tempfile.cer
4917     perl ${CONVERTSCRIPT} > tempfile.crt
4918     keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
4919     echo "Certificate ${keyhash} is not trusted!  Removing..."
4920     rm -f tempfile.cer tempfile.crt "${tempfile}"
4921     continue
4922   fi
4923
4924   # If execution made it to here in the loop, the temp cert is trusted
4925   # Find the cert data and generate a cert file for it
4926
4927   cp "${tempfile}" tempfile.cer
4928   perl ${CONVERTSCRIPT} > tempfile.crt
4929   keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
4930   mv tempfile.crt "certs/${keyhash}.pem"
4931   rm -f tempfile.cer "${tempfile}"
4932   echo "Created ${keyhash}.pem"
4933 done
4934
4935 # Remove blacklisted files
4936 # MD5 Collision Proof of Concept CA
4937 if test -f certs/8f111d69.pem; then
4938   echo "Certificate 8f111d69 is not trusted!  Removing..."
4939   rm -f certs/8f111d69.pem
4940 fi
4941
4942 # Finally, generate the bundle and clean up.
4943 cat certs/*.pem >  ${BUNDLE}
4944 rm -r "${TEMPDIR}"
4945 EOF
4946
4947 chmod +x /bin/make-ca.sh
4948
4949
4950
4951 cat > /bin/remove-expired-certs.sh << 'EOF'
4952 #!/bin/sh
4953 # Begin /bin/remove-expired-certs.sh
4954 #
4955 # Version 20120211
4956
4957 # Make sure the date is parsed correctly on all systems
4958 mydate()
4959 {
4960   local y=$( echo $1 | cut -d" " -f4 )
4961   local M=$( echo $1 | cut -d" " -f1 )
4962   local d=$( echo $1 | cut -d" " -f2 )
4963   local m
4964
4965   if [ ${d} -lt 10 ]; then d="0${d}"; fi
4966
4967   case $M in
4968     Jan) m="01";;
4969     Feb) m="02";;
4970     Mar) m="03";;
4971     Apr) m="04";;
4972     May) m="05";;
4973     Jun) m="06";;
4974     Jul) m="07";;
4975     Aug) m="08";;
4976     Sep) m="09";;
4977     Oct) m="10";;
4978     Nov) m="11";;
4979     Dec) m="12";;
4980   esac
4981
4982   certdate="${y}${m}${d}"
4983 }
4984
4985 OPENSSL=/bin/openssl
4986 DIR=/etc/ssl/certs
4987
4988 if [ $# -gt 0 ]; then
4989   DIR="$1"
4990 fi
4991
4992 certs=$( find ${DIR} -type f -name "*.pem" -o -name "*.crt" )
4993 today=$( date +%Y%m%d )
4994
4995 for cert in $certs; do
4996   notafter=$( $OPENSSL x509 -enddate -in "${cert}" -noout )
4997   date=$( echo ${notafter} |  sed 's/^notAfter=//' )
4998   mydate "$date"
4999
5000   if [ ${certdate} -lt ${today} ]; then
5001      echo "${cert} expired on ${certdate}! Removing..."
5002      rm -f "${cert}"
5003   fi
5004 done
5005 EOF
5006
5007 chmod +x /bin/remove-expired-certs.sh
5008
5009
5010 make-ca.sh
5011 remove-expired-certs.sh certs
5012
5013
5014 install -d /etc/ssl/certs
5015 cp -v certs/*.pem /etc/ssl/certs
5016 c_rehash
5017 install BLFS-ca-bundle*.crt /etc/ssl/ca-bundle.crt
5018 ln -sfv ../ca-bundle.crt /etc/ssl/certs/ca-certificates.crt
5019
5020 rm BLFS-ca-bundle*.crt
5021 rm certdata.txt
5022 rm -rf certs
5023
5024 cd
5025 @end verbatim
5026
5027
5028 @node Inetutils 2
5029 @section Inetutils 2
5030
5031 Installed @samp{ifconfig} may hang. Reinstalling under GLLFSC to fix this:
5032
5033 @verbatim
5034 tar xf ${DOWNLOAD_DIR}/inetutils-1.9.1.tar.gz -C ${BUILD_DIR}
5035 cd ${BUILD_DIR}/inetutils-1.9.1
5036 sed -i '/gets is a security hole/d' lib/stdio.in.h
5037 #sed -i -e '/PATH_PROCNET_DEV/s/\ no//' paths
5038 ./configure \
5039     --prefix=
5040 make
5041 make DESTDIR= install
5042 cd ..
5043 rm -rf inetutils-1.9.1
5044 cd
5045 @end verbatim
5046
5047
5048 @node Man-db 2
5049 @section Man-db 2
5050
5051 Installed @samp{man} is buggy. Reinstalling under GLLFSC to fix this:
5052
5053 @verbatim
5054 tar xf ${DOWNLOAD_DIR}/man-db-2.6.7.1.tar.xz -C ${BUILD_DIR}
5055 cd ${BUILD_DIR}/man-db-2.6.7.1
5056 libpipeline_CFLAGS="-I/include" \
5057     libpipeline_LIBS="-L/lib -lpipeline" \
5058     ./configure \
5059     --prefix=
5060 make
5061 make DESTDIR= install
5062 cd ..
5063 rm -rf man-db-2.6.7.1
5064 cd
5065 @end verbatim
5066
5067
5068 @node Archiving Complete System
5069 @section Archiving the Complete System
5070
5071 @verbatim
5072 # Clean up:
5073 rm /src/*
5074 rm /root/*
5075 rm /root/.bash*
5076 rm -rf /share/doc
5077 mv /share/man/man* /share
5078 rm -rf /share/man/*
5079 mv /share/man[1-8] /share/man
5080
5081 # Strip binaries
5082 # 109 MB before, 36 MB after
5083 strip --strip-all /bin/*
5084
5085 # To be done outside GLLFSC:
5086 tar -cjf gllfsc-pentium4-1.7-completed.tar.bz2 \
5087     bin boot dev etc home include lib* local man mnt proc root run \
5088     sbin service share src sys tmp usr var
5089 @end verbatim
5090
5091
5092 @node Add User
5093 @section Add User
5094
5095 To create a new user, without root rights:
5096
5097 @verbatim
5098 useradd -m USER
5099 @end verbatim
5100
5101 This will create a new user named @samp{USER}, with group
5102 @samp{USER} and user's home at @file{/home/USER}.
5103
5104 To give a password to this user:
5105
5106 @verbatim
5107 passwd USER
5108 @end verbatim
5109
5110 You may want to change the color of this user's prompt:
5111
5112 @verbatim
5113 cat > /home/USER/.bash_profile << EOF
5114 export PS1='\[\e[32m\]\A-\W\[\e[00m\]$ '
5115 EOF
5116 chown USER:USER /home/USER/.bash_profile
5117 @end verbatim
5118
5119
5120 @node Halting Computer
5121 @section Halting the Computer
5122
5123 In order to halt the computer after this build process, type:
5124
5125 @verbatim
5126 init.sysv 0
5127 @end verbatim
5128
5129 If you prefer to reboot instead type:
5130
5131 @verbatim
5132 init.sysv 6
5133 @end verbatim
5134
5135 The next time you use GLLFSC, runit will be the default init system
5136 and you will have to type @samp{init 0} to halt the operating system
5137 and @samp{init 6} to reboot.
5138
5139
5140 @node Further Readings
5141 @chapter Further Readings
5142
5143 On my personal website at
5144 @uref{http://cjarry.org/gnu-linux/gllfsc@//gllfsc.en.html},
5145 there is some information on how to extend GLLFSC, for instance
5146 instructions on how to build Xorg and programs on top of it.
5147
5148 Haiyong Sun's website (in Chinese):
5149 @uref{http://blog.chinaunix.net/uid/436750.html}. It includes documents on building a
5150 GNU/Linux system for Loongson and a GNU/Hurd system for x86.
5151
5152 Cross [GNU/]Linux from scratch: @uref{http://www.clfs.org} (PDF
5153 files may be downloaded from @uref{http://clfs.org/files/BOOK/}).
5154 Includes a lot of documentation to build a GNU/Linux system by
5155 cross-compilation on a variety of hardware, no information (yet) for
5156 cross-compiling with sysroot on MIPS though. There is also a
5157 Community-driven Beyond [GNU/]Linux From Scratch on
5158 @uref{http://cblfs.clfs.org/index.php/Main_Page}. It documents
5159 the building of Xorg and TeXLive among other things.
5160
5161 @c Some patches from the above project are available for download on
5162 @c @uref{http://svn.clfs.org/svn/repos/patches/}.
5163
5164 @uref{http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_@/man.txt}
5165 documents an interesting way of managing packages. Quotation from the
5166 file:
5167
5168 @quotation
5169 DESCRIPTION:
5170 @itemize
5171
5172 @item
5173 You want to know which packages your files belong to?
5174
5175 @item
5176 You want to deinstall software that doesn't have make uninstall?
5177
5178 @item
5179 You are bothered by programs installed setuid root behind your back?
5180
5181 @item
5182 You don't like packages quietly overwriting files from other packages?
5183
5184 @item
5185 You don't like package managers like RPM?
5186
5187 @item
5188 YOU WANT TOTAL CONTROL USING ONLY UNIX BUILTINS?
5189 @end itemize
5190 @end quotation
5191
5192 The suckless team@footnote{@uref{http://suckless.org}} is a group of
5193 programmers that share the following
5194 philosophy@footnote{@uref{http://suckless.org/philosophy}}:
5195
5196 @quotation
5197 Focus on simplicity, clarity and frugality. Our philosophy is about
5198 keeping things simple, minimal and usable. We believe this should
5199 become the mainstream philosophy in the IT sector. Unfortunately, the
5200 tendency for complex, error-prone and slow software seems to be
5201 prevalent in the present-day software industry. We intend to prove the
5202 opposite with our software projects.
5203 @end quotation
5204
5205 The simple and lightweight programs released by this team are
5206 interesting for everyone who like small, reactive and reliable
5207 programs.
5208
5209
5210 @ignore
5211 @node Thanks
5212 @chapter Thanks
5213
5214 I thank Lemote and particularily the CEO, Fuxin Zhang, for offering me
5215 a Yeeloong 8133, Huacai Chen and Haiyong Sun for their help in fixing
5216 the bugs I found in the deblobbed kernel.
5217
5218 I am particularily grateful to Haiyong Sun for having shared his
5219 knowledge on building a free operating system for Loongson 2F
5220 machines, this document is heavily based on this.
5221 @end ignore
5222
5223
5224 @node GNU Free Documentation License
5225 @appendix GNU Free Documentation License
5226 @include fdl-1.3.texi
5227
5228
5229 @node GNU General Public License
5230 @appendix GNU General Public License
5231 @include gpl.texi
5232
5233 @bye