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