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