From: Jason Self Date: Fri, 15 Oct 2021 04:39:52 +0000 (-0700) Subject: Import GNU/Linux-libre from source code from https://cjarry.org/gnu-linux/gllfsc/ X-Git-Url: https://jxself.org/git/?p=gllfsc.git;a=commitdiff_plain;h=2ba5a6520482cefbf53ab24fc8568c8a4fa3bd1c Import GNU/Linux-libre from source code from https://cjarry.org/gnu-linux/gllfsc/ --- 2ba5a6520482cefbf53ab24fc8568c8a4fa3bd1c diff --git a/fdl.txt b/fdl.txt new file mode 100644 index 0000000..bf128be --- /dev/null +++ b/fdl.txt @@ -0,0 +1,451 @@ + + GNU Free Documentation License + Version 1.3, 3 November 2008 + + + Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +0. PREAMBLE + +The purpose of this License is to make a manual, textbook, or other +functional and useful document "free" in the sense of freedom: to +assure everyone the effective freedom to copy and redistribute it, +with or without modifying it, either commercially or noncommercially. +Secondarily, this License preserves for the author and publisher a way +to get credit for their work, while not being considered responsible +for modifications made by others. + +This License is a kind of "copyleft", which means that derivative +works of the document must themselves be free in the same sense. It +complements the GNU General Public License, which is a copyleft +license designed for free software. + +We have designed this License in order to use it for manuals for free +software, because free software needs free documentation: a free +program should come with manuals providing the same freedoms that the +software does. But this License is not limited to software manuals; +it can be used for any textual work, regardless of subject matter or +whether it is published as a printed book. We recommend this License +principally for works whose purpose is instruction or reference. + + +1. APPLICABILITY AND DEFINITIONS + +This License applies to any manual or other work, in any medium, that +contains a notice placed by the copyright holder saying it can be +distributed under the terms of this License. Such a notice grants a +world-wide, royalty-free license, unlimited in duration, to use that +work under the conditions stated herein. The "Document", below, +refers to any such manual or work. Any member of the public is a +licensee, and is addressed as "you". You accept the license if you +copy, modify or distribute the work in a way requiring permission +under copyright law. + +A "Modified Version" of the Document means any work containing the +Document or a portion of it, either copied verbatim, or with +modifications and/or translated into another language. + +A "Secondary Section" is a named appendix or a front-matter section of +the Document that deals exclusively with the relationship of the +publishers or authors of the Document to the Document's overall +subject (or to related matters) and contains nothing that could fall +directly within that overall subject. (Thus, if the Document is in +part a textbook of mathematics, a Secondary Section may not explain +any mathematics.) The relationship could be a matter of historical +connection with the subject or with related matters, or of legal, +commercial, philosophical, ethical or political position regarding +them. + +The "Invariant Sections" are certain Secondary Sections whose titles +are designated, as being those of Invariant Sections, in the notice +that says that the Document is released under this License. If a +section does not fit the above definition of Secondary then it is not +allowed to be designated as Invariant. The Document may contain zero +Invariant Sections. If the Document does not identify any Invariant +Sections then there are none. + +The "Cover Texts" are certain short passages of text that are listed, +as Front-Cover Texts or Back-Cover Texts, in the notice that says that +the Document is released under this License. A Front-Cover Text may +be at most 5 words, and a Back-Cover Text may be at most 25 words. + +A "Transparent" copy of the Document means a machine-readable copy, +represented in a format whose specification is available to the +general public, that is suitable for revising the document +straightforwardly with generic text editors or (for images composed of +pixels) generic paint programs or (for drawings) some widely available +drawing editor, and that is suitable for input to text formatters or +for automatic translation to a variety of formats suitable for input +to text formatters. A copy made in an otherwise Transparent file +format whose markup, or absence of markup, has been arranged to thwart +or discourage subsequent modification by readers is not Transparent. +An image format is not Transparent if used for any substantial amount +of text. A copy that is not "Transparent" is called "Opaque". + +Examples of suitable formats for Transparent copies include plain +ASCII without markup, Texinfo input format, LaTeX input format, SGML +or XML using a publicly available DTD, and standard-conforming simple +HTML, PostScript or PDF designed for human modification. Examples of +transparent image formats include PNG, XCF and JPG. Opaque formats +include proprietary formats that can be read and edited only by +proprietary word processors, SGML or XML for which the DTD and/or +processing tools are not generally available, and the +machine-generated HTML, PostScript or PDF produced by some word +processors for output purposes only. + +The "Title Page" means, for a printed book, the title page itself, +plus such following pages as are needed to hold, legibly, the material +this License requires to appear in the title page. For works in +formats which do not have any title page as such, "Title Page" means +the text near the most prominent appearance of the work's title, +preceding the beginning of the body of the text. + +The "publisher" means any person or entity that distributes copies of +the Document to the public. + +A section "Entitled XYZ" means a named subunit of the Document whose +title either is precisely XYZ or contains XYZ in parentheses following +text that translates XYZ in another language. (Here XYZ stands for a +specific section name mentioned below, such as "Acknowledgements", +"Dedications", "Endorsements", or "History".) To "Preserve the Title" +of such a section when you modify the Document means that it remains a +section "Entitled XYZ" according to this definition. + +The Document may include Warranty Disclaimers next to the notice which +states that this License applies to the Document. These Warranty +Disclaimers are considered to be included by reference in this +License, but only as regards disclaiming warranties: any other +implication that these Warranty Disclaimers may have is void and has +no effect on the meaning of this License. + +2. VERBATIM COPYING + +You may copy and distribute the Document in any medium, either +commercially or noncommercially, provided that this License, the +copyright notices, and the license notice saying this License applies +to the Document are reproduced in all copies, and that you add no +other conditions whatsoever to those of this License. You may not use +technical measures to obstruct or control the reading or further +copying of the copies you make or distribute. However, you may accept +compensation in exchange for copies. If you distribute a large enough +number of copies you must also follow the conditions in section 3. + +You may also lend copies, under the same conditions stated above, and +you may publicly display copies. + + +3. COPYING IN QUANTITY + +If you publish printed copies (or copies in media that commonly have +printed covers) of the Document, numbering more than 100, and the +Document's license notice requires Cover Texts, you must enclose the +copies in covers that carry, clearly and legibly, all these Cover +Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on +the back cover. Both covers must also clearly and legibly identify +you as the publisher of these copies. The front cover must present +the full title with all words of the title equally prominent and +visible. You may add other material on the covers in addition. +Copying with changes limited to the covers, as long as they preserve +the title of the Document and satisfy these conditions, can be treated +as verbatim copying in other respects. + +If the required texts for either cover are too voluminous to fit +legibly, you should put the first ones listed (as many as fit +reasonably) on the actual cover, and continue the rest onto adjacent +pages. + +If you publish or distribute Opaque copies of the Document numbering +more than 100, you must either include a machine-readable Transparent +copy along with each Opaque copy, or state in or with each Opaque copy +a computer-network location from which the general network-using +public has access to download using public-standard network protocols +a complete Transparent copy of the Document, free of added material. +If you use the latter option, you must take reasonably prudent steps, +when you begin distribution of Opaque copies in quantity, to ensure +that this Transparent copy will remain thus accessible at the stated +location until at least one year after the last time you distribute an +Opaque copy (directly or through your agents or retailers) of that +edition to the public. + +It is requested, but not required, that you contact the authors of the +Document well before redistributing any large number of copies, to +give them a chance to provide you with an updated version of the +Document. + + +4. MODIFICATIONS + +You may copy and distribute a Modified Version of the Document under +the conditions of sections 2 and 3 above, provided that you release +the Modified Version under precisely this License, with the Modified +Version filling the role of the Document, thus licensing distribution +and modification of the Modified Version to whoever possesses a copy +of it. In addition, you must do these things in the Modified Version: + +A. Use in the Title Page (and on the covers, if any) a title distinct + from that of the Document, and from those of previous versions + (which should, if there were any, be listed in the History section + of the Document). You may use the same title as a previous version + if the original publisher of that version gives permission. +B. List on the Title Page, as authors, one or more persons or entities + responsible for authorship of the modifications in the Modified + Version, together with at least five of the principal authors of the + Document (all of its principal authors, if it has fewer than five), + unless they release you from this requirement. +C. State on the Title page the name of the publisher of the + Modified Version, as the publisher. +D. Preserve all the copyright notices of the Document. +E. Add an appropriate copyright notice for your modifications + adjacent to the other copyright notices. +F. Include, immediately after the copyright notices, a license notice + giving the public permission to use the Modified Version under the + terms of this License, in the form shown in the Addendum below. +G. Preserve in that license notice the full lists of Invariant Sections + and required Cover Texts given in the Document's license notice. +H. Include an unaltered copy of this License. +I. Preserve the section Entitled "History", Preserve its Title, and add + to it an item stating at least the title, year, new authors, and + publisher of the Modified Version as given on the Title Page. If + there is no section Entitled "History" in the Document, create one + stating the title, year, authors, and publisher of the Document as + given on its Title Page, then add an item describing the Modified + Version as stated in the previous sentence. +J. Preserve the network location, if any, given in the Document for + public access to a Transparent copy of the Document, and likewise + the network locations given in the Document for previous versions + it was based on. These may be placed in the "History" section. + You may omit a network location for a work that was published at + least four years before the Document itself, or if the original + publisher of the version it refers to gives permission. +K. For any section Entitled "Acknowledgements" or "Dedications", + Preserve the Title of the section, and preserve in the section all + the substance and tone of each of the contributor acknowledgements + and/or dedications given therein. +L. Preserve all the Invariant Sections of the Document, + unaltered in their text and in their titles. Section numbers + or the equivalent are not considered part of the section titles. +M. Delete any section Entitled "Endorsements". Such a section + may not be included in the Modified Version. +N. Do not retitle any existing section to be Entitled "Endorsements" + or to conflict in title with any Invariant Section. +O. Preserve any Warranty Disclaimers. + +If the Modified Version includes new front-matter sections or +appendices that qualify as Secondary Sections and contain no material +copied from the Document, you may at your option designate some or all +of these sections as invariant. To do this, add their titles to the +list of Invariant Sections in the Modified Version's license notice. +These titles must be distinct from any other section titles. + +You may add a section Entitled "Endorsements", provided it contains +nothing but endorsements of your Modified Version by various +parties--for example, statements of peer review or that the text has +been approved by an organization as the authoritative definition of a +standard. + +You may add a passage of up to five words as a Front-Cover Text, and a +passage of up to 25 words as a Back-Cover Text, to the end of the list +of Cover Texts in the Modified Version. Only one passage of +Front-Cover Text and one of Back-Cover Text may be added by (or +through arrangements made by) any one entity. If the Document already +includes a cover text for the same cover, previously added by you or +by arrangement made by the same entity you are acting on behalf of, +you may not add another; but you may replace the old one, on explicit +permission from the previous publisher that added the old one. + +The author(s) and publisher(s) of the Document do not by this License +give permission to use their names for publicity for or to assert or +imply endorsement of any Modified Version. + + +5. COMBINING DOCUMENTS + +You may combine the Document with other documents released under this +License, under the terms defined in section 4 above for modified +versions, provided that you include in the combination all of the +Invariant Sections of all of the original documents, unmodified, and +list them all as Invariant Sections of your combined work in its +license notice, and that you preserve all their Warranty Disclaimers. + +The combined work need only contain one copy of this License, and +multiple identical Invariant Sections may be replaced with a single +copy. If there are multiple Invariant Sections with the same name but +different contents, make the title of each such section unique by +adding at the end of it, in parentheses, the name of the original +author or publisher of that section if known, or else a unique number. +Make the same adjustment to the section titles in the list of +Invariant Sections in the license notice of the combined work. + +In the combination, you must combine any sections Entitled "History" +in the various original documents, forming one section Entitled +"History"; likewise combine any sections Entitled "Acknowledgements", +and any sections Entitled "Dedications". You must delete all sections +Entitled "Endorsements". + + +6. COLLECTIONS OF DOCUMENTS + +You may make a collection consisting of the Document and other +documents released under this License, and replace the individual +copies of this License in the various documents with a single copy +that is included in the collection, provided that you follow the rules +of this License for verbatim copying of each of the documents in all +other respects. + +You may extract a single document from such a collection, and +distribute it individually under this License, provided you insert a +copy of this License into the extracted document, and follow this +License in all other respects regarding verbatim copying of that +document. + + +7. AGGREGATION WITH INDEPENDENT WORKS + +A compilation of the Document or its derivatives with other separate +and independent documents or works, in or on a volume of a storage or +distribution medium, is called an "aggregate" if the copyright +resulting from the compilation is not used to limit the legal rights +of the compilation's users beyond what the individual works permit. +When the Document is included in an aggregate, this License does not +apply to the other works in the aggregate which are not themselves +derivative works of the Document. + +If the Cover Text requirement of section 3 is applicable to these +copies of the Document, then if the Document is less than one half of +the entire aggregate, the Document's Cover Texts may be placed on +covers that bracket the Document within the aggregate, or the +electronic equivalent of covers if the Document is in electronic form. +Otherwise they must appear on printed covers that bracket the whole +aggregate. + + +8. TRANSLATION + +Translation is considered a kind of modification, so you may +distribute translations of the Document under the terms of section 4. +Replacing Invariant Sections with translations requires special +permission from their copyright holders, but you may include +translations of some or all Invariant Sections in addition to the +original versions of these Invariant Sections. You may include a +translation of this License, and all the license notices in the +Document, and any Warranty Disclaimers, provided that you also include +the original English version of this License and the original versions +of those notices and disclaimers. In case of a disagreement between +the translation and the original version of this License or a notice +or disclaimer, the original version will prevail. + +If a section in the Document is Entitled "Acknowledgements", +"Dedications", or "History", the requirement (section 4) to Preserve +its Title (section 1) will typically require changing the actual +title. + + +9. TERMINATION + +You may not copy, modify, sublicense, or distribute the Document +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense, or distribute it is void, and +will automatically terminate your rights under this License. + +However, if you cease all violation of this License, then your license +from a particular copyright holder is reinstated (a) provisionally, +unless and until the copyright holder explicitly and finally +terminates your license, and (b) permanently, if the copyright holder +fails to notify you of the violation by some reasonable means prior to +60 days after the cessation. + +Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, receipt of a copy of some or all of the same material does +not give you any rights to use it. + + +10. FUTURE REVISIONS OF THIS LICENSE + +The Free Software Foundation may publish new, revised versions of the +GNU Free Documentation License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in +detail to address new problems or concerns. See +https://www.gnu.org/licenses/. + +Each version of the License is given a distinguishing version number. +If the Document specifies that a particular numbered version of this +License "or any later version" applies to it, you have the option of +following the terms and conditions either of that specified version or +of any later version that has been published (not as a draft) by the +Free Software Foundation. If the Document does not specify a version +number of this License, you may choose any version ever published (not +as a draft) by the Free Software Foundation. If the Document +specifies that a proxy can decide which future versions of this +License can be used, that proxy's public statement of acceptance of a +version permanently authorizes you to choose that version for the +Document. + +11. RELICENSING + +"Massive Multiauthor Collaboration Site" (or "MMC Site") means any +World Wide Web server that publishes copyrightable works and also +provides prominent facilities for anybody to edit those works. A +public wiki that anybody can edit is an example of such a server. A +"Massive Multiauthor Collaboration" (or "MMC") contained in the site +means any set of copyrightable works thus published on the MMC site. + +"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 +license published by Creative Commons Corporation, a not-for-profit +corporation with a principal place of business in San Francisco, +California, as well as future copyleft versions of that license +published by that same organization. + +"Incorporate" means to publish or republish a Document, in whole or in +part, as part of another Document. + +An MMC is "eligible for relicensing" if it is licensed under this +License, and if all works that were first published under this License +somewhere other than this MMC, and subsequently incorporated in whole or +in part into the MMC, (1) had no cover texts or invariant sections, and +(2) were thus incorporated prior to November 1, 2008. + +The operator of an MMC Site may republish an MMC contained in the site +under CC-BY-SA on the same site at any time before August 1, 2009, +provided the MMC is eligible for relicensing. + + +ADDENDUM: How to use this License for your documents + +To use this License in a document you have written, include a copy of +the License in the document and put the following copyright and +license notices just after the title page: + + Copyright (c) YEAR YOUR NAME. + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 + or any later version published by the Free Software Foundation; + with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. + A copy of the license is included in the section entitled "GNU + Free Documentation License". + +If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, +replace the "with...Texts." line with this: + + with the Invariant Sections being LIST THEIR TITLES, with the + Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. + +If you have Invariant Sections without Cover Texts, or some other +combination of the three, merge those two alternatives to suit the +situation. + +If your document contains nontrivial examples of program code, we +recommend releasing these examples in parallel under your choice of +free software license, such as the GNU General Public License, +to permit their use in free software. diff --git a/gllfsc-loongson2f-1.0.texi b/gllfsc-loongson2f-1.0.texi new file mode 100644 index 0000000..05229ed --- /dev/null +++ b/gllfsc-loongson2f-1.0.texi @@ -0,0 +1,4793 @@ +\input texinfo +@c -*-texinfo-*- +@c %**start of header +@setfilename gllfsc-loongson2f-1.0.info +@settitle GNU/Linux-libre from source code +@c Comment the following if you want Letter format instead of A4 for +@c PDF output +@afourpaper +@c %**end of header +@c Book headers for PDF version +@setchapternewpage odd +@c To support Haiyong Sun's ideograms +@documentencoding UTF-8 + +@copying +This is edition 1.0 (last updated 14 October 2012) of +@cite{GNU/Linux-libre from source code for Loongson 2F}. + +Copyright @copyright{} 2012 Christophe Jarry. + +This document is based on the Chinese page +@url{http://zdbr.net.cn/download/Loongson64-@/2.0.htm}, which is +copyright @copyright{} 2009 +@c Because TeX does not handle Chinese fonts automatically, we need to +@c do the following: +@ifnottex +Haiyong Sun (孙海勇). +@end ifnottex +@iftex +Haiyong Sun. +@end iftex +His blog is on @url{http://youbest.cublog.cn}. + +Various formats of this manual as well as its texinfo source are +available on +@uref{http://cjarry.org/gnu-linux/gllfsc/}. + +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 +or any later version published by the Free Software Foundation; +with no Invariant Sections, no Front-Cover Texts, and no Back-Cover +Texts. A copy of the license is included in the section entitled ``GNU +Free Documentation License''. +@end quotation + +@quotation +Computer instructions in this manual are free software: you can +redistribute them and/or modify them under the terms of the GNU +General Public License as published by the Free Software Foundation, +either version 3 of the License, or (at your option) any later +version. + +Those instructions are distributed in the hope that they will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this manual. If not, see . +@end quotation + +@end copying + +@c @setchapternewpage odd + +@titlepage +@title GNU/Linux-libre from source code +@subtitle for Loongson 2F +@c @subtitle SUBTITLE-IF-ANY +@c @subtitle SECOND-SUBTITLE +@author Christophe Jarry +@c @author Haiyong Sun (original author) + +@c The following two commands +@c start the copyright page. +@page +@vskip 0pt plus 1filll +@insertcopying + +@c Published by ... +@end titlepage + +@c Short table of contents +@shortcontents + +@c So the toc is printed at the start. +@contents + +@ifnottex +@node Top +@top GNU/Linux-libre from source code for Loongson 2F + +This manual describes how to build a GNU/Linux-libre system from +source for Loongson 2F processor. + +@insertcopying +@end ifnottex + +@menu +* Introduction:: What this document is all about. +* Prerequisites:: Useful knowledge before proceeding. +* Preliminary Work:: Preparing the build. +* Building the Cross-Compilation Toolchain:: Building the cross- + compilation Toolchain. +* Building Cross-Compilation Tools:: Building the cross-compilation + Tools. +* Building the Target System:: How to build the target system. +* Configuration Files:: Creating configuration files + needed by the new system. +* End:: Final things to do. +* Further Readings:: Websites useful to know more. +* GNU Free Documentation License:: Your rights and freedoms with the + text. +* GNU General Public License:: Your rights and freedoms with the + commands. +@end menu + + +@node Introduction +@chapter Introduction + +@menu +* GNU/Linux History:: A brief history of GNU/Linux. +* Purpose of this Document:: What this document is all about. +@end menu + + +@node GNU/Linux History +@section GNU/Linux History + +@menu +* GNU:: Presentation of the GNU project +* HURD:: Presentation of the HURD +* Linux:: Presentation of the kernel Linux +* Linux-libre:: Presentation of the kernel Linux-libre +* References:: Where to get more information +@end menu + +@node GNU +@subsection GNU + +@acronym{GNU} (GNU's Not Unix) is a project launched by Richard +Stallman in 1984 with the goal of building an entirely free operating +system compatible with Unix@footnote{See +@uref{http://en.wikipedia.org/wiki/Unix}}. ``Free'' here means ``free +as in freedom''. In this context, a free operating system is an +operating system you can use and share in freedom. A core part of his +motivation is given in the GNU +Manifesto@footnote{@uref{http://www.gnu.org/gnu/manifesto.html}}: + +@quotation +I consider that the Golden Rule requires that if I like a program I +must share it with other people who like it. Software sellers want to +divide the users and conquer them, making each user agree not to share +with others. I refuse to break solidarity with other users in this +way. I cannot in good conscience sign a nondisclosure agreement or a +software license agreement. For years I worked within the Artificial +Intelligence Lab to resist such tendencies and other inhospitalities, +but eventually they had gone too far: I could not remain in an +institution where such things are done for me against my will. + +So that I can continue to use computers without dishonor, I have +decided to put together a sufficient body of free software so that I +will be able to get along without any software that is not free. I +have resigned from the AI Lab to deny MIT any legal excuse to prevent +me from giving GNU away. +@end quotation + +A program is free software if the program's user has the four +essential freedoms: + +@itemize +@item +The freedom to run the program, for any purpose (freedom 0). + +@item +The freedom to study how the program works, and change it so it does +her computing as she wishes (freedom 1). Access to the source code is +a precondition for this. + +@item +The freedom to redistribute copies so she can help her neighbor +(freedom 2). + +@item +The freedom to distribute copies of her modified versions to others +(freedom 3). By doing this she can give the whole community a chance +to benefit from her changes. Access to the source code is a +precondition for this. +@end itemize + +One of the most popular free software license is the GNU General +Public License (GNU +GPL@footnote{@uref{http://www.gnu.org/licenses/gpl.html}}). + +The free software movement is supported by the Free Software +Foundation (FSF@footnote{@uref{http://www.fsf.org}}). + + +@node HURD +@subsection HURD + +The @acronym{HURD} is an acronym for @acronym{HIRD} (HURD of +interfaces representing depth) of Unix-replacing daemons. It is the +GNU project's replacement for the Unix kernel. It is a collection of +servers that run on the Mach microkernel to implement file systems, +network protocols, file access control, and other features that are +implemented by the Unix kernel or similar kernels (such as Linux). + +The purpose of the GNU HURD is to improve the user's freedom on her +operating system by allowing her to either add or remove a feature of +the kernel on the fly. + +From early on, the HURD was developed to use GNU Mach as the +microkernel. This was a technical decision made by Richard Stallman, +who thought it would speed up the work by saving a large part of +it. He has admitted that he was wrong about that. + +Nevertheless, development of the HURD is increasingly attracting +developers and GNU/HURD systems exist and are usable. + + +@node Linux +@subsection Linux + +Linux is a monolithic kernel created by Linus Torvalds in 1991. Linus +Torvalds initially wrote a terminal emulator, which he used to access +the large UNIX servers of his university. He wrote the program +specifically for the hardware he was using and independent of an +operating system because he wanted to use the functions of his new PC +with an 80386 processor. This later became the kernel Linux. + +Initially, Torvalds first published the kernel Linux under its own +licence, which had a restriction on commercial activity. + +In the notes for the first release of the kernel Linux, Torvalds lists +the GNU software that is required to run Linux: + +@quotation +Sadly, a kernel by itself gets you nowhere. To get a working system +you need a shell, compilers, a library etc. [...] Most of the tools +used with linux are GNU software and are under the GNU copyleft. +@end quotation + +In 1992, he suggested releasing the kernel under the GNU General +Public License. He first announced this decision in the release notes +of version 0.12. In the middle of December 1992 he published version +0.99 using the GNU GPL. + +The kernel Linux is now a contribution of many professionals and +volonteers around the world. + + +@node Linux-libre +@subsection Linux-libre + +Linux, the kernel developed and distributed by Linus Torvalds et al, +contains non-Free Software@footnote{For more information about the +presence of proprietary firmware in the kernel Linux, read +@uref{http://www.fsfla.org/svnwiki/anuncio/2010-03-Linux-2.6.33-libre.en} +and +@uref{http://www.gnu.org/@/distros/free-system-distribution-guidelines.html#nonfree-firmware}.}, +i.e., software that does not respect your essential freedoms, and it +induces you to install additional non-Free Software that it doesn't +contain. + +GNU +Linux-libre@footnote{@uref{http://www.fsfla.org/svnwiki/selibre/linux-libre/index.en.html}} +is a project to maintain and publish 100% Free distributions of Linux, +suitable for use in Free System Distributions@footnote{For a full list +of free as in freedom GNU/Linux distributions, see +@uref{http://www.gnu.org/distros}.}, removing software that is +included without source code, with obfuscated or obscured source code, +under non-Free Software licenses, that do not permit you to change the +software so that it does what you wish, and that induces or requires +you to install additional pieces of non-Free Software. + + +@node References +@subsection References + +For more information on the GNU project and its relation with the +kernel Linux, you can read @uref{http://www.gnu.org/gnu/thegnuproject.html} +and @uref{http://www.gnu.org/gnu/gnu-linux-faq.html}. + +For more information on the history of the HURD, I recommend you to +read @uref{http://www.h-online.com/open/features/GNU-HURD-Altered-visions-and-lost-promise@/-1030942.html}. + +For more information on the HURD, read @uref{http://www.gnu.org/software/hurd}. + + +@node Purpose of this Document +@section Purpose of this Document + +I bought a Lemote Yeeloong 8101 in 2010 and used +gNewSense@footnote{@uref{http://www.gnewsense.org}} on it. After a +while, I wanted to use a faster and simpler operating system, but the +number of available GNU/Linux@footnote{Note: in this document, we use +the term ``GNU/Linux'' to name the entire system and ``Linux'' to name +the kernel. For more information, read +@uref{http://www.gnu.org/gnu/why-gnu-linux.html}.} distributions that +supported the mipsel architecture (Loongson 2F) were limited: only a +handful, from which only gNewSense committed to give its users full +freedom. Since then, another distribution called +Parabola@footnote{@uref{https://parabolagnulinux.org}} has been +developed: it is free as in freedom and supports the mips64el +architecture. + +I decided to build a GNU/Linux system from source code by +myself. Hopefully, I found a document in Chinese describing the +process of building a GNU/Linux system for Loongson processor: +@uref{http://zdbr.net.cn/download/Loongson64-2.0.htm}@footnote{At the +time of writing (september 2012), the site @uref{http://zdbr.net.cn/} +does not exist anymore. The author of this document was +@ifnottex +Haiyong Sun (孙海勇), +@end ifnottex +@iftex +Haiyong Sun, +@end iftex +and his (interesting) blog is on @uref{http://youbest.cublog.cn}.}. +The document was old (2009) but I updated succesfully most packages +from it, replaced Linux with Linux-libre and added some information I +felt was useful and it gave the document you are reading. + + +@node Prerequisites +@chapter Prerequisites + +@menu +* Definitions:: Definitions of important notions used to build the + system +* Commands:: Help on commands +@end menu + + +@node Definitions +@section Definitions + +@menu +* sysroot:: @option{sysroot} +* Toolchain:: What a Toolchain is. +* build host target:: Understanding the meaning of the + @option{build}-@option{host}-@option{target} + triplet. +* FHS:: The Filesystem Hierarchy Standard. +@end menu + + +@node sysroot +@subsection @option{sysroot} + +The traditional way of building a GNU/Linux operating system consists +on building a (cross-) compilation toolchain to build a temporary +operating system which in turn will be used to build the target +system@footnote{@xref{Further Readings} section for more +details}. This requires almost as much time to complete the temporary +system as to build the target one. Using sysroot resolves this +problem. + +From GCC installation manual, under Cross-Compiler-Specific Options: + +@table @code +@item --with-sysroot +@itemx --with-sysroot=@var{dir} +Tells GCC to consider @var{dir} as the root of a tree that contains (a +subset of) the root filesystem of the target operating system. Target +system headers, libraries and run-time object files will be searched +in there. More specifically, this acts as if +@option{--sysroot=@var{dir}} was added to the default options of the +built compiler. The specified directory is not copied into the +install tree, unlike the options @option{--with-headers} and +@option{--with-libs} that this option obsoletes. The default value, +in case @option{--with-sysroot} is not given an argument, is +@option{$@{gcc_tooldir@}/sys-root}. If the specified directory is a +subdirectory of @option{$@{exec_prefix@}}, then it will be found +relative to the GCC binaries if the installation tree is moved. + +This option affects the system root for the compiler used to build +target libraries (which runs on the build system) and the compiler +newly installed with @code{make install}; it does not affect the +compiler which is used to build GCC itself. +@end table + + +@node Toolchain +@subsection Toolchain + +According to +Wikipedia@footnote{@uref{http://www.wikipedia.org/wiki/Toolchain}}: + +@quotation +In software, a toolchain is the set of programming tools that are used +to create a product (typically another computer program or system of +programs). The tools may be used in a chain, so that the output of +each tool becomes the input for the next, but the term is used widely +to refer to any set of linked development tools. + +A simple software development toolchain consists of a text editor for +editing source code, a compiler and linker to transform the source +code into an executable program, libraries to provide interfaces to +the operating system, and a debugger. +@end quotation + + +@node build host target +@subsection @option{build}, @option{host} and @option{target} + +During a cross-compilation, @option{build} @option{host} and +@option{target} are among the most used options: understanding the +precise meaning of those parameters is very important. We could define +them thus: + +@itemize +@item @option{--build=@var{platform on which the program is +compiled}}, +@item @option{--host=@var{platform on which the program will run}}, +@item @option{--target=@var{platform for which the program will create +output}}. +@end itemize + +Let's use GCC as an example to explain the role of those three +parameters. + +During GCC compilation, we use: + +@samp{./configure --build=@var{build-platform} +--host=@var{host-platform} --target=@var{target-platform} [various +compilation parameters]} + +So in those configuration parameters: + +@itemize +@item +@option{--build} provides the name of the platform currently running. +If we were using an Intel Pentium processor to compile the system, our +@var{build-platform} would be something like @samp{i686-pc-linux-gnu}. + +If this parameter is not specified, it will be guessed automatically. + +@item +@option{--host} represents the type of machine we are going to run GCC +on after the compilation succeeds. During a cross-compilation this has +to be specified, because the current machine can not know which +architecture we wish to target. We want to produce executables to run +on @emph{Loongson}, but there is currently no way we can specify +@samp{Loongson} directly; because of this we specify +@samp{mips64el-unknown-linux-gnu}. + +@option{--host} can also be left unspecified, in that case, +@var{host-platform} would automatically define itself as +@var{build-platform}, but this is not cross-compilation anymore. + +@quotation Note +when @option{--build} and @option{--host} are different, configuration +files will maintain the cross-compilation mode. +@end quotation + +@item +@option{--target} defines the system for which compiler tools will +create output. + +@var{target-platform} parameter is useful only for a limited number of +programs. Although this parameter is often present when issuing +@samp{./configure --help}, hardly any packages will need it. + +This parameter is only useful for performing tasks with different +platforms; for instance, executable files compiled for different +platforms can have a totally different code. +@end itemize + +If we summarize, we have: + +@itemize +@item @var{build-platform}: automatically guessed from platform in +use; has to be specified if not guessed. + +@item @var{host-platform}: if unspecified, automatically equals +@var{build-platform}. When @var{build-platform} and +@var{host-platform} values are identical, it is a local compilation; +otherwise it is a cross-compilation. + +@item @var{target-platform}: defines the system for which compiler +tools will create output; it equals @var{host-platform} if +unspecified. GCC, binutils, and programs related to the platform's +instructions have this parameter; most programs do not use this +parameter. +@end itemize + + +@node FHS +@subsection FHS + +The Filesystem Hierarchy Standard (FHS) has been created to specify +the location and use of main directories on a GNU/Linux operating +system. Common commands, user data, libraries have to be put inside a +specific directory given in the standard. During the build process, +some commands are used to comply with FHS. + + +@node Commands +@section Commands + +In this document, because most commands are common for a regular Unix +user, only uncommon commands are explained in this document. If you do +not understand a command that is not explained, you can use the +documentation available on your computer; in a terminal, typing +@samp{man @var{command}} should give you enough information. For GNU +software, @samp{info @var{package}} can also give additional +information. + + +@node Preliminary Work +@chapter Preliminary Work + +@quotation Important +In order to complete the first steps of this chapter, you will need to +have root permissions. +@end quotation + +@menu +* Build Partition Creation:: Creating a partition for the build. +* Build User Creation:: Creating a user account dedicated to + the build. +* Work Directory Creation:: Creating the parent directory for the + build. +* Partition Mount:: Mounting the partition dedicated to the + build. +* Useful Directories Creation:: Creating the directories for downloads + and compilations. +* User Switch:: Switching to the user dedicated to the + build. +* Environment Variables Setup:: Setting up the environment variables + of the target system. +* Downloads:: Downloading needed packages and + patches. +* Final Preparations:: Preparing the system for the build. +@end menu + + +@node Build Partition Creation +@section Build Partition Creation + +To dedicate the partition @file{/dev/sda4} to the system build, and to +define the filesystem to be used for it as @samp{ext3}: + +@verbatim +mke2fs -t ext3 /dev/sda4 +@end verbatim + +Option @option{-t} is followed by the type of filesystem to be +used. The filesystem @samp{ext3} is used as it is one of the most +common filesystem used with the kernel Linux. + + +@node Build User Creation +@section Build User Creation + +To create the builder group, user and password: + +@verbatim +groupadd gllfsc +useradd -s /bin/bash -g gllfsc -m -k /dev/null gllfsc +passwd gllfsc +@end verbatim + +@itemize +@item +Option @option{-s} (or @option{--shell}) is used to define the created +user's default shell, here @file{/bin/bash}. + +@item +Option @option{-g} (or @option{--gid}) is used to define the group +name or number of the created user's initial login group, here +@samp{gllfsc}. + +@item +Option @option{-m} (or @option{--create-home}) does create the user's +home directory if it does not exist (@file{/home/@var{username}}). + +@item +Option @option{-k} (or @option{--skel}) is used to define the skeleton +directory to be copied in the user's home directory, here +@file{/dev/null}. @file{/dev/null} is a special file which, in this +case, will give no skeleton at all to @command{useradd}. +@end itemize + + +@node Work Directory Creation +@section Work Directory Creation + +To create the directory @file{/gllfsc} in which the system will be +built: + +@verbatim +export TARGET_DIR="/gllfsc" +mkdir -pv ${TARGET_DIR} +@end verbatim + +@samp{export TARGET_DIR="/gllfsc"} sets the value of the variable +@env{TARGET_DIR} to @file{/gllfsc}, the directory in which the system +will be built. + + +@node Partition Mount +@section Mounting Partition + +To mount the hard drive partition, for instance @file{/dev/sda4}, used +to build the system: + +@verbatim +mount /dev/sda4 ${TARGET_DIR} +@end verbatim + + +@node Useful Directories Creation +@section Creating Compilation and Download Directories + +@verbatim +mkdir -pv ${TARGET_DIR}/{build,download} +chown -Rv gllfsc ${TARGET_DIR} +@end verbatim + + +@node User Switch +@section Switching to the Build User + +To login as the user that will build the system: + +@verbatim +su - gllfsc +@end verbatim + +With the command @command{su}, it is possible to change the user +ID. The option @option{-} provides an environment similar to what the +user would expect had the user logged in directly. + + +@node Environment Variables Setup +@section Setting up Required Environment Variables + +@file{~/.bash_profile} is a personal initialization file that is read +when Bash is invoked as an interactive login shell (@file{~} is the +location of the user's home directory). To write the content of the +file @file{~/.bash_profile}: + +@verbatim +cat > ~/.bash_profile << "EOF" +exec env -i HOME=${HOME} TERM=${TERM} PS1=${PS1} /bin/bash +EOF +@end verbatim + +The first line creates the file @file{~/.bash_profile} and opens it +for writing until @samp{@acronym{EOF}} (End Of File) is written in it. + +The second line tells Bash to execute @file{/bin/bash} with the option +@option{-i} (or @option{--ignore-environment}) which will make Bash +start with an empty environment. Variables @env{HOME}, @env{TERM} and +@env{PS1} define respectively the home directory of the current user, +the terminal used and the primary prompt string displayed. + +@file{~/.bashrc} is a personal initialization file that is read when +Bash is invoked as an interactive shell but not a login one. To write +the content of the file @file{~/.bashrc}: + +@verbatim +cat > ~/.bashrc << "EOF" +set +h +umask 022 +export PS1='\[\e[32m\]\A-\W\[\e[00m\]\$ ' +export TARGET_DIR=/gllfsc +export LC_ALL=POSIX +export BUILD_DIR="${TARGET_DIR}/build" +export DOWNLOAD_DIR="${TARGET_DIR}/download" +export CROSS_HOST="$(echo $MACHTYPE |\ + sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")" +export CROSS_TARGET="mips64el-unknown-linux-gnu" +#export MABI="n32" +export MABI="64" +#export MARCH="loongson2e" +export MARCH="loongson2f" +export PATH=${TARGET_DIR}/cross-tools/bin:/bin:/usr/bin +unset CFLAGS +unset CXXFLAGS +EOF +source ~/.bash_profile +@end verbatim + +@samp{set +h} tells Bash to not locate nor remember commands (hash) as +they are looked up for execution. + +@samp{umask 022} sets Bash process' file creation mask to +@samp{022}. This results in permissions of `755' for those files. + +@samp{export PS1='\[\e[32m\]\A-\W\[\e[00m\]\$ '} sets the primary +prompt strings. The primary prompt strings are the strings you see +before the commands you type in the terminal. The part @samp{\A-\W} +means that the time, in 24-hour HH:MM format and the basename of +@env{$PWD} will be displayed separated by a `-', as in +@samp{19:33-bin}. The part @samp{\$} adds a dollar sign at the end, +@samp{\[\e[32m\]} colors the strings in green and @samp{\[\e[00m\]} +gets the original color back. For other colors, you can browse +@uref{http://en.wikipedia.org/wiki/ANSI_escape_code}. + +@env{LC_ALL} is a macro used to define a single locale to overwrite +other @env{LC_*} and @env{LANG} environment variables so that +language, numeric values, time and other locale-dependant values have +all the same value. It is set to the standard POSIX locale. + +@samp{export BUILD_DIR="$@{TARGET_DIR@}/build"} sets the environment +variable @env{BUILD_DIR} to the value of @samp{$@{TARGET_DIR@}/build} +which is @samp{/gllfsc/build} in this document. + +The value of variable @env{CROSS_HOST} equals the value of variable +@env{MACHTYPE} of the current machine (for instance +@samp{i686-pc-linux-gnu}) modulo the second word, which is replaced by +@samp{cross} (i.e. @samp{i686-cross-linux-gnu}). + +The value of variable @env{CROSS_TARGET} equals the value of variable +@env{MACHTYPE} of the machine for which the system is built (i.e. +@samp{mips64el-unknown-linux-gnu}). + +The variable @env{MABI} defines the @acronym{ABI} (Application Binary +Interface) for which the system will be built. @option{-mabi} is an +option of GCC. n32/64 are for 64-bit CPUs only. 64 has 64-bit pointers +and long integers, whereas n32 has 32-bit pointers and long integers. + +The variable @env{MARCH} defines the architecture for which the system +will be built. @option{-march} is an option of @acronym{GCC} (GNU +Compiler Collection). + +The variable @env{PATH} contains a colon-separated list of directories +in which the shell looks for commands. The shell will first look for +commands in @file{$@{TARGET_DIR@}/cross-tools/bin}, then, if the +command was not found, in @file{/bin} and finally in @file{/usr/bin}. + +@command{unset} command removes the variable associated, here +@env{CFLAGS} and @env{CXXFLAGS}. Those variables are used by GCC as +extra flags given to the C compiler and the C++ compiler +respectively. + +Finally @samp{source ~/.bash_profile} reads and executes the content +of the file @file{~/.bash_profile}. + + +@node Downloads +@section Downloads + +@menu +* Packages Download:: List of packages to be downloaded. +* Patches Download:: List of patches to be downloaded. +@end menu + + +@node Packages Download +@subsection Downloading Packages + +The packages listed below are those used in this document. You can try +other versions but you will need a recent version of Binutils and the +kernel Linux in order to use the two options +@option{-mfix-loongson2f-nop} and +@option{-mfix-loongson2f-jump}. Those work around a problem related to +the Loongson2F architecture@footnote{For more information about the +issue, see +@uref{http://groups.google.com/group/loongson-dev/browse_thread/thread/d9103283141c00fb/e9a8830b01cc1913?hide_quotes=no#msg_d44adf83639fb0bd} +and @uref{http://sourceware.org/ml/binutils/2009-11/msg00387.html}.}. + +Download those files under @env{$@{DOWNLOAD_DIR@}} (which is +@file{/gllfsc/download} in this document). + + +@itemize +@item +Autoconf: @uref{http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz}. + +@item +Automake: @uref{http://ftpmirror.gnu.org/automake/automake-1.12.4.tar.gz}. + +@item +Bash: @uref{http://ftpmirror.gnu.org/bash/bash-4.2.tar.gz}. + +@item +Binutils: @uref{http://ftpmirror.gnu.org/binutils/binutils-2.22.tar.bz2}. + +@item +Bison: @uref{http://ftpmirror.gnu.org/bison/bison-2.5.tar.bz2}. + +@item +Bootscripts: @uref{http://ftp.cross-lfs.org/pub/clfs/conglomeration/bootscripts-@/cross-lfs/bootscripts-cross-lfs-1.2-pre11.tar.bz2}. +@c @uref{http://ftp.cross-lfs.org/pub/clfs/conglomeration/bootscripts@/-cross-lfs/bootscripts-cross-lfs-2.0-pre2.tar.xz}. + +@item +Bzip2: @uref{http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz}. + +@item +Coreutils: @uref{http://ftpmirror.gnu.org/coreutils/coreutils-8.19.tar.xz}. + +@item +DHCPCD: @uref{http://roy.marples.name/downloads/dhcpcd/dhcpcd-5.6.2.tar@/.bz2}. + +@item +Diffutils: @uref{http://ftpmirror.gnu.org/diffutils/diffutils-3.2.tar.gz}. + +@item +E2fsprogs: @uref{http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.42.6.tar@/.gz}. + +@item +File: @uref{ftp://ftp.astron.com/pub/file/file-5.11.tar.gz}. + +@item +Findutils: @uref{http://ftpmirror.gnu.org/findutils/findutils-4.4.2.tar.gz}. + +@item +Flex: @uref{http://downloads.sourceforge.net/flex/flex-2.5.37.tar.bz2}. + +@item +Gawk: @uref{http://ftpmirror.gnu.org/gawk/gawk-4.0.1.tar.gz}. + +@item +GCC: @uref{http://ftpmirror.gnu.org/gcc/gcc-4.7.2/gcc-4.7.2.tar.bz2}. + +@item +Gettext: @uref{http://ftpmirror.gnu.org/gettext/gettext-0.18.1.1.tar.gz}. + +@item +Glibc: @uref{http://ftpmirror.gnu.org/glibc/glibc-2.13.tar.bz2}. +@c @uref{http://ftpmirror.gnu.org/glibc/glibc-2.16.0.tar.bz2}. +@c fails to generate localedef + +@item +Glibc-Ports: @uref{http://ftpmirror.gnu.org/glibc/glibc-ports-2.13.tar.bz2}. + +@item +Gmp: @uref{http://ftpmirror.gnu.org/gmp/gmp-5.0.5.tar.bz2}. + +@item +Grep: @uref{http://ftpmirror.gnu.org/grep/grep-2.14.tar.xz}. + +@item +Groff: @uref{http://ftpmirror.gnu.org/groff/groff-1.21.tar.gz}. + +@item +Gzip: @uref{http://ftpmirror.gnu.org/gzip/gzip-1.5.tar.gz}. + +@item +Iana-Etc: @uref{http://sethwklein.net/iana-etc-2.30.tar.bz2}. + +@item +Iputils: @uref{http://www.skbuff.net/iputils/iputils-s20071127.tar.bz2}. +@c @uref{http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2}. +@c depends on sysfs headers. + +@item +Iproute2: @uref{http://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.5.1@/.tar.bz2} + +@item +Kbd: @uref{http://ftp.altlinux.org/pub/people/legion/kbd/kbd-1.15.3.tar.gz}. + +@item +Kmod: @uref{http://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-10.tar.gz}. + +@item +Less: @uref{http://www.greenwoodsoftware.com/less/less-451.tar.gz}. + +@item +Libtool: @uref{http://ftpmirror.gnu.org/libtool/libtool-2.4.tar.gz}. + +@item +Linux-Libre @footnote{The kernel Linux is shipped with proprietary +firmware. The version called Linux-Libre exists without them, it is +available for download at +@uref{http://www.fsfla.org/svnwiki/selibre/linux-libre/}.}: +@uref{http://linux-libre.fsfla.org/pub/linux-libre/releases/3.5.4-gnu@//linux-libre-3.5.4-gnu.tar.bz2}. + +@item +M4: @uref{http://ftpmirror.gnu.org/m4/m4-1.4.16.tar.bz2}. + +@item +Make: @uref{http://ftpmirror.gnu.org/make/make-3.82.tar.bz2}. + +@item +Man-Pages: @uref{http://www.kernel.org/pub/linux/docs/man-pages/Archive/man-pages-@/3.32.tar.bz2}. + +@item +Man: @uref{http://primates.ximian.com/~flucifredi/man/man-1.6g.tar.gz}. + +@item +Mpc: @uref{http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz}. + +@item +Mpfr: @uref{http://www.mpfr.org/mpfr-3.1.1/mpfr-3.1.1.tar.bz2}. + +@item +Nano: @uref{http://ftpmirror.gnu.org/nano/nano-2.3.1.tar.gz} + +@item +Ncurses: @uref{ftp://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz}. + +@item +Patch: @uref{http://ftpmirror.gnu.org/patch/patch-2.7.1.tar.bz2}. + +@item +Procps: @uref{http://procps.sourceforge.net/procps-3.2.8.tar.gz}. + +@item +Psmisc: @uref{http://sourceforge.net/projects/psmisc/files/psmisc/psmisc-22.20.tar@/.gz/download}. + +@item +Readline: @uref{http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz}. + +@item +Rsyslog: @uref{http://rsyslog.com/files/download/rsyslog/rsyslog-5.8.6.tar.gz}. + +@item +Sed: @uref{http://ftpmirror.gnu.org/sed/sed-4.2.1.tar.bz2}. + +@item +Shadow: @uref{http://pkg-shadow.alioth.debian.org/releases/shadow-4.1.4.3.tar.bz2}. +@c @uref{http://pkg-shadow.alioth.debian.org/releases/shadow-4.1.5.1.tar@/.bz2}. + +@item +Sysvinit: @uref{http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf@/.tar.bz2}. + +@item +Tar: @uref{http://ftpmirror.gnu.org/tar/tar-1.26.tar.bz2}. + +@item +Texinfo: @uref{http://ftpmirror.gnu.org/texinfo/texinfo-4.13a.tar.gz}. + +@item +Udev: @uref{ftp://ftp.kernel.org/pub/linux/utils/kernel/hotplug/udev-175.tar.gz}. +@c @uref{http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-182.tar.bz2}. +@c troubles with blkid + +@item +Util-Linux: @uref{http://www.kernel.org/pub/linux/utils/util-linux/v2.19/util-@/linux-2.19.1.tar.bz2}. +@c @uref{http://www.kernel.org/pub/linux/utils/util-linux/v2.22/util-linux-2.22.tar.bz2}. +@c requires PAM headers + +@item +XZ-Utils: @uref{http://tukaani.org/xz/xz-5.0.4.tar.bz2}. + +@item +Zlib: @uref{http://sourceforge.net/projects/libpng/files/zlib/1.2.7/zlib-1.2.7.tar@/.bz2/download}. +@end itemize + + +@node Patches Download +@subsection Downloading Patches + +Patches and configuration files location: + +@itemize +@item +@uref{http://cjarry.org/gnu-linux/gllfsc/gllfsc-loongson2f-1.0-@/patches.tar.gz}. After +having downloaded this file under @env{$@{DOWNLOAD_DIR@}}, execute +the following commands to extract its content: + +@verbatim +pushd ${DOWNLOAD_DIR} +tar xvf gllfsc-loongson2f-1.0-patches.tar.gz +popd +@end verbatim + + +@item +The page +@uref{http://microcai.gsalex.net/old/archives/2011/01/fbcon_UNICODE_font_support.html} +is useful for users who want support for @acronym{CJK} (Chinese +Japanese Korean) characters under the (non-graphical) terminal. It +gives access to a git@footnote{@uref{http://git-scm.com/}} repository +with kernel patches@footnote{The patches to use with version 3.5 of +the kernel are the first four on +@uref{http://repo.or.cz/w/linux-2.6/cjktty.git/shortlog/refs/heads/3.5-utf8}.} +that permit direct rendering of UTF-8 characters under the framebuffer +environment. Be aware though that applying those CJK patches to the +kernel may make characters that are both non-CJK and non-ASCII +unreadable (accented letters, cyrillic, etc.). + +@item +@uref{http://www.fsfla.org/svn/fsfla/software/linux-libre/lemote/gnewsense/tags/@/3.5.4-gnu_0loongsonlibre/100gnu+freedo.patch} +this patch adds a picture of a GNU beside Freedo, Freedo being the +mascot of Linux-Libre. The image can be seen on +@uref{http://www.fsfla.org/svnwiki/selibre/linux-libre/100gnu+freedo}. +@end itemize + + +@node Final Preparations +@section Final Preparations + +@menu +* Target Filesystem Hierarchy Creation:: Creating the directories of + the target system. +* Needed Files Creation:: Creating files for needed + user, groups and log. +@end menu + + +@node Target Filesystem Hierarchy Creation +@subsection Target Filesystem Hierarchy Creation + +@verbatim +pushd ${TARGET_DIR} +mkdir -pv bin boot dev {etc/,}opt home lib mnt +mkdir -pv proc media/{floppy,cdrom} sbin srv sys +mkdir -pv var/{lock,log,mail,run,spool} +mkdir -pv var/{opt,cache,lib/{misc,locate},local} +install -dv -m 0750 root +install -dv -m 1777 {var/,}tmp +mkdir -pv usr/{,local/}{bin,include,lib,sbin,src} +mkdir -pv usr/{,local/}share/{doc,info,locale,man} +mkdir -pv usr/{,local/}share/{misc,terminfo,zoneinfo} +mkdir -pv usr/{,local/}share/man/man{1..8} +for dir in usr{,/local}; do + ln -sv share/{man,doc,info} $dir +done +ln -svf lib lib64 +ln -svf lib lib32 +ln -svf lib usr/lib64 +ln -svf lib usr/lib32 +cd boot +ln -svf . boot +popd +@end verbatim + +The command @samp{install -dv -m 1777 @{var/,@}tmp} creates the +directories @file{var/tmp} and @file{tmp} with the permissions to +read, write and execute for everyone. The '1' in @samp{1777} is the +sticky bit which allows deletion of the file or directory having this +attribute only for the owner of the file or directory. + +The command @samp{ln -svf lib lib64} creates a symbolic link (option +@option{-s}) with the name @file{lib64} which will point to +@file{lib}. + + +@node Needed Files Creation +@subsection Creating needed user, groups and log files + +@verbatim +cat > ${TARGET_DIR}/etc/passwd << "EOF" +root::0:0:root:/root:/bin/bash +EOF +@end verbatim + +The file @file{/etc/passwd} contains one line for each user account, +with seven fields delimited by colons. These fields are: + +@itemize +@item +login name; + +@item +optional encrypted password; + +@item +numerical user ID; + +@item +numerical group ID; + +@item +user name or comment field; + +@item +user home directory; + +@item +optional user command interpreter. +@end itemize + + +@verbatim +cat > ${TARGET_DIR}/etc/group << "EOF" +root:x:0: +bin:x:1: +sys:x:2: +kmem:x:3: +tty:x:4: +tape:x:5: +daemon:x:6: +floppy:x:7: +disk:x:8: +lp:x:9: +dialout:x:10: +audio:x:11: +video:x:12: +utmp:x:13: +usb:x:14: +cdrom:x:15: +EOF +@end verbatim + +The file @file{/etc/group} is a text file which defines the groups on +the system. There is one entry per line, with the following format: +@samp{group_name:password:GID:user_list}. + + +@verbatim +touch ${TARGET_DIR}/var/run/utmp \ + ${TARGET_DIR}/var/log/{btmp,lastlog,wtmp} +chmod -v 664 ${TARGET_DIR}/var/run/utmp \ + ${TARGET_DIR}/var/log/lastlog +@end verbatim + + +@node Building the Cross-Compilation Toolchain +@chapter Building the Cross-Compilation Toolchain + +In this chapter, the cross-compilation toolchain is built as well as +core components of the target system. Those will then be used to build +the target system. + +@menu +* Target Linux-Header:: Linux-Header for target system. +* Cross Binutils:: Binutils for cross-compilation. +* Cross GCC:: GCC for cross-compilation (C support only). +* Target glibc:: glibc for target system. +* Cross GCC CXX:: GCC for cross-compilation (C and C++ support). +@end menu + + +@node Target Linux-Header +@section Target Linux-Header + +To build a GNU/Linux distribution for Loongson 2F without patch, you +need at least version 2.6.33 of the kernel Linux (-libre) as it +includes: basic CS5536 VSM support, CS5536 MFGPT timer support, CPU +frequency scaling support, suspend support framework, basic Loongson +2F support, support for GZIP / BZIP2 / LZMA compressed kernel images +@footnote{See @uref{http://kernelnewbies.org/Linux_2_6_33} for more +information.}. Moreover, version 2.6.35 and above include fixes for +Loongson2F processor @footnote{See +@uref{http://lwn.net/Articles/386986/} for more information.}. + +I chose version stable 3.5.4-gnu because it is from the stable branch, +it has been deblobed with the latest version of the deblob +script@footnote{@uref{http://linux-libre.fsfla.org/pub/linux-libre/releases/3.5.4-gnu/deblob-main}} +and because it is recent and as such it should include the most +complete support for Loongson 2F. + + +@verbatim +# 6 minutes +tar xf ${DOWNLOAD_DIR}/linux-libre-3.5.4-gnu.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/linux-3.5.4 +make mrproper +make ARCH=mips headers_check +make ARCH=mips INSTALL_HDR_PATH=dest headers_install +cp -rv dest/include/* ${TARGET_DIR}/usr/include +cd .. +rm -rf linux-3.5.4 +popd +@end verbatim + +@samp{6 minutes} is the time it takes to build the package on Lemote +Yeeloong with a Loongson 2F processor. + +The command @samp{make mrproper} cleans the sources. + +We need to specify @samp{ARCH=mips} as we are cross-compiling. + + +@node Cross Binutils +@section Cross Binutils + +GNU Binutils (GNU binary utilities) is a collection of programs for +manipulating binaries. + + +@verbatim +# 35 minutes +tar xf ${DOWNLOAD_DIR}/binutils-2.22.tar.bz2 -C ${BUILD_DIR} +pushd $BUILD_DIR/binutils-2.22 +mkdir -pv ../binutils-build +cd ../binutils-build +CC="gcc" AR="ar" \ + ../binutils-2.22/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --enable-64-bit-bfd \ + --with-sysroot=${TARGET_DIR} \ + --disable-nls \ + --enable-shared +make configure-host +make +make install +cp -v ../binutils-2.22/include/libiberty.h \ + ${TARGET_DIR}/usr/include +cd .. +rm -rf binutils-build +rm -rf binutils-2.22 +popd +@end verbatim + +@samp{CC="gcc"} and @samp{AR="ar"} are flags that tell the +@file{configure} script to use the local commands @command{gcc} as the +C compiler and @command{ar} as the program that handles archives. + +@option{--prefix=$@{TARGET_DIR@}/cross-tools} tells the configure +script to install architecture-independant files in +@file{$@{TARGET_DIR@}/cross-tools}. + +The option @option{--enable-64-bit-bfd} enables 64 bit for +@acronym{BFD} (the Binary File Descriptor). + +@option{--with-sysroot=@env{$@{TARGET_DIR@}}} tells Binutils to +consider @env{$@{TARGET_DIR@}} as the root of a tree that contains (a +subset of) the root filesystem of the target operating system. Target +system headers, libraries and run-time object files will be searched +in there. + +The @option{--enable-nls} option enables Native Language Support +(NLS), which lets Binutils output diagnostics in languages other than +American English. Native Language Support is enabled by default if not +doing a canadian cross build. The @option{--disable-nls} option +disables NLS. + +The option @option{--enable-shared} is used to build shared versions +of libraries, if shared libraries are supported on the target +platform. Use @option{--disable-shared} to build only static +libraries. + +@c cp -v ../binutils-2.22/include/libiberty.h \ +@c ${TARGET_DIR}/usr/include + + +@node Cross GCC +@section Cross GCC (C support only) + +GCC is the GNU compiler collection. It can compile many languages, of +which only C and C++ will be enabled in this document. + +In this section, we build a minimal GCC in order to build glibc. + +@quotation Warning +to build GMP (a GCC dependency), you need a version of GCC different +from 4.3.2 on you system@footnote{@uref{http://gmplib.org/#STATUS}}: +@end quotation + +@quotation +GCC 4.3.2 miscompiles GMP on 64-bit machines; please use a different +gcc version (e.g., gcc 4.3.1 and gcc 4.3.3 both work properly). We +have not been able to find any workaround for this gcc bug. +Unfortunately, Debian 5.0 has decided to stay with this trouble gcc +version, resulting in that many users strike this bug. +@end quotation + +I recommend installing @samp{gcc-4.4} on gNewSense Parkes to avoid +this issue. + +@verbatim +# 2 hours +tar xf ${DOWNLOAD_DIR}/gcc-4.7.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gcc-4.7.2 +tar xf ${DOWNLOAD_DIR}/gmp-5.0.5.tar.bz2 +mv gmp-5.0.5 gmp +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz +mv mpc-1.0.1 mpc +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.1.tar.bz2 +mv mpfr-3.1.1 mpfr +mkdir -pv ../gcc-build +cd ../gcc-build +../gcc-4.7.2/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --with-sysroot=${TARGET_DIR} \ + --disable-multilib \ + --with-newlib \ + --disable-nls \ + --disable-shared \ + --disable-threads \ + --enable-languages=c \ + --with-abi=${MABI} +make all-gcc +make all-target-libgcc +make install-gcc +make install-target-libgcc +cd .. +rm -r gcc-build +rm -r gcc-4.7.2 +popd +@end verbatim + +@option{--disable-multilib} specifies that multiple target libraries +to support different target variants@footnote{Such as different ABI, +for instance n32 and 64.}, calling conventions, etc@:. should not be +built. The default is to build a predefined set of them. + +@option{--with-newlib} specifies that @samp{newlib} is being used as +the target C library. + +@option{--disable-threads} specifies that threading support should be +disabled. + +@option{--enable-languages=c} specifies that only the C compiler and +its runtime libraries should be built. + +@c --with-abi=${MABI} + +GCC provides a low-level runtime library, @file{libgcc.a} or +@file{libgcc_s.so.1} on some platforms. GCC generates calls to +routines in this library automatically, whenever it needs to perform +some operation that is too complicated to emit inline code for. This +is built with @samp{make all-target-libgcc} and installed with +@samp{make install-target-libgcc} + + +@node Target glibc +@section Target glibc + +Glibc is the GNU C library. It provides macros, type definitions, and +functions for tasks like string handling, mathematical computations, +input/output processing, memory allocation and several other operating +system services. + +@verbatim +# 4 hours +tar xf ${DOWNLOAD_DIR}/glibc-2.13.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/glibc-2.13 +tar xf ${DOWNLOAD_DIR}/glibc-ports-2.13.tar.bz2 +mv -v glibc-ports-2.13 ports +#sed -i.orig "s/\ -lgcc_eh\|\ -lgcc_s//g" Makeconfig +patch -Np1 -i ${DOWNLOAD_DIR}/glibc-2.13-libgcc_eh.patch +patch -Np1 -i ${DOWNLOAD_DIR}/glibc-2.13-ldd-rewrite-script.patch +patch -Np1 -i ${DOWNLOAD_DIR}/glibc-2.13-localedef_segfault-1.patch +patch -Np1 -i ${DOWNLOAD_DIR}/glibc-2.13-cross_hacks-2.patch +echo "" > ports/sysdeps/mips/mips64/n64/Makefile +echo "" > ports/sysdeps/mips/mips64/n32/Makefile +echo "" > ports/sysdeps/mips/mips32/Makefile +sed -i "/default) machine=/s/n32/${MABI}/g" \ + ports/sysdeps/mips/preconfigure +mkdir -pv ../glibc-build +cd ../glibc-build + +cat > config.cache << EOF +libc_cv_c_cleanup=yes +libc_cv_slibdir=/lib +EOF + +cat > configparms << EOF +install_root=${TARGET_DIR} +libdir=/usr/lib +EOF + +BUILD_CC="gcc" \ + CC="${CROSS_TARGET}-gcc -march=${MARCH} -mabi=${MABI}" \ + AR="${CROSS_TARGET}-ar" \ + RANLIB="${CROSS_TARGET}-ranlib" \ + ../glibc-2.13/configure \ + --prefix=/usr \ + --libexecdir=/usr/lib/glibc \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --disable-profile \ + --enable-add-ons \ + --with-tls \ + --enable-kernel=3.5.4 \ + --with-__thread \ + --with-binutils=${TARGET_DIR}/cross-tools/bin \ + --with-headers=${TARGET_DIR}/usr/include \ + --cache-file=config.cache +make +make install +make localedata/install-locales +cd .. +rm -rf glibc-build +rm -rf glibc-2.13 +popd + +cat > ${TARGET_DIR}/etc/nsswitch.conf << "EOF" +# Begin /etc/nsswitch.conf + +passwd: files +group: files +shadow: files + +hosts: files dns +networks: files + +protocols: files +services: files +ethers: files +rpc: files + +# End /etc/nsswitch.conf +EOF + +cp -v --remove-destination \ + ${TARGET_DIR}/usr/share/zoneinfo/Europe/Paris \ + ${TARGET_DIR}/etc/localtime + +cat > ${TARGET_DIR}/etc/ld.so.conf << "EOF" +# Begin /etc/ld.so.conf + +/usr/local/lib +/opt/lib + +# End /etc/ld.so.conf +EOF +@end verbatim + +@c @samp{sed -i.orig "s/\ -lgcc_eh\|\ -lgcc_s//g" Makeconfig} + +The patch @file{glibc-2.13-libgcc_eh.patch} is used in order not to +use library @samp{gcc_eh} to build @samp{libgcc_eh} and +@samp{static-gnulib} if current compiler does not have +@samp{libgcc_eh}. + +The patch @file{glibc-2.13-ldd-rewrite-script.patch} is used to fix a +bug in glibc when the configure script is called from a relative path. + +The patch @file{glibc-2.13-localedef_segfault-1.patch} is used to +overcome a segfault you may have when generating locales if you use +PaX. PaX is a patch for the kernel Linux that implements least +privilege protections for memory pages. + +The patch @file{glibc-2.13-cross_hacks-2.patch} is used specially to +build locales by cross-compilation. + +Glibc uses @samp{n32} ABI by default with MIPS. To use @env{MABI} +instead, we do the following: + +@verbatim +echo "" > ports/sysdeps/mips/mips64/n64/Makefile +echo "" > ports/sysdeps/mips/mips64/n32/Makefile +echo "" > ports/sysdeps/mips/mips32/Makefile +sed -i "/default) machine=/s/n32/${MABI}/g" \ + ports/sysdeps/mips/preconfigure +@end verbatim + +@ignore +Contents of the files above. + +cat mips64/n64/Makefile +# `long double' is a distinct type we support. +long-double-fcts = yes + +ifeq ($(filter -mabi=64,$(CC)),) +CC += -mabi=64 +endif + +cat mips64/n32/Makefile +# `long double' is a distinct type we support. +long-double-fcts = yes + +ifeq ($(filter -mabi=n32,$(CC)),) +CC += -mabi=n32 +endif + +cat mips32/Makefile +ifeq ($(filter -mabi=32,$(CC)),) +CC += -mabi=32 +endif + +grep 'default)' preconfigure + + default) machine=mips/mips64/n32 mips_config_abi=n32 ;; + +@end ignore + +The file @file{config.cache} is used to attribute values to variables +of the configure script. + +@samp{libc_cv_forced_unwind=yes} is used to avoid the error message +@samp{error: forced unwind support is required}. + +@samp{libc_cv_c_cleanup=yes} is used to avoid the error message +@samp{error: the compiler must support C cleanup handling}. + +@samp{libc_cv_slibdir=/lib} defines @file{/lib} as the directory in +which the C library of the target system will be installed, instead of +@file{/lib64} or @file{/lib32}. + +You can install glibc somewhere other than where you configured it to +go by setting the @code{install_root} variable on the command line for +@samp{make install}. The value of this variable is prepended to all +the paths for installation. This is useful when setting up a chroot +environment or preparing a binary distribution. The directory should +be specified with an absolute file name. + +Files listed in @samp{install-lib} are installed in the directory +specified by @samp{libdir} in @file{configparms} or @file{Makeconfig}. + +@verbatim +BUILD_CC="gcc" \ + CC="${CROSS_TARGET}-gcc -march=${MARCH} -mabi=${MABI}" \ + AR="${CROSS_TARGET}-ar" \ + RANLIB="${CROSS_TARGET}-ranlib" +@end verbatim + +@samp{CC="$@{CROSS_TARGET@}-gcc -march=$@{MARCH@} -mabi=$@{MABI@}"} +sets @code{CC} to the cross-compiler for the target's architecture, +processor and ABI we configured the library for. @code{AR} and +@code{RANLIB} are set to cross-compiling versions of @code{ar} and +@code{ranlib} as the native tools are not configured to work with +object files for the target we configured for. + +@option{--prefix=/usr} tells the @file{configure} script to install +glibc in the @file{/usr} directory of the target system. + +@c @option{--libexecdir=/usr/lib/glibc} tells the configure script to +@c install glibc executables inside @file{/usr/lib/glibc}. + +Unlike previous builds, @option{--host} now equals +@env{$@{CROSS_TARGET@}} instead of @env{$@{CROSS_HOST@}}. This is +because we are building the glibc version that the target system will +use. We won't have to build it later. + +Profiling can be of help to optimize a program by analysing memory +use, the usage of particular instructions, etc. Option +@option{--disable-profile} is used to disable this. + +Option @option{--enable-add-ons} is used to enable all the add-on +packages in the main source directory, which includes the glibc-ports +used to support the MIPS architecture. + +The option @option{--with-tls} tells the configure script to use +@acronym{TLS} (thread-local storage). Thread-local storage is a +computer programming method that uses memory local to a thread. + +The @samp{3.5.4} parameter given to option @option{--enable-kernel} +describes the smallest version of the Linux kernel the generated +library is expected to support. The higher the version number is, the +less compatibility code is added, and the faster the code gets. + +Option @option{--with-__thread} enables threads in glibc. + +The option @option{--with-binutils=$@{TARGET_DIR@}/cross-tools/bin} +tells the @file{configure} script to use the binutils (assembler and +linker) built in the cross-compilation toolchain process. + +@option{--with-headers=$@{TARGET_DIR@}/usr/include} indicates the +location of the kernel Linux' headers. + +@option{--cache-file=config.cache} specifies the file in which cache +variables are listed for @file{configure}. + +@samp{make localedata/install-locales} configures all locales that are +supported by glibc. + +The file @file{$@{TARGET_DIR@}/etc/nsswitch.conf} contains the +configuration of @acronym{NSS} (Name Service Switch). NSS is a facility +in Unix-like operating systems that provides a variety of sources for +common configuration databases and name resolution mechanisms. These +sources include local operating system files (such as +@file{/etc/passwd}, @file{/etc/group}, and @file{/etc/hosts}), the +Domain Name System (DNS), the Network Information Service (NIS), and +LDAP. + +The timezone is defined for `Paris'. + +@c Purpose of the file @file{$@{TARGET_DIR@}/etc/ld.so.conf} + + +@node Cross GCC CXX +@section Cross GCC (C and C++ support) + +In this section, we build a complete cross-compiler with support for C +and C++ languages. + +@verbatim +# 3 hours and 30 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gcc-4.7.2 +tar xf ${DOWNLOAD_DIR}/gmp-5.0.5.tar.bz2 +mv gmp-5.0.5 gmp +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz +mv mpc-1.0.1 mpc +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.1.tar.bz2 +mv mpfr-3.1.1 mpfr +mkdir -v ../gcc-build +cd ../gcc-build +../gcc-4.7.2/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --with-sysroot=${TARGET_DIR} \ + --disable-nls \ + --enable-shared \ + --enable-__cxa_atexit \ + --disable-multilib \ + --with-abi=${MABI} \ + --enable-c99 \ + --enable-long-long \ + --enable-threads=posix \ + --enable-languages=c,c++ +make +make install +cd .. +rm -rf gcc-build +rm -rf gcc-4.7.2 +popd +@end verbatim + +@option{--enable-__cxa_atexit} enables @code{__cxa_atexit}, rather +than @code{atexit}, to register C++ destructors for local statics and +global objects. This is essential for fully standards-compliant +handling of destructors, but requires @code{__cxa_atexit} in libc. + +@option{--enable-c99} enables support for the C99 standard. + +@option{--enable-long-long} enables support for @code{long long int} +types. + +@c @option{--enable-threads=posix} + + +@node Building Cross-Compilation Tools +@chapter Building the Cross-Compilation Tools + +@menu +* Cross File:: File for cross-compilation. +* Cross Groff:: Groff for cross-compilation. +* Cross Shadow:: Shadow for cross-compilation. +* Cross M4:: M4 for cross-compilation. +* Cross Ncurses:: Ncurses for cross-compilation. +* Cross Cleaning:: Cleaning up the cross-compilation toolchain. +@end menu + + +@node Cross File +@section File + +The command @command{file} is used to determine the type of a file: +text, executable or data. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/file-5.11.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/file-5.11 +./configure \ + --prefix=${TARGET_DIR}/cross-tools +make +make install +cd .. +rm -rf file-5.11 +popd +@end verbatim + + +@node Cross Groff +@section Groff + +Groff is the GNU version of the roff document formatting system which +is used to produce man pages. + +You need G++ on your system to compile this program from source. Under +gNewSense Parkes, try @samp{sudo apt-get install g++-4.4}. + +@ignore +@quotation Note +psselect (part of psutils) is needed for documentation in HTML (see +@uref{http://cblfs.cross-lfs.org/index.php/PSUtils}). +@end quotation +@end ignore + + +@verbatim +# 15 minutes +tar xf ${DOWNLOAD_DIR}/groff-1.21.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/groff-1.21 +PAGE=A4 \ + ./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --without-x +make +make install +cd .. +rm -rf groff-1.21 +popd +@end verbatim + +@samp{PAGE=A4} defines the default format of pages for printed output. + +@option{--without-x} disables the dependancy on the X window system. + + +@node Cross Shadow +@section Shadow + +The package contains programs to handle users, groups and passwords in +a secure way: passwords are encrypted. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/shadow-4.1.4.3 +patch -Np1 -i ${DOWNLOAD_DIR}/shadow-4.1.4.3-sysroot_hacks-1.patch +sed -i.orig \ + 's/bindir)\/\$\$i/bindir)\/mips64el-unknown-linux-gnu-\$\$i/' \ + src/Makefile.am +automake-1.11 +echo "shadow_cv_passwd_dir=${TARGET_DIR}/bin" > config.cache +echo "ac_cv_func_lckpwdf=no" >> config.cache +./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --sbindir=${TARGET_DIR}/cross-tools/bin \ + --sysconfdir=${TARGET_DIR}/etc \ + --disable-shared \ + --without-audit \ + --without-libpam \ + --without-selinux \ + --program-prefix=${CROSS_TARGET}- \ + --cache-file=config.cache +sed -i.orig "/PASSWD_PROGRAM/s/passwd/${CROSS_TARGET}-&/" config.h +make +make install +cd .. +rm -rf shadow-4.1.4.3 +popd +@end verbatim + +@c @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin} +@c @samp{ac_cv_func_lckpwdf=no} + +The patch @file{shadow-4.1.4.3-sysroot_hacks-1.patch} is used so that +shadow can be built with the sysroot method. Because we use this +patch, @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin} and +@samp{ac_cv_func_lckpwdf=no} have to be added in @file{config.cache} +in order for the @file{configure} script not to test the +functionalities associated. + +@c @option{--sbindir=$@{TARGET_DIR@}/cross-tools/bin} + +@c @option{--sysconfdir=$@{TARGET_DIR@}/etc} + +@option{--without-audit}, @option{--without-libpam} and +@option{--without-selinux} disable support for auditing, @acronym{PAM} +(Pluggable authentication modules) and @acronym{SELinux} +(Security-Enhanced Linux). We do not need those extra features. + +@option{--program-prefix=$@{CROSS_TARGET@}-} prepends the value of +@env{CROSS_TARGET} (that is @samp{mips64el-unknown-linux-gnu} in this +document) to installed program names for cross-compilation. + +@c @samp{sed -i.orig "/PASSWD_PROGRAM/s/passwd/$@{CROSS_TARGET@}-&/" +@c config.h} is used to avoid the error message + + +@node Cross M4 +@section Cross M4 + +Bison 2.5 requires M4 to be built. + +GNU M4 is a package containing an implementation of the m4 macro +language. GNU M4 is used in GNU Autoconf' @file{configure} files. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/m4-1.4.16.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/m4-1.4.16 +./configure \ + --prefix=${TARGET_DIR}/cross-tools +make +make install +cd .. +rm -rf m4-1.4.16 +popd +@end verbatim + + +@node Cross Ncurses +@section Ncurses + +GNU ncurses contains a library used to write text-based user +interfaces in a terminal-independent manner. + +@verbatim +# 15 minutes +tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/ncurses-5.9 +./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --without-shared +make -C include +make -C progs tic +install -m755 progs/tic ${TARGET_DIR}/cross-tools/bin +cd .. +rm -rf ncurses-5.9 +popd +@end verbatim + +@option{--without-shared} is used to avoid building the whole library +as only @command{tic} is installed. + + +@node Cross Cleaning +@section Cleaning up Cross-Compilation Toolchain + +In order to save some space, binaries and libraries of +cross-compilation tools can be stripped out. + +@quotation Warning +incorrect cleaning arguments used against library files can lead to +library files breaking. For this reason, be careful of the command +arguments. If you are not comfortable with this, you can skip this +section as it will have no effect on the process of building the +target system. +@end quotation + + +@verbatim +pushd ${TARGET_DIR}/cross-tools +strip --strip-all bin/* +strip --strip-debug lib/* +popd +@end verbatim + +@option{--strip-all} removes all symbols. This command reduces the +size of the @file{bin} directory's content from 29 MB to 12 MB. + +@option{--strip-debug} removes debugging symbols only. This command +reduces the size of the @file{lib} directory's content from 21 MB to +20 MB. + + +@node Building the Target System +@chapter Building the Target System + +After having set up the cross-compilation toolchain and tools, the +operating system for the target machine is built in this chapter. + +@menu +* Environment Setup:: Setting up the environment. +* Man Pages:: Building Man Pages. +* Zlib:: Building Zlib. +* Binutils:: Building Binutils. +* GMP:: Building GMP. +* MPFR:: Building MPFR. +* MPC:: Building MPC. +* GCC:: Building GCC. +* Sed:: Building Sed. +* E2fsprogs:: Building E2fsprogs. +* Coreutils:: Building Coreutils. +* iana-etc:: Building iana-etc. +* M4:: Building M4. +* Bison:: Building Bison. +* Ncurses:: Building Ncurses. +* Procps:: Building Procps. +* Libtool:: Building Libtool. +* Readline:: Building Readline. +* Autoconf:: Building Autoconf. +* Automake:: Building Automake. +* Bash:: Building Bash. +* Bzip2:: Building Bzip2. +* DHCPCD:: Building DHCPCD. +* Diffutils:: Building Diffutils. +* File:: Building File. +* Findutils:: Building Findutils. +* Flex:: Building Flex. +* Gawk:: Building Gawk. +* Gettext:: Building Gettext. +* Grep:: Building Grep. +* Groff:: Building Groff. +* Gzip:: Building Gzip. +@c * Sysfsutils:: Building Sysfsutils. +* IPutils:: Building IPutils. +* Iproute2:: Building Iproute2. +* Kbd:: Building Kbd. +* Kmod:: Building Kmod. +* Less:: Building Less. +* Make:: Building Make. +* Man:: Building Man. +* Nano:: Building Nano. +* Patch:: Building Patch. +* Psmisc:: Building Psmisc. +* Rsyslog:: Building Rsyslog. +* Shadow:: Building Shadow. +* Sysvinit:: Building Sysvinit. +* Tar:: Building Tar. +* Texinfo:: Building Texinfo. +* Udev:: Building Udev. +* Util-Linux:: Building Util-Linux. +@c * Emacs:: Building Emacs. +* XZ-Utils:: Building XZ-Utils. +* Bootscripts:: Building Bootscripts. +* Kernel:: Building the Kernel. +@end menu + + +@node Environment Setup +@section Setting up the Environment + +Because this chapter is about the build of the target system and not +the build of the cross-compilation toolchain and tools anymore, we +need to update some environment variables. + +For more convenience, we can set environment variables up in the +@file{~/.bashrc} file, so that this setup is preserved when logging +in: + + +@verbatim +cat >> ~/.bashrc << EOF +export CFLAGS="-Wa,-mfix-loongson2f-nop" +export CC="${CROSS_TARGET}-gcc -march=${MARCH} -mabi=${MABI}" +export CXX="${CROSS_TARGET}-g++ -march=${MARCH} -mabi=${MABI}" +export AR="${CROSS_TARGET}-ar" +export AS="${CROSS_TARGET}-as" +export RANLIB="${CROSS_TARGET}-ranlib" +export LD="${CROSS_TARGET}-ld" +export STRIP="${CROSS_TARGET}-strip" +EOF +source ~/.bash_profile +@end verbatim + +The variable @env{CFLAGS} is set to @option{-Wa,-mfix-loongson2f-nop} +in which @option{-Wa} is a GCC option used to pass +@option{-mfix-loongson2f-nop} to the assembler. This option replaces +@code{NOP}@footnote{See @uref{http://en.wikipedia.org/wiki/NOP} for +more information} by @code{or at,at,zero} to work around the +Loongson2F @code{NOP} errata. Without it, under extreme cases, CPU +might deadlock@footnote{For more information about the issue, see +@uref{http://groups.google.com/group/loongson-dev/browse_thread/thread/d9103283141c00fb/e9a8830b01cc1913?hide_quotes=no#msg_d44adf83639fb0bd} +and +@uref{http://sourceware.org/ml/binutils/2009-11/msg00387.html}.}. + +@env{CC} is the flag that indicates the C compiler to be used, +@env{CXX} the C++ compiler, @env{AR} the archiver, @env{AS} the +assembler, @env{RANLIB} the archives' index generator, @env{LD} the +linker and @env{STRIP} the program for stripping. + +All the programs to be used are prefixed with +@samp{$@{CROSS_TARGET@}-} in order to use the cross-compilation +toolchain instead of the toolchain of the host. + + +@node Man Pages +@section Man Pages + +The man-pages package documents the kernel Linux and C library's +interfaces that are used by user-space programs. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/man-pages-3.32.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/man-pages-3.32 +make prefix=${TARGET_DIR}/usr install +cd .. +rm -rf man-pages-3.32 +popd +@end verbatim + +The option @option{prefix=$@{TARGET_DIR@}/usr} is used to install the +man pages on the target partition's @env{TARGET_DIR} instead of the +@file{/usr} directory of the host. + + +@node Zlib +@section Zlib + +Zlib is a compression/decompression library. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/zlib-1.2.7.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/zlib-1.2.7 +./configure \ + --prefix=/usr +make AR="${AR}" +make prefix=${TARGET_DIR}/usr install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/lib/libz.so.* ${TARGET_DIR}/lib +#ln -svf ../../lib/libz.so.1 ${TARGET_DIR}/usr/lib/libz.so +cd .. +rm -rf zlib-1.2.7 +popd +@end verbatim + +In order to build zlib by cross-compilation, the flag @env{AR} has to +be equal to @samp{$@{AR@}}. + +@ignore +@samp{mv -v $@{TARGET_DIR@}/usr/lib/libz.so.* $@{TARGET_DIR@}/lib} and +@samp{ln -svf ../../lib/libz.so.1 $@{TARGET_DIR@}/usr/lib/libz.so} are +used to comply with the @acronym{FHS} (filesystem hierarchy standard). +@end ignore + + +@node Binutils +@section Binutils + +@verbatim +# 30 minutes +tar xf ${DOWNLOAD_DIR}/binutils-2.22.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/binutils-2.22 +mkdir -pv ../binutils-build +cd ../binutils-build +../binutils-2.22/configure \ + --prefix=/usr \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --target=${CROSS_TARGET} \ + --enable-64-bit-bfd \ + --enable-shared +make configure-host +make tooldir=/usr +make DESTDIR=${TARGET_DIR} tooldir=/usr install +cp -v ../binutils-2.22/include/libiberty.h ${TARGET_DIR}/usr/include +cd .. +rm -rf binutils-build +rm -rf binutils-2.22 +popd +@end verbatim + +The option @option{--host} is now set to @env{CROSS_TARGET} because +the host that will run this build will be the target system. + +@c @samp{make tooldir=/usr} +@c @samp{make DESTDIR=$@{TARGET_DIR@} tooldir=/usr install} + + +@node GMP +@section GMP + +@acronym{GMP} (GNU multiple precision arithmetic library) is required +to build GCC. + +@verbatim +# 20 minutes +tar xf ${DOWNLOAD_DIR}/gmp-5.0.5.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gmp-5.0.5 +./configure \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --enable-cxx \ + --enable-mpbsd +make +make DESTDIR=${TARGET_DIR} install +rm -v ${TARGET_DIR}/usr/lib/lib{gmp,gmpxx,mp}.la +cd .. +rm -rf gmp-5.0.5 +popd +@end verbatim + +The option @option{--enable-cxx} enables support for the C++ language. + +The Berkeley MP compatibility library (libmp) and header file +(@file{mp.h}) are built and installed if the option +@option{--enable-mpbsd} is used. + +The files @file{$@{TARGET_DIR@}/usr/lib/lib@{gmp,gmpxx,mp@}.la} are +removed to avoid the following error when building MPFR: +@samp{/usr/lib/libgmp.so: could not read symbols: File in wrong +format}. + + +@node MPFR +@section MPFR + +GNU @acronym{MPFR} (Multiple Precision Floating-Point Reliably) is a +portable C library for arbitrary-precision binary floating-point +computation with correct rounding. + +@verbatim +# 7 minutes +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.1.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/mpfr-3.1.1 +./configure \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +rm -v ${TARGET_DIR}/usr/lib/libmpfr.la +cd .. +rm -rf mpfr-3.1.1 +popd +@end verbatim + +The file @file{$@{TARGET_DIR@}/usr/lib/libmpfr.la} is removed to +avoid the following error when building MPC: +@samp{/usr/lib/libmpfr.so: could not read symbols: File in wrong +format}. + + +@node MPC +@section MPC + +GNU @acronym{MPC} (Multiple Precision Complex Library) is a C library +for the arithmetic of complex numbers with arbitrarily high precision +and correct rounding of the result. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/mpc-1.0.1 +./configure \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf mpc-1.0.1 +popd +@end verbatim + + +@node GCC +@section GCC + +@verbatim +# 3 hours and 30 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gcc-4.7.2 +sed -i.orig 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in +sed -i.orig 's@\./fixinc\.sh@-c true@' gcc/Makefile.in +mkdir -v ../gcc-build +cd ../gcc-build +../gcc-4.7.2/configure \ + --prefix=/usr \ + --libexecdir=/usr/lib \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --target=${CROSS_TARGET} \ + --enable-shared \ + --enable-threads=posix \ + --enable-__cxa_atexit \ + --enable-c99 \ + --enable-long-long \ + --disable-multilib \ + --with-abi=${MABI} \ + --enable-clocale=gnu \ + --enable-languages=c,c++ \ + --disable-libstdcxx-pch +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#ln -sv ../usr/bin/cpp ${TARGET_DIR}/lib +ln -sv gcc ${TARGET_DIR}/usr/bin/cc +cd .. +rm -rf gcc-build +rm -rf gcc-4.7.2 +popd +@end verbatim + +@ignore +# The following patch seems needless to me as it only replaces +# {usr,}/lib32 with {usr,}/lib64 and we already have: +# {usr,}/lib32 -> {usr,}/lib +# {usr,}/lib64 -> {usr,}/lib +#patch -Np1 -i ${DOWNLOAD_DIR}/gcc-4.6.0-pure64-1.patch +@end ignore + +@samp{sed -i.orig 's/install_to_$(INSTALL_DEST) //' +libiberty/Makefile.in} is used as we already installed the library +@file{libiberty.a} with Binutils. + +@c We use @samp{sed -i.orig 's@@\./fixinc\.sh@@-c true@@' +@c gcc/Makefile.in} to avoid using fixincludes that may output errors if +@c headers have been modified. + +Using @option{--enable-clocale=gnu} option ensures that the correct +locale will automatically be chosen. + +Option @option{--disable-libstdcxx-pch} disables support for +precompiled headers (PCH). + +@c ln -sv ../usr/bin/cpp ${TARGET_DIR}/lib FHS? + +The line @samp{ln -sv gcc $@{TARGET_DIR@}/usr/bin/cc} creates a +symbolic link @file{cc} that points on @file{gcc}. + + +@node Sed +@section Sed + +GNU sed is a stream editor: it is used to perform basic text +transformations on an input stream (a file or input from a pipeline). + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/sed-4.2.1.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/sed-4.2.1 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf sed-4.2.1 +popd +@end verbatim + +@c @option{--bindir=/bin} FHS? + + +@node E2fsprogs +@section E2fsprogs + +E2fsprogs is a package that contains tools to handle the ext2, ext3 +and ext4 filesystems. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/e2fsprogs-1.42.6.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/e2fsprogs-1.42.6 +mkdir -v build +cd build +../configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --with-root-prefix="" \ + --enable-elf-shlibs +make +make DESTDIR=${TARGET_DIR} install +make DESTDIR=${TARGET_DIR} install-libs +rm -v ${TARGET_DIR}/usr/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so +ln -sv ../../lib/libblkid.so.1 ${TARGET_DIR}/usr/lib/libblkid.so +ln -sv ../../lib/libcom_err.so.2 ${TARGET_DIR}/usr/lib/libcom_err.so +ln -sv ../../lib/libe2p.so.2 ${TARGET_DIR}/usr/lib/libe2p.so +ln -sv ../../lib/libext2fs.so.2 ${TARGET_DIR}/usr/lib/libext2fs.so +ln -sv ../../lib/libss.so.2 ${TARGET_DIR}/usr/lib/libss.so +ln -sv ../../lib/libuuid.so.1 ${TARGET_DIR}/usr/lib/libuuid.so +cd ../.. +rm -rf e2fsprogs-1.42.6 +popd +@end verbatim + +@option{--with-root-prefix=""} is used to put e2fsprogs binaries +inside @file{/sbin} instead of @file{@var{PREFIX}/sbin} which would be +@file{/usr/sbin}. + +Option @option{--enable-elf-shlibs} enables e2fsprogs shared +libraries. + +@samp{make DESTDIR=$@{TARGET_DIR@} install-libs} is used to install +libraries, those are not installed with @samp{make +DESTDIR=$@{TARGET_DIR@} install}. + +The sequence of commands that follows first removes symbolic links +@file{$@{TARGET_DIR@}/usr/lib/lib@{@/blkid,com_err,e2p,ext2fs,ss,uuid@}.so} +which point on abolute paths +@file{/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so}. In order to +use the libraries of the target operating system, we need to symlink +@file{$@{TARGET_DIR@}/usr/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so} +to their relative paths files. + + +@node Coreutils +@section Coreutils + +GNU coreutils (core utilities) includes the standard programs for text +and file manipulation. + +On gNewSense Parkes, you need to install @file{xz-utils} to extract +the package. + +@verbatim +# 30 minutes +tar xf ${DOWNLOAD_DIR}/coreutils-8.19.tar.xz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/coreutils-8.19 +sed -i.orig '/strftime/s/\ LC_ALL//' man/help2man +cat > config.cache << EOF +fu_cv_sys_stat_statfs2_bsize=yes +gl_cv_func_mbrtowc_incomplete_state=yes +gl_cv_func_mbrtowc_nul_retval=yes +gl_cv_func_mbrtowc_null_arg=yes +gl_cv_func_mbrtowc_retval=yes +gl_cv_func_btowc_eof=yes +gl_cv_func_wcrtomb_retval=yes +gl_cv_func_wctob_works=yes +gl_cv_func_fstatat_zero_flag=yes +# From C[G]LFS: +#fu_cv_sys_stat_statfs2_bsize=yes +#gl_cv_func_working_mkstemp=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --enable-install-program=hostname \ + --enable-no-install-program=kill,uptime \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/{cat,chgrp,chmod,chown,cp,date} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/{dd,df,echo,false,hostname,ls,mkdir} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/{mv,pwd,rm,rmdir,stty,true,ln,uname} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/chroot ${TARGET_DIR}/usr/sbin +#mv -v ${TARGET_DIR}/usr/bin/{[,basename,head,install,nice} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/{readlink,sleep,sync,test,touch} \ +# ${TARGET_DIR}/bin +#ln -svf ../../bin/install ${TARGET_DIR}/usr/bin +cd .. +rm -rf coreutils-8.19 +popd +@end verbatim + +@c @samp{sed -i.orig '/strftime/s/\ LC_ALL//' man/help2man} + +The variables listed in the file @file{config.cache} are used in order +to avoid that the @file{configure} script evaluate their values: +otherwise the build may fail when cross-compiling. + +We use @option{--enable-install-program=hostname} to install the +command @command{hostname} which is not built by default. + +We use @option{--enable-no-install-program=kill,uptime} in order not +to install commands @command{kill} and @command{uptime}. Those +commands will be installed by the package procps. + +@ignore +@verbatim +mv -v ${TARGET_DIR}/usr/bin/{cat,chgrp,chmod,chown,cp,date} \ + ${TARGET_DIR}/bin +mv -v ${TARGET_DIR}/usr/bin/{dd,df,echo,false,hostname,ls,mkdir} \ + ${TARGET_DIR}/bin +mv -v ${TARGET_DIR}/usr/bin/{mv,pwd,rm,rmdir,stty,true,ln,uname} \ + ${TARGET_DIR}/bin +mv -v ${TARGET_DIR}/usr/bin/chroot ${TARGET_DIR}/usr/sbin +mv -v ${TARGET_DIR}/usr/bin/{[,basename,head,install,nice} \ + ${TARGET_DIR}/bin +mv -v ${TARGET_DIR}/usr/bin/{readlink,sleep,sync,test,touch} \ + ${TARGET_DIR}/bin +@end verbatim + +All programs of coreutils are moved from target system's +@file{/usr/bin} to @file{/bin} for consistency. +@end ignore + +@ignore +Because some programs use the target system's location @file{/usr/bin} +and others the location @file{/bin} to call the command +@command{install}, we symlink using @samp{ln -svf ../../bin/install +$@{TARGET_DIR@}/usr/bin}. +@end ignore + + +@node iana-etc +@section iana-etc + +The iana-etc package installs services and protocols using data from +the Internet Assigned Numbers Authority (IANA). + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/iana-etc-2.30.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/iana-etc-2.30 +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf iana-etc-2.30 +popd +@end verbatim + + +@node M4 +@section M4 + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/m4-1.4.16.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/m4-1.4.16 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf m4-1.4.16 +popd +@end verbatim + + +@node Bison +@section Bison + +GNU bison parser generator. + +@verbatim +# 7 minutes +tar xf ${DOWNLOAD_DIR}/bison-2.5.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bison-2.5 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +echo '#define YYENABLE_NLS 1' >> config.h +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf bison-2.5 +popd +@end verbatim + +@samp{echo '#define YYENABLE_NLS 1' >> config.h} is used to build +@acronym{NLS} (native language support) inside bison. + + +@node Ncurses +@section Ncurses + +@verbatim +# 15 minutes +tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/ncurses-5.9 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --with-shared \ + --enable-widec \ + --without-debug \ + --without-ada \ + --with-build-cc="gcc -D_GNU_SOURCE" \ + --libdir=/lib +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/lib/lib{panel,menu,form,ncurses,ncurses++}w.a \ +# ${TARGET_DIR}/usr/lib +#rm -v ${TARGET_DIR}/lib/lib{ncurses,menu,panel,form}w.so +#ln -svf ../../lib/libncursesw.so.5 \ +# ${TARGET_DIR}/usr/lib/libncursesw.so +#ln -svf ../../lib/libmenuw.so.5 ${TARGET_DIR}/usr/lib/libmenuw.so +#ln -svf ../../lib/libpanelw.so.5 ${TARGET_DIR}/usr/lib/libpanelw.so +#ln -svf ../../lib/libformw.so.5 ${TARGET_DIR}/usr/lib/libformw.so +#for lib in curses ncurses form panel menu ; do +# echo "INPUT(-l${lib}w)" > ${TARGET_DIR}/usr/lib/lib${lib}.so +# ln -sfv lib${lib}w.a ${TARGET_DIR}/usr/lib/lib${lib}.a +# done +ln -sfv libncursesw.so ${TARGET_DIR}/lib/libncurses.so +#ln -sfv libncursesw.so ${TARGET_DIR}/usr/lib/libcursesw.so +#ln -sfv libncursesw.a ${TARGET_DIR}/usr/lib/libcursesw.a +#ln -sfv libncurses++w.a ${TARGET_DIR}/usr/lib/libncurses++.a +#ln -sfv ncursesw5-config ${TARGET_DIR}/usr/bin/ncurses5-config +#ln -sfv ../../usr/share/terminfo ${TARGET_DIR}/usr/lib/terminfo +cd .. +rm -rf ncurses-5.9 +popd +@end verbatim + +Option @option{--enable-widec} enables wide characters support in +ncurses. + +@c Option @option{--without-debug} + +Option @option{--without-ada} disables support for the Ada programming +language inside ncurses. + +@c Option @option{--with-build-cc="gcc -D_GNU_SOURCE"} + +@c Option @option{--libdir=/lib} + +@ignore +@verbatim +mv -v ${TARGET_DIR}/lib/lib{panel,menu,form,ncurses,ncurses++}w.a \ + ${TARGET_DIR}/usr/lib +rm -v ${TARGET_DIR}/lib/lib{ncurses,menu,panel,form}w.so +ln -svf ../../lib/libncursesw.so.5 \ + ${TARGET_DIR}/usr/lib/libncursesw.so +ln -svf ../../lib/libmenuw.so.5 ${TARGET_DIR}/usr/lib/libmenuw.so +ln -svf ../../lib/libpanelw.so.5 ${TARGET_DIR}/usr/lib/libpanelw.so +ln -svf ../../lib/libformw.so.5 ${TARGET_DIR}/usr/lib/libformw.so +@end verbatim + +According to the filesystem hierarchy standard (FHS), ncurses +libraries should be inside @file{/usr/lib} instead of @file{/lib}. + +@verbatim +for lib in curses ncurses form panel menu ; do + echo "INPUT(-l${lib}w)" > ${TARGET_DIR}/usr/lib/lib${lib}.so + ln -sfv lib${lib}w.a ${TARGET_DIR}/usr/lib/lib${lib}.a + done +ln -sfv libncursesw.so ${TARGET_DIR}/usr/lib/libcursesw.so +ln -sfv libncursesw.a ${TARGET_DIR}/usr/lib/libcursesw.a +ln -sfv libncurses++w.a ${TARGET_DIR}/usr/lib/libncurses++.a +ln -sfv ncursesw5-config ${TARGET_DIR}/usr/bin/ncurses5-config +@end verbatim + +The commands above create symlinks from libraries without support for +wide characters to libraries with support for them. +@end ignore + +@c PROCPS issue: +The command @samp{ln -sfv libncursesw.so $@{TARGET_DIR@}/lib/libncurses.so} +creates the symlink @file{libcurses.so} so that programs that do not +know @file{libncursesw.so} can be linked against it. + +@c ln -sfv ../../usr/share/terminfo ${TARGET_DIR}/usr/lib/terminfo + + +@node Procps +@section Procps + +The procps package contains utilities that give information about +processes using the @file{/proc} filesystem. The package includes the +commands @command{ps}, @command{top}, @command{vmstat}, @command{w}, +@command{kill}, @command{free}, @command{slabtop}, and +@command{skill}. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/procps-3.2.8.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/procps-3.2.8 +make \ + CPPFLAGS= \ + lib64=lib +make \ + DESTDIR=${TARGET_DIR} \ + lib64=lib \ + ldconfig= \ + install="install -D" \ + install +cd .. +rm -rf procps-3.2.8 +popd +@end verbatim + +Option @option{CPPFLAGS= } is used so that the target system's ncurses +library will be used, default value would have been +@option{-I/usr/include/ncurses}. + +Option @option{lib64=lib} makes the directory @file{/lib} the one +where to put 64 bit libraries, default would be @file{/lib64}. + +Option @option{ldconfig= } is used in order not to use current host's +@command{ldconfig}. + +Option @option{install="install -D"} is used so that all the files +installed are owned by the current user. By default, all installed +files are owned by root. + + +@node Libtool +@section Libtool + +GNU libtool is a generic library support script. It hides the +complexity of using shared libraries behind a consistent, portable +interface. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/libtool-2.4.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/libtool-2.4 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf libtool-2.4 +popd +@end verbatim + + +@node Readline +@section Readline + +The GNU Readline library provides a set of functions for use by +applications that allow users to edit command lines as they are typed +in. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/readline-6.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/readline-6.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --libdir=/lib +make +make DESTDIR=${TARGET_DIR} install +make DESTDIR=${TARGET_DIR} install-doc +# For FHS compatibility: +#mv -v ${TARGET_DIR}/lib/lib{readline,history}.a ${TARGET_DIR}/usr/lib +#rm -v ${TARGET_DIR}/lib/lib{readline,history}.so +#ln -svf ../../lib/libreadline.so.6 \ +# ${TARGET_DIR}/usr/lib/libreadline.so +#ln -svf ../../lib/libhistory.so.6 ${TARGET_DIR}/usr/lib/libhistory.so +cd .. +rm -rf readline-6.2 +popd +@end verbatim + +@c sed -i 's:^SHLIB_LIBS=:SHLIB_LIBS=-lncursesw:' support/shobj-conf + +@ignore +mv -v ${TARGET_DIR}/lib/lib{readline,history}.a ${TARGET_DIR}/usr/lib +rm -v ${TARGET_DIR}/lib/lib{readline,history}.so +ln -svf ../../lib/libreadline.so.6 \ + ${TARGET_DIR}/usr/lib/libreadline.so +ln -svf ../../lib/libhistory.so.6 ${TARGET_DIR}/usr/lib/libhistory.so +@end ignore + + +@node Autoconf +@section Autoconf + +GNU autoconf is an extensible package of M4 macros that produce shell +scripts to automatically configure software source code +packages. These scripts can adapt the packages to many kinds of +UNIX-like systems without manual user intervention. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/autoconf-2.69.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/autoconf-2.69 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf autoconf-2.69 +popd +@end verbatim + + +@node Automake +@section Automake + +GNU automake is a tool for automatically generating @file{Makefile.in} +files compliant with the GNU Coding +Standards@footnote{@uref{http://www.gnu.org/prep/standards/}}. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/automake-1.12.4.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/automake-1.12.4 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf automake-1.12.4 +popd +@end verbatim + + +@node Bash +@section Bash + +GNU @acronym{Bash} (Bourne again shell) is an sh-compatible shell that +incorporates useful features from the Korn shell (ksh) and C shell +(csh). + +@verbatim +# 15 minutes +tar xf ${DOWNLOAD_DIR}/bash-4.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bash-4.2 +cat > config.cache << "EOF" +ac_cv_func_mmap_fixed_mapped=yes +ac_cv_func_strcoll_works=yes +ac_cv_func_working_mktime=yes +bash_cv_func_sigsetjmp=present +bash_cv_getcwd_malloc=yes +bash_cv_job_control_missing=present +bash_cv_printf_a_format=yes +bash_cv_sys_named_pipes=present +bash_cv_ulimit_maxfds=yes +bash_cv_under_sys_siglist=yes +bash_cv_unusable_rtsigs=no +gt_cv_int_divbyzero_sigfpe=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --cache-file=config.cache \ + --without-bash-malloc \ + --with-installed-readline +make +make \ + DESTDIR=${TARGET_DIR} \ + htmldir=/usr/share/doc/bash-4.2 \ + install +ln -sv bash ${TARGET_DIR}/bin/sh +cd .. +rm -rf bash-4.2 +popd +@end verbatim + +The variables listed in the file @file{config.cache} are used in order +to avoid that the @file{configure} script evaluate their values: +otherwise the build may fail when cross-compiling. + +@c --bindir=/bin instead of /usr/bin, FHS? + +Option @option{--without-bash-malloc} tells the @file{configure} +script not to use the @code{malloc} function shipped with +Bash. Glibc's version will be used instead. + +Option @option{--with-installed-readline} tells the configure script +to use the installed readline library instead of the one shipped with +Bash. + +@c htmldir=/usr/share/doc/bash-4.2 + +@samp{ln -sv bash $@{TARGET_DIR@}/bin/sh} creates a symlink @file{sh} +to @file{bash}. + + +@node Bzip2 +@section Bzip2 + +Bzip2 is a package that contains utilities to compress and decompress +files with a better original size/compressed size ratio than gzip. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/bzip2-1.0.6.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bzip2-1.0.6 +sed -i.orig -e "/^all:/s/ test//" Makefile +sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile +make \ + -f Makefile-libbz2_so \ + CC="${CC}" \ + AR="${AR}" \ + RANLIB="${RANLIB}" +make clean +make \ + CC="${CC}" \ + AR="${AR}" \ + RANLIB="${RANLIB}" +make \ + PREFIX=${TARGET_DIR}/usr \ + install +cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2 +cp -av libbz2.so* ${TARGET_DIR}/lib +ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/usr/lib/libbz2.so +rm -v ${TARGET_DIR}/usr/bin/{bunzip2,bzcat,bzip2} +ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2 +ln -sv bzip2 ${TARGET_DIR}/bin/bzcat +cd .. +rm -rf bzip2-1.0.6 +popd +@end verbatim + +@samp{sed -i.orig -e "/^all:/s/ test//" Makefile} is used to skip +tests when building. + +@samp{sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile} is used +in order to have relative path symlinks instead of absolute ones. + +Option @option{-f Makefile-libbz2_so} is used to build shared +libraries. + +Flags @env{CC}, @env{AR} and @env{RANLIB} are used so that bzip2 is +built using cross-compilation tools instead of the host's ones. + +@samp{make clean} is used to clean up temporary files. + +The second build commands are used to build static libraries. + +@ignore +cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2 +cp -av libbz2.so* ${TARGET_DIR}/lib +ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/usr/lib/libbz2.so +rm -v ${TARGET_DIR}/usr/bin/{bunzip2,bzcat,bzip2} +ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2 +ln -sv bzip2 ${TARGET_DIR}/bin/bzcat +@end ignore + + +@node DHCPCD +@section DHCPCD + +DHCPCD is a wrapper for the @acronym{DHCP} (Dynamic Host Configuration +Protocol) client daemon. + +@verbatim +# 3 minutes +tar xf ${DOWNLOAD_DIR}/dhcpcd-5.6.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/dhcpcd-5.6.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/sbin \ + --sysconfdir=/etc \ + --dbdir=/var/lib/dhcpcd \ + --libexecdir=/usr/lib/dhcpcd +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf dhcpcd-5.6.2 +popd +@end verbatim + +@c Option @option{--bindir=/sbin} is used to comply with FHS? +@c @option{--sysconfdir=/etc} @file{/etc} instead of ? +@c @option{--dbdir=/var/lib/dhcpcd} @file{/var/lib/dhcpcd} instead of? +@c @option{--libexecdir=/usr/lib/dhcpcd} @file{/usr/lib/dhcpcd} instead of ? + + +@node Diffutils +@section Diffutils + +GNU Diffutils is a package of several programs related to finding +differences between files. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/diffutils-3.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/diffutils-3.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf diffutils-3.2 +popd +@end verbatim + +@c patch -Np1 -i ${DOWNLOAD_DIR}/diffutils-3.0-i18n-1.patch + +@c touch man/*.1 + + +@node File +@section File + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/file-5.11.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/file-5.11 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf file-5.11 +popd +@end verbatim + + +@node Findutils +@section Findutils + +The GNU Find Utilities are typically used to provide directory search +and file locating capabilities. + +@verbatim +# 7 minutes +tar xf ${DOWNLOAD_DIR}/findutils-4.4.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/findutils-4.4.2 +cat > config.cache << EOF +gl_cv_func_wcwidth_works=yes +gl_cv_header_working_fcntl_h=yes +ac_cv_func_fnmatch_gnu=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --libexecdir=/usr/lib/locate \ + --localstatedir=/var/lib/locate \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +#mv -v ${TARGET_DIR}/usr/bin/find ${TARGET_DIR}/bin +#sed -i.orig 's@find:=${BINDIR}@find:=/bin@' \ +# ${TARGET_DIR}/usr/bin/updatedb +cd .. +rm -rf findutils-4.4.2 +popd +@end verbatim + +@c --libexecdir=/usr/lib/locate +@c --localstatedir=/var/lib/locate + +@ignore +File @file{find} is moved from target's system @file{/usr/bin} to +@file{/bin} in order to comply with the FHS. + +Because we changed the location of @file{find}, we need to update its +location in @file{/usr/bin/updatedb}. +@end ignore + + +@node Flex +@section Flex + +Flex is a tool for generating scanners. A scanner, sometimes called a +tokenizer, is a program which recognizes lexical patterns in text. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/flex-2.5.37.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/flex-2.5.37 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +ln -sv libfl.a ${TARGET_DIR}/usr/lib/libl.a +cd .. +rm -r flex-2.5.37 +popd + +cat > ${TARGET_DIR}/usr/bin/lex << "EOF" +#!/bin/sh +exec /usr/bin/flex -l "$@" +EOF +chmod -v 755 ${TARGET_DIR}/usr/bin/lex +@end verbatim + +For compatibility issues, we create the symlink @file{libl.a}. + +We then create target system's @file{/usr/bin/lex} that will execute +@command{flex} with option @option{-l} in order to behave with maximal +compatibility like @command{lex}. + +@ignore +@samp{sed -i.orig "s/-I@@includedir@@//g" Makefile.in} is used in +order not to use host's headers in @file{/usr/include} during +cross-compilation. +@end ignore + +@c Variables @samp{ac_cv_func_malloc_0_nonnull=yes} and +@c @samp{ac_cv_func_realloc_0_nonnull=yes} are used to get rid of +@c error message: @samp{}. + +@c We use option @option{-fPIC} passed to the cross-compiler in order to +@c generate position-independent code (PIC). + + +@node Gawk +@section Gawk + +GNU awk (Gawk) is a program used to select particular records in a +file and perform operations upon them. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/gawk-4.0.1.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gawk-4.0.1 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --libexecdir=/usr/lib +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -r gawk-4.0.1 +popd +@end verbatim + + +@node Gettext +@section Gettext + +GNU gettext utilities are a set of tools that provides a framework to +help packages produce multi-lingual messages. + +@verbatim +# 1 hour +tar xf ${DOWNLOAD_DIR}/gettext-0.18.1.1.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gettext-0.18.1.1 +cat > config.cache << EOF +am_cv_func_iconv_works=yes +gl_cv_func_wcwidth_works=yes +gt_cv_func_printf_posix=yes +gt_cv_int_divbyzero_sigfpe=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache +make +#cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i} +#cp gettext-tools/src/.libs/libgettextsrc.la{,i} +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf gettext-0.18.1.1 +popd +@end verbatim + +@c The following patch may be skipped +@c patch -Np1 -i ${DOWNLOAD_DIR}/gettext-0.18.1.1-rpath-1.patch + +@c cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i} ? +@c cp gettext-tools/src/.libs/libgettextsrc.la{,i} ? + + +@node Grep +@section Grep + +GNU @command{grep} command searches one or more input files for lines +containing a match to a specified pattern. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/grep-2.14.tar.xz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/grep-2.14 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --disable-perl-regexp +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf grep-2.14 +popd +@end verbatim + +Option @option{--disable-perl-regexp} disables support of Perl-style +regular expressions (regexp). + + +@node Groff +@section Groff + +@verbatim +# 15 minutes +tar xf ${DOWNLOAD_DIR}/groff-1.21.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/groff-1.21 +patch -Np1 -i ${DOWNLOAD_DIR}/groff-1.21-cross-compilation.patch +PAGE=A4 \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make \ + TROFFBIN=troff \ + GROFFBIN=groff \ + GROFF_BIN_PATH= +make prefix=${TARGET_DIR}/usr install +ln -sv soelim ${TARGET_DIR}/usr/bin/zsoelim +ln -sv eqn ${TARGET_DIR}/usr/bin/geqn +ln -sv tbl ${TARGET_DIR}/usr/bin/gtbl +cd .. +rm -rf groff-1.21 +popd +@end verbatim + +The patch @file{groff-1.21-cross-compilation.patch} fixes a bug in +groff' @file{Makefile.in} that prevents the cross-compilation build. + +The variables @env{TROFFBIN=troff} and @env{GROFFBIN=groff} tell +@command{make} to use @command{troff} and @command{groff} commands +installed in the @ref{Building Cross-Compilation Tools} to build +documentation. + +The variable @env{GROFF_BIN_PATH} before @env{PATH} is checked for +programs @command{groff} is calling (preprocessors, troff, and output +devices). If not set, it defaults to the directory where the +@file{groff} binary is located. + +The symlinks are used for compatibility. + + +@node Gzip +@section Gzip + +GNU Gzip is a data compression program. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/gzip-1.5.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gzip-1.5 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/bin/z{egrep,cmp,diff,fgrep,force,grep,less,more} \ +# ${TARGET_DIR}/usr/bin +#mv -v ${TARGET_DIR}/bin/znew \ +# ${TARGET_DIR}/usr/bin +cd .. +rm -rf gzip-1.5 +popd +@end verbatim + + +@node IPutils +@section IPutils + +The iputils package is a set of small utilities for networking. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/iputils-s20071127.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/iputils-s20071127 +patch -Np1 -i ${DOWNLOAD_DIR}/iputils-s20071127-fixes-2.patch +make CC="${CC}" +install -v -m755 ping{,6} ${TARGET_DIR}/bin +install -v -m755 arping ${TARGET_DIR}/usr/bin +install -v -m755 clockdiff ${TARGET_DIR}/usr/bin +install -v -m755 rdisc ${TARGET_DIR}/usr/bin +install -v -m755 tracepath ${TARGET_DIR}/usr/bin +install -v -m755 trace{path,route}6 ${TARGET_DIR}/usr/bin +cd .. +rm -rf iputils-s20071127 +popd +@end verbatim + +@c patch -Np1 -i ${DOWNLOAD_DIR}/iputils-s20071127-manpages-2.patch + + +@node Iproute2 +@section Iproute2 + +Iproute2 is a collection of utilities for controlling TCP and UDP IP +networking and traffic. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/iproute2-3.5.1.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/iproute2-3.5.1 +sed -i.orig '/^TARGETS/s@arpd@@g' misc/Makefile +make \ + DESTDIR=${TARGET_DIR} \ + CC="${CC}" \ + DOCDIR=/usr/share/doc/iproute2 \ + MANDIR=/usr/share/man +make \ + DESTDIR=${TARGET_DIR} \ + DOCDIR=/usr/share/doc/iproute2 \ + MANDIR=/usr/share/man \ + install +cd .. +rm -rf iproute2-3.5.1 +popd +@end verbatim + +@samp{sed -i.orig '/^TARGETS/s@@arpd@@@@g' misc/Makefile} is used to +disable the build of @command{arpd} as it requires Berkeley DB to be +installed. + +@env{DOCDIR} and @env{MANDIR} indicate the location in which the +documentation and the manual pages will be installed, +respectively. Those are no absolute paths but use the value of +@env{DESTDIR} as a prefix. + + +@node Kbd +@section Kbd + +Kbd contains keytable files and keyboard utilities. + +@verbatim +# 3 minutes +tar xf ${DOWNLOAD_DIR}/kbd-1.15.3.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/kbd-1.15.3 +patch -Np1 -i ${DOWNLOAD_DIR}/kbd-1.15.3-es.po-fix-1.patch +cat > config.cache << EOF +ac_cv_func_setpgrp_void=yes +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility +#mv -v ${TARGET_DIR}/usr/bin/{kbd_mode,dumpkeys,loadkeys,openvt} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/setfont \ +# ${TARGET_DIR}/bin +cd .. +rm -rf kbd-1.15.3 +popd +@end verbatim + +The patch @file{kbd-1.15.3-es.po-fix-1.patch} fixes a bug in +@file{po/es.po}. + + +@node Kmod +@section Kmod + +Kmod (previously known as module-init-tools) provide userspace-side +assistance in loading kernel modules and their dependencies. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/kmod-10.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/kmod-10 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --sbindir=/sbin \ + --with-zlib +make +make \ + DESTDIR=${TARGET_DIR} \ + INSTALL=install \ + install +cd .. +rm -rf kmod-10 +popd +@end verbatim + +@option{--with-zlib} enables support for modules compressed with +zlib. + +By default, installation uses @env{INSTALL=install-with-care} which +checks if old utilities have not been destroyed. To avoid this check, +we use @env{INSTALL=install}. + + +@node Less +@section Less + +Less is a file pager. A file pager is used to view the content of a +text file. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/less-451.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/less-451 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --sysconfdir=/etc +make +make prefix=${TARGET_DIR}/usr install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/less ${TARGET_DIR}/bin +cd .. +rm -rf less-451 +popd +@end verbatim + + +@node Make +@section Make + +GNU @command{make} utility determines automatically which pieces of a +large program need to be recompiled, and issues the commands to +recompile them. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/make-3.82.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/make-3.82 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf make-3.82 +popd +@end verbatim + + +@node Man +@section Man + +Man is an interface to the on-line reference manuals. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/man-1.6g.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/man-1.6g +sed -i.orig -e "/PREPATH=/s@=.*@=\"$(eval echo \ + ${TARGET_DIR}/{,usr/}{sbin,bin})\"@g" -e 's@-is@&Rc@g' configure +sed -i.orig -e 's@MANPATH./usr/man@#&@g' \ + -e 's@MANPATH./usr/local/man@#&@g' src/man.conf.in +./configure \ + -confdir=/etc +sed -i.orig "s@${TARGET_DIR}@@" conf_script +gcc src/makemsg.c -o src/makemsg +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf man-1.6g +popd +@end verbatim + +@c The patch below is needed to have full utf8 +@c patch -Np1 -i ${DOWNLOAD_DIR}/man-1.6g-i18n-1.patch +@c patch -Np1 -i ${DOWNLOAD_DIR}/man-1.6g-new_compressors-1.patch + +In the first use of @command{sed}, the first part replaces +@env{PREPATH} default value +@samp{/bin:/usr/bin:/usr/ucb:/usr/local/@/bin:$PATH} with +@samp{$@{TARGET_DIR@}/@{,usr/@}@{sbin,bin@}}. The variable +@env{TARGET_DIR} is used to avoid errors when running the +@file{configure} script. + +The second part is used to replace default options of the man pager +@option{-is} with @option{-isRc}. Option @option{-c} will cause +@command{less} to display man pages faster as this option disables +scrolling. + +@c What about -R? + +The second call of @command{sed} tells @command{man} where the cat +pages corresponding to given man pages should not be stored: +@file{/usr/man} and @file{/usr/local/man}. + +Option @option{-confdir} is used to define configuration files +location to target system's @file{/etc}. + +The third call of @command{sed} is used in order to remove the +presence of @env{TARGET_DIR} on the target system's programs. + +@command{makemsg} will be used during the build, but because using the +cross-compiler may make its build fail, we use the host's compiler. + + +@node Nano +@section Nano + +GNU nano is a lightweight text editor. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/nano-2.3.1.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/nano-2.3.1 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf nano-2.3.1 +popd +@end verbatim + +@quotation Note +commands in nano are displayed as in `^X'. The `^' character means +@key{CTRL} key, so `^X' means @kbd{CTRL-X}. +@end quotation + + +@node Patch +@section Patch + +GNU patch takes a patch file containing a difference listing produced +by the @command{diff} program and applies those differences to one or +more original files, producing patched versions. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/patch-2.7.1.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/patch-2.7.1 +cat > config.cache << EOF +ac_cv_path_ed_PROGRAM=ed +ac_cv_func_strnlen_working=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache +make +make prefix=${TARGET_DIR}/usr install +cd .. +rm -rf patch-2.7.1 +popd +@end verbatim + + +@node Psmisc +@section Psmisc + +This package contains utilities that use the proc filesystem. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/psmisc-22.20.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/psmisc-22.20 +cat > config.cache << EOF +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --exec-prefix="" \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/bin/pstree* ${TARGET_DIR}/usr/bin +#ln -sv killall ${TARGET_DIR}/bin/pidof +cd .. +rm -rf psmisc-22.20 +popd +@end verbatim + + +@node Rsyslog +@section Rsyslog + +Rsyslog is an utility creating log messages. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/rsyslog-5.8.6.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/rsyslog-5.8.6 +cat > config.cache << EOF +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +EOF +PKG_CONFIG_PATH="${TARGET_DIR}/usr/lib/pkgconfig" \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --sbindir=/sbin \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +install -dv ${TARGET_DIR}/etc/rsyslog.d +cd .. +rm -rf rsyslog-5.8.6 +popd + +cat > ${TARGET_DIR}/etc/rsyslog.conf << "EOF" +$ModLoad imuxsock.so +$ModLoad imklog.so + +$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat + +$FileOwner root +$FileGroup root +$FileCreateMode 0640 +$DirCreateMode 0755 + +$ModLoad imudp +$UDPServerRun 514 + +$RepeatedMsgReduction on + +$IncludeConfig /etc/rsyslog.d/*.conf + +auth,authpriv.* /var/log/auth.log +*.*;auth,authpriv.none -/var/log/syslog +daemon.* -/var/log/daemon.log +kern.* -/var/log/kern.log +lpr.* -/var/log/lpr.log +mail.* -/var/log/mail.log +user.* -/var/log/user.log + +# Catch All Logs +*.=debug;\ + auth,authpriv.none;\ + news.none;mail.none -/var/log/debug +*.=info;*.=notice;*.=warn;\ + auth,authpriv.none;\ + cron,daemon.none;\ + mail,news.none -/var/log/messages + +# Emergency are shown to everyone +*.emerg * +EOF +@end verbatim + +@samp{install -dv $@{TARGET_DIR@}/etc/rsyslog.d} is used to create +target system's @file{/etc/rsyslog.d} directory. Rsyslog looks for +user-defined configuration files in this directory. The line +@samp{$IncludeConfig /etc/rsyslog.d/*.conf} in the target system's +configuration file @file{/etc/rsyslog.conf} has this purpose. + +We then create the target system's configuration file +@file{/etc/rsyslog.conf}. + + +@node Shadow +@section Shadow + +@verbatim +# 7 minutes +tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/shadow-4.1.4.3 +patch -Np1 -i ${DOWNLOAD_DIR}/shadow-4.1.4.3-man-ru.patch +automake-1.11 +echo "ac_cv_func_setpgrp_void=yes" > config.cache +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --libdir=/lib \ + --sysconfdir=/etc \ + --enable-shared \ + --without-audit \ + --without-libpam \ + --without-selinux \ + --cache-file=config.cache \ + --enable-man +sed -i.orig 's/groups$(EXEEXT) //' src/Makefile +for mkf in $(find man -name Makefile) + do + sed -i.orig -e '/groups.1.xml/d' -e 's/groups.1 //' ${mkf} + done +make +make DESTDIR=${TARGET_DIR} install +sed -i.orig -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \ + -e 's@/var/spool/mail@/var/mail@' \ + ${TARGET_DIR}/etc/login.defs +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/passwd ${TARGET_DIR}/bin +${CROSS_TARGET}-pwconv +${CROSS_TARGET}-grpconv +${CROSS_TARGET}-passwd root +cd .. +rm -rf shadow-4.1.4.3 +popd +@end verbatim + +@ignore +Problem with those three commands with 4.1.5.1: + +${CROSS_TARGET}-pwconv +mips64el-unknown-linux-gnu-pwconv: failure while writing changes to /gllfsc/etc/shadow +${CROSS_TARGET}-grpconv +mips64el-unknown-linux-gnu-grpconv: failure while writing changes to /gllfsc/etc/gshadow +${CROSS_TARGET}-passwd root +mips64el-unknown-linux-gnu-passwd: Permission denied. +@end ignore + +@ignore + ${CROSS_TARGET}-passwd root +gives the following message: + Cannot change ID to root. +@end ignore + +The patch @file{shadow-4.1.4.3-man-ru.patch} contains a fix to +@file{man/ru/Makefile.am} preventing @samp{make install} to +complete. @command{automake-1.11} is then run to update the makefile +prototype @file{Makefile.in}. + +@c echo "ac_cv_func_setpgrp_void=yes" > config.cache + +The option @option{--enable-man} is used to generate man pages. + +The first call of @command{sed} disables the build of command +@command{groups}, as coreutils already installed it. + +The second call of @command{sed} enables support for MD5 encrypted +passwords and changes the mail default directory from +@file{/var/spool/mail} to @file{/var/mail}. + +The @command{pwconv} command creates @file{shadow} file from file +@file{passwd} and an optionally existing @file{shadow} file. + +The @command{grpconv} command creates @file{gshadow} file from file +@file{group} and an optionally existing @file{gshadow} file. + +The command @samp{passwd root} will create the password for the root +user, you will need it when logging in as root on your new system. + + +@node Sysvinit +@section Sysvinit + +Sysvinit is the system-V style init process. Init is the first process +started during booting. It is started by the kernel. Init continues +running as a daemon until the system is shut down. It is the direct or +indirect ancestor of all other processes and automatically adopts all +orphaned processes. + + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/sysvinit-2.88dsf.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/sysvinit-2.88dsf +sed -i.orig -e 's@/dev/initctl@$(ROOT)&@g' \ + -e 's@\(mknod \)-m \([0-9]* \)\(.* \)p@\1\3p; chmod \2\3@g' \ + -e '/^ifeq/s/$(ROOT)//' \ + -e 's@/usr/lib@$(ROOT)&@' \ + src/Makefile +make -C src clobber +make -C src ROOT=${TARGET_DIR} CC="${CC}" +make -C src ROOT=${TARGET_DIR} INSTALL="install" install +cd .. +rm -rf sysvinit-2.88dsf +popd + +cat > ${TARGET_DIR}/etc/inittab << "EOF" +# Begin /etc/inittab + +id:3:initdefault: + +si::sysinit:/etc/rc.d/init.d/rc sysinit + +l0:0:wait:/etc/rc.d/init.d/rc 0 +l1:S1:wait:/etc/rc.d/init.d/rc 1 +l2:2:wait:/etc/rc.d/init.d/rc 2 +l3:3:wait:/etc/rc.d/init.d/rc 3 +l4:4:wait:/etc/rc.d/init.d/rc 4 +l5:5:wait:/etc/rc.d/init.d/rc 5 +l6:6:wait:/etc/rc.d/init.d/rc 6 + +ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now + +su:S016:once:/sbin/sulogin + +1:2345:respawn:/sbin/agetty tty1 9600 +2:2345:respawn:/sbin/agetty tty2 9600 +3:2345:respawn:/sbin/agetty tty3 9600 +4:2345:respawn:/sbin/agetty tty4 9600 +5:2345:respawn:/sbin/agetty tty5 9600 +6:2345:respawn:/sbin/agetty tty6 9600 + +#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100 + +# End /etc/inittab +EOF +@end verbatim + +The first call of @command{sed} replaces @file{/dev/initctl} with +@file{$(ROOT)/dev/initctl}, and @file{/usr/lib} with +@file{$(ROOT)/usr/lib} among other things in order to install sysvinit +on the target system. + +@samp{make -C src clobber} is used to clean up the @file{src} +directory. + +Then, we create the @file{inittab} file that describes which processes +are started at bootup and during normal operation. + +The line @samp{#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100} is +commented out (with @code{#}) in order to avoid the message: +@samp{INIT: Id "c0" respawning too fast: disabled for 5 minutes} on +the target system. + +@c patch -Np1 -i ${DOWNLOAD_DIR}/sysvinit-2.88dsf-fixes-1.patch + + +@node Tar +@section Tar + +GNU tar is an archiving utility: it stores and extracts files from a +tape or disk archive. + +@verbatim +# 8 minutes +tar xf ${DOWNLOAD_DIR}/tar-1.26.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/tar-1.26 +cat > config.cache << EOF +gl_cv_func_btowc_eof=yes +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +gl_cv_func_mbrtowc_incomplete_state=yes +gl_cv_func_mbrtowc_nul_retval=yes +gl_cv_func_mbrtowc_null_arg=yes +gl_cv_func_mbrtowc_retval=yes +gl_cv_func_wcrtomb_retval=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --libexecdir=/usr/sbin \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf tar-1.26 +popd +@end verbatim + +@c patch -Np1 -i ${DOWNLOAD_DIR}/tar-1.26-man_page-1.patch +@c patch -Np1 -i ${DOWNLOAD_DIR}/tar-1.26-new_compressors-1.patch + + +@node Texinfo +@section Texinfo + +GNU Texinfo is a documentation system that can produce both online +information and a printed manual from a single source. + +@verbatim +# 15 minutes +tar xf ${DOWNLOAD_DIR}/texinfo-4.13a.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/texinfo-4.13 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make -C tools/gnulib/lib +make -C tools +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf texinfo-4.13 +popd + +pushd ${TARGET_DIR}/usr/share/info +rm dir +for f in * + do install-info $f dir 2>/dev/null +done +popd +@end verbatim + +@c patch -Np1 -i ${DOWNLOAD_DIR}/texinfo-4.13-new_compressors-1.patch + +The first three calls of @command{make} make it possible to build +Texinfo by cross-compilation. + +For Info to work, the @file{info} directory must contain a file that +serves as a top level directory for the Info system. By convention, +this file is called @file{dir}. We update this file for the target +system. + + +@node Udev +@section Udev + +Udev is the dynamic device management of the kernel Linux. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/udev-175.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/udev-175 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --sysconfdir=/etc \ + --sbindir=/sbin \ + --with-rootlibdir=/lib \ + --libexecdir=/lib/udev \ + --docdir=/usr/share/doc/udev-175 \ + --disable-introspection \ + --with-pci-ids-path=no \ + --with-usb-ids-path=no \ + --disable-gudev +make +make DESTDIR=${TARGET_DIR} install +install -dv ${TARGET_DIR}/lib/firmware +ln -sv ../lib/udev/udevd ${TARGET_DIR}/sbin/udevd +cd .. +rm -rf udev-175 +popd +@end verbatim + +@c The option @option{--disable-introspection} depends on +@c gobject-introspection which is not installed + +@ignore +Version 182 needs blkid headers given by e2fsprogs: +configure: error: Package requirements (blkid >= 2.20) were not met: + +No package 'blkid' found + +but + +BLKID_CFLAGS="-I${TARGET_DIR}/usr/include/blkid" \ + BLKID_LIBS="-L${TARGET_DIR}/lib -lblkid" \ + KMOD_CFLAGS="-I${TARGET_DIR}/usr/include" \ + KMOD_LIBS="-L${TARGET_DIR}/lib -lkmod" \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --sysconfdir=/etc \ + --sbindir=/sbin \ + --with-rootlibdir=/lib \ + --libexecdir=/lib/udev \ + --docdir=/usr/share/doc/udev-182 \ + --disable-introspection \ + --with-pci-ids-path=no \ + --with-usb-ids-path=no \ + --disable-gudev + +fails after `make` with: + +make --no-print-directory all-recursive +Making all in . + CC src/udevadm-udev-builtin-blkid.o +src/udev-builtin-blkid.c:84:30: error: unknown type name 'blkid_probe' +src/udev-builtin-blkid.c: In function 'builtin_blkid': +src/udev-builtin-blkid.c:122:9: error: unknown type name 'blkid_probe' +src/udev-builtin-blkid.c:160:17: error: 'BLKID_SUBLKS_LABEL' undeclared (first +use in this function) +src/udev-builtin-blkid.c:160:17: note: each undeclared identifier is reported +only once for each function it appears in +src/udev-builtin-blkid.c:160:38: error: 'BLKID_SUBLKS_UUID' undeclared (first +use in this function) +src/udev-builtin-blkid.c:161:17: error: 'BLKID_SUBLKS_TYPE' undeclared (first +use in this function) +src/udev-builtin-blkid.c:161:37: error: 'BLKID_SUBLKS_SECTYPE' undeclared +(first use in this function) +src/udev-builtin-blkid.c:162:17: error: 'BLKID_SUBLKS_USAGE' undeclared (first +use in this function) +src/udev-builtin-blkid.c:162:38: error: 'BLKID_SUBLKS_VERSION' undeclared +(first use in this function) +src/udev-builtin-blkid.c:165:58: error: 'BLKID_FLTR_NOTIN' undeclared (first +use in this function) src/udev-builtin-blkid.c:165:76: error: +'BLKID_USAGE_RAID' undeclared (first use in this function) make[2]: *** +[src/udevadm-udev-builtin-blkid.o] Error 1 +make[1]: *** [all-recursive] Error 1 +make: *** [all] Error 2 + +@end ignore + +@ignore +@verbatim +install -dv ${TARGET_DIR}/lib/firmware +@end verbatim + +is used to install target system's @file{/lib/firmware} which will +contain modules? +@end ignore + + +@node Util-Linux +@section Util-Linux + +util-linux is a random collection of utilities for use with the kernel +Linux. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/util-linux-2.19.1.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/util-linux-2.19.1 +sed -i.orig 's@etc/adjtime@var/lib/hwclock/adjtime@g' \ + hwclock/hwclock.c +mkdir -pv ${TARGET_DIR}/var/lib/hwclock +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --enable-arch \ + --enable-partx \ + --disable-wall \ + --enable-write \ + --disable-makeinstall-chown +make +make DESTDIR=${TARGET_DIR} install +mv -v ${TARGET_DIR}/usr/bin/logger ${TARGET_DIR}/bin +cd .. +rm -r util-linux-2.19.1 +popd +@end verbatim + +The @command{sed} command modifies the location of @file{adjtime} from +the target system's @file{/etc} directory to its +@file{/lib/hwclock/adjtime} to comply with FHS. + +@ignore +Error on configure for util-linux 2.22: +configure: error: login selected, but required PAM header file not available +@end ignore + +Option @option{--enable-arch} enables the build and installation of +the @command{arch} command. + +Option @option{--enable-partx} enables the build and installation of +the @command{addpart}, @command{delpart} and @command{partx} commands. + +Option @option{--disable-wall} disables the build of the +@command{wall} command which is already provided by sysvinit. + +Option @option{--enable-write} enables the build and installation of +the @command{write} command. + +Option @option{--disable-makeinstall-chown} disables the change of +owner to root for installed programs. + + +@node XZ-Utils +@section XZ-Utils + +XZ Utils is a general-purpose data compression software with high +compression ratio. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/xz-5.0.4.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/xz-5.0.4 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/{xz,lzma,lzcat,unlzma,unxz,xzcat} \ +# ${TARGET_DIR}/bin +cd .. +rm -rf xz-5.0.4 +popd +@end verbatim + + +@node Bootscripts +@section Bootscripts + +The bootscript archive contains scripts that manage services during +system's bootup and shutdown. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/bootscripts-cross-lfs-1.2-pre11.tar.bz2 \ + -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bootscripts-cross-lfs-1.2-pre11 +make DESTDIR=${TARGET_DIR} install-bootscripts +make DESTDIR=${TARGET_DIR} install-network +cd .. +rm -rf bootscripts-cross-lfs-1.2-pre11 +popd +@end verbatim + +This installs basic bootscripts required for bootup and shutdown, and +network-related bootscripts. + + +@node Kernel +@section The Kernel + +To avoid potential kernel lockup on Loongson 2F machines, we need to +add the option @option{-mfix-loongson2f-jump} to the environment +variable @env{CFLAGS}@footnote{For more information about the issue, +see +@uref{http://groups.google.com/group/loongson-dev/browse_thread/thread/d9103283141c00fb/e9a8830b01cc1913?hide_quotes=no#msg_d44adf83639fb0bd} +and +@uref{http://sourceware.org/ml/binutils/2009-11/msg00387.html}.}: + +@c commits on +@c @uref{http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=622844bf0b4cfa4f76d4a0ddc44266938385f5ab} +@c @uref{http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=54413b825ca502b9384edabf972c512c29d64010}.}. + +@verbatim +sed -i.orig \ + "/CFLAGS/s/-mfix-loongson2f-nop/& -Wa,-mfix-loongson2f-jump/" \ + ~/.bashrc +source ~/.bash_profile +@end verbatim + +Then: + +@verbatim +tar xf ${DOWNLOAD_DIR}/linux-libre-3.5.4-gnu.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/linux-3.5.4 +make mrproper +@end verbatim + +Then, if you are compiling the kernel for an Yeeloong @samp{2f} +netbook: + +@verbatim +cp arch/mips/configs/lemote2f_defconfig .config +patch -Np1 -i ${DOWNLOAD_DIR}/100gnu+freedo.patch +@end verbatim + +Then, if you want to change the configuration: + +@verbatim +#make ARCH=mips CROSS_COMPILE=${CROSS_TARGET}- config +make ARCH=mips CROSS_COMPILE=${CROSS_TARGET}- menuconfig +@end verbatim + +@menu +* CPU selection:: Selecting your CPU +* Optimizations:: Optimizing your kernel +* Compatibility of executables:: Configuring compatibility of + executables +* Power Management:: Configuring ower management +* Network card configuration:: Configuring your network card +* Flash media:: Configuring USB keys and SDcards +* File Systems:: Configuring the file systems +* Input devices:: Configuring keyboard and mouse +* Display:: Configuring the display +* Unicode support:: Supporting Unicode +* Kernel Compilation:: Kernel Compilation +@end menu + +@c ???Needed for some reason: +@c +@c Executable file formats +@c Kernel support for MISC binaries + + +@node CPU selection +@subsection CPU selection + +To know the CPU model you have on a given computer, type @samp{cat +/proc/cpuinfo} inside a terminal. + +@verbatim +Machine selection + System type + (X) Loongson family of machines + Machine type + (X) Lemote Loongson 2F family machines +@end verbatim + +As you will discover when you type @samp{lspci | grep CS5536} in a +terminal, AMD CS5536 is used for a variety of things on the Yeeloong: +ISA bridge, IDE interface, Multimedia audio controller and two USB +Controllers. In order to get the correct time, we need to enable the +following option: + +@c @emph{why does CS5536 need this?} + +@verbatim + [*] CS5536 MFGPT Timer +@end verbatim + +@quotation Note +@acronym{MFGPT} stands for Multi-Function General Purpose Timer. +@end quotation + +MIPS architecture exists in two flavours: big endian and little +endian. The difference resides in the order in which the Bytes are +stored in the hardware: little endian's first Byte is the least +significant one while big endian's first Byte is the most significant +one. In our case, we have a little endian architecture, so: + +@verbatim +Endianess selection + (X) Little endian + +CPU selection + CPU type + (X) Loongson 2F +@end verbatim + +If your version of Binutils is 2.20.2 or later, select the following +option: + +@verbatim +CPU selection + [*] Loongson 2F Workarounds +@end verbatim + +It fixes some issues with the Loongson 2F processors@footnote{For more +information about the issue, see +@uref{http://groups.google.com/group/loongson-dev/browse_thread/thread/d9103283141c00fb/e9a8830b01cc1913?hide_quotes=no#msg_d44adf83639fb0bd} +and +@uref{http://sourceware.org/ml/binutils/2009-11/msg00387.html}.}. + +Then, whatever your version of Binutils is: + +@verbatim +Kernel type + Kernel code model + (X) 64-bit kernel +@end verbatim + + +@node Optimizations +@subsection Optimizations + +If you want higher performance but with increased memory consumption, +select a @option{Kernel page size} of 16kB: + +@verbatim +Kernel type + Kernel page size + (X) 16kB +@end verbatim + +Then, if you want to reduce the size of your kernel (this may increase +decompression time at bootup though): + +@verbatim +General setup + Kernel compression mode + (X) Bzip2 +@end verbatim + +Then, whatever your choice: + +@verbatim +General setup + [*] Support for paging of anonymous memory (swap) +@end verbatim + +To be able to copy your kernel configuration through kernel versions, +you may want to select the following options: + +@verbatim +General setup + <*> Kernel .config support + [*] Enable access to .config through /proc/config.gz +@end verbatim + +If you want to optimize your kernel for size (but not necessarily for +speed), select the following option: + +@verbatim +General setup + [*] Optimize for size +@end verbatim + +Selecting this option will use option @option{-Os} of GCC instead of +the default @option{-O2}. + + +@node Compatibility of executables +@subsection Compatibility of executables + +@acronym{ELF} (Executable and Linkable Format) is a common standard +file format for executables, object code, shared libraries, and core +dumps. + +@verbatim +Executable file formats + [*] Kernel support for ELF binaries + [*] Kernel support for Linux/MIPS 32-bit binary compatibility + [*] Kernel support for o32 binaries + [*] Kernel support for n32 binaries +@end verbatim + + +@node Power Management +@subsection Power Management + +Power management is a feature that turns off the power or switches the +system to a low-power state when inactive. + +@verbatim +Power management options + [*] Power Management support + [*] Power Management Debug Support + [*] Verbose Power Management debugging + [*] Suspend to RAM and standby + [*] Hibernation (aka 'suspend to disk') +@end verbatim + +To be able to get information on your battery status, select the +following option: + +@verbatim +Device Drivers + <*> Power supply class support + [*] Power supply debug +@end verbatim + + +@node Network card configuration +@subsection Network card configuration + +The network card is the component of your computer that lets you +browse the internet and receive emails, among other things. This +section covers both wired and wireless network cards. + +@menu +* Ethernet card configuration:: Configuring your ethernet card +* Wireless card configuration:: Configuring your wireless card +@end menu + + +@node Ethernet card configuration +@subsubsection Ethernet card configuration + +To know which ethernet controller you have, type in a terminal: + +@verbatim +lspci | grep Ethernet +@end verbatim + +In order to build the driver for the RTL-8139 ethernet controller: + +@verbatim +Device Drivers + [*] Network device support + [*] Ethernet (10 or 100Mbit) + <*> Realtek RTL-8129/8130/8139 PCI Fast Ethernet Adapter + support +@end verbatim + +@c [*] Support for uncommon RTL-8139 rev. K (automatic +@c channel equalization) + + +@node Wireless card configuration +@subsubsection Wireless card configuration + +To know which wireless card is connected to your USB port, in a +terminal, type: + +@verbatim +lsusb | grep Wireless +@end verbatim + +To be able to build the option @option{cfg80211}, which is the current +wireless configuration API, @emph{not as a module} inside the kernel, +you will have to select the following option first: + +@verbatim +[*] Networking support + <*> RF Switch subsystem support +@end verbatim + +Then: + +@verbatim +[*] Networking support + -*- Wireless + <*> cfg80211 -wireless configuration API + [*] cfg80211 wireless extensions compatibility + <*> Wireless extensions sysfs files + <*> Common routines for IEEE802.11 drivers + [*] lib80211 debugging messages +@end verbatim + +mac80211 is a framework which driver developers can use to write +drivers for SoftMAC wireless devices@footnote{See +@uref{http://www.linuxwireless.org/en/developers/Documentation/mac80211/} +for more information.}. + +The following option needs to be built @emph{not as a module} in order +for the option @option{Realtek 8187 and 8187B USB support} to be +built inside the kernel @emph{not as a module}: + +@verbatim +[*] Networking support + -*- Wireless + <*> Generic IEEE 802.11 Networking stack (mac80211) +@end verbatim + +Enabling EEPROM 93CX6 is required in order to build option +@option{Realtek 8187 and 8187B USB support} inside the kernel: + +@verbatim +Device Drivers + [*] Misc devices + EEPROM support + -*- EEPROM 93CX6 support +@end verbatim + +If you want built-in support for Realtek 8187 and 8187B: + +@verbatim +Device Drivers + Network device support + [*] Wireless LAN + <*> Realtek 8187 and 8187B USB support +@end verbatim + +Then: + +@verbatim +Device Drivers + [*] USB support + {*} Enable Wireless USB extensions (EXPERIMENTAL) +@end verbatim + +@ignore + +@verbatim +Device Drivers + Generic Driver Options + - - Userspace firmware loading support + [ ] Include in-kernel firmware blobs in kernel binary +@end verbatim +@end ignore + + +@node Flash media +@subsection Flash media + +To know which driver to enable in the kernel, type @samp{lsusb | grep +multicard} in a terminal. + +If you want to enable support for USB keys and SDcard: + +@verbatim +Device Drivers + SCSI device support + <*> SCSI device support + <*> SCSI disk support + + [*] USB support + USB Mass Storage support + + <*> MMC/SD/SDIO card support + <*> USB SD Host Controller (USHC) support +@end verbatim + + +@node File Systems +@subsection File Systems + +By default, we recommend using Ext3 filesystem: + +@verbatim +File systems + <*> Ext3 journalling file system support +@end verbatim + +If you don't need support for RAID or LVM: + +@verbatim +Device Drivers + [ ] Multiple devices driver support (RAID and LVM) +@end verbatim + + +@node Input devices +@subsection Input devices + +To configure Keyboard: + +@verbatim +Device Drivers + Input device support + [*] Keyboards + <*> AT keyboard + [*] Mice + <*> PS/2 mouse + <*> Synaptics PS/2 mouse protocol extension +@end verbatim + + +@node Display +@subsection Display + +To know your @acronym{VGA} (Video Graphics Array) controller model +(@acronym{VGA} refers to display hardware), type @samp{lspci | grep +VGA} in a terminal. A @dfn{framebuffer} is a video output device +that drives a video display from a memory buffer containing a complete +frame of data@footnote{For more information, see +@uref{http://en.wikipedia.org/wiki/Framebuffer}.}. + +@verbatim +Device Drivers + Graphics support + <*> Support for frame buffer devices + Userspace VESA VGA graphics support + Console display driver support + <*> Framebuffer Console support + -*- VGA 8x16 font + + [*] Staging drivers + <*> Silicon Motion SM7XX Frame Buffer Support +@end verbatim + +@c [*] VESA VGA graphics support + + +@node Unicode support +@subsection Unicode support + +Unicode is a computing industry standard for the consistent encoding, +representation and handling of text expressed in most of the world's +writing systems@footnote{For more information, read +@uref{http://en.wikipedia.org/wiki/Unicode}.}. + +@verbatim +File systems + -*- Native language support + <*> NLS UTF-8 +@end verbatim + +@c Device Drivers +@c [*] Multifunction device drivers +@c <*> Support for CS5535 and CS5536 southbridge core functions + +@c In File systems, remove support for Btrfs filesystem, otherwise +@c compilation will fail. + + +@node Kernel Compilation +@subsection Kernel Compilation + +@verbatim +# 2 hours and 40 minutes +make \ + ARCH=mips \ + CROSS_COMPILE=${CROSS_TARGET}- +make \ + ARCH=mips \ + CROSS_COMPILE=${CROSS_TARGET}- \ + INSTALL_MOD_PATH=${TARGET_DIR} \ + modules_install +cp vmlinuz ${TARGET_DIR}/boot/vmlinuz +cp System.map ${TARGET_DIR}/boot/System.map +cp .config ${TARGET_DIR}/boot/config +cd .. +popd +@end verbatim + +@quotation Tip +because future compilation may need kernel sources, the compilation +directory of the kernel should be preserved. +@end quotation + + +@node Configuration Files +@chapter Creating Required Configuration Files for the New System + +@menu +* Time Setup File:: File for time setup. +* Bash Keyboard Setup:: Setting up keyboard function keys + for the Shell. +* Bash Startup Files:: Setting up Bash shell startup files. +* Localhost Setup:: Setting up localhost. +* hosts Setup:: Setting up @file{hosts} file. +* Network Address Setup:: Setting up network address. +* DNS Setup:: Setting up DNS. +* fstab File Creation:: Creating @file{fstab} file. +@end menu + + +@node Time Setup File +@section File for Time Setup + +@verbatim +cat > ${TARGET_DIR}/etc/sysconfig/clock << "EOF" +# Begin /etc/sysconfig/clock + +UTC=1 + +# End /etc/sysconfig/clock +EOF +@end verbatim + + +@node Bash Keyboard Setup +@section Setting up Keyboard Function keys for the Shell + +Readline default configuration file is set: + +@verbatim +cat > ${TARGET_DIR}/etc/inputrc << "EOF" +set bell-style none +set convert-meta Off +set horizontal-scroll-mode Off +set input-meta On +set output-meta On +"\eOd": backward-word +"\eOc": forward-word +"\e[1~": beginning-of-line +"\e[4~": end-of-line +"\e[5~": beginning-of-history +"\e[6~": end-of-history +"\e[3~": delete-char +"\e[2~": quoted-insert +"\eOH": beginning-of-line +"\eOF": end-of-line +"\e[H": beginning-of-line +"\e[F": end-of-line +EOF +@end verbatim + +If @option{convert-meta} is set to @samp{on}, Readline will convert +characters with the eighth bit set to an @sc{ascii} key sequence by +stripping the eighth bit and prefixing an @key{ESC} character, +converting them to a meta-prefixed key sequence. + +@option{horizontal-scroll-mode} set to @samp{off} means that the text +of the lines being edited will be wrapped onto a new screen line when +they are longer than the width of the screen, instead of being +scrolled horizontally on a single screen line. + +@c set meta-flag On + +@option{input-meta} If set to @samp{on}, Readline will enable +eight-bit input (it will not clear the eighth bit in the characters it +reads), regardless of what the terminal claims it can support. + +If @option{output-meta} is set to @samp{on}, Readline will display +characters with the eighth bit set directly rather than as a +meta-prefixed escape sequence. + +@ignore +"\eOd": backward-word +"\eOc": forward-word +"\e[1~": beginning-of-line +"\e[4~": end-of-line +"\e[5~": beginning-of-history +"\e[6~": end-of-history +"\e[3~": delete-char +"\e[2~": quoted-insert +"\eOH": beginning-of-line +"\eOF": end-of-line +"\e[H": beginning-of-line +"\e[F": end-of-line +@end ignore + + +@node Bash Startup Files +@section Setting up Bash Shell Startup Files + +@verbatim +cat > ${TARGET_DIR}/etc/profile << "EOF" +# Begin /etc/profile + +export LANG=en_US.UTF-8 +export INPUTRC=/etc/inputrc +export PS1='\[\e[31m\]\A-\W\[\e[00m\]\$ ' + +# End /etc/profile +EOF +@end verbatim + +The environement variable @env{LANG} defines the default language that +should be used on the system. @samp{en_US.UTF-8} means ``english'' +language, country ``US'' and @acronym{UTF-8} (UCS Transformation +Format—8-bit) encoding (Unicode). + +@c For a full list, see??? + +For explanations on @env{PS1}, @pxref{Environment Variables Setup}. + + +@node Localhost Setup +@section Localhost Setup + +@verbatim +echo "HOSTNAME=gllfsc" > ${TARGET_DIR}/etc/sysconfig/network +@end verbatim + + +@node hosts Setup +@section Setting up @file{hosts} File + +@verbatim +cat > ${TARGET_DIR}/etc/hosts << "EOF" +# Begin /etc/hosts + +127.0.0.1 gllfsc localhost + +# End /etc/hosts +EOF +@end verbatim + + +@node Network Address Setup +@section Setting up Network Address + +You can choose to have a network static or dynamic address. + +@menu +* Network Static Address Setup:: Setting up Network Static Address. +* Network Dynamic Address Setup:: Setting up Network Dynamic + Address. +@end menu + + +@node Network Static Address Setup +@subsection Setting up Network Static Address + +@verbatim +pushd ${TARGET_DIR}/etc/sysconfig/network-devices +mkdir -v ifconfig.eth0 +cat > ifconfig.eth0/ipv4 << "EOF" +ONBOOT=yes +SERVICE=ipv4-static +IP=192.168.1.1 +GATEWAY=192.168.1.2 +PREFIX=24 +BROADCAST=192.168.1.255 +EOF +popd +@end verbatim + +@quotation Warning +@code{IP}, @code{GATEWAY}, @code{BROADCAST} addresses are set up +according to one's situation. +@end quotation + + +@node Network Dynamic Address Setup +@subsection Setting up Network Dynamic Address + +@verbatim +pushd ${TARGET_DIR}/etc/sysconfig/network-devices +mkdir -v ifconfig.eth0 +cat > ifconfig.eth0/ip << "EOF" +ONBOOT=yes +SERVICE=dhcpcd +DHCP_START="-t10" +DHCP_STOP="-k" +EOF +popd +@end verbatim + + +@node DNS Setup +@section Setting up DNS + +@verbatim +cat > ${TARGET_DIR}/etc/resolv.conf << "EOF" +# Begin /etc/resolv.conf + +nameserver your-main-DNS-address +nameserver your-secondary-DNS-address + +# End /etc/resolv.conf +EOF +@end verbatim + + +@node fstab File Creation +@section @file{fstab} File Creation + +The file @file{/etc/fstab} is used at boot to mount partitions under +the requested directories. + +@verbatim +cat > ${TARGET_DIR}/etc/fstab << "EOF" +# Begin /etc/fstab + +# file system mount-point type options dump fsck order + +/dev/hda4 / ext3 defaults 1 1 +/dev/hda3 swap swap pri=1 0 0 +proc /proc proc defaults 0 0 +sysfs /sys sysfs defaults 0 0 +devpts /dev/pts devpts gid=4,mode=620 0 0 +shm /dev/shm tmpfs defaults 0 0 + +# End /etc/fstab +EOF +@end verbatim + +@quotation Warning +the name of the hard drive and the name of filesystem used here have +to be modified to reflect @emph{your} real situation. +@end quotation + + +@node End +@chapter The End + +@menu +* Archiving:: All the system archived in one + package. +* Recommendations:: Some tips. +@end menu + + +@node Archiving +@section Archiving the System + +After the system has been completed, we use the command @command{exit} +to logout as the @emph{gllfsc} user. + +Now, login as the @emph{root} user. + +Then fix the permissions on the new system: + +@verbatim +export TARGET_DIR=/gllfsc +pushd ${TARGET_DIR} +mknod -m 600 dev/console c 5 1 +mknod -m 666 dev/null c 1 3 +cp -a dev/{console,null} lib/udev/devices/ +chown -R root:root * +@end verbatim + +We archive the entire system by using the following command: + +@verbatim +# 20 minutes without kernel sources nor cross-tools +tar -cjf gllfsc-20121006.tar.bz2 bin boot dev etc home lib* media \ + mnt opt proc root sbin srv sys tmp usr var +# 60 minutes with kernel sources + cross-tools +#tar -cjf gllfsc-20121006.tar.bz2 * +@end verbatim + +It is then easy to copy the archive to the target machine and extract. + + +@node Recommendations +@section Some Recommendations + +We recommend extracting the system to an empty partition. Moreover, +the filesystem of the chosen partition has to be a filesystem +supported by the kernel you compiled. Finally, this partition has to +be consistent with the system description in the file +@file{/etc/fstab} you created during setup (@pxref{fstab File +Creation}). + +Then, you will have to edit the PMON BIOS configuration file of the +target machine: @file{/boot.cfg}. This file has to be put on the first +partition of the hard +drive@footnote{@uref{http://gnewsense.org/Projects/Lemote#Updating_of_the_PMON_configuration}}. A +minimal @file{/boot.cfg} could be: + +@verbatim +default 0 +timeout 2 +showmenu 1 + +title GLLFSC +kernel (wd0,3)/boot/vmlinuz +args console=tty no_auto_cmd root=/dev/hda4 rootdelay=8 machtype=8.9 +@end verbatim + + +@node Further Readings +@chapter Further Readings + +Haiyong Sun's website (in Chinese): +@uref{http://youbest.cublog.cn}. It includes documents on building a +GNU/Linux system for Loongson and a GNU/Hurd system for x86. + +Cross [GNU/]Linux from scratch: @uref{http://www.cross-lfs.org}. +Includes a lot of documentation to build a GNU/Linux system by +cross-compilation on a variety of hardware, no information (yet) for +cross-compiling with sysroot on MIPS though. There is also a +Community-driven Beyond [GNU/]Linux From Scratch on +@uref{http://cblfs.cross-lfs.org}. It documents the building of Xorg +and TeXLive among other things. + +@c Some patches from the above project are available for download on +@c @uref{http://svn.cross-lfs.org/svn/repos/patches/}. + +@uref{http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_@/man.txt} +documents an interesting way of managing packages. Quotation from the +file: + +@quotation +DESCRIPTION: +@itemize + +@item +You want to know which packages your files belong to? + +@item +You want to deinstall software that doesn't have make uninstall? + +@item +You are bothered by programs installed setuid root behind your back? + +@item +You don't like packages quietly overwriting files from other packages? + +@item +You don't like package managers like RPM? + +@item +YOU WANT TOTAL CONTROL USING ONLY UNIX BUILTINS? +@end itemize +@end quotation + +The suckless team@footnote{@uref{http://suckless.org}} is a group of +programmers that share the following +philosophy@footnote{@uref{http://suckless.org/philosophy}}: + +@quotation +Focus on simplicity, clarity and frugality. Our philosophy is about +keeping things simple, minimal and usable. We believe this should +become the mainstream philosophy in the IT sector. Unfortunately, the +tendency for complex, error-prone and slow software seems to be +prevalent in the present-day software industry. We intend to prove the +opposite with our software projects. +@end quotation + +The simple and lightweight programs released by this team are +interesting for machines based on Loongson 2F processor as performance +is limited compared to current x86 processors. + + +@node GNU Free Documentation License +@appendix GNU Free Documentation License +@include fdl-1.3.texi + + +@node GNU General Public License +@appendix GNU General Public License +@include gpl.texi + +@bye diff --git a/gllfsc-loongson3a-1.0.texi b/gllfsc-loongson3a-1.0.texi new file mode 100644 index 0000000..2797efa --- /dev/null +++ b/gllfsc-loongson3a-1.0.texi @@ -0,0 +1,4299 @@ +\input texinfo +@c -*-texinfo-*- +@c %**start of header +@setfilename gllfsc-loongson3a-1.0.info +@settitle GNU/Linux-libre from source code for Loongson 3A +@c Comment the following if you want Letter format instead of A4 for +@c PDF output +@afourpaper +@c %**end of header +@c Book headers for PDF version +@setchapternewpage odd +@documentencoding UTF-8 + +@copying +This is edition 1.0 (last updated 31 July 2013) of +@cite{GNU/Linux-libre from source code for Loongson 3A}. + +Copyright @copyright{} 2013 Christophe Jarry. + +This document is based on the Chinese page +@url{http://zdbr.net.cn/download/Loongson64-@/2.0.htm}, which is +copyright @copyright{} 2009 +@c Because TeX does not handle Chinese fonts automatically, we need to +@c do the following: +@ifnottex +Haiyong Sun (孙海勇). +@end ifnottex +@iftex +Haiyong Sun. +@end iftex +His blog is on @url{http://youbest.cublog.cn}. + +Various formats of this manual as well as its texinfo source are +available on +@uref{http://cjarry.org/gnu-linux/gllfsc/}. + +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 +or any later version published by the Free Software Foundation; +with no Invariant Sections, no Front-Cover Texts, and no Back-Cover +Texts. A copy of the license is included in the section entitled ``GNU +Free Documentation License''. +@end quotation + +@quotation +Computer instructions in this manual are free software: you can +redistribute them and/or modify them under the terms of the GNU +General Public License as published by the Free Software Foundation, +either version 3 of the License, or (at your option) any later +version. + +Those instructions are distributed in the hope that they will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this manual. If not, see . +@end quotation + +@end copying + +@c @setchapternewpage odd + +@titlepage +@title GNU/Linux-libre from source code +@subtitle for Loongson 3A +@c @subtitle SUBTITLE-IF-ANY +@c @subtitle SECOND-SUBTITLE +@author Christophe Jarry + +@c The following two commands +@c start the copyright page. +@page +@vskip 0pt plus 1filll +@insertcopying + +@c Published by ... +@end titlepage + +@c Short table of contents +@shortcontents + +@c So the toc is printed at the start. +@contents + +@ifnottex +@node Top +@top GNU/Linux-libre from source code for Loongson 3A + +This manual describes how to build a GNU/Linux-libre system from +source for Loongson 3A processor. + +@insertcopying +@end ifnottex + +@menu +* Introduction:: What this document is all about. +* Prerequisites:: Useful knowledge before proceeding. +* Preliminary Work:: Preparing the build. +* Building the Cross-Compilation Toolchain:: Building the cross- + compilation Toolchain. +* Building Cross-Compilation Tools:: Building the cross-compilation + Tools. +* Building the Target System:: How to build the target system. +* Configuration Files:: Creating configuration files + needed by the new system. +* End:: Final things to do. +* Further Readings:: Websites useful to know more. +* Thanks:: Thanks. +* GNU Free Documentation License:: Your rights and freedoms with the + text. +* GNU General Public License:: Your rights and freedoms with the + commands. +@end menu + + +@node Introduction +@chapter Introduction + +@menu +* GNU/Linux History:: A brief history of GNU/Linux. +* Purpose of this Document:: What this document is all about. +@end menu + + +@node GNU/Linux History +@section GNU/Linux History + +@menu +* GNU:: Presentation of the GNU project +* HURD:: Presentation of the HURD +* Linux:: Presentation of the kernel Linux +* Linux-libre:: Presentation of the kernel Linux-libre +* References:: Where to get more information +@end menu + +@node GNU +@subsection GNU + +@acronym{GNU} (GNU's Not Unix) is a project launched by Richard +Stallman in 1984 with the goal of building an entirely free operating +system compatible with Unix@footnote{See +@uref{http://en.wikipedia.org/wiki/Unix}}. ``Free'' here means ``free +as in freedom''. In this context, a free operating system is an +operating system you can use and share in freedom. A core part of his +motivation is given in the GNU +Manifesto@footnote{@uref{http://www.gnu.org/gnu/manifesto.html}}: + +@quotation +I consider that the Golden Rule requires that if I like a program I +must share it with other people who like it. Software sellers want to +divide the users and conquer them, making each user agree not to share +with others. I refuse to break solidarity with other users in this +way. I cannot in good conscience sign a nondisclosure agreement or a +software license agreement. For years I worked within the Artificial +Intelligence Lab to resist such tendencies and other inhospitalities, +but eventually they had gone too far: I could not remain in an +institution where such things are done for me against my will. + +So that I can continue to use computers without dishonor, I have +decided to put together a sufficient body of free software so that I +will be able to get along without any software that is not free. I +have resigned from the AI Lab to deny MIT any legal excuse to prevent +me from giving GNU away. +@end quotation + +A program is free software if the program's user has the four +essential freedoms: + +@itemize +@item +The freedom to run the program, for any purpose (freedom 0). + +@item +The freedom to study how the program works, and change it so it does +her computing as she wishes (freedom 1). Access to the source code is +a precondition for this. + +@item +The freedom to redistribute copies so she can help her neighbor +(freedom 2). + +@item +The freedom to distribute copies of her modified versions to others +(freedom 3). By doing this she can give the whole community a chance +to benefit from her changes. Access to the source code is a +precondition for this. +@end itemize + +One of the most popular free software license is the GNU General +Public License (GNU +GPL@footnote{@uref{http://www.gnu.org/licenses/gpl.html}}). + +The free software movement is supported by the Free Software +Foundation (FSF@footnote{@uref{http://www.fsf.org}}). + + +@node HURD +@subsection HURD + +The @acronym{HURD} is an acronym for @acronym{HIRD} (HURD of +interfaces representing depth) of Unix-replacing daemons. It is the +GNU project's replacement for the Unix kernel. It is a collection of +servers that run on the Mach microkernel to implement file systems, +network protocols, file access control, and other features that are +implemented by the Unix kernel or similar kernels (such as Linux). + +The purpose of the GNU HURD is to improve the user's freedom on her +operating system by allowing her to either add or remove a feature of +the kernel on the fly. + +From early on, the HURD was developed to use GNU Mach as the +microkernel. This was a technical decision made by Richard Stallman, +who thought it would speed up the work by saving a large part of +it. He has admitted that he was wrong about that. + +Nevertheless, development of the HURD is increasingly attracting +developers and GNU/HURD systems exist and are usable. + + +@node Linux +@subsection Linux + +Linux is a monolithic kernel created by Linus Torvalds in 1991. Linus +Torvalds initially wrote a terminal emulator, which he used to access +the large UNIX servers of his university. He wrote the program +specifically for the hardware he was using and independent of an +operating system because he wanted to use the functions of his new PC +with an 80386 processor. This later became the kernel Linux. + +Initially, Torvalds first published the kernel Linux under its own +licence, which had a restriction on commercial activity. + +In the notes for the first release of the kernel Linux, Torvalds lists +the GNU software that is required to run Linux: + +@quotation +Sadly, a kernel by itself gets you nowhere. To get a working system +you need a shell, compilers, a library etc. [...] Most of the tools +used with linux are GNU software and are under the GNU copyleft. +@end quotation + +In 1992, he suggested releasing the kernel under the GNU General +Public License. He first announced this decision in the release notes +of version 0.12. In the middle of December 1992 he published version +0.99 using the GNU GPL. + +The kernel Linux is now a contribution of many professionals and +volonteers around the world. + + +@node Linux-libre +@subsection Linux-libre + +Linux, the kernel developed and distributed by Linus Torvalds et al, +contains non-Free Software@footnote{For more information about the +presence of proprietary firmware in the kernel Linux, read +@uref{http://www.fsfla.org/svnwiki/anuncio/2010-03-Linux-2.6.33-libre.en} +and +@uref{http://www.gnu.org/@/distros/free-system-distribution-guidelines.html#nonfree-firmware}.}, +i.e., software that does not respect your essential freedoms, and it +induces you to install additional non-Free Software that it doesn't +contain. + +GNU +Linux-libre@footnote{@uref{http://www.fsfla.org/svnwiki/selibre/linux-libre/index.en.html}} +is a project to maintain and publish 100% Free distributions of Linux, +suitable for use in Free System Distributions@footnote{For a full list +of free as in freedom GNU/Linux distributions, see +@uref{http://www.gnu.org/distros}.}, removing software that is +included without source code, with obfuscated or obscured source code, +under non-Free Software licenses, that do not permit you to change the +software so that it does what you wish, and that induces or requires +you to install additional pieces of non-Free Software. + + +@node References +@subsection References + +For more information on the GNU project and its relation with the +kernel Linux, you can read @uref{http://www.gnu.org/gnu/thegnuproject.html} +and @uref{http://www.gnu.org/gnu/gnu-linux-faq.html}. + +For more information on the history of the HURD, I recommend you to +read @uref{http://www.h-online.com/open/features/GNU-HURD-Altered-visions-and-lost-promise@/-1030942.html}. + +For more information on the HURD, read @uref{http://www.gnu.org/software/hurd}. + + +@node Purpose of this Document +@section Purpose of this Document + +Lemote offered me a Yeeloong 8133 in late 2012. I wanted to adapt some +parts of gNewSense@footnote{@uref{http://www.gnewsense.org}} for MIPS +to this particular laptop. I also wanted to port the document I wrote +for Loongson 2F to Loongson 3A: GNU/Linux@footnote{Note: in this +document, we use the term ``GNU/Linux'' to name the entire system and +``Linux'' to name the kernel. For more information, read +@uref{http://www.gnu.org/gnu/why-gnu-linux.html}.} Libre from Source +Code for Loongson 3A was born. + + +@node Prerequisites +@chapter Prerequisites + +@menu +* Definitions:: Definitions of important notions used to build the + system +* Commands:: Help on commands +@end menu + + +@node Definitions +@section Definitions + +@menu +* sysroot:: @option{sysroot} +* Toolchain:: What a Toolchain is. +* build host target:: Understanding the meaning of the + @option{build}-@option{host}-@option{target} + triplet. +* FHS:: The Filesystem Hierarchy Standard. +@end menu + + +@node sysroot +@subsection @option{sysroot} + +The traditional way of building a GNU/Linux operating system consists +on building a (cross-) compilation toolchain to build a temporary +operating system which in turn will be used to build the target +system@footnote{@pxref{Further Readings} section for more +details}. This requires almost as much time to complete the temporary +system as to build the target one. Using sysroot resolves this +problem. + +From GCC installation manual, under Cross-Compiler-Specific Options: + +@table @code +@item --with-sysroot +@itemx --with-sysroot=@var{dir} +Tells GCC to consider @var{dir} as the root of a tree that contains (a +subset of) the root filesystem of the target operating system. Target +system headers, libraries and run-time object files will be searched +in there. More specifically, this acts as if +@option{--sysroot=@var{dir}} was added to the default options of the +built compiler. The specified directory is not copied into the +install tree, unlike the options @option{--with-headers} and +@option{--with-libs} that this option obsoletes. The default value, +in case @option{--with-sysroot} is not given an argument, is +@option{$@{gcc_tooldir@}/sys-root}. If the specified directory is a +subdirectory of @option{$@{exec_prefix@}}, then it will be found +relative to the GCC binaries if the installation tree is moved. + +This option affects the system root for the compiler used to build +target libraries (which runs on the build system) and the compiler +newly installed with @code{make install}; it does not affect the +compiler which is used to build GCC itself. +@end table + + +@node Toolchain +@subsection Toolchain + +According to +Wikipedia@footnote{@uref{http://www.wikipedia.org/wiki/Toolchain}}: + +@quotation +In software, a toolchain is the set of programming tools that are used +to create a product (typically another computer program or system of +programs). The tools may be used in a chain, so that the output of +each tool becomes the input for the next, but the term is used widely +to refer to any set of linked development tools. + +A simple software development toolchain consists of a text editor for +editing source code, a compiler and linker to transform the source +code into an executable program, libraries to provide interfaces to +the operating system, and a debugger. +@end quotation + + +@node build host target +@subsection @option{build}, @option{host} and @option{target} + +During a cross-compilation, @option{build} @option{host} and +@option{target} are among the most used options: understanding the +precise meaning of those parameters is very important. We could define +them thus: + +@itemize +@item @option{--build=@var{platform on which the program is +compiled}}, +@item @option{--host=@var{platform on which the program will run}}, +@item @option{--target=@var{platform for which the program will create +output}}. +@end itemize + +Let's use GCC as an example to explain the role of those three +parameters. + +During GCC compilation, we use: + +@samp{./configure --build=@var{build-platform} +--host=@var{host-platform} --target=@var{target-platform} [various +compilation parameters]} + +So in those configuration parameters: + +@itemize +@item +@option{--build} provides the name of the platform currently running. +If we were using an Intel Pentium processor to compile the system, our +@var{build-platform} would be something like @samp{i686-pc-linux-gnu}. + +If this parameter is not specified, it will be guessed automatically. + +@item +@option{--host} represents the type of machine we are going to run GCC +on after the compilation succeeds. During a cross-compilation this has +to be specified, because the current machine can not know which +architecture we wish to target. We want to produce executables to run +on @emph{Loongson}, but there is currently no way we can specify +@samp{Loongson} directly; because of this we specify +@samp{mips64el-unknown-linux-gnu}. + +@option{--host} can also be left unspecified, in that case, +@var{host-platform} would automatically define itself as +@var{build-platform}, but this is not cross-compilation anymore. + +@quotation Note +when @option{--build} and @option{--host} are different, configuration +files will maintain the cross-compilation mode. +@end quotation + +@item +@option{--target} defines the system for which compiler tools will +create output. + +@var{target-platform} parameter is useful only for a limited number of +programs. Although this parameter is often present when issuing +@samp{./configure --help}, hardly any packages will need it. + +This parameter is only useful for performing tasks with different +platforms; for instance, executable files compiled for different +platforms can have a totally different code. +@end itemize + +If we summarize, we have: + +@itemize +@item @var{build-platform}: automatically guessed from platform in +use; has to be specified if not guessed. + +@item @var{host-platform}: if unspecified, automatically equals +@var{build-platform}. When @var{build-platform} and +@var{host-platform} values are identical, it is a local compilation; +otherwise it is a cross-compilation. + +@item @var{target-platform}: defines the system for which compiler +tools will create output; it equals @var{host-platform} if +unspecified. GCC, binutils, and programs related to the platform's +instructions have this parameter; most programs do not use this +parameter. +@end itemize + + +@node FHS +@subsection FHS + +The Filesystem Hierarchy Standard (FHS) has been created to specify +the location and use of main directories on a GNU/Linux operating +system. Common commands, user data, libraries have to be put inside a +specific directory given in the standard. During the build process, +some commands are used to comply with FHS. + + +@node Commands +@section Commands + +Because most commands are common for a regular Unix user, only +uncommon commands are explained in this document. If you do not +understand a command that is not explained, you can use the +documentation available on your computer; in a terminal, typing +@samp{man @var{command}} should give you enough information. For GNU +software, @samp{info @var{package}} can also give additional +information. + +To know more about command line, I suggest you read "Introduction to +the Command Line" which is available on +@uref{http://flossmanuals.net/command-line/}. + + +@node Preliminary Work +@chapter Preliminary Work + +@quotation Important +In order to complete the first steps of this chapter, you will need to +have root permissions. +@end quotation + +@menu +* Build Partition Creation:: Creating a partition for the build. +* Build User Creation:: Creating a user account dedicated to + the build. +* Work Directory Creation:: Creating the parent directory for the + build. +* Partition Mount:: Mounting the partition dedicated to the + build. +* Useful Directories Creation:: Creating the directories for downloads + and compilations. +* User Switch:: Switching to the user dedicated to the + build. +* Environment Variables Setup:: Setting up the environment variables + of the target system. +* Downloads:: Downloading needed packages and + patches. +* Final Preparations:: Preparing the system for the build. +@end menu + + +@node Build Partition Creation +@section Build Partition Creation + +To dedicate the partition @file{/dev/sda8} to the system build, and to +define the filesystem to be used for it as @samp{ext3}: + +@verbatim +mke2fs -t ext3 /dev/sda8 +@end verbatim + +Option @option{-t} is followed by the type of filesystem to be +used. The filesystem @samp{ext3} is used as it is one of the most +common filesystem used with the kernel Linux. + + +@node Build User Creation +@section Build User Creation + +To create the builder group, user and password: + +@verbatim +groupadd gllfsc +useradd -s /bin/bash -g gllfsc -m -k /dev/null gllfsc +passwd gllfsc +@end verbatim + +@itemize +@item +Option @option{-s} (or @option{--shell}) is used to define the created +user's default shell, here @file{/bin/bash}. + +@item +Option @option{-g} (or @option{--gid}) is used to define the group +name or number of the created user's initial login group, here +@samp{gllfsc}. + +@item +Option @option{-m} (or @option{--create-home}) does create the user's +home directory if it does not exist (@file{/home/@var{username}}). + +@item +Option @option{-k} (or @option{--skel}) is used to define the skeleton +directory to be copied in the user's home directory, here +@file{/dev/null}. @file{/dev/null} is a special file which, in this +case, will give no skeleton at all to @command{useradd}. +@end itemize + + +@node Work Directory Creation +@section Work Directory Creation + +To create the directory @file{/gllfsc} in which the system will be +built: + +@verbatim +export TARGET_DIR="/gllfsc" +mkdir -pv ${TARGET_DIR} +@end verbatim + +@samp{export TARGET_DIR="/gllfsc"} sets the value of the variable +@env{TARGET_DIR} to @file{/gllfsc}, the directory in which the system +will be built. + + +@node Partition Mount +@section Mounting Partition + +To mount the hard drive partition, for instance @file{/dev/sda8}, used +to build the system: + +@verbatim +mount /dev/sda8 ${TARGET_DIR} +@end verbatim + + +@node Useful Directories Creation +@section Creating Compilation and Download Directories + +@verbatim +mkdir -pv ${TARGET_DIR}/{build,download} +chown -Rv gllfsc ${TARGET_DIR} +@end verbatim + + +@node User Switch +@section Switching to the Build User + +To login as the user that will build the system: + +@verbatim +su - gllfsc +@end verbatim + +With the command @command{su}, it is possible to change the user +ID. The option @option{-} provides an environment similar to what the +user would expect had the user logged in directly. + + +@node Environment Variables Setup +@section Setting up Required Environment Variables + +@file{~/.bash_profile} is a personal initialization file that is read +when Bash is invoked as an interactive login shell (@file{~} is the +location of the user's home directory). To write the content of the +file @file{~/.bash_profile}: + +@verbatim +cat > ~/.bash_profile << "EOF" +exec env -i HOME=${HOME} TERM=${TERM} PS1=${PS1} /bin/bash +EOF +@end verbatim + +The first line creates the file @file{~/.bash_profile} and opens it +for writing until @samp{@acronym{EOF}} (End Of File) is written in it. + +The second line tells Bash to execute @file{/bin/bash} with the option +@option{-i} (or @option{--ignore-environment}) which will make Bash +start with an empty environment. Variables @env{HOME}, @env{TERM} and +@env{PS1} define respectively the home directory of the current user, +the terminal used and the primary prompt string displayed. + +@file{~/.bashrc} is a personal initialization file that is read when +Bash is invoked as an interactive shell but not a login one. To write +the content of the file @file{~/.bashrc}: + +@verbatim +cat > ~/.bashrc << "EOF" +set +h +umask 022 +alias make='make -j4' +export PS1='\[\e[35m\]\A-\W\[\e[00m\]\$ ' +export TARGET_DIR=/gllfsc +export LC_ALL=POSIX +export BUILD_DIR="${TARGET_DIR}/build" +export DOWNLOAD_DIR="${TARGET_DIR}/download" +export CROSS_HOST="$(echo $MACHTYPE |\ + sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")" +export CROSS_TARGET="mips64el-unknown-linux-gnu" +export MABI="n32" +#export MABI="64" +export MARCH="loongson3a" +export PATH=${TARGET_DIR}/cross-tools/bin:/bin:/usr/bin +unset CFLAGS +unset CXXFLAGS +EOF +source ~/.bash_profile +@end verbatim + +@samp{set +h} tells Bash to not locate nor remember commands (hash) as +they are looked up for execution. + +@samp{umask 022} sets Bash process' file creation mask to +@samp{022}. This results in permissions of `755' for those files. + +@samp{alias make='make -j4'} tells Bash to replace every call of +@samp{make} by @samp{make -j4}. This makes full use of the four cores +available in the Loongson 3A to build packages by parallelizing tasks. + +@samp{export PS1='\[\e[35m\]\A-\W\[\e[00m\]\$ '} sets the primary +prompt strings. The primary prompt strings are the strings you see +before the commands you type in the terminal. The part @samp{\A-\W} +means that the time, in 24-hour HH:MM format and the basename of +@env{$PWD} will be displayed separated by a `-', as in +@samp{19:33-bin}. The part @samp{\$} adds a dollar sign at the end, +@samp{\[\e[35m\]} colors the strings in purple and @samp{\[\e[00m\]} +gets the original color back. For other colors, you can browse +@uref{http://en.wikipedia.org/wiki/ANSI_escape_code}. + +@env{LC_ALL} is a macro used to define a single locale to overwrite +other @env{LC_*} and @env{LANG} environment variables so that +language, numeric values, time and other locale-dependant values have +all the same value. It is set to the standard POSIX locale. + +@samp{export BUILD_DIR="$@{TARGET_DIR@}/build"} sets the environment +variable @env{BUILD_DIR} to the value of @samp{$@{TARGET_DIR@}/build} +which is @samp{/gllfsc/build} in this document. + +The value of variable @env{CROSS_HOST} equals the value of variable +@env{MACHTYPE} of the current machine (for instance +@samp{i686-pc-linux-gnu}) modulo the second word, which is replaced by +@samp{cross} (i.e. @samp{i686-cross-linux-gnu}). + +The value of variable @env{CROSS_TARGET} equals the value of variable +@env{MACHTYPE} of the machine for which the system is built (i.e. +@samp{mips64el-unknown-linux-gnu}). + +The variable @env{MABI} defines the @acronym{ABI} (Application Binary +Interface) for which the system will be built. @option{-mabi} is an +option of GCC. n32/64 are for 64-bit CPUs only. 64 has 64-bit pointers +and long integers, whereas n32 has 32-bit pointers and long integers. + +The variable @env{MARCH} defines the architecture for which the system +will be built. @option{-march} is an option of @acronym{GCC} (GNU +Compiler Collection). + +The variable @env{PATH} contains a colon-separated list of directories +in which the shell looks for commands. The shell will first look for +commands in @file{$@{TARGET_DIR@}/cross-tools/bin}, then, if the +command was not found, in @file{/bin} and finally in @file{/usr/bin}. + +@command{unset} command removes the variable associated, here +@env{CFLAGS} and @env{CXXFLAGS}. Those variables are used by GCC as +extra flags given to the C compiler and the C++ compiler +respectively. + +Finally @samp{source ~/.bash_profile} reads and executes the content +of the file @file{~/.bash_profile}. + + +@node Downloads +@section Downloads + +@menu +* Packages Download:: List of packages to be downloaded. +* Patches Download:: List of patches to be downloaded. +@end menu + + +@node Packages Download +@subsection Downloading Packages + +The packages listed below are those used in this document. You can try +other versions but you will need a recent version of Binutils, GCC and +the kernel Linux in order to build GLLFSC for Loongson 3A. + +Download those files under @env{$@{DOWNLOAD_DIR@}} (which is +@file{/gllfsc/download} in this document). + + +@itemize +@item +Autoconf: @uref{http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz}. + +@item +Automake: @uref{http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz}. +@c @uref{http://ftpmirror.gnu.org/automake/automake-1.13.1.tar.gz}. + +@item +Bash: @uref{http://ftpmirror.gnu.org/bash/bash-4.2.tar.gz}. + +@item +Binutils: @uref{http://ftpmirror.gnu.org/binutils/binutils-2.23.2.tar.bz2}. +@c @uref{http://ftpmirror.gnu.org/binutils/binutils-2.23.1.tar.bz2}. + +@item +Bison: @uref{http://ftpmirror.gnu.org/bison/bison-2.7.tar.gz}. +@c @uref{http://ftpmirror.gnu.org/bison/bison-2.5.tar.bz2}. + +@item +Bootscripts: @uref{http://ftp.cross-lfs.org/pub/clfs/conglomeration/bootscripts@/-cross-lfs/bootscripts-cross-lfs-2.0.0.tar.xz}. +@c @uref{http://ftp.cross-lfs.org/pub/clfs/conglomeration/bootscripts-@/cross-lfs/bootscripts-cross-lfs-1.2-pre11.tar.bz2}. + +@item +Bzip2: @uref{http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz}. + +@item +Coreutils: @uref{http://ftpmirror.gnu.org/coreutils/coreutils-8.19.tar.xz}. +@c @uref{http://ftpmirror.gnu.org/coreutils/coreutils-8.21.tar.xz} fails. + +@item +DHCPCD: @uref{http://roy.marples.name/downloads/dhcpcd/dhcpcd-6.0.2.tar@/.bz2}. +@c @uref{http://roy.marples.name/downloads/dhcpcd/dhcpcd-5.99.3.tar@/.bz2}. + +@item +Diffutils: @uref{http://ftpmirror.gnu.org/diffutils/diffutils-3.2.tar.gz}. + +@item +E2fsprogs: @uref{http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.42.8.tar@/.gz}. +@c @uref{http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.42.7.tar@/.gz}. + +@item +File: @uref{ftp://ftp.astron.com/pub/file/file-5.14.tar.gz}. +@c @uref{ftp://ftp.astron.com/pub/file/file-5.12.tar.gz}. + +@item +Findutils: @uref{http://ftpmirror.gnu.org/findutils/findutils-4.4.2.tar.gz}. + +@item +Flex: @uref{http://downloads.sourceforge.net/flex/flex-2.5.37.tar.bz2}. + +@item +Gawk: @uref{http://ftpmirror.gnu.org/gawk/gawk-4.1.0.tar.gz}. +@c @uref{http://ftpmirror.gnu.org/gawk/gawk-4.0.2.tar.gz}. + +@item +GCC: @uref{http://ftpmirror.gnu.org/gcc/gcc-4.7.3/gcc-4.7.3.tar.bz2}. +@c 4.8.1 gives the following error message at `make`: +@c /usr/include/bits/resource.h:137: error: declaration does not declare anything +@c ../../gcc-4.8.1/gcc/system.h:448: error: new declaration 'char* strstr(const char*, const char*)' +@c @uref{http://ftpmirror.gnu.org/gcc/gcc-4.7.2/gcc-4.7.2.tar.bz2}. + +@item +Gettext: @uref{http://ftpmirror.gnu.org/gettext/gettext-0.18.3.tar.gz}. +@c @uref{http://ftpmirror.gnu.org/gettext/gettext-0.18.2.tar.gz}. + +@item +Glibc: @uref{http://ftpmirror.gnu.org/glibc/glibc-2.16.0.tar.bz2}. +@c fails to generate localedef, see +@c http://sourceware.org/bugzilla/show_bug.cgi?id=14624 +@c @uref{http://ftpmirror.gnu.org/glibc/glibc-2.13.tar.bz2}. + +@item +Glibc-Ports: @uref{http://ftpmirror.gnu.org/glibc/glibc-ports-2.16.0.tar.bz2}. +@c @uref{http://ftpmirror.gnu.org/glibc/glibc-ports-2.13.tar.bz2}. + +@item +Gmp: @uref{http://ftpmirror.gnu.org/gmp/gmp-5.1.2.tar.bz2}. +@c @uref{http://ftpmirror.gnu.org/gmp/gmp-5.0.5.tar.bz2}. + +@item +Grep: @uref{http://ftpmirror.gnu.org/grep/grep-2.14.tar.xz}. + +@item +Groff: @uref{http://ftpmirror.gnu.org/groff/groff-1.22.2.tar.gz}. +@c @uref{http://ftpmirror.gnu.org/groff/groff-1.22.1.tar.gz}. + +@item +Gzip: @uref{http://ftpmirror.gnu.org/gzip/gzip-1.6.tar.gz}. +@c @uref{http://ftpmirror.gnu.org/gzip/gzip-1.5.tar.gz}. + +@item +Iana-Etc: @uref{http://sethwklein.net/iana-etc-2.30.tar.bz2}. + +@item +Inetutils: @uref{http://ftpmirror.gnu.org/inetutils/inetutils-1.9.1.tar.gz} +@c Iputils: @uref{http://www.skbuff.net/iputils/iputils-s20071127.tar.bz2}. +@c @uref{http://www.skbuff.net/iputils/iputils-s20121221.tar.bz2}. +@c @uref{http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2}. +@c depends on sysfs headers. + +@item +Iproute2: @uref{http://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.10.0@/.tar.bz2} +@c @uref{http://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.7.0@/.tar.bz2} + +@item +Kbd: @uref{http://ftp.altlinux.org/pub/people/legion/kbd/kbd-1.15.5.tar.gz}. +@c @uref{http://ftp.altlinux.org/pub/people/legion/kbd/kbd-1.15.3.tar.gz}. + +@item +Kmod: @uref{http://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-14.tar.gz}. +@c @uref{http://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-12.tar.gz}. + +@item +Less: @uref{http://www.greenwoodsoftware.com/less/less-458.tar.gz}. +@c @uref{http://www.greenwoodsoftware.com/less/less-451.tar.gz}. + +@item +Libtool: @uref{http://ftpmirror.gnu.org/libtool/libtool-2.4.tar.gz}. + +@item +Linux-Libre @footnote{The kernel Linux is shipped with proprietary +firmware. The version called Linux-Libre exists without them, it is +available for download at +@uref{http://www.fsfla.org/svnwiki/selibre/linux-libre/}.}. +@c @uref{http://linux-libre.fsfla.org/pub/linux-libre/releases/3.5.4-gnu@//linux-libre-3.5.4-gnu.tar.bz2}. + +@item +M4: @uref{http://ftpmirror.gnu.org/m4/m4-1.4.16.tar.bz2}. + +@item +Make: @uref{http://ftpmirror.gnu.org/make/make-3.82.tar.bz2}. + +@item +Man-Pages: @uref{http://www.kernel.org/pub/linux/docs/man-pages/Archive/man-pages-@/3.52.tar.bz2}. +@c @uref{http://www.kernel.org/pub/linux/docs/man-pages/Archive/man-pages-@/3.46.tar.bz2}. + +@item +Man: @uref{http://primates.ximian.com/~flucifredi/man/man-1.6g.tar.gz}. + +@item +Mpc: @uref{http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz}. + +@item +Mpfr: @uref{http://www.mpfr.org/mpfr-3.1.1/mpfr-3.1.2.tar.bz2}. +@c @uref{http://www.mpfr.org/mpfr-3.1.1/mpfr-3.1.1.tar.bz2}. + +@item +Nano: @uref{http://ftpmirror.gnu.org/nano/nano-2.3.2.tar.gz} +@c @uref{http://ftpmirror.gnu.org/nano/nano-2.3.1.tar.gz} + +@item +Ncurses: @uref{ftp://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz}. + +@item +Patch: @uref{http://ftpmirror.gnu.org/patch/patch-2.7.1.tar.bz2}. + +@item +Procps: @uref{http://procps.sourceforge.net/procps-3.2.8.tar.gz}. + +@item +Psmisc: @uref{http://sourceforge.net/projects/psmisc/files/psmisc/psmisc-22.20.tar@/.gz/download}. + +@item +Readline: @uref{http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz}. + +@item +Rsyslog: @uref{http://rsyslog.com/files/download/rsyslog/rsyslog-5.8.6.tar.gz}. +@c @uref{http://rsyslog.com/files/download/rsyslog/rsyslog-7.2.5.tar.gz}. +@c has too many dependencies + +@item +Sed: @uref{http://ftpmirror.gnu.org/sed/sed-4.2.2.tar.bz2}. +@c @uref{http://ftpmirror.gnu.org/sed/sed-4.2.1.tar.bz2}. + +@item +Shadow: @uref{http://pkg-shadow.alioth.debian.org/releases/shadow-4.1.4.3.tar.bz2}. +@c Requires automake 1.11.5 and autoconf 2.69: +@c @uref{http://pkg-shadow.alioth.debian.org/releases/shadow-4.1.5.1.tar@/.bz2}. + +@item +Sysvinit: @uref{http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf@/.tar.bz2}. + +@item +Tar: @uref{http://ftpmirror.gnu.org/tar/tar-1.26.tar.bz2}. + +@item +Texinfo: @uref{http://ftpmirror.gnu.org/texinfo/texinfo-5.1.tar.gz}. +@c @uref{http://ftpmirror.gnu.org/texinfo/texinfo-4.13a.tar.gz}. + +@item +Udev: @uref{ftp://ftp.kernel.org/pub/linux/utils/kernel/hotplug/udev-175.tar.gz}. +@c @uref{http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-182.tar.bz2}. +@c troubles with blkid + +@item +Util-Linux: @uref{http://www.kernel.org/pub/linux/utils/util-linux/v2.19/util-@/linux-2.19.1.tar.bz2}. +@c requires PAM headers +@c @uref{http://www.kernel.org/pub/linux/utils/util-linux/v2.22/util-linux-2.22.tar.bz2}. + +@item +XZ-Utils: @uref{http://tukaani.org/xz/xz-5.0.5.tar.bz2}. +@c @uref{http://tukaani.org/xz/xz-5.0.4.tar.bz2}. + +@item +Zlib: @uref{http://www.zlib.net/zlib-1.2.8.tar.gz}. +@c @uref{http://sourceforge.net/projects/libpng/files/zlib/1.2.7/zlib-1.2.7.tar@/.bz2/download}. +@end itemize + + +@node Patches Download +@subsection Downloading Patches + +Patches and configuration files location: + +@itemize +@item +@uref{http://cjarry.org/gnu-linux/gllfsc/gllfsc-loongson3a-1.0-@/patches.tar.gz}. After +having downloaded this file under @env{$@{DOWNLOAD_DIR@}}, execute +the following commands to extract its content: + +@verbatim +pushd ${DOWNLOAD_DIR} +tar xvf gllfsc-loongson3a-1.0-patches.tar.gz +popd +@end verbatim + +@item +The page +@uref{http://dev.lemote.com/cgit/linux-official.git/commit/?h=linux-3.6@/&id=94fe1f0a7d2e3042fa7fadfd15da71b9d0c11809} +describes the changes to be made to the kernel in order to add support +for Chinese fonts in console. The patch applies to Linux 3.6. +Be aware though that applying this patch to the kernel may make +characters that are both non-@acronym{CJK} (Chinese Japanese Korean) +and non-ASCII unreadable (accented letters, cyrillic, etc.). + +@item +The page +@uref{http://microcai.gsalex.net/old/archives/2011/01/fbcon_UNICODE_font_support.html} +is useful for users who want support for @acronym{CJK} (Chinese +Japanese Korean) characters under the (non-graphical) terminal. It +gives access to a git@footnote{@uref{http://git-scm.com/}} repository +with kernel patches@footnote{The patches to use with version 3.5 of +the kernel are the first four on +@uref{http://repo.or.cz/w/linux-2.6/cjktty.git/shortlog/refs/heads/3.5-utf8}.} +that permit direct rendering of UTF-8 characters under the framebuffer +environment. Be aware though that applying those CJK patches to the +kernel may make characters that are both non-CJK and non-ASCII +unreadable (accented letters, cyrillic, etc.). + +@item +@uref{http://www.fsfla.org/svn/fsfla/software/linux-libre/lemote/gnewsense/tags/@/3.9.0-gnu_0loongsonlibre/100gnu+freedo.patch} +@footnote{@uref{http://www.fsfla.org/svn/fsfla/software/linux-libre/lemote/gnewsense/tags/@/2.6.36-libre-lemote_0lxo/100gnu+freedo.patch} +if you choose version 2.6.36 of the kernel.} +this patch adds a picture of a GNU beside Freedo, Freedo being the +mascot of Linux-Libre. The image can be seen on +@uref{http://www.fsfla.org/svnwiki/selibre/linux-libre/100gnu+freedo}. +@end itemize + + +@node Final Preparations +@section Final Preparations + +@menu +* Target Filesystem Hierarchy Creation:: Creating the directories of + the target system. +* Needed Files Creation:: Creating files for needed + user, groups and log. +@end menu + + +@node Target Filesystem Hierarchy Creation +@subsection Target Filesystem Hierarchy Creation + +@verbatim +pushd ${TARGET_DIR} +mkdir -pv bin boot dev {etc/,}opt home lib mnt +mkdir -pv proc media/{floppy,cdrom} sbin srv sys +mkdir -pv var/{lock,log,mail,run,spool} +mkdir -pv var/{opt,cache,lib/{misc,locate},local} +install -dv -m 0750 root +install -dv -m 1777 {var/,}tmp +mkdir -pv usr/{,local/}{bin,include,lib,sbin,src} +mkdir -pv usr/{,local/}share/{doc,info,locale,man} +mkdir -pv usr/{,local/}share/{misc,terminfo,zoneinfo} +mkdir -pv usr/{,local/}share/man/man{1..8} +for dir in usr{,/local}; do + ln -sv share/{man,doc,info} $dir +done +ln -svf lib lib64 +ln -svf lib lib32 +ln -svf lib usr/lib64 +ln -svf lib usr/lib32 +cd boot +ln -svf . boot +popd +@end verbatim + +The command @samp{install -dv -m 1777 @{var/,@}tmp} creates the +directories @file{var/tmp} and @file{tmp} with the permissions to +read, write and execute for everyone. The '1' in @samp{1777} is the +sticky bit which allows deletion of the file or directory having this +attribute only for the owner of the file or directory. + +The command @samp{ln -svf lib lib64} creates a symbolic link (option +@option{-s}) with the name @file{lib64} which will point to +@file{lib}. + + +@node Needed Files Creation +@subsection Creating needed user, groups and log files + +@verbatim +cat > ${TARGET_DIR}/etc/passwd << "EOF" +root::0:0:root:/root:/bin/bash +EOF +@end verbatim + +The file @file{/etc/passwd} contains one line for each user account, +with seven fields delimited by colons. These fields are: + +@itemize +@item +login name; + +@item +optional encrypted password; + +@item +numerical user ID; + +@item +numerical group ID; + +@item +user name or comment field; + +@item +user home directory; + +@item +optional user command interpreter. +@end itemize + + +@verbatim +cat > ${TARGET_DIR}/etc/group << "EOF" +root:x:0: +bin:x:1: +sys:x:2: +kmem:x:3: +tty:x:4: +tape:x:5: +daemon:x:6: +floppy:x:7: +disk:x:8: +lp:x:9: +dialout:x:10: +audio:x:11: +video:x:12: +utmp:x:13: +usb:x:14: +cdrom:x:15: +EOF +@end verbatim + +The file @file{/etc/group} is a text file which defines the groups on +the system. There is one entry per line, with the following format: +@samp{group_name:password:GID:user_list}. + + +@verbatim +touch ${TARGET_DIR}/var/run/utmp \ + ${TARGET_DIR}/var/log/{btmp,lastlog,wtmp} +chmod -v 664 ${TARGET_DIR}/var/run/utmp \ + ${TARGET_DIR}/var/log/lastlog +@end verbatim + + +@node Building the Cross-Compilation Toolchain +@chapter Building the Cross-Compilation Toolchain + +In this chapter, the cross-compilation toolchain is built as well as +core components of the target system. Those will then be used to build +the target system. + +@menu +* Target Linux-Header:: Linux-Header for target system. +* Cross Binutils:: Binutils for cross-compilation. +* Cross GCC:: GCC for cross-compilation (C support only). +* Target glibc:: glibc for target system. +* Cross GCC CXX:: GCC for cross-compilation (C and C++ support). +@end menu + + +@node Target Linux-Header +@section Target Linux-Header + +In this document, the kernel used is the one modified by Lemote to +support Loongson 3A. It is planned to merge the changes made by Lemote +into the official kernel maintained by Linus Torvalds. At the time of +writing, this merge has not been made. + +@verbatim +# 5 hours mostly to get the kernel from git +pushd ${BUILD_DIR} +# The following command takes about 5 hours to complete +# with a high band width internet connection +#3.9.0: +git clone git://dev.lemote.com/linux-official.git +# The following command takes about 30 minutes to complete +# with a high band width internet connection +#2.6.36-21.lemote: +#git clone git://dev.lemote.com/linux-3A.git +wget http://linux-libre.fsfla.org/pub/linux-libre/releases/3.9-gnu/deblob-{3.9,check} +#wget http://linux-libre.fsfla.org/pub/linux-libre/releases/2.6.36-gnu/deblob-{2.6.36,check} +chmod u+x deblob* +cd linux-official +#cd linux-3A +# About 60 minutes for the following command +../deblob-3.9 --force +# About 45 minutes for the following command +#../deblob-2.6.36 --force +cd .. +# About 2 minutes for the following one (1.1G) +tar -cf linux-3.9-loongson3a-deblobbed.tar linux-official +#tar -cf linux-2.6.36-21-loongson3a-deblobbed.tar linux-3A +cd linux-official +#cd linux-3A +make mrproper +make ARCH=mips headers_check +make ARCH=mips INSTALL_HDR_PATH=dest headers_install +cp -rv dest/include/* ${TARGET_DIR}/usr/include +cd .. +rm -rf linux-official deblob* +#rm -rf linux-3A deblob* +popd +@end verbatim + +@samp{5 hours} is the time it takes to build the package on Lemote +Yeeloong with a Loongson 3A processor. For this particular package, it +incudes the time required to pull the source from git. + +The command @samp{make mrproper} cleans the sources. + +We need to specify @samp{ARCH=mips} as we are cross-compiling. + + +@node Cross Binutils +@section Cross Binutils + +GNU Binutils (GNU binary utilities) is a collection of programs for +manipulating binaries. + + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/binutils-2.23.2.tar.bz2 -C ${BUILD_DIR} +pushd $BUILD_DIR/binutils-2.23.2 +mkdir -pv ../binutils-build +cd ../binutils-build +CC="gcc" AR="ar" \ + ../binutils-2.23.2/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --enable-64-bit-bfd \ + --with-sysroot=${TARGET_DIR} \ + --disable-nls \ + --enable-shared +make configure-host +make +make install +cp -v ../binutils-2.23.2/include/libiberty.h \ + ${TARGET_DIR}/usr/include +cd .. +rm -rf binutils-build +rm -rf binutils-2.23.2 +popd +@end verbatim + +@samp{CC="gcc"} and @samp{AR="ar"} are flags that tell the +@file{configure} script to use the local commands @command{gcc} as the +C compiler and @command{ar} as the program that handles archives. + +@option{--prefix=$@{TARGET_DIR@}/cross-tools} tells the configure +script to install architecture-independant files in +@file{$@{TARGET_DIR@}/cross-tools}. + +The option @option{--enable-64-bit-bfd} enables 64 bit for +@acronym{BFD} (the Binary File Descriptor). + +@option{--with-sysroot=@env{$@{TARGET_DIR@}}} tells Binutils to +consider @env{$@{TARGET_DIR@}} as the root of a tree that contains (a +subset of) the root filesystem of the target operating system. Target +system headers, libraries and run-time object files will be searched +in there. + +The @option{--enable-nls} option enables Native Language Support +(NLS), which lets Binutils output diagnostics in languages other than +American English. Native Language Support is enabled by default if not +doing a canadian cross build. The @option{--disable-nls} option +disables NLS. + +The option @option{--enable-shared} is used to build shared versions +of libraries, if shared libraries are supported on the target +platform. Use @option{--disable-shared} to build only static +libraries. + +@c cp -v ../binutils-2.22/include/libiberty.h \ +@c ${TARGET_DIR}/usr/include + + +@node Cross GCC +@section Cross GCC (C support only) + +GCC is the GNU compiler collection. It can compile many languages, of +which only C and C++ will be enabled in this document. + +In this section, we build a minimal GCC in order to build glibc. + +@quotation Warning +to build GMP (a GCC dependency), you need a version of GCC different +from 4.3.2 on you system@footnote{@uref{http://gmplib.org/#STATUS}}: +@end quotation + +@quotation +GCC 4.3.2 miscompiles GMP on 64-bit machines; please use a different +gcc version (e.g., gcc 4.3.1 and gcc 4.3.3 both work properly). We +have not been able to find any workaround for this gcc bug. +Unfortunately, Debian 5.0 has decided to stay with this trouble gcc +version, resulting in that many users strike this bug. +@end quotation + +I recommend installing @samp{gcc-4.4} on gNewSense Parkes to avoid +this issue. + +@verbatim +# 35 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gcc-4.7.3 +tar xf ${DOWNLOAD_DIR}/gmp-5.1.2.tar.bz2 +mv gmp-5.1.2 gmp +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz +mv mpc-1.0.1 mpc +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2 +mv mpfr-3.1.2 mpfr +mkdir -pv ../gcc-build +cd ../gcc-build +../gcc-4.7.3/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --with-sysroot=${TARGET_DIR} \ + --disable-multilib \ + --with-newlib \ + --disable-nls \ + --disable-shared \ + --disable-threads \ + --enable-languages=c \ + --with-abi=${MABI} \ + --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \ + --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs" +make all-gcc +make all-target-libgcc +make install-gcc +make install-target-libgcc +cd .. +rm -r gcc-build +rm -r gcc-4.7.3 +popd +@end verbatim + +@option{--disable-multilib} specifies that multiple target libraries +to support different target variants@footnote{Such as different ABI, +for instance n32 and 64.}, calling conventions, etc@:. should not be +built. The default is to build a predefined set of them. + +@option{--with-newlib} specifies that @samp{newlib} is being used as +the target C library. + +@option{--disable-threads} specifies that threading support should be +disabled. + +@option{--enable-languages=c} specifies that only the C compiler and +its runtime libraries should be built. + +@c --with-abi=${MABI} + +@c --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \ +@c --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs" +@c to avoid error: libmpfr not found or uses a different ABI (including static vs shared). + +GCC provides a low-level runtime library, @file{libgcc.a} or +@file{libgcc_s.so.1} on some platforms. GCC generates calls to +routines in this library automatically, whenever it needs to perform +some operation that is too complicated to emit inline code for. This +is built with @samp{make all-target-libgcc} and installed with +@samp{make install-target-libgcc} + + +@node Target glibc +@section Target glibc + +Glibc is the GNU C library. It provides macros, type definitions, and +functions for tasks like string handling, mathematical computations, +input/output processing, memory allocation and several other operating +system services. + +@verbatim +# 1 hour 30 minutes +tar xf ${DOWNLOAD_DIR}/glibc-2.16.0.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/glibc-2.16.0 +tar xf ${DOWNLOAD_DIR}/glibc-ports-2.16.0.tar.bz2 +mv -v glibc-ports-2.16.0 ports +sed -i.orig "s/\ -lgcc_eh\|\ -lgcc_s//g" Makeconfig +patch -Np1 -i ${DOWNLOAD_DIR}/glibc-2.16.0-cross_hacks-2.patch +echo "" > ports/sysdeps/mips/mips64/n64/Makefile +echo "" > ports/sysdeps/mips/mips64/n32/Makefile +echo "" > ports/sysdeps/mips/mips32/Makefile +sed -i "/default) machine=/s/n32/${MABI}/g" \ + ports/sysdeps/mips/preconfigure +mkdir -pv ../glibc-build +cd ../glibc-build + +cat > config.cache << EOF +libc_cv_c_cleanup=yes +libc_cv_slibdir=/lib +EOF + +cat > configparms << EOF +install_root=${TARGET_DIR} +libdir=/usr/lib +EOF + +BUILD_CC="gcc" \ + CC="${CROSS_TARGET}-gcc -march=${MARCH} -mabi=${MABI}" \ + AR="${CROSS_TARGET}-ar" \ + RANLIB="${CROSS_TARGET}-ranlib" \ + ../glibc-2.16.0/configure \ + --prefix=/usr \ + --libexecdir=/usr/lib/glibc \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --disable-profile \ + --enable-add-ons \ + --with-tls \ + --enable-kernel=2.6.36 \ + --with-__thread \ + --with-binutils=${TARGET_DIR}/cross-tools/bin \ + --with-headers=${TARGET_DIR}/usr/include \ + --cache-file=config.cache + +make # to be run twice? + +make install + +#make localedata/install-locales +# fails with (localedef patch does not fix the following): +#....../bin/sh: /gllfsc/build/glibc-build/locale/localedef-native: not found +#Giving up installing locales for now + +cd .. +rm -rf glibc-build +rm -rf glibc-2.16.0 +popd + +cat > ${TARGET_DIR}/etc/nsswitch.conf << "EOF" +# Begin /etc/nsswitch.conf + +passwd: files +group: files +shadow: files + +hosts: files dns +networks: files + +protocols: files +services: files +ethers: files +rpc: files + +# End /etc/nsswitch.conf +EOF + +cat > ${TARGET_DIR}/etc/ld.so.conf << "EOF" +# Begin /etc/ld.so.conf + +/usr/local/lib +/opt/lib + +# End /etc/ld.so.conf +EOF +@end verbatim + +@c @samp{sed -i.orig "s/\ -lgcc_eh\|\ -lgcc_s//g" Makeconfig} + +@file{glibc-2.16.0-cross_hacks-2.patch} is used to avoid the error +@samp{/usr/bin/install: cannot remove `/usr/lib/libc.a': Permission +denied}. + +Glibc uses @samp{n32} ABI by default with MIPS. To use @env{MABI} +instead, we do the following: + +@verbatim +echo "" > ports/sysdeps/mips/mips64/n64/Makefile +echo "" > ports/sysdeps/mips/mips64/n32/Makefile +echo "" > ports/sysdeps/mips/mips32/Makefile +sed -i "/default) machine=/s/n32/${MABI}/g" \ + ports/sysdeps/mips/preconfigure +@end verbatim + +@ignore +Contents of the files above. + +cat mips64/n64/Makefile +# `long double' is a distinct type we support. +long-double-fcts = yes + +ifeq ($(filter -mabi=64,$(CC)),) +CC += -mabi=64 +endif + +cat mips64/n32/Makefile +# `long double' is a distinct type we support. +long-double-fcts = yes + +ifeq ($(filter -mabi=n32,$(CC)),) +CC += -mabi=n32 +endif + +cat mips32/Makefile +ifeq ($(filter -mabi=32,$(CC)),) +CC += -mabi=32 +endif + +grep 'default)' preconfigure + + default) machine=mips/mips64/n32 mips_config_abi=n32 ;; + +@end ignore + +The file @file{config.cache} is used to attribute values to variables +of the configure script. + +@samp{libc_cv_forced_unwind=yes} is used to avoid the error message +@samp{error: forced unwind support is required}. + +@samp{libc_cv_c_cleanup=yes} is used to avoid the error message +@samp{error: the compiler must support C cleanup handling}. + +@samp{libc_cv_slibdir=/lib} defines @file{/lib} as the directory in +which the C library of the target system will be installed, instead of +@file{/lib64} or @file{/lib32}. + +You can install glibc somewhere other than where you configured it to +go by setting the @code{install_root} variable on the command line for +@samp{make install}. The value of this variable is prepended to all +the paths for installation. This is useful when setting up a chroot +environment or preparing a binary distribution. The directory should +be specified with an absolute file name. + +Files listed in @samp{install-lib} are installed in the directory +specified by @samp{libdir} in @file{configparms} or @file{Makeconfig}. + +@verbatim +BUILD_CC="gcc" \ + CC="${CROSS_TARGET}-gcc -march=${MARCH} -mabi=${MABI}" \ + AR="${CROSS_TARGET}-ar" \ + RANLIB="${CROSS_TARGET}-ranlib" +@end verbatim + +@samp{CC="$@{CROSS_TARGET@}-gcc -march=$@{MARCH@} -mabi=$@{MABI@}"} +sets @code{CC} to the cross-compiler for the target's architecture, +processor and ABI we configured the library for. @code{AR} and +@code{RANLIB} are set to cross-compiling versions of @code{ar} and +@code{ranlib} as the native tools are not configured to work with +object files for the target we configured for. + +@option{--prefix=/usr} tells the @file{configure} script to install +glibc in the @file{/usr} directory of the target system. + +@c @option{--libexecdir=/usr/lib/glibc} tells the configure script to +@c install glibc executables inside @file{/usr/lib/glibc}. + +Unlike previous builds, @option{--host} now equals +@env{$@{CROSS_TARGET@}} instead of @env{$@{CROSS_HOST@}}. This is +because we are building the glibc version that the target system will +use. We won't have to build it later. + +Profiling can be of help to optimize a program by analysing memory +use, the usage of particular instructions, etc. Option +@option{--disable-profile} is used to disable this. + +Option @option{--enable-add-ons} is used to enable all the add-on +packages in the main source directory, which includes the glibc-ports +used to support the MIPS architecture. + +The option @option{--with-tls} tells the configure script to use +@acronym{TLS} (thread-local storage). Thread-local storage is a +computer programming method that uses memory local to a thread. + +The @samp{2.6.36} parameter given to option @option{--enable-kernel} +describes the smallest version of the Linux kernel the generated +library is expected to support. The higher the version number is, the +less compatibility code is added, and the faster the code gets. + +Option @option{--with-__thread} enables threads in glibc. + +The option @option{--with-binutils=$@{TARGET_DIR@}/cross-tools/bin} +tells the @file{configure} script to use the binutils (assembler and +linker) built in the cross-compilation toolchain process. + +@option{--with-headers=$@{TARGET_DIR@}/usr/include} indicates the +location of the kernel Linux' headers. + +@option{--cache-file=config.cache} specifies the file in which cache +variables are listed for @file{configure}. + +@c @samp{make localedata/install-locales} configures all locales that are +@c supported by glibc. + +The file @file{$@{TARGET_DIR@}/etc/nsswitch.conf} contains the +configuration of @acronym{NSS} (Name Service Switch). NSS is a facility +in Unix-like operating systems that provides a variety of sources for +common configuration databases and name resolution mechanisms. These +sources include local operating system files (such as +@file{/etc/passwd}, @file{/etc/group}, and @file{/etc/hosts}), the +Domain Name System (DNS), the Network Information Service (NIS), and +LDAP. + +@c The timezone is defined for `Paris'. + +@c Purpose of the file @file{$@{TARGET_DIR@}/etc/ld.so.conf} + + +@node Cross GCC CXX +@section Cross GCC (C and C++ support) + +In this section, we build a complete cross-compiler with support for C +and C++ languages. + +@verbatim +# 3 hours and 30 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gcc-4.7.3 +tar xf ${DOWNLOAD_DIR}/gmp-5.1.2.tar.bz2 +mv gmp-5.1.2 gmp +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz +mv mpc-1.0.1 mpc +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2 +mv mpfr-3.1.2 mpfr +mkdir -v ../gcc-build +cd ../gcc-build +../gcc-4.7.3/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --with-sysroot=${TARGET_DIR} \ + --disable-nls \ + --enable-shared \ + --enable-__cxa_atexit \ + --disable-multilib \ + --with-abi=${MABI} \ + --enable-c99 \ + --enable-long-long \ + --enable-threads=posix \ + --enable-languages=c,c++ \ + --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \ + --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs" +make # to be run twice +make install +cd .. +rm -rf gcc-build +rm -rf gcc-4.7.3 +popd +@end verbatim + +@option{--enable-__cxa_atexit} enables @code{__cxa_atexit}, rather +than @code{atexit}, to register C++ destructors for local statics and +global objects. This is essential for fully standards-compliant +handling of destructors, but requires @code{__cxa_atexit} in libc. + +@option{--enable-c99} enables support for the C99 standard. + +@option{--enable-long-long} enables support for @code{long long int} +types. + +@c @option{--enable-threads=posix} + + +@node Building Cross-Compilation Tools +@chapter Building the Cross-Compilation Tools + +@menu +* Cross File:: File for cross-compilation. +* Cross Groff:: Groff for cross-compilation. +* Cross Shadow:: Shadow for cross-compilation. +* Cross M4:: M4 for cross-compilation. +* Cross Ncurses:: Ncurses for cross-compilation. +* Cross Cleaning:: Cleaning up the cross-compilation toolchain. +@end menu + + +@node Cross File +@section File + +The command @command{file} is used to determine the type of a file: +text, executable or data. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/file-5.14.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/file-5.14 +./configure \ + --prefix=${TARGET_DIR}/cross-tools +make +make install +cd .. +rm -rf file-5.14 +popd +@end verbatim + + +@node Cross Groff +@section Groff + +Groff is the GNU version of the roff document formatting system which +is used to produce man pages. + +You need G++ on your system to compile this program from source. Under +gNewSense Parkes, try @samp{sudo apt-get install g++-4.4}. + +@ignore +@quotation Note +psselect (part of psutils) is needed for documentation in HTML (see +@uref{http://cblfs.cross-lfs.org/index.php/PSUtils}). +@end quotation +@end ignore + + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/groff-1.22.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/groff-1.22.2 +PAGE=A4 \ + ./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --without-x +make +make install +cd .. +rm -rf groff-1.22.2 +popd +@end verbatim + +@samp{PAGE=A4} defines the default format of pages for printed output. + +@option{--without-x} disables the dependancy on the X window system. + + +@node Cross Shadow +@section Shadow + +The package contains programs to handle users, groups and passwords in +a secure way: passwords are encrypted. + +@verbatim +# 3 minutes +tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/shadow-4.1.4.3 +patch -Np1 -i ${DOWNLOAD_DIR}/shadow-4.1.4.3-sysroot_hacks-1.patch +sed -i.orig \ + 's/bindir)\/\$\$i/bindir)\/mips64el-unknown-linux-gnu-\$\$i/' \ + src/Makefile.am +automake +echo "shadow_cv_passwd_dir=${TARGET_DIR}/bin" > config.cache +echo "ac_cv_func_lckpwdf=no" >> config.cache +./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --sbindir=${TARGET_DIR}/cross-tools/bin \ + --sysconfdir=${TARGET_DIR}/etc \ + --disable-shared \ + --without-audit \ + --without-libpam \ + --without-selinux \ + --program-prefix=${CROSS_TARGET}- \ + --cache-file=config.cache +sed -i.orig "/PASSWD_PROGRAM/s/passwd/${CROSS_TARGET}-&/" config.h +make +make install +cd .. +rm -rf shadow-4.1.4.3 +popd +@end verbatim + +@c @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin} +@c @samp{ac_cv_func_lckpwdf=no} + +The patch @file{shadow-4.1.4.3-sysroot_hacks-1.patch} is used so that +shadow can be built with the sysroot method. Because we use this +patch, @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin} and +@samp{ac_cv_func_lckpwdf=no} have to be added in @file{config.cache} +in order for the @file{configure} script not to test the +functionalities associated. + +@c @option{--sbindir=$@{TARGET_DIR@}/cross-tools/bin} + +@c @option{--sysconfdir=$@{TARGET_DIR@}/etc} + +@option{--without-audit}, @option{--without-libpam} and +@option{--without-selinux} disable support for auditing, @acronym{PAM} +(Pluggable authentication modules) and @acronym{SELinux} +(Security-Enhanced Linux). We do not need those extra features. + +@option{--program-prefix=$@{CROSS_TARGET@}-} prepends the value of +@env{CROSS_TARGET} (that is @samp{mips64el-unknown-linux-gnu} in this +document) to installed program names for cross-compilation. + +@c @samp{sed -i.orig "/PASSWD_PROGRAM/s/passwd/$@{CROSS_TARGET@}-&/" +@c config.h} is used to avoid the error message + + +@node Cross M4 +@section M4 + +Bison 2.5 requires M4 to be built. + +GNU M4 is a package containing an implementation of the m4 macro +language. GNU M4 is used in GNU Autoconf' @file{configure} files. + +@verbatim +# 3 minutes +tar xf ${DOWNLOAD_DIR}/m4-1.4.16.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/m4-1.4.16 +./configure \ + --prefix=${TARGET_DIR}/cross-tools +make +make install +cd .. +rm -rf m4-1.4.16 +popd +@end verbatim + + +@node Cross Ncurses +@section Ncurses + +GNU ncurses contains a library used to write text-based user +interfaces in a terminal-independent manner. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/ncurses-5.9 +./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --without-shared +make -C include +make -C progs tic +install -m755 progs/tic ${TARGET_DIR}/cross-tools/bin +cd .. +rm -rf ncurses-5.9 +popd +@end verbatim + +@option{--without-shared} is used to avoid building the whole library +as only @command{tic} is installed. + + +@node Cross Cleaning +@section Cleaning up Cross-Compilation Toolchain + +In order to save some space, binaries and libraries of +cross-compilation tools can be stripped out. + +@quotation Warning +incorrect cleaning arguments used against library files can lead to +library files breaking. For this reason, be careful of the command +arguments. If you are not comfortable with this, you can skip this +section as it will have no effect on the process of building the +target system. +@end quotation + + +@verbatim +pushd ${TARGET_DIR}/cross-tools +strip --strip-all bin/* +strip --strip-debug lib/* +popd +@end verbatim + +@option{--strip-all} removes all symbols. This command reduces the +size of the @file{bin} directory's content from 29 MB to 12 MB. + +@option{--strip-debug} removes debugging symbols only. This command +reduces the size of the @file{lib} directory's content from 21 MB to +20 MB. + + +@node Building the Target System +@chapter Building the Target System + +After having set up the cross-compilation toolchain and tools, the +operating system for the target machine is built in this chapter. + +@menu +* Environment Setup:: Setting up the environment. +* Man Pages:: Building Man Pages. +* Zlib:: Building Zlib. +* Binutils:: Building Binutils. +* GMP:: Building GMP. +* MPFR:: Building MPFR. +* MPC:: Building MPC. +* GCC:: Building GCC. +* Sed:: Building Sed. +* E2fsprogs:: Building E2fsprogs. +* Coreutils:: Building Coreutils. +* iana-etc:: Building iana-etc. +* M4:: Building M4. +* Bison:: Building Bison. +* Ncurses:: Building Ncurses. +* Procps:: Building Procps. +* Libtool:: Building Libtool. +* Readline:: Building Readline. +* Autoconf:: Building Autoconf. +* Automake:: Building Automake. +* Bash:: Building Bash. +* Bzip2:: Building Bzip2. +* DHCPCD:: Building DHCPCD. +* Diffutils:: Building Diffutils. +* File:: Building File. +* Findutils:: Building Findutils. +* Flex:: Building Flex. +* Gawk:: Building Gawk. +* Gettext:: Building Gettext. +* Grep:: Building Grep. +* Groff:: Building Groff. +* Gzip:: Building Gzip. +* Inetutils:: Building Inetutils. +* Iproute2:: Building Iproute2. +* Kbd:: Building Kbd. +* Kmod:: Building Kmod. +* Less:: Building Less. +* Make:: Building Make. +* Man:: Building Man. +* Nano:: Building Nano. +* Patch:: Building Patch. +* Psmisc:: Building Psmisc. +* Rsyslog:: Building Rsyslog. +* Shadow:: Building Shadow. +* Sysvinit:: Building Sysvinit. +* Tar:: Building Tar. +* Texinfo:: Building Texinfo. +* Udev:: Building Udev. +* Util-Linux:: Building Util-Linux. +* XZ-Utils:: Building XZ-Utils. +* Bootscripts:: Building Bootscripts. +* Kernel:: Building the Kernel. +@end menu + + +@node Environment Setup +@section Setting up the Environment + +Because this chapter is about the build of the target system and not +the build of the cross-compilation toolchain and tools anymore, we +need to update some environment variables. + +For more convenience, we can set environment variables up in the +@file{~/.bashrc} file, so that this setup is preserved when logging +in: + + +@verbatim +cat >> ~/.bashrc << EOF +export CC="${CROSS_TARGET}-gcc -march=${MARCH} -mabi=${MABI}" +export CXX="${CROSS_TARGET}-g++ -march=${MARCH} -mabi=${MABI}" +export AR="${CROSS_TARGET}-ar" +export AS="${CROSS_TARGET}-as" +export RANLIB="${CROSS_TARGET}-ranlib" +export LD="${CROSS_TARGET}-ld" +export STRIP="${CROSS_TARGET}-strip" +EOF +source ~/.bash_profile +@end verbatim + +@env{CC} is the flag that indicates the C compiler to be used, +@env{CXX} the C++ compiler, @env{AR} the archiver, @env{AS} the +assembler, @env{RANLIB} the archives' index generator, @env{LD} the +linker and @env{STRIP} the program for stripping. + +All the programs to be used are prefixed with +@samp{$@{CROSS_TARGET@}-} in order to use the cross-compilation +toolchain instead of the toolchain of the host. + + +@node Man Pages +@section Man Pages + +The man-pages package documents the kernel Linux and C library's +interfaces that are used by user-space programs. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/man-pages-3.52.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/man-pages-3.52 +#tar xf ${DOWNLOAD_DIR}/man-pages-3.46.tar.bz2 -C ${BUILD_DIR} +#pushd ${BUILD_DIR}/man-pages-3.46 +make prefix=${TARGET_DIR}/usr install +cd .. +rm -rf man-pages-3.52 +#rm -rf man-pages-3.46 +popd +@end verbatim + +The option @option{prefix=$@{TARGET_DIR@}/usr} is used to install the +man pages on the target partition's @env{TARGET_DIR} instead of the +@file{/usr} directory of the host. + + +@node Zlib +@section Zlib + +Zlib is a compression/decompression library. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/zlib-1.2.8.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/zlib-1.2.8 +./configure \ + --prefix=/usr +make AR="${AR}" +make prefix=${TARGET_DIR}/usr install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/lib/libz.so.* ${TARGET_DIR}/lib +#ln -svf ../../lib/libz.so.1 ${TARGET_DIR}/usr/lib/libz.so +cd .. +rm -rf zlib-1.2.8 +popd +@end verbatim + +In order to build zlib by cross-compilation, the flag @env{AR} has to +be equal to @samp{$@{AR@}}. + + +@node Binutils +@section Binutils + +@verbatim +# 15 minutes +tar xf ${DOWNLOAD_DIR}/binutils-2.23.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/binutils-2.23.2 +mkdir -pv ../binutils-build +cd ../binutils-build +../binutils-2.23.2/configure \ + --prefix=/usr \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --target=${CROSS_TARGET} \ + --enable-64-bit-bfd \ + --enable-shared +make configure-host +make tooldir=/usr +make DESTDIR=${TARGET_DIR} tooldir=/usr install +cp -v ../binutils-2.23.2/include/libiberty.h ${TARGET_DIR}/usr/include +cd .. +rm -rf binutils-build +rm -rf binutils-2.23.2 +popd +@end verbatim + +The option @option{--host} is now set to @env{CROSS_TARGET} because +the host that will run this build will be the target system. + +@c @samp{make tooldir=/usr} +@c @samp{make DESTDIR=$@{TARGET_DIR@} tooldir=/usr install} + + +@node GMP +@section GMP + +@acronym{GMP} (GNU multiple precision arithmetic library) is required +to build GCC. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/gmp-5.1.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gmp-5.1.2 +./configure \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --enable-cxx +make +make DESTDIR=${TARGET_DIR} install +rm -v ${TARGET_DIR}/usr/lib/lib{gmp,gmpxx,mp}.la +cd .. +rm -rf gmp-5.1.2 +popd +@end verbatim + +The option @option{--enable-cxx} enables support for the C++ language. + +The files @file{$@{TARGET_DIR@}/usr/lib/lib@{gmp,gmpxx,mp@}.la} are +removed to avoid the following error when building MPFR: +@samp{/usr/lib/libgmp.so: could not read symbols: File in wrong +format}. + + +@node MPFR +@section MPFR + +GNU @acronym{MPFR} (Multiple Precision Floating-Point Reliably) is a +portable C library for arbitrary-precision binary floating-point +computation with correct rounding. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/mpfr-3.1.2 +./configure \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +rm -v ${TARGET_DIR}/usr/lib/libmpfr.la +cd .. +rm -rf mpfr-3.1.2 +popd +@end verbatim + +The file @file{$@{TARGET_DIR@}/usr/lib/libmpfr.la} is removed to +avoid the following error when building MPC: +@samp{/usr/lib/libmpfr.so: could not read symbols: File in wrong +format}. + + +@node MPC +@section MPC + +GNU @acronym{MPC} (Multiple Precision Complex Library) is a C library +for the arithmetic of complex numbers with arbitrarily high precision +and correct rounding of the result. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/mpc-1.0.1 +./configure \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf mpc-1.0.1 +popd +@end verbatim + + +@node GCC +@section GCC + +@verbatim +# 3 hours and 30 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gcc-4.7.3 +sed -i.orig 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in +sed -i.orig 's@\./fixinc\.sh@-c true@' gcc/Makefile.in +mkdir -v ../gcc-build +cd ../gcc-build +../gcc-4.7.3/configure \ + --prefix=/usr \ + --libexecdir=/usr/lib \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --target=${CROSS_TARGET} \ + --enable-shared \ + --enable-threads=posix \ + --enable-__cxa_atexit \ + --enable-c99 \ + --enable-long-long \ + --disable-multilib \ + --with-abi=${MABI} \ + --enable-clocale=gnu \ + --enable-languages=c,c++ \ + --disable-libstdcxx-pch +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#ln -sv ../usr/bin/cpp ${TARGET_DIR}/lib +ln -sv gcc ${TARGET_DIR}/usr/bin/cc +cd .. +rm -rf gcc-build +rm -rf gcc-4.7.3 +popd +@end verbatim + +@ignore +# The following patch seems needless to me as it only replaces +# {usr,}/lib32 with {usr,}/lib64 and we already have: +# {usr,}/lib32 -> {usr,}/lib +# {usr,}/lib64 -> {usr,}/lib +#patch -Np1 -i ${DOWNLOAD_DIR}/gcc-4.6.0-pure64-1.patch +@end ignore + +@samp{sed -i.orig 's/install_to_$(INSTALL_DEST) //' +libiberty/Makefile.in} is used as we already installed the library +@file{libiberty.a} with Binutils. + +@c We use @samp{sed -i.orig 's@@\./fixinc\.sh@@-c true@@' +@c gcc/Makefile.in} to avoid using fixincludes that may output errors if +@c headers have been modified. + +Using @option{--enable-clocale=gnu} option ensures that the correct +locale will automatically be chosen. + +Option @option{--disable-libstdcxx-pch} disables support for +precompiled headers (PCH). + +The line @samp{ln -sv gcc $@{TARGET_DIR@}/usr/bin/cc} creates a +symbolic link @file{cc} that points on @file{gcc}. + + +@node Sed +@section Sed + +GNU sed is a stream editor: it is used to perform basic text +transformations on an input stream (a file or input from a pipeline). + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/sed-4.2.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/sed-4.2.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf sed-4.2.2 +popd +@end verbatim + +@c @option{--bindir=/bin} FHS? + + +@node E2fsprogs +@section E2fsprogs + +E2fsprogs is a package that contains tools to handle the ext2, ext3 +and ext4 filesystems. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/e2fsprogs-1.42.8.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/e2fsprogs-1.42.8 +mkdir -v build +cd build +../configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --with-root-prefix="" \ + --enable-elf-shlibs +make +make DESTDIR=${TARGET_DIR} install +make DESTDIR=${TARGET_DIR} install-libs +rm -v ${TARGET_DIR}/usr/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so +ln -sv ../../lib/libblkid.so.1 ${TARGET_DIR}/usr/lib/libblkid.so +ln -sv ../../lib/libcom_err.so.2 ${TARGET_DIR}/usr/lib/libcom_err.so +ln -sv ../../lib/libe2p.so.2 ${TARGET_DIR}/usr/lib/libe2p.so +ln -sv ../../lib/libext2fs.so.2 ${TARGET_DIR}/usr/lib/libext2fs.so +ln -sv ../../lib/libss.so.2 ${TARGET_DIR}/usr/lib/libss.so +ln -sv ../../lib/libuuid.so.1 ${TARGET_DIR}/usr/lib/libuuid.so +cd ../.. +rm -rf e2fsprogs-1.42.8 +popd +@end verbatim + +@option{--with-root-prefix=""} is used to put e2fsprogs binaries +inside @file{/sbin} instead of @file{@var{PREFIX}/sbin} which would be +@file{/usr/sbin}. + +Option @option{--enable-elf-shlibs} enables e2fsprogs shared +libraries. + +@samp{make DESTDIR=$@{TARGET_DIR@} install-libs} is used to install +libraries, those are not installed with @samp{make +DESTDIR=$@{TARGET_DIR@} install}. + +The sequence of commands that follows first removes symbolic links +@file{$@{TARGET_DIR@}/usr/lib/lib@{@/blkid,com_err,e2p,ext2fs,ss,uuid@}.so} +which point on abolute paths +@file{/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so}. In order to +use the libraries of the target operating system, we need to symlink +@file{$@{TARGET_DIR@}/usr/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so} +to their relative paths files. + + +@node Coreutils +@section Coreutils + +GNU coreutils (core utilities) includes the standard programs for text +and file manipulation. + +On gNewSense Parkes, you need to install @file{xz-utils} to extract +the package. + +@verbatim +# 30 minutes +tar xf ${DOWNLOAD_DIR}/coreutils-8.19.tar.xz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/coreutils-8.19 +cat > config.cache << EOF +fu_cv_sys_stat_statfs2_bsize=yes +gl_cv_func_mbrtowc_incomplete_state=yes +gl_cv_func_mbrtowc_nul_retval=yes +gl_cv_func_mbrtowc_null_arg=yes +gl_cv_func_mbrtowc_retval=yes +gl_cv_func_btowc_eof=yes +gl_cv_func_wcrtomb_retval=yes +gl_cv_func_wctob_works=yes +gl_cv_func_fstatat_zero_flag=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --enable-install-program=hostname \ + --enable-no-install-program=kill,uptime \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/{cat,chgrp,chmod,chown,cp,date} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/{dd,df,echo,false,hostname,ls,mkdir} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/{mv,pwd,rm,rmdir,stty,true,ln,uname} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/chroot ${TARGET_DIR}/usr/sbin +#mv -v ${TARGET_DIR}/usr/bin/{[,basename,head,install,nice} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/{readlink,sleep,sync,test,touch} \ +# ${TARGET_DIR}/bin +#ln -svf ../../bin/install ${TARGET_DIR}/usr/bin +cd .. +rm -rf coreutils-8.19 +popd +@end verbatim + +@c @samp{sed -i.orig '/strftime/s/\ LC_ALL//' man/help2man} + +The variables listed in the file @file{config.cache} are used in order +to avoid that the @file{configure} script evaluate their values: +otherwise the build may fail when cross-compiling. + +We use @option{--enable-install-program=hostname} to install the +command @command{hostname} which is not built by default. + +We use @option{--enable-no-install-program=kill,uptime} in order not +to install commands @command{kill} and @command{uptime}. Those +commands will be installed by the package procps. + + +@node iana-etc +@section iana-etc + +The iana-etc package installs services and protocols using data from +the Internet Assigned Numbers Authority (IANA). + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/iana-etc-2.30.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/iana-etc-2.30 +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf iana-etc-2.30 +popd +@end verbatim + + +@node M4 +@section M4 + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/m4-1.4.16.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/m4-1.4.16 +sed -i.orig '/gets is a security hole/d' lib/stdio.in.h +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf m4-1.4.16 +popd +@end verbatim + +@samp{sed -i.orig '/gets is a security hole/d' lib/stdio.in.h} is used +to fix the following error when issuing @samp{make}: +@samp{./stdio.h:477:1: error: 'gets' undeclared here (not in a +function)}. + +@c It deletes the following line in lib/stdio.in.h: +@c _GL_WARN_ON_USE (gets, ``gets is a security hole - use fgets instead''); + + +@node Bison +@section Bison + +GNU bison parser generator. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/bison-2.7.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bison-2.7 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +echo '#define YYENABLE_NLS 1' >> config.h +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf bison-2.7 +popd +@end verbatim + +@samp{echo '#define YYENABLE_NLS 1' >> config.h} is used to build +@acronym{NLS} (native language support) inside bison. + + +@node Ncurses +@section Ncurses + +@verbatim +# 7 minutes +tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/ncurses-5.9 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --with-shared \ + --enable-widec \ + --without-debug \ + --without-ada \ + --with-build-cc="gcc -D_GNU_SOURCE" \ + --libdir=/lib +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/lib/lib{panel,menu,form,ncurses,ncurses++}w.a \ +# ${TARGET_DIR}/usr/lib +#rm -v ${TARGET_DIR}/lib/lib{ncurses,menu,panel,form}w.so +#ln -svf ../../lib/libncursesw.so.5 \ +# ${TARGET_DIR}/usr/lib/libncursesw.so +#ln -svf ../../lib/libmenuw.so.5 ${TARGET_DIR}/usr/lib/libmenuw.so +#ln -svf ../../lib/libpanelw.so.5 ${TARGET_DIR}/usr/lib/libpanelw.so +#ln -svf ../../lib/libformw.so.5 ${TARGET_DIR}/usr/lib/libformw.so +#for lib in curses ncurses form panel menu ; do +# echo "INPUT(-l${lib}w)" > ${TARGET_DIR}/usr/lib/lib${lib}.so +# ln -sfv lib${lib}w.a ${TARGET_DIR}/usr/lib/lib${lib}.a +# done +ln -sfv libncursesw.so ${TARGET_DIR}/lib/libncurses.so +#ln -sfv libncursesw.so ${TARGET_DIR}/usr/lib/libcursesw.so +#ln -sfv libncursesw.a ${TARGET_DIR}/usr/lib/libcursesw.a +#ln -sfv libncurses++w.a ${TARGET_DIR}/usr/lib/libncurses++.a +#ln -sfv ncursesw5-config ${TARGET_DIR}/usr/bin/ncurses5-config +#ln -sfv ../../usr/share/terminfo ${TARGET_DIR}/usr/lib/terminfo +cd .. +rm -rf ncurses-5.9 +popd +@end verbatim + +Option @option{--enable-widec} enables wide characters support in +ncurses. + +@c Option @option{--without-debug} + +Option @option{--without-ada} disables support for the Ada programming +language inside ncurses. + +@c Option @option{--with-build-cc="gcc -D_GNU_SOURCE"} + +@c Option @option{--libdir=/lib} + +@ignore +@verbatim +for lib in curses ncurses form panel menu ; do + echo "INPUT(-l${lib}w)" > ${TARGET_DIR}/usr/lib/lib${lib}.so + ln -sfv lib${lib}w.a ${TARGET_DIR}/usr/lib/lib${lib}.a + done +ln -sfv libncursesw.so ${TARGET_DIR}/usr/lib/libcursesw.so +ln -sfv libncursesw.a ${TARGET_DIR}/usr/lib/libcursesw.a +ln -sfv libncurses++w.a ${TARGET_DIR}/usr/lib/libncurses++.a +ln -sfv ncursesw5-config ${TARGET_DIR}/usr/bin/ncurses5-config +@end verbatim + +The commands above create symlinks from libraries without support for +wide characters to libraries with support for them. +@end ignore + +@c PROCPS issue: +The command @samp{ln -sfv libncursesw.so $@{TARGET_DIR@}/lib/libncurses.so} +creates the symlink @file{libcurses.so} so that programs that do not +know @file{libncursesw.so} can be linked against it. + +@c ln -sfv ../../usr/share/terminfo ${TARGET_DIR}/usr/lib/terminfo + + +@node Procps +@section Procps + +The procps package contains utilities that give information about +processes using the @file{/proc} filesystem. The package includes the +commands @command{ps}, @command{top}, @command{vmstat}, @command{w}, +@command{kill}, @command{free}, @command{slabtop}, and +@command{skill}. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/procps-3.2.8.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/procps-3.2.8 +make \ + CPPFLAGS= \ + lib64=lib +make \ + DESTDIR=${TARGET_DIR} \ + lib64=lib \ + ldconfig= \ + install="install -D" \ + install +cd .. +rm -rf procps-3.2.8 +popd +@end verbatim + +Option @option{CPPFLAGS= } is used so that the target system's ncurses +library will be used, default value would have been +@option{-I/usr/include/ncurses}. + +Option @option{lib64=lib} makes the directory @file{/lib} the one +where to put 64 bit libraries, default would be @file{/lib64}. + +Option @option{ldconfig= } is used in order not to use current host's +@command{ldconfig}. + +Option @option{install="install -D"} is used so that all the files +installed are owned by the current user. By default, all installed +files are owned by root. + + +@node Libtool +@section Libtool + +GNU libtool is a generic library support script. It hides the +complexity of using shared libraries behind a consistent, portable +interface. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/libtool-2.4.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/libtool-2.4 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf libtool-2.4 +popd +@end verbatim + + +@node Readline +@section Readline + +The GNU Readline library provides a set of functions for use by +applications that allow users to edit command lines as they are typed +in. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/readline-6.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/readline-6.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --libdir=/lib +make +make DESTDIR=${TARGET_DIR} install +make DESTDIR=${TARGET_DIR} install-doc +# For FHS compatibility: +#mv -v ${TARGET_DIR}/lib/lib{readline,history}.a ${TARGET_DIR}/usr/lib +#rm -v ${TARGET_DIR}/lib/lib{readline,history}.so +#ln -svf ../../lib/libreadline.so.6 \ +# ${TARGET_DIR}/usr/lib/libreadline.so +#ln -svf ../../lib/libhistory.so.6 ${TARGET_DIR}/usr/lib/libhistory.so +cd .. +rm -rf readline-6.2 +popd +@end verbatim + +@c sed -i 's:^SHLIB_LIBS=:SHLIB_LIBS=-lncursesw:' support/shobj-conf + + +@node Autoconf +@section Autoconf + +GNU autoconf is an extensible package of M4 macros that produce shell +scripts to automatically configure software source code +packages. These scripts can adapt the packages to many kinds of +UNIX-like systems without manual user intervention. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/autoconf-2.69.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/autoconf-2.69 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf autoconf-2.69 +popd +@end verbatim + + +@node Automake +@section Automake + +GNU automake is a tool for automatically generating @file{Makefile.in} +files compliant with the GNU Coding +Standards@footnote{@uref{http://www.gnu.org/prep/standards/}}. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/automake-1.14.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/automake-1.14 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf automake-1.14 +popd +@end verbatim + + +@node Bash +@section Bash + +GNU @acronym{Bash} (Bourne again shell) is an sh-compatible shell that +incorporates useful features from the Korn shell (ksh) and C shell +(csh). + +@verbatim +# 7 minutes +tar xf ${DOWNLOAD_DIR}/bash-4.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bash-4.2 +cat > config.cache << "EOF" +ac_cv_func_mmap_fixed_mapped=yes +ac_cv_func_strcoll_works=yes +ac_cv_func_working_mktime=yes +bash_cv_func_sigsetjmp=present +bash_cv_getcwd_malloc=yes +bash_cv_job_control_missing=present +bash_cv_printf_a_format=yes +bash_cv_sys_named_pipes=present +bash_cv_ulimit_maxfds=yes +bash_cv_under_sys_siglist=yes +bash_cv_unusable_rtsigs=no +gt_cv_int_divbyzero_sigfpe=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --cache-file=config.cache \ + --without-bash-malloc \ + --with-installed-readline +make +make \ + DESTDIR=${TARGET_DIR} \ + htmldir=/usr/share/doc/bash-4.2 \ + install +ln -sv bash ${TARGET_DIR}/bin/sh +cd .. +rm -rf bash-4.2 +popd +@end verbatim + +The variables listed in the file @file{config.cache} are used in order +to avoid that the @file{configure} script evaluate their values: +otherwise the build may fail when cross-compiling. + +@c --bindir=/bin instead of /usr/bin, FHS? + +Option @option{--without-bash-malloc} tells the @file{configure} +script not to use the @code{malloc} function shipped with +Bash. Glibc's version will be used instead. + +Option @option{--with-installed-readline} tells the configure script +to use the installed readline library instead of the one shipped with +Bash. + +@c htmldir=/usr/share/doc/bash-4.2 + +@samp{ln -sv bash $@{TARGET_DIR@}/bin/sh} creates a symlink @file{sh} +to @file{bash}. + + +@node Bzip2 +@section Bzip2 + +Bzip2 is a package that contains utilities to compress and decompress +files with a better original size/compressed size ratio than gzip. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/bzip2-1.0.6.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bzip2-1.0.6 +sed -i.orig -e "/^all:/s/ test//" Makefile +sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile +make \ + -f Makefile-libbz2_so \ + CC="${CC}" \ + AR="${AR}" \ + RANLIB="${RANLIB}" +make clean +make \ + CC="${CC}" \ + AR="${AR}" \ + RANLIB="${RANLIB}" +make \ + PREFIX=${TARGET_DIR}/usr \ + install +cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2 +cp -av libbz2.so* ${TARGET_DIR}/lib +ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/usr/lib/libbz2.so +rm -v ${TARGET_DIR}/usr/bin/{bunzip2,bzcat,bzip2} +ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2 +ln -sv bzip2 ${TARGET_DIR}/bin/bzcat +cd .. +rm -rf bzip2-1.0.6 +popd +@end verbatim + +@samp{sed -i.orig -e "/^all:/s/ test//" Makefile} is used to skip +tests when building. + +@samp{sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile} is used +in order to have relative path symlinks instead of absolute ones. + +Option @option{-f Makefile-libbz2_so} is used to build shared +libraries. + +Flags @env{CC}, @env{AR} and @env{RANLIB} are used so that bzip2 is +built using cross-compilation tools instead of the host's ones. + +@samp{make clean} is used to clean up temporary files. + +The second build commands are used to build static libraries. + +@ignore +cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2 +cp -av libbz2.so* ${TARGET_DIR}/lib +ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/usr/lib/libbz2.so +rm -v ${TARGET_DIR}/usr/bin/{bunzip2,bzcat,bzip2} +ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2 +ln -sv bzip2 ${TARGET_DIR}/bin/bzcat +@end ignore + + +@node DHCPCD +@section DHCPCD + +DHCPCD is a wrapper for the @acronym{DHCP} (Dynamic Host Configuration +Protocol) client daemon. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/dhcpcd-6.0.2.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/dhcpcd-6.0.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/sbin \ + --sysconfdir=/etc \ + --dbdir=/var/lib/dhcpcd \ + --libexecdir=/usr/lib/dhcpcd +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf dhcpcd-6.0.2 +popd +@end verbatim + +@c Option @option{--bindir=/sbin} is used to comply with FHS? +@c @option{--sysconfdir=/etc} @file{/etc} instead of ? +@c @option{--dbdir=/var/lib/dhcpcd} @file{/var/lib/dhcpcd} instead of? +@c @option{--libexecdir=/usr/lib/dhcpcd} @file{/usr/lib/dhcpcd} instead of ? + + +@node Diffutils +@section Diffutils + +GNU Diffutils is a package of several programs related to finding +differences between files. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/diffutils-3.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/diffutils-3.2 +sed -i.orig '/gets is a security hole/d' lib/stdio.in.h +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf diffutils-3.2 +popd +@end verbatim + +@samp{sed -i.orig '/gets is a security hole/d' lib/stdio.in.h} is used +to fix the following error when issuing @samp{make}: +@samp{./stdio.h:1012:1: error: 'gets' undeclared here (not in a +function)}. + +@c It deletes the following line in lib/stdio.in.h: +@c _GL_WARN_ON_USE (gets, ``gets is a security hole - use fgets instead''); + + +@node File +@section File + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/file-5.14.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/file-5.14 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf file-5.14 +popd +@end verbatim + + +@node Findutils +@section Findutils + +The GNU Find Utilities are typically used to provide directory search +and file locating capabilities. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/findutils-4.4.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/findutils-4.4.2 +cat > config.cache << EOF +gl_cv_func_wcwidth_works=yes +gl_cv_header_working_fcntl_h=yes +ac_cv_func_fnmatch_gnu=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --libexecdir=/usr/lib/locate \ + --localstatedir=/var/lib/locate \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/find ${TARGET_DIR}/bin +#sed -i.orig 's@find:=${BINDIR}@find:=/bin@' \ +# ${TARGET_DIR}/usr/bin/updatedb +cd .. +rm -rf findutils-4.4.2 +popd +@end verbatim + +@c --libexecdir=/usr/lib/locate +@c --localstatedir=/var/lib/locate + + +@node Flex +@section Flex + +Flex is a tool for generating scanners. A scanner, sometimes called a +tokenizer, is a program which recognizes lexical patterns in text. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/flex-2.5.37.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/flex-2.5.37 +cat > config.cache << EOF +ac_cv_path_M4="/usr/bin/m4" +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +ln -sv libfl.a ${TARGET_DIR}/usr/lib/libl.a +cd .. +rm -r flex-2.5.37 +popd + +cat > ${TARGET_DIR}/usr/bin/lex << "EOF" +#!/bin/sh +exec /usr/bin/flex -l "$@" +EOF +chmod -v 755 ${TARGET_DIR}/usr/bin/lex +@end verbatim + +@file{config.cache} forces flex to use @file{/usr/bin/m4} instead of +@file{/gllfsc/cross-tools/bin/m4} on the target machine. + +For compatibility issues, we create the symlink @file{libl.a}. + +We then create target system's @file{/usr/bin/lex} that will execute +@command{flex} with option @option{-l} in order to behave with maximal +compatibility like @command{lex}. + +@ignore +@samp{sed -i.orig "s/-I@@includedir@@//g" Makefile.in} is used in +order not to use host's headers in @file{/usr/include} during +cross-compilation. +@end ignore + +@c Variables @samp{ac_cv_func_malloc_0_nonnull=yes} and +@c @samp{ac_cv_func_realloc_0_nonnull=yes} are used to get rid of +@c error message: @samp{}. + +@c We use option @option{-fPIC} passed to the cross-compiler in order to +@c generate position-independent code (PIC). + + +@node Gawk +@section Gawk + +GNU awk (Gawk) is a program used to select particular records in a +file and perform operations upon them. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/gawk-4.1.0.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gawk-4.1.0 +sed -i.orig \ + '/check-recursive all-recursive/s/ check-for-shared-lib-support//' \ + extension/Makefile.in +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --libexecdir=/usr/lib +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -r gawk-4.1.0 +popd +@end verbatim + +The sed expression is used to avoid the error @samp{Building the +extensions is not supported on this platform}. + + +@node Gettext +@section Gettext + +GNU gettext utilities are a set of tools that provides a framework to +help packages produce multi-lingual messages. + +@verbatim +# 20 minutes +tar xf ${DOWNLOAD_DIR}/gettext-0.18.3.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gettext-0.18.3 +cat > config.cache << EOF +am_cv_func_iconv_works=yes +gl_cv_func_wcwidth_works=yes +gt_cv_func_printf_posix=yes +gt_cv_int_divbyzero_sigfpe=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache +make +#cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i} +#cp gettext-tools/src/.libs/libgettextsrc.la{,i} +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf gettext-0.18.3 +popd +@end verbatim + +@c cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i} ? +@c cp gettext-tools/src/.libs/libgettextsrc.la{,i} ? + + +@node Grep +@section Grep + +GNU @command{grep} command searches one or more input files for lines +containing a match to a specified pattern. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/grep-2.14.tar.xz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/grep-2.14 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --disable-perl-regexp +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf grep-2.14 +popd +@end verbatim + +Option @option{--disable-perl-regexp} disables support of Perl-style +regular expressions (regexp). + + +@node Groff +@section Groff + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/groff-1.22.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/groff-1.22.2 +PAGE=A4 \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make \ + TROFFBIN=troff \ + GROFFBIN=groff \ + GROFF_BIN_PATH= +make prefix=${TARGET_DIR}/usr install +ln -sv soelim ${TARGET_DIR}/usr/bin/zsoelim +ln -sv eqn ${TARGET_DIR}/usr/bin/geqn +ln -sv tbl ${TARGET_DIR}/usr/bin/gtbl +cd .. +rm -rf groff-1.22.2 +popd +@end verbatim + +The variables @env{TROFFBIN=troff} and @env{GROFFBIN=groff} tell +@command{make} to use @command{troff} and @command{groff} commands +installed in the @ref{Building Cross-Compilation Tools} to build +documentation. + +The variable @env{GROFF_BIN_PATH} before @env{PATH} is checked for +programs @command{groff} is calling (preprocessors, troff, and output +devices). If not set, it defaults to the directory where the +@file{groff} binary is located. + +The symlinks are used for compatibility. + + +@node Gzip +@section Gzip + +GNU Gzip is a data compression program. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/gzip-1.6.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/gzip-1.6 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/bin/z{egrep,cmp,diff,fgrep,force,grep,less,more} \ +# ${TARGET_DIR}/usr/bin +#mv -v ${TARGET_DIR}/bin/znew \ +# ${TARGET_DIR}/usr/bin +cd .. +rm -rf gzip-1.6 +popd +@end verbatim + + +@node Inetutils +@section Inetutils + +Inetutils is a collection of common network programs. + +@verbatim +# 6 minutes +tar xf ${DOWNLOAD_DIR}/inetutils-1.9.1.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/inetutils-1.9.1 +sed -i.orig '/gets is a security hole/d' lib/stdio.in.h +sed -i.orig -e '/PATH_PROCNET_DEV/s/\ no//' paths +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf inetutils-1.9.1 +popd +@end verbatim + +@samp{sed -i.orig '/gets is a security hole/d' lib/stdio.in.h} is used +to fix the following error when issuing @samp{make}: +@samp{./stdio.h:1030:1: error: 'gets' undeclared here (not in a +function)}. + +@c It deletes the following line in lib/stdio.in.h: +@c _GL_WARN_ON_USE (gets, ``gets is a security hole - use fgets instead''); + +@samp{sed -i.orig -e '/PATH_PROCNET_DEV/s/\ no//' paths} is used to +fix the following error when issuing @samp{make}: +@samp{'PATH_PROCNET_DEV' undeclared (first use in this function)}. + + +@node Iproute2 +@section Iproute2 + +Iproute2 is a collection of utilities for controlling TCP and UDP IP +networking and traffic. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/iproute2-3.10.0.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/iproute2-3.10.0 +sed -i.orig '/^TARGETS/s@arpd@@g' misc/Makefile +make \ + DESTDIR=${TARGET_DIR} \ + CC="${CC}" \ + DOCDIR=/usr/share/doc/iproute2 \ + MANDIR=/usr/share/man +make \ + DESTDIR=${TARGET_DIR} \ + DOCDIR=/usr/share/doc/iproute2 \ + MANDIR=/usr/share/man \ + install +cd .. +rm -rf iproute2-3.10.0 +popd +@end verbatim + +@samp{sed -i.orig '/^TARGETS/s@@arpd@@@@g' misc/Makefile} is used to +disable the build of @command{arpd} as it requires Berkeley DB to be +installed. + +@env{DOCDIR} and @env{MANDIR} indicate the location in which the +documentation and the manual pages will be installed, +respectively. Those are no absolute paths but use the value of +@env{DESTDIR} as a prefix. + + +@node Kbd +@section Kbd + +Kbd contains keytable files and keyboard utilities. + +@verbatim +# 3 minutes +tar xf ${DOWNLOAD_DIR}/kbd-1.15.5.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/kbd-1.15.5 +cat > config.cache << EOF +ac_cv_func_setpgrp_void=yes +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache \ + --disable-vlock +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility +#mv -v ${TARGET_DIR}/usr/bin/{kbd_mode,dumpkeys,loadkeys,openvt} \ +# ${TARGET_DIR}/bin +#mv -v ${TARGET_DIR}/usr/bin/setfont \ +# ${TARGET_DIR}/bin +cd .. +rm -rf kbd-1.15.5 +popd +@end verbatim + +Option @option{--disable-vlock} disables the build of vlock. vlock +needs PAM library headers to be present on the build system and is not +necessary for us, so we do not build it. + + +@node Kmod +@section Kmod + +Kmod (previously known as module-init-tools) provide userspace-side +assistance in loading kernel modules and their dependencies. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/kmod-14.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/kmod-14 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --sbindir=/sbin \ + --with-zlib +make +make \ + DESTDIR=${TARGET_DIR} \ + INSTALL=install \ + install +cd .. +rm -rf kmod-14 +popd + +# For bootscripts: +ln -sv kmod ${TARGET_DIR}/bin/lsmod +ln -sv ../bin/kmod ${TARGET_DIR}/sbin/depmod +ln -sv ../bin/kmod ${TARGET_DIR}/sbin/insmod +ln -sv ../bin/kmod ${TARGET_DIR}/sbin/modprobe +ln -sv ../bin/kmod ${TARGET_DIR}/sbin/modinfo +ln -sv ../bin/kmod ${TARGET_DIR}/sbin/rmmod +@end verbatim + +@option{--with-zlib} enables support for modules compressed with +zlib. + +By default, installation uses @env{INSTALL=install-with-care} which +checks if old utilities have not been destroyed. To avoid this check, +we use @env{INSTALL=install}. + + +@node Less +@section Less + +Less is a file pager. A file pager is used to view the content of a +text file. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/less-458.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/less-458 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --sysconfdir=/etc +make +make prefix=${TARGET_DIR}/usr install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/less ${TARGET_DIR}/bin +cd .. +rm -rf less-458 +popd +@end verbatim + + +@node Make +@section Make + +GNU @command{make} utility determines automatically which pieces of a +large program need to be recompiled, and issues the commands to +recompile them. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/make-3.82.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/make-3.82 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf make-3.82 +popd +@end verbatim + + +@node Man +@section Man + +Man is an interface to the on-line reference manuals. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/man-1.6g.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/man-1.6g +sed -i.orig -e "/PREPATH=/s@=.*@=\"$(eval echo \ + ${TARGET_DIR}/{,usr/}{sbin,bin})\"@g" -e 's@-is@&Rc@g' configure +sed -i.orig -e 's@MANPATH./usr/man@#&@g' \ + -e 's@MANPATH./usr/local/man@#&@g' src/man.conf.in +./configure \ + -confdir=/etc +sed -i.orig "s@${TARGET_DIR}@@" conf_script +gcc src/makemsg.c -o src/makemsg +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf man-1.6g +popd +@end verbatim + +In the first use of @command{sed}, the first part replaces +@env{PREPATH} default value +@samp{/bin:/usr/bin:/usr/ucb:/usr/local/@/bin:$PATH} with +@samp{$@{TARGET_DIR@}/@{,usr/@}@{sbin,bin@}}. The variable +@env{TARGET_DIR} is used to avoid errors when running the +@file{configure} script. + +The second part is used to replace default options of the man pager +@option{-is} with @option{-isRc}. Option @option{-c} will cause +@command{less} to display man pages faster as this option disables +scrolling. + +@c What about -R? + +The second call of @command{sed} tells @command{man} where the cat +pages corresponding to given man pages should not be stored: +@file{/usr/man} and @file{/usr/local/man}. + +Option @option{-confdir} is used to define configuration files +location to target system's @file{/etc}. + +The third call of @command{sed} is used in order to remove the +presence of @env{TARGET_DIR} on the target system's programs. + +@command{makemsg} will be used during the build, but because using the +cross-compiler may make its build fail, we use the host's compiler. + + +@node Nano +@section Nano + +GNU nano is a lightweight text editor. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/nano-2.3.2.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/nano-2.3.2 +#tar xf ${DOWNLOAD_DIR}/nano-2.3.1.tar.gz -C ${BUILD_DIR} +#pushd ${BUILD_DIR}/nano-2.3.1 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +sed -i.orig -e \ + '/CPPFLAGS/s/\/usr\/include\/ncursesw/${TARGET_DIR}\/usr\/include/' \ + `find . -iname 'Makefile'` +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf nano-2.3.2 +popd +@end verbatim + +The sed expression is used to replace @file{/usr/include/ncursesw} +with @file{$@{TARGET_DIR@}/usr/include} in every file named +@file{Makefile} in order to overcome the error +@samp{/usr/include/ncursesw/ncurses.h:60:34: fatal error: +ncursesw/ncurses_dll.h: No such file or directory}. + +@quotation Note +commands in nano are displayed as in `^X'. The `^' character means +@key{CTRL} key, so `^X' means @kbd{CTRL-X}. +@end quotation + + +@node Patch +@section Patch + +GNU patch takes a patch file containing a difference listing produced +by the @command{diff} program and applies those differences to one or +more original files, producing patched versions. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/patch-2.7.1.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/patch-2.7.1 +cat > config.cache << EOF +ac_cv_path_ed_PROGRAM=ed +ac_cv_func_strnlen_working=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --cache-file=config.cache +make +make prefix=${TARGET_DIR}/usr install +cd .. +rm -rf patch-2.7.1 +popd +@end verbatim + + +@node Psmisc +@section Psmisc + +This package contains utilities that use the proc filesystem. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/psmisc-22.20.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/psmisc-22.20 +cat > config.cache << EOF +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --exec-prefix="" \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/bin/pstree* ${TARGET_DIR}/usr/bin +#ln -sv killall ${TARGET_DIR}/bin/pidof +cd .. +rm -rf psmisc-22.20 +popd +@end verbatim + + +@node Rsyslog +@section Rsyslog + +Rsyslog is an utility creating log messages. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/rsyslog-5.8.6.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/rsyslog-5.8.6 +cat > config.cache << EOF +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +EOF +PKG_CONFIG_PATH="${TARGET_DIR}/usr/lib/pkgconfig" \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --sbindir=/sbin \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +install -dv ${TARGET_DIR}/etc/rsyslog.d +cd .. +rm -rf rsyslog-5.8.6 +popd + +cat > ${TARGET_DIR}/etc/rsyslog.conf << "EOF" +$ModLoad imuxsock.so +$ModLoad imklog.so + +$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat + +$FileOwner root +$FileGroup root +$FileCreateMode 0640 +$DirCreateMode 0755 + +$ModLoad imudp +$UDPServerRun 514 + +$RepeatedMsgReduction on + +$IncludeConfig /etc/rsyslog.d/*.conf + +auth,authpriv.* /var/log/auth.log +*.*;auth,authpriv.none -/var/log/syslog +daemon.* -/var/log/daemon.log +kern.* -/var/log/kern.log +lpr.* -/var/log/lpr.log +mail.* -/var/log/mail.log +user.* -/var/log/user.log + +# Catch All Logs +*.=debug;\ + auth,authpriv.none;\ + news.none;mail.none -/var/log/debug +*.=info;*.=notice;*.=warn;\ + auth,authpriv.none;\ + cron,daemon.none;\ + mail,news.none -/var/log/messages + +# Emergency are shown to everyone +*.emerg * +EOF +@end verbatim + +@samp{install -dv $@{TARGET_DIR@}/etc/rsyslog.d} is used to create +target system's @file{/etc/rsyslog.d} directory. Rsyslog looks for +user-defined configuration files in this directory. The line +@samp{$IncludeConfig /etc/rsyslog.d/*.conf} in the target system's +configuration file @file{/etc/rsyslog.conf} has this purpose. + +We then create the target system's configuration file +@file{/etc/rsyslog.conf}. + + +@node Shadow +@section Shadow + +@verbatim +# 4 minutes +tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/shadow-4.1.4.3 +patch -Np1 -i ${DOWNLOAD_DIR}/shadow-4.1.4.3-man-ru.patch +automake +echo "ac_cv_func_setpgrp_void=yes" > config.cache +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --libdir=/lib \ + --sysconfdir=/etc \ + --enable-shared \ + --without-audit \ + --without-libpam \ + --without-selinux \ + --cache-file=config.cache \ + --enable-man +sed -i.orig 's/groups$(EXEEXT) //' src/Makefile +for mkf in $(find man -name Makefile) + do + sed -i.orig -e '/groups.1.xml/d' -e 's/groups.1 //' ${mkf} + done +make +make DESTDIR=${TARGET_DIR} install +sed -i.orig -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \ + -e 's@/var/spool/mail@/var/mail@' \ + ${TARGET_DIR}/etc/login.defs +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/passwd ${TARGET_DIR}/bin +${CROSS_TARGET}-pwconv +${CROSS_TARGET}-grpconv +${CROSS_TARGET}-passwd root +cd .. +rm -rf shadow-4.1.4.3 +popd +@end verbatim + +@ignore + ${CROSS_TARGET}-passwd root +gives the following message: + Cannot change ID to root. +@end ignore + +The patch @file{shadow-4.1.4.3-man-ru.patch} contains a fix to +@file{man/ru/Makefile.am} preventing @samp{make install} to +complete. @command{automake-1.11} is then run to update the makefile +prototype @file{Makefile.in}. + +@c echo "ac_cv_func_setpgrp_void=yes" > config.cache + +The option @option{--enable-man} is used to generate man pages. + +The first call of @command{sed} disables the build of command +@command{groups}, as coreutils already installed it. + +The second call of @command{sed} enables support for MD5 encrypted +passwords and changes the mail default directory from +@file{/var/spool/mail} to @file{/var/mail}. + +The @command{pwconv} command creates @file{shadow} file from file +@file{passwd} and an optionally existing @file{shadow} file. + +The @command{grpconv} command creates @file{gshadow} file from file +@file{group} and an optionally existing @file{gshadow} file. + +The command @samp{passwd root} will create the password for the root +user, you will need it when logging in as root on your new system. + + +@node Sysvinit +@section Sysvinit + +Sysvinit is the system-V style init process. Init is the first process +started during booting. It is started by the kernel. Init continues +running as a daemon until the system is shut down. It is the direct or +indirect ancestor of all other processes and automatically adopts all +orphaned processes. + + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/sysvinit-2.88dsf.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/sysvinit-2.88dsf +sed -i.orig -e 's@/dev/initctl@$(ROOT)&@g' \ + -e 's@\(mknod \)-m \([0-9]* \)\(.* \)p@\1\3p; chmod \2\3@g' \ + -e '/^ifeq/s/$(ROOT)//' \ + -e 's@/usr/lib@$(ROOT)&@' \ + src/Makefile +make -C src clobber +make -C src ROOT=${TARGET_DIR} CC="${CC}" +make -C src ROOT=${TARGET_DIR} INSTALL="install" install +cd .. +rm -rf sysvinit-2.88dsf +popd + +cat > ${TARGET_DIR}/etc/inittab << "EOF" +# Begin /etc/inittab + +id:3:initdefault: + +si::sysinit:/etc/rc.d/init.d/rc sysinit + +l0:0:wait:/etc/rc.d/init.d/rc 0 +l1:S1:wait:/etc/rc.d/init.d/rc 1 +l2:2:wait:/etc/rc.d/init.d/rc 2 +l3:3:wait:/etc/rc.d/init.d/rc 3 +l4:4:wait:/etc/rc.d/init.d/rc 4 +l5:5:wait:/etc/rc.d/init.d/rc 5 +l6:6:wait:/etc/rc.d/init.d/rc 6 + +ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now + +su:S016:once:/sbin/sulogin + +1:2345:respawn:/sbin/agetty tty1 9600 +2:2345:respawn:/sbin/agetty tty2 9600 +3:2345:respawn:/sbin/agetty tty3 9600 +4:2345:respawn:/sbin/agetty tty4 9600 +5:2345:respawn:/sbin/agetty tty5 9600 +6:2345:respawn:/sbin/agetty tty6 9600 + +#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100 + +# End /etc/inittab +EOF +@end verbatim + +The first call of @command{sed} replaces @file{/dev/initctl} with +@file{$(ROOT)/dev/initctl}, and @file{/usr/lib} with +@file{$(ROOT)/usr/lib} among other things in order to install sysvinit +on the target system. + +@samp{make -C src clobber} is used to clean up the @file{src} +directory. + +Then, we create the @file{inittab} file that describes which processes +are started at bootup and during normal operation. + +The line @samp{#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100} is +commented out (with @code{#}) in order to avoid the message: +@samp{INIT: Id "c0" respawning too fast: disabled for 5 minutes} on +the target system. + + +@node Tar +@section Tar + +GNU tar is an archiving utility: it stores and extracts files from a +tape or disk archive. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/tar-1.26.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/tar-1.26 +cat > config.cache << EOF +gl_cv_func_btowc_eof=yes +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +gl_cv_func_mbrtowc_incomplete_state=yes +gl_cv_func_mbrtowc_nul_retval=yes +gl_cv_func_mbrtowc_null_arg=yes +gl_cv_func_mbrtowc_retval=yes +gl_cv_func_wcrtomb_retval=yes +EOF +sed -i.orig '/gets is a security hole/d' gnu/stdio.in.h +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --libexecdir=/usr/sbin \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf tar-1.26 +popd +@end verbatim + +The sed expression is use to avoid the error @samp{./stdio.h:479:1: +error: 'gets' undeclared here (not in a function)}. + + +@node Texinfo +@section Texinfo + +GNU Texinfo is a documentation system that can produce both online +information and a printed manual from a single source. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/texinfo-5.1.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/texinfo-5.1 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make -C tools/gnulib/lib +make -C tools +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf texinfo-5.1 +popd + +pushd ${TARGET_DIR}/usr/share/info +rm dir +for f in * + do install-info $f dir 2>/dev/null +done +popd +@end verbatim + +The first three calls of @command{make} make it possible to build +Texinfo by cross-compilation. + +For Info to work, the @file{info} directory must contain a file that +serves as a top level directory for the Info system. By convention, +this file is called @file{dir}. We update this file for the target +system. + + +@node Udev +@section Udev + +Udev is the dynamic device management of the kernel Linux. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/udev-175.tar.gz -C ${BUILD_DIR} +pushd ${BUILD_DIR}/udev-175 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr \ + --sysconfdir=/etc \ + --sbindir=/sbin \ + --with-rootlibdir=/lib \ + --libexecdir=/lib/udev \ + --docdir=/usr/share/doc/udev-175 \ + --disable-introspection \ + --with-pci-ids-path=no \ + --with-usb-ids-path=no \ + --disable-gudev +make +make DESTDIR=${TARGET_DIR} install +install -dv ${TARGET_DIR}/lib/firmware +ln -sv ../lib/udev/udevd ${TARGET_DIR}/sbin/udevd +cd .. +rm -rf udev-175 +popd +@end verbatim + + +@node Util-Linux +@section Util-Linux + +util-linux is a random collection of utilities for use with the kernel +Linux. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/util-linux-2.23.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/util-linux-2.23 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --enable-partx \ + --disable-wall \ + --enable-write \ + --disable-makeinstall-chown +make +make DESTDIR=${TARGET_DIR} install +mv -v ${TARGET_DIR}/usr/bin/logger ${TARGET_DIR}/bin +cd .. +rm -r util-linux-2.23 +popd +@end verbatim + +Option @option{--enable-partx} enables the build and installation of +the @command{addpart}, @command{delpart} and @command{partx} commands. + +Option @option{--disable-wall} disables the build of the +@command{wall} command which is already provided by sysvinit. + +Option @option{--enable-write} enables the build and installation of +the @command{write} command. + +Option @option{--disable-makeinstall-chown} disables the change of +owner to root for installed programs. + + +@node XZ-Utils +@section XZ-Utils + +XZ Utils is a general-purpose data compression software with high +compression ratio. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/xz-5.0.5.tar.bz2 -C ${BUILD_DIR} +pushd ${BUILD_DIR}/xz-5.0.5 +#tar xf ${DOWNLOAD_DIR}/xz-5.0.4.tar.bz2 -C ${BUILD_DIR} +#pushd ${BUILD_DIR}/xz-5.0.4 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix=/usr +make +make DESTDIR=${TARGET_DIR} install +# For FHS compatibility: +#mv -v ${TARGET_DIR}/usr/bin/{xz,lzma,lzcat,unlzma,unxz,xzcat} \ +# ${TARGET_DIR}/bin +cd .. +rm -rf xz-5.0.5 +popd +@end verbatim + + +@node Bootscripts +@section Bootscripts + +The bootscript archive contains scripts that manage services during +system's bootup and shutdown. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/bootscripts-cross-lfs-2.0.0.tar.xz \ + -C ${BUILD_DIR} +pushd ${BUILD_DIR}/bootscripts-cross-lfs-2.0-pre2 +make DESTDIR=${TARGET_DIR} install-bootscripts +make DESTDIR=${TARGET_DIR} install-network +cd .. +rm -rf bootscripts-cross-lfs-2.0-pre2 +popd +@end verbatim + +This installs basic bootscripts required for bootup and shutdown, and +network-related bootscripts. + + +@node Kernel +@section The Kernel + +@verbatim +# 40 minutes +tar xf ${DOWNLOAD_DIR}/linux-3.9-loongson3a-deblobbed.tar \ + -C ${BUILD_DIR} +pushd ${BUILD_DIR}/linux-official +#tar xf ${DOWNLOAD_DIR}/linux-2.6.36-21-loongson3a-deblobbed.tar \ +# -C ${BUILD_DIR} +#pushd ${BUILD_DIR}/linux-3A +patch -Np1 -i $DOWNLOAD_DIR/linux-3.9-firmware-timeout.patch +patch -Np1 -i $DOWNLOAD_DIR/linux-3.9-kernel-panic.patch +#patch -Np1 -i $DOWNLOAD_DIR/linux-2.6.36-firmware-timeout.patch +#patch -Np1 -i $DOWNLOAD_DIR/linux-2.6.36-kernel-panic.patch +make mrproper +@end verbatim + +@file{linux-3.9-firmware-timeout.patch} is used to avoid waiting 60 +seconds for the binary-blob firmware to load, as those have been +removed by the @file{deblob} script. + +@file{linux-3.9-kernel-panic.patch} is used in order to avoid a kernel +panic that may occur frequently at boot with the deblobbed kernel. + +Then: + +@verbatim +#cp arch/mips/configs/loongson3a_defconfig .config +cp arch/mips/configs/loongson3_defconfig .config +#cp arch/mips/configs/loongson3_config .config +#Skip the following as, with 4 CPUs, the result is ugly: +#patch -Np1 -i ${DOWNLOAD_DIR}/100gnu+freedo.patch +@end verbatim + +Then, if you want to change the configuration: + +@verbatim +#make ARCH=mips CROSS_COMPILE=${CROSS_TARGET}- config +make ARCH=mips CROSS_COMPILE=${CROSS_TARGET}- menuconfig +@end verbatim + +@verbatim +make \ + ARCH=mips \ + CROSS_COMPILE=${CROSS_TARGET}- +make \ + ARCH=mips \ + CROSS_COMPILE=${CROSS_TARGET}- \ + INSTALL_MOD_PATH=${TARGET_DIR} \ + modules_install +cp vmlinuz ${TARGET_DIR}/boot/vmlinuz +cp System.map ${TARGET_DIR}/boot/System.map +cp .config ${TARGET_DIR}/boot/config +cd .. +popd +@end verbatim + +@quotation Tip +because future compilation may need kernel sources, the compilation +directory of the kernel should be preserved. +@end quotation + + +@node Configuration Files +@chapter Creating Required Configuration Files for the New System + +@menu +* Time Setup File:: File for time setup. +* Bash Keyboard Setup:: Setting up keyboard function keys + for the Shell. +* Bash Startup Files:: Setting up Bash shell startup files. +* Localhost Setup:: Setting up localhost. +* hosts Setup:: Setting up @file{hosts} file. +* Network Address Setup:: Setting up network address. +* DNS Setup:: Setting up DNS. +* fstab File Creation:: Creating @file{fstab} file. +@end menu + + +@node Time Setup File +@section File for Time Setup + +@verbatim +cat > ${TARGET_DIR}/etc/sysconfig/clock << "EOF" +# Begin /etc/sysconfig/clock + +UTC=1 + +# End /etc/sysconfig/clock +EOF +@end verbatim + + +@node Bash Keyboard Setup +@section Setting up Keyboard Function keys for the Shell + +Readline default configuration file is set: + +@verbatim +cat > ${TARGET_DIR}/etc/inputrc << "EOF" +set bell-style none +set convert-meta Off +set horizontal-scroll-mode Off +set input-meta On +set output-meta On +"\eOd": backward-word +"\eOc": forward-word +"\e[1~": beginning-of-line +"\e[4~": end-of-line +"\e[5~": beginning-of-history +"\e[6~": end-of-history +"\e[3~": delete-char +"\e[2~": quoted-insert +"\eOH": beginning-of-line +"\eOF": end-of-line +"\e[H": beginning-of-line +"\e[F": end-of-line +EOF +@end verbatim + +If @option{convert-meta} is set to @samp{on}, Readline will convert +characters with the eighth bit set to an @sc{ascii} key sequence by +stripping the eighth bit and prefixing an @key{ESC} character, +converting them to a meta-prefixed key sequence. + +@option{horizontal-scroll-mode} set to @samp{off} means that the text +of the lines being edited will be wrapped onto a new screen line when +they are longer than the width of the screen, instead of being +scrolled horizontally on a single screen line. + +@c set meta-flag On + +@option{input-meta} If set to @samp{on}, Readline will enable +eight-bit input (it will not clear the eighth bit in the characters it +reads), regardless of what the terminal claims it can support. + +If @option{output-meta} is set to @samp{on}, Readline will display +characters with the eighth bit set directly rather than as a +meta-prefixed escape sequence. + +@ignore +"\eOd": backward-word +"\eOc": forward-word +"\e[1~": beginning-of-line +"\e[4~": end-of-line +"\e[5~": beginning-of-history +"\e[6~": end-of-history +"\e[3~": delete-char +"\e[2~": quoted-insert +"\eOH": beginning-of-line +"\eOF": end-of-line +"\e[H": beginning-of-line +"\e[F": end-of-line +@end ignore + + +@node Bash Startup Files +@section Setting up Bash Shell Startup Files + +@verbatim +cat > ${TARGET_DIR}/etc/profile << "EOF" +# Begin /etc/profile + +export LANG=en_US.UTF-8 +export INPUTRC=/etc/inputrc +export PS1='\[\e[31m\]\A-\W\[\e[00m\]\$ ' + +# End /etc/profile +EOF +@end verbatim + +The environement variable @env{LANG} defines the default language that +should be used on the system. @samp{en_US.UTF-8} means ``english'' +language, country ``US'' and @acronym{UTF-8} (UCS Transformation +Format—8-bit) encoding (Unicode). + +@c For a full list, see??? + +For explanations on @env{PS1}, @pxref{Environment Variables Setup}. + + +@node Localhost Setup +@section Localhost Setup + +@verbatim +echo "HOSTNAME=gllfsc" > ${TARGET_DIR}/etc/sysconfig/network +@end verbatim + + +@node hosts Setup +@section Setting up @file{hosts} File + +@verbatim +cat > ${TARGET_DIR}/etc/hosts << "EOF" +# Begin /etc/hosts + +127.0.0.1 gllfsc localhost + +# End /etc/hosts +EOF +@end verbatim + + +@node Network Address Setup +@section Setting up Network Address + +You can choose to have a network static or dynamic address. + +@menu +* Network Static Address Setup:: Setting up Network Static Address. +* Network Dynamic Address Setup:: Setting up Network Dynamic + Address. +@end menu + + +@node Network Static Address Setup +@subsection Setting up Network Static Address + +@verbatim +pushd ${TARGET_DIR}/etc/sysconfig/network-devices +mkdir -v ifconfig.eth0 +cat > ifconfig.eth0/ipv4 << "EOF" +ONBOOT=yes +SERVICE=ipv4-static +IP=192.168.1.1 +GATEWAY=192.168.1.2 +PREFIX=24 +BROADCAST=192.168.1.255 +EOF +popd +@end verbatim + +@quotation Warning +@code{IP}, @code{GATEWAY}, @code{BROADCAST} addresses are set up +according to one's situation. +@end quotation + + +@node Network Dynamic Address Setup +@subsection Setting up Network Dynamic Address + +@verbatim +pushd ${TARGET_DIR}/etc/sysconfig/network-devices +mkdir -v ifconfig.eth0 +cat > ifconfig.eth0/dhcpcd << "EOF" +ONBOOT=yes +SERVICE=dhcpcd +DHCP_START="-q" +DHCP_STOP="-k" +EOF +popd +@end verbatim + + +@node DNS Setup +@section Setting up DNS + +@verbatim +cat > ${TARGET_DIR}/etc/resolv.conf << "EOF" +# Begin /etc/resolv.conf + +nameserver your-main-DNS-address +nameserver your-secondary-DNS-address + +# End /etc/resolv.conf +EOF +@end verbatim + + +@node fstab File Creation +@section @file{fstab} File Creation + +The file @file{/etc/fstab} is used at boot to mount partitions under +the requested directories. + +@verbatim +cat > ${TARGET_DIR}/etc/fstab << "EOF" +# Begin /etc/fstab + +# file system mount-point type options dump fsck order + +/dev/sda8 / ext3 defaults 1 1 +/dev/sda3 swap swap pri=1 0 0 +proc /proc proc defaults 0 0 +sysfs /sys sysfs defaults 0 0 +devpts /dev/pts devpts gid=4,mode=620 0 0 +shm /dev/shm tmpfs defaults 0 0 + +# End /etc/fstab +EOF +@end verbatim + +@quotation Warning +the name of the hard drive and the name of filesystem used here have +to be modified to reflect @emph{your} real situation. +@end quotation + + +@node End +@chapter The End + +@menu +* Archiving:: All the system archived in one + package. +* Recommendations:: Some tips. +@end menu + + +@node Archiving +@section Archiving the System + +After the system has been completed, we use the command @command{exit} +to logout as the @emph{gllfsc} user. + +Now, login as the @emph{root} user. + +Then fix the permissions on the new system: + +@verbatim +export TARGET_DIR=/gllfsc +pushd ${TARGET_DIR} +mknod -m 600 dev/console c 5 1 +mknod -m 666 dev/null c 1 3 +cp -a dev/{console,null} lib/udev/devices/ +chown -R root:root * +@end verbatim + +We archive the entire system by using the following command: + +@verbatim +# 20 minutes without kernel sources nor cross-tools +#tar -cjf gllfsc-20130723.tar.bz2 bin boot dev etc home lib* media \ +# mnt opt proc root sbin srv sys tmp usr var + +# 20 minutes without kernel sources +tar -cjf gllfsc-20130723.tar.bz2 bin boot cross-tools dev etc home \ + lib* media mnt opt proc root sbin srv sys tmp usr var + +# 60 minutes with kernel sources + cross-tools +#tar -cjf gllfsc-20130723.tar.bz2 * +@end verbatim + +It is then easy to copy the archive to the target machine and extract. + + +@node Recommendations +@section Some Recommendations + +We recommend extracting the system to an empty partition. Moreover, +the filesystem of the chosen partition has to be a filesystem +supported by the kernel you compiled. Finally, this partition has to +be consistent with the system description in the file +@file{/etc/fstab} you created during setup (@pxref{fstab File +Creation}). + +Then, you will have to edit the PMON BIOS configuration file of the +target machine: @file{/boot.cfg}. This file has to be put on the first +partition of the hard +drive@footnote{@uref{http://gnewsense.org/Projects/Lemote#Updating_of_the_PMON_configuration}}. A +minimal @file{/boot.cfg} could be: + +On the Yeeloong 8133, vmlinuz must be on the first primary partition +to be able to boot. + +@verbatim +default 0 +timeout 2 +showmenu 1 + +title GLLFSC +kernel /dev/fs/ext2@wd0/vmlinuz +args console=tty1 root=/dev/sda8 +@end verbatim + + +@node Further Readings +@chapter Further Readings + +Haiyong Sun's website (in Chinese): +@uref{http://youbest.cublog.cn}. It includes documents on building a +GNU/Linux system for Loongson and a GNU/Hurd system for x86. + +Cross [GNU/]Linux from scratch: @uref{http://www.cross-lfs.org}. +Includes a lot of documentation to build a GNU/Linux system by +cross-compilation on a variety of hardware, no information (yet) for +cross-compiling with sysroot on MIPS though. There is also a +Community-driven Beyond [GNU/]Linux From Scratch on +@uref{http://cblfs.cross-lfs.org}. It documents the building of Xorg +and TeXLive among other things. + +@c Some patches from the above project are available for download on +@c @uref{http://svn.cross-lfs.org/svn/repos/patches/}. + +@uref{http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_@/man.txt} +documents an interesting way of managing packages. Quotation from the +file: + +@quotation +DESCRIPTION: +@itemize + +@item +You want to know which packages your files belong to? + +@item +You want to deinstall software that doesn't have make uninstall? + +@item +You are bothered by programs installed setuid root behind your back? + +@item +You don't like packages quietly overwriting files from other packages? + +@item +You don't like package managers like RPM? + +@item +YOU WANT TOTAL CONTROL USING ONLY UNIX BUILTINS? +@end itemize +@end quotation + +The suckless team@footnote{@uref{http://suckless.org}} is a group of +programmers that share the following +philosophy@footnote{@uref{http://suckless.org/philosophy}}: + +@quotation +Focus on simplicity, clarity and frugality. Our philosophy is about +keeping things simple, minimal and usable. We believe this should +become the mainstream philosophy in the IT sector. Unfortunately, the +tendency for complex, error-prone and slow software seems to be +prevalent in the present-day software industry. We intend to prove the +opposite with our software projects. +@end quotation + +The simple and lightweight programs released by this team are +interesting for machines based on Loongson 3A processor as performance +is limited compared to current x86 processors. + + +@node Thanks +@chapter Thanks + +I thank Lemote and particularily the CEO, Fuxin Zhang, for offering me +a Yeeloong 8133, Huacai Chen and Haiyong Sun for their help in fixing +the bugs I found in the deblobbed kernel. + +I am particularily grateful to Haiyong Sun for having shared his +knowledge on building a free operating system for Loongson 2F +machines, this document is heavily based on this. + + +@node GNU Free Documentation License +@appendix GNU Free Documentation License +@include fdl-1.3.texi + + +@node GNU General Public License +@appendix GNU General Public License +@include gpl.texi + +@bye diff --git a/gllfsc-pentium4-1.7.texi b/gllfsc-pentium4-1.7.texi new file mode 100644 index 0000000..110a65b --- /dev/null +++ b/gllfsc-pentium4-1.7.texi @@ -0,0 +1,5233 @@ +\input texinfo +@c -*-texinfo-*- +@c %**start of header +@setfilename gllfsc-pentium4-1.7.info +@settitle GNU/Linux-libre from source code for Pentium 4 +@c Comment the following if you want Letter format instead of A4 for +@c PDF output +@afourpaper +@c %**end of header +@c Book headers for PDF version +@setchapternewpage odd +@documentencoding UTF-8 + +@copying +This is edition 1.7 (last updated April 2020) of +@cite{GNU/Linux-libre from source code for Pentium 4}. + +Copyright @copyright{} 2020 Christophe Jarry. + +@ignore +This document is based on the Chinese page +@url{http://zdbr.net.cn/download/Loongson64-@/2.0.htm}, which is +copyright @copyright{} 2009 +@c Because TeX does not handle Chinese fonts automatically, we need to +@c do the following: +@ifnottex +Haiyong Sun (孙海勇). +@end ifnottex +@iftex +Haiyong Sun. +@end iftex +His blog is on @url{http://blog.chinaunix.net/uid/436750.html}. +@end ignore + +Various formats of this manual as well as its texinfo source are +available on +@uref{http://cjarry.org/gnu-linux/gllfsc/pentium4/}. + +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 +or any later version published by the Free Software Foundation; +with no Invariant Sections, no Front-Cover Texts, and no Back-Cover +Texts. A copy of the license is included in the section entitled ``GNU +Free Documentation License''. +@end quotation + +@quotation +Computer instructions in this manual are free software: you can +redistribute them and/or modify them under the terms of the GNU +General Public License as published by the Free Software Foundation, +either version 3 of the License, or (at your option) any later +version. + +Those instructions are distributed in the hope that they will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this manual. If not, see . +@end quotation + +@end copying + +@c @setchapternewpage odd + +@titlepage +@title GNU/Linux-libre from source code +@subtitle for Pentium 4 +@c @subtitle SUBTITLE-IF-ANY +@c @subtitle SECOND-SUBTITLE +@author Christophe Jarry + +@c The following two commands +@c start the copyright page. +@page +@vskip 0pt plus 1filll +@insertcopying + +@c Published by ... +@end titlepage + +@c Short table of contents +@shortcontents + +@c So the toc is printed at the start. +@contents + +@ifnottex +@node Top +@top GNU/Linux-libre from source code for Pentium 4 + +This manual describes how to build a GNU/Linux-libre system from +source for Pentium 4 processor. + +@insertcopying +@end ifnottex + +@menu +* Introduction:: What this document is all about. +* Prerequisites:: Useful knowledge before proceeding. +* Preliminary Work:: Preparing the build. +* Building the Cross-Compilation Toolchain:: Building the cross- + compilation Toolchain. +* Building the Cross-Compilation Tools:: Building the + cross-compilation Tools. +* Building the Target System:: How to build the target system. +* Configuration Files:: Creating configuration files + needed by the new system. +* Before Booting GLLFSC:: Final things to do before booting + into the new system. +* After Booting GLLFSC:: Some packages to install and + configuration to tweek in order + to extend the system. +* Further Readings:: Websites useful to know more. +@c * Thanks:: Thanks. +* GNU Free Documentation License:: Your rights and freedoms with the + text. +* GNU General Public License:: Your rights and freedoms with the + commands. +@end menu + + +@node Introduction +@chapter Introduction + +@menu +* GNU/Linux History:: A brief history of GNU/Linux. +* Purpose of this Document:: What this document is all about. +@end menu + + +@node GNU/Linux History +@section GNU/Linux History + +@menu +* GNU:: Presentation of the GNU project +* HURD:: Presentation of the HURD +* Linux:: Presentation of the kernel Linux +* Linux-libre:: Presentation of the kernel Linux-libre +* References:: Where to get more information +@end menu + +@node GNU +@subsection GNU + +@acronym{GNU} (GNU's Not Unix) is a project launched by Richard +Stallman in 1984 with the goal of building an entirely free operating +system compatible with Unix@footnote{See +@uref{http://en.wikipedia.org/wiki/Unix}}. ``Free'' here means ``free +as in freedom''. In this context, a free operating system is an +operating system you can use and share in freedom. A core part of his +motivation is given in the GNU +Manifesto@footnote{@uref{http://www.gnu.org/gnu/manifesto.html}}: + +@quotation +I consider that the Golden Rule requires that if I like a program I +must share it with other people who like it. Software sellers want to +divide the users and conquer them, making each user agree not to share +with others. I refuse to break solidarity with other users in this +way. I cannot in good conscience sign a nondisclosure agreement or a +software license agreement. For years I worked within the Artificial +Intelligence Lab to resist such tendencies and other inhospitalities, +but eventually they had gone too far: I could not remain in an +institution where such things are done for me against my will. + +So that I can continue to use computers without dishonor, I have +decided to put together a sufficient body of free software so that I +will be able to get along without any software that is not free. I +have resigned from the AI Lab to deny MIT any legal excuse to prevent +me from giving GNU away. +@end quotation + +A program is free software if the program's user has the four +essential freedoms: + +@itemize +@item +The freedom to run the program, for any purpose (freedom 0). + +@item +The freedom to study how the program works, and change it so it does +her computing as she wishes (freedom 1). Access to the source code is +a precondition for this. + +@item +The freedom to redistribute copies so she can help her neighbor +(freedom 2). + +@item +The freedom to distribute copies of her modified versions to others +(freedom 3). By doing this she can give the whole community a chance +to benefit from her changes. Access to the source code is a +precondition for this. +@end itemize + +One of the most popular free software license is the GNU General +Public License (GNU +GPL@footnote{@uref{http://www.gnu.org/licenses/gpl.html}}). + +The free software movement is supported by the Free Software +Foundation (FSF@footnote{@uref{http://www.fsf.org}}). + + +@node HURD +@subsection HURD + +The @acronym{HURD} is an acronym for @acronym{HIRD} (HURD of +interfaces representing depth) of Unix-replacing daemons. It is the +GNU project's replacement for the Unix kernel. It is a collection of +servers that run on the Mach microkernel to implement file systems, +network protocols, file access control, and other features that are +implemented by the Unix kernel or similar kernels (such as Linux). + +The purpose of the GNU HURD is to improve the user's freedom on her +operating system by allowing her to either add or remove a feature of +the kernel on the fly. + +From early on, the HURD was developed to use GNU Mach as the +microkernel. This was a technical decision made by Richard Stallman, +who thought it would speed up the work by saving a large part of +it. He has admitted that he was wrong about that. + +Nevertheless, development of the HURD is increasingly attracting +developers and GNU/HURD systems exist and are usable. + + +@node Linux +@subsection Linux + +Linux is a monolithic kernel created by Linus Torvalds in 1991. Linus +Torvalds initially wrote a terminal emulator, which he used to access +the large UNIX servers of his university. He wrote the program +specifically for the hardware he was using and independent of an +operating system because he wanted to use the functions of his new PC +with an 80386 processor. This later became the kernel Linux. + +Initially, Torvalds first published the kernel Linux under its own +licence, which had a restriction on commercial activity. + +In the notes for the first release of the kernel Linux, Torvalds lists +the GNU software that is required to run Linux: + +@quotation +Sadly, a kernel by itself gets you nowhere. To get a working system +you need a shell, compilers, a library etc. [...] Most of the tools +used with linux are GNU software and are under the GNU copyleft. +@end quotation + +In 1992, he suggested releasing the kernel under the GNU General +Public License. He first announced this decision in the release notes +of version 0.12. In the middle of December 1992 he published version +0.99 using the GNU GPL. + +The kernel Linux is now a contribution of many professionals and +volonteers around the world. + + +@node Linux-libre +@subsection Linux-libre + +Linux, the kernel developed and distributed by Linus Torvalds et al, +contains non-Free Software@footnote{For more information about the +presence of proprietary firmware in the kernel Linux, read +@uref{http://www.fsfla.org/ikiwiki/anuncio/2010-03-Linux-2.6.33-libre.en} +and +@uref{http://www.gnu.org/@/distros/free-system-distribution-guidelines.html#nonfree-firmware}.}, +i.e., software that does not respect your essential freedoms, and it +induces you to install additional non-Free Software that it doesn't +contain. + +GNU +Linux-libre@footnote{@uref{http://www.fsfla.org/ikiwiki/selibre/linux-libre/index.en.html}} +is a project to maintain and publish 100% Free distributions of Linux, +suitable for use in Free System Distributions@footnote{For a full list +of free as in freedom GNU/Linux distributions, see +@uref{http://www.gnu.org/distros/}.}, removing software that is +included without source code, with obfuscated or obscured source code, +under non-Free Software licenses, that do not permit you to change the +software so that it does what you wish, and that induces or requires +you to install additional pieces of non-Free Software. + + +@node References +@subsection References + +For more information on the GNU project and its relation with the +kernel Linux, you can read @uref{http://www.gnu.org/gnu/thegnuproject.html} +and @uref{http://www.gnu.org/gnu/gnu-linux-faq.html}. + +For more information on the history of the HURD, I recommend you to +read @uref{http://www.h-online.com/open/features/GNU-HURD-Altered-visions-and-lost-promise@/-1030942.html}. + +For more information on the HURD, read @uref{http://www.gnu.org/software/hurd/}. + +For more information on the early versions of the kernel Linux, read +@uref{https://www.cs.cmu.edu/~awb/linux.history.html}. + + +@node Purpose of this Document +@section Purpose of this Document + +One day I found a Dell Optiplex 745 minitower with a Pentium 4 CPU in +a municipal waste. I just replaced the button battery and the computer +was able to boot. I decided to adapt the work I did for the Lemote +Yeeloong 8133: GNU/Linux@footnote{Note: in this document, we use the +term ``GNU/Linux'' to name the entire system and ``Linux'' to name the +kernel. For more information, read +@uref{http://www.gnu.org/gnu/why-gnu-linux.html}.} Libre from Source +Code for Pentium 4 was born. + + +@node Prerequisites +@chapter Prerequisites + +@menu +* Definitions:: Definitions of important notions used to build the + system +* Commands:: Help on commands +@end menu + + +@node Definitions +@section Definitions + +@menu +* sysroot:: @option{sysroot} +* Toolchain:: What a Toolchain is. +* build host target:: Understanding the meaning of the + @option{build}-@option{host}-@option{target} + triplet. +* FHS:: The Filesystem Hierarchy Standard. +@end menu + + +@node sysroot +@subsection @option{sysroot} + +The traditional way of building a GNU/Linux operating system consists +on building a (cross-) compilation toolchain to build a temporary +operating system which in turn will be used to build the target +system@footnote{@pxref{Further Readings} for more details}. This +requires almost as much time to complete the temporary system as to +build the target one. Using sysroot resolves this problem. + +From GCC installation manual, under Cross-Compiler-Specific Options: + +@table @code +@item --with-sysroot +@itemx --with-sysroot=@var{dir} +Tells GCC to consider @var{dir} as the root of a tree that contains (a +subset of) the root filesystem of the target operating system. Target +system headers, libraries and run-time object files will be searched +in there. More specifically, this acts as if +@option{--sysroot=@var{dir}} was added to the default options of the +built compiler. The specified directory is not copied into the +install tree, unlike the options @option{--with-headers} and +@option{--with-libs} that this option obsoletes. The default value, +in case @option{--with-sysroot} is not given an argument, is +@option{$@{gcc_tooldir@}/sys-root}. If the specified directory is a +subdirectory of @option{$@{exec_prefix@}}, then it will be found +relative to the GCC binaries if the installation tree is moved. + +This option affects the system root for the compiler used to build +target libraries (which runs on the build system) and the compiler +newly installed with @code{make install}; it does not affect the +compiler which is used to build GCC itself. +@end table + + +@node Toolchain +@subsection Toolchain + +According to +Wikipedia@footnote{@uref{http://en.wikipedia.org/wiki/Toolchain}}: + +@quotation +In software, a toolchain is the set of programming tools that are used +to create a product (typically another computer program or system of +programs). The tools may be used in a chain, so that the output of +each tool becomes the input for the next, but the term is used widely +to refer to any set of linked development tools. + +A simple software development toolchain consists of a text editor for +editing source code, a compiler and linker to transform the source +code into an executable program, libraries to provide interfaces to +the operating system, and a debugger. +@end quotation + + +@node build host target +@subsection @option{build}, @option{host} and @option{target} + +During a cross-compilation, @option{build} @option{host} and +@option{target} are among the most used options: understanding the +precise meaning of those parameters is very important. We could define +them thus: + +@itemize +@item @option{--build=@var{platform on which the program is +compiled}}, +@item @option{--host=@var{platform on which the program will run}}, +@item @option{--target=@var{platform for which the program will create +output}}. +@end itemize + +Let's use GCC as an example to explain the role of those three +parameters. + +During GCC compilation, we use: + +@samp{./configure --build=@var{build-platform} +--host=@var{host-platform} --target=@var{target-platform} [various +compilation parameters]} + +So in those configuration parameters: + +@itemize +@item +@option{--build} provides the name of the platform currently running. +If we were using an Intel Pentium processor to compile the system, our +@var{build-platform} would be something like @samp{i686-pc-linux-gnu}. + +If this parameter is not specified, it will be guessed automatically. + +@item +@option{--host} represents the type of machine we are going to run GCC +on after the compilation succeeds. During a cross-compilation this has +to be specified, because the current machine can not know which +architecture we wish to target. We want to produce executables to run +on @emph{Pentium4}, but there is currently no way we can specify +@samp{Pentium4} directly; because of this we specify +@samp{i386-unknown-linux-gnu}. + +@option{--host} can also be left unspecified, in that case, +@var{host-platform} would automatically define itself as +@var{build-platform}, but this is not cross-compilation anymore. + +@quotation Note +when @option{--build} and @option{--host} are different, configuration +files will maintain the cross-compilation mode. +@end quotation + +@item +@option{--target} defines the system for which compiler tools will +create output. + +@var{target-platform} parameter is useful only for a limited number of +programs. Although this parameter is often present when issuing +@samp{./configure --help}, hardly any packages will need it. + +This parameter is only useful for performing tasks with different +platforms; for instance, executable files compiled for different +platforms can have a totally different code. +@end itemize + +If we summarize, we have: + +@itemize +@item @var{build-platform}: automatically guessed from platform in +use; has to be specified if not guessed. + +@item @var{host-platform}: if unspecified, automatically equals +@var{build-platform}. When @var{build-platform} and +@var{host-platform} values are identical, it is a local compilation; +otherwise it is a cross-compilation. + +@item @var{target-platform}: defines the system for which compiler +tools will create output; it equals @var{host-platform} if +unspecified. GCC, binutils, and programs related to the platform's +instructions have this parameter; most programs do not use this +parameter. +@end itemize + + +@node FHS +@subsection FHS + +The Filesystem Hierarchy Standard (FHS) has been created to specify +the location and use of main directories on a GNU/Linux operating +system. Common commands, user data, libraries have to be put inside a +specific directory given in the standard. During the build process, +some commands are used to comply with FHS. + + +@node Commands +@section Commands + +Because most commands are common for a regular Unix user, only +uncommon commands are explained in this document. If you do not +understand a command that is not explained, you can use the +documentation available on your computer; in a terminal, typing +@samp{man @var{command}} should give you enough information. For GNU +software, @samp{info @var{package}} can also give additional +information. + +To know more about command line, I suggest you read "Introduction to +the Command Line" which is available on +@uref{http://flossmanuals.net/command-line/}. + + +@node Preliminary Work +@chapter Preliminary Work + +@quotation Important +In order to complete the first steps of this chapter, you will need to +have root permissions. +@end quotation + +@menu +* Build Partition Creation:: Creating a partition for the build. +* Build User Creation:: Creating a user account dedicated to + the build. +* Work Directory Creation:: Creating the parent directory for the + build. +* Partition Mount:: Mounting the partition dedicated to the + build. +* Useful Directories Creation:: Creating the directories for downloads + and compilations. +* User Switch:: Switching to the user dedicated to the + build. +* Environment Variables Setup:: Setting up the environment variables + of the target system. +* Downloads:: Downloading needed packages and + patches. +* Final Preparations:: Preparing the system for the build. +@end menu + + +@node Build Partition Creation +@section Build Partition Creation + +To dedicate the partition @file{/dev/sda1} to the system build, and to +define the filesystem to be used for it as @samp{ext3}: + +@verbatim +mke2fs -t ext3 /dev/sda1 +@end verbatim + +Option @option{-t} is followed by the type of filesystem to be +used. The filesystem @samp{ext3} is used as it is one of the most +common filesystem used with the kernel Linux. + + +@node Build User Creation +@section Build User Creation + +To create the builder group, user and password: + +@verbatim +groupadd gllfsc +useradd -s /bin/bash -g gllfsc -m -k /dev/null gllfsc +passwd gllfsc +@end verbatim + +@itemize +@item +Option @option{-s} (or @option{--shell}) is used to define the created +user's default shell, here @file{/bin/bash}. + +@item +Option @option{-g} (or @option{--gid}) is used to define the group +name or number of the created user's initial login group, here +@samp{gllfsc}. + +@item +Option @option{-m} (or @option{--create-home}) does create the user's +home directory if it does not exist (@file{/home/@var{username}}). + +@item +Option @option{-k} (or @option{--skel}) is used to define the skeleton +directory to be copied in the user's home directory, here +@file{/dev/null}. @file{/dev/null} is a special file which, in this +case, will give no skeleton at all to @command{useradd}. +@end itemize + + +@node Work Directory Creation +@section Work Directory Creation + +To create the directory @file{/gllfsc} in which the system will be +built: + +@verbatim +export TARGET_DIR="/gllfsc" +mkdir -pv ${TARGET_DIR} +@end verbatim + +@samp{export TARGET_DIR="/gllfsc"} sets the value of the variable +@env{TARGET_DIR} to @file{/gllfsc}, the directory in which the system +will be built. + + +@node Partition Mount +@section Mounting Partition + +To mount the hard drive partition, for instance @file{/dev/sda1}, used +to build the system: + +@verbatim +mount /dev/sda1 ${TARGET_DIR} +@end verbatim + + +@node Useful Directories Creation +@section Creating Compilation and Download Directories + +@verbatim +mkdir -pv ${TARGET_DIR}/{build,download} +chown -Rv gllfsc ${TARGET_DIR} +@end verbatim + + +@node User Switch +@section Switching to the Build User + +To login as the user that will build the system: + +@verbatim +su - gllfsc +@end verbatim + +With the command @command{su}, it is possible to change the user +ID. The option @option{-} provides an environment similar to what the +user would expect had the user logged in directly. + + +@node Environment Variables Setup +@section Setting up Required Environment Variables + +@file{~/.bash_profile} is a personal initialization file that is read +when Bash is invoked as an interactive login shell (@file{~} is the +location of the user's home directory). To write the content of the +file @file{~/.bash_profile}: + +@verbatim +cat > ~/.bash_profile << 'EOF' +exec env -i HOME=${HOME} TERM=${TERM} PS1=${PS1} /bin/bash +EOF +@end verbatim + +The first line creates the file @file{~/.bash_profile} and opens it +for writing until @samp{@acronym{EOF}} (End Of File) is written in it. + +The second line tells Bash to execute @file{/bin/bash} with the option +@option{-i} (or @option{--ignore-environment}) which will make Bash +start with an empty environment. Variables @env{HOME}, @env{TERM} and +@env{PS1} define respectively the home directory of the current user, +the terminal used and the primary prompt string displayed. + +@file{~/.bashrc} is a personal initialization file that is read when +Bash is invoked as an interactive shell but not a login one. To write +the content of the file @file{~/.bashrc}: + +@verbatim +export TARGET_DIR=/gllfsc +cat > ~/.bashrc << EOF +set +h +umask 022 +#alias make='make -j5' +export PS1='\[\e[35m\]\A-\W\[\e[00m\]$ ' +export LC_ALL=POSIX +export TARGET_DIR=/gllfsc +export BUILD_DIR="${TARGET_DIR}/build" +export DOWNLOAD_DIR="${TARGET_DIR}/download" +export CROSS_HOST="$(echo $MACHTYPE |\ + sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")" +export CROSS_TARGET="i686-unknown-linux-gnu" +#export MABI="n32" +#export MABI="64" +export MARCH="pentium4" +export PATH=${TARGET_DIR}/cross-tools/bin:/bin:/usr/bin +unset CFLAGS +unset CXXFLAGS +EOF +source ~/.bash_profile +@end verbatim + +@samp{set +h} tells Bash to not locate nor remember commands (hash) as +they are looked up for execution. + +@samp{umask 022} sets Bash process' file creation mask to +@samp{022}. This results in permissions of `755' for those files. + +@samp{alias make='make -j5'} tells Bash to replace every call of +@samp{make} by @samp{make -j5}. This is useful for multiple-cores CPUs +as it parallelizes tasks. + +@samp{export PS1='\[\e[35m\]\A-\W\[\e[00m\]$ '} sets the primary +prompt strings. The primary prompt strings are the strings you see +before the commands you type in the terminal. The part @samp{\A-\W} +means that the time, in 24-hour HH:MM format and the basename of +@env{$PWD} will be displayed separated by a `-', as in +@samp{19:33-bin}. The part @samp{\$} adds a dollar sign at the end, +@samp{\[\e[35m\]} colors the strings in purple and @samp{\[\e[00m\]} +gets the original color back. For other colors, you can browse +@uref{http://en.wikipedia.org/wiki/ANSI_escape_code}. + +@env{LC_ALL} is a macro used to define a single locale to overwrite +other @env{LC_*} and @env{LANG} environment variables so that +language, numeric values, time and other locale-dependant values have +all the same value. It is set to the standard POSIX locale. + +@samp{export BUILD_DIR="$@{TARGET_DIR@}/build"} sets the environment +variable @env{BUILD_DIR} to the value of @samp{$@{TARGET_DIR@}/build} +which is @samp{/gllfsc/build} in this document. + +The value of variable @env{CROSS_HOST} equals the value of variable +@env{MACHTYPE} of the current machine (for instance +@samp{i686-pc-linux-gnu}) modulo the second word, which is replaced by +@samp{cross} (i.e. @samp{i486-cross-linux-gnu}). + +The value of variable @env{CROSS_TARGET} equals the value of variable +@env{MACHTYPE} of the machine for which the system is built (i.e. +@samp{i686-unknown-linux-gnu}). + +The variable @env{MABI} defines the @acronym{ABI} (Application Binary +Interface) for which the system will be built. @option{-mabi} is an +option of GCC. n32/64 are for 64-bit CPUs only. 64 has 64-bit pointers +and long integers, whereas n32 has 32-bit pointers and long integers. +This does not apply to pentium 4 machines. + +The variable @env{MARCH} defines the architecture for which the system +will be built. @option{-march} is an option of @acronym{GCC} (GNU +Compiler Collection). + +The variable @env{PATH} contains a colon-separated list of directories +in which the shell looks for commands. The shell will first look for +commands in @file{$@{TARGET_DIR@}/cross-tools/bin}, then, if the +command was not found, in @file{/bin} and finally in @file{/usr/bin}. + +@command{unset} command removes the variable associated, here +@env{CFLAGS} and @env{CXXFLAGS}. Those variables are used by GCC as +extra flags given to the C compiler and the C++ compiler +respectively. + +Finally @samp{source ~/.bash_profile} reads and executes the content +of the file @file{~/.bash_profile}. + + +@node Downloads +@section Downloads + +@menu +* Packages Download:: List of packages to be downloaded. +* Patches Download:: List of patches to be downloaded. +@end menu + + +@node Packages Download +@subsection Downloading Packages + +The packages listed below are those used in this document. You can try +other versions but you will need a recent version of Binutils, GCC and +the kernel Linux in order to build GLLFSC. + +Download those files under @env{$@{DOWNLOAD_DIR@}} (which is +@file{/gllfsc/download} in this document). + +@quotation Note +If you have trouble with a savannah mirror, you can have a full list +of them at @uref{http://download.savannah.gnu.org/mirmon/savannah/}. +If you have trouble with a GNU mirror, you can have a full list +of them at @uref{http://www.gnu.org/prep/ftp.html}. +@end quotation + +@itemize +@item +Autoconf: @uref{http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz}. + +@item +Automake: @uref{http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz}. + +@item +Bash: @uref{http://ftpmirror.gnu.org/bash/bash-4.2.tar.gz}. + +@item +Binutils: @uref{http://ftpmirror.gnu.org/binutils/binutils-2.24.tar.bz2}. + +@item +Bison: @uref{http://ftpmirror.gnu.org/bison/bison-2.7.tar.gz}. + +@item +Bootscripts: @uref{http://ftp.clfs.org/pub/clfs/conglomeration/bootscripts@/-cross@/-lfs/@/bootscripts-cross-lfs-2.0.0.tar.xz}. + +@item +Bzip2: @uref{http://downloads.sourceforge.net/bzip2/bzip2-1.0.6.tar.gz}. + +@item +CA-Certificates: @uref{http://anduin.linuxfromscratch.org/sources/other/certdata.txt}. + +@item +Coreutils: @uref{http://ftpmirror.gnu.org/coreutils/coreutils-8.19.tar.xz}. + +@item +DHCPCD: @uref{https://roy.marples.name/downloads/dhcpcd/dhcpcd-6.1.0.tar.bz2}. + +@item +Diffutils: @uref{http://ftpmirror.gnu.org/diffutils/diffutils-3.3.tar.xz}. + +@item +E2fsprogs: @uref{http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.42.8.tar@/.gz}. + +@item +File: @uref{ftp://ftp.astron.com/pub/file/file-5.16.tar.gz}. + +@item +Findutils: @uref{http://ftpmirror.gnu.org/findutils/findutils-4.4.2.tar.gz}. + +@item +Flex: @uref{http://downloads.sourceforge.net/flex/flex-2.5.37.tar.bz2}. + +@item +Gawk: @uref{http://ftpmirror.gnu.org/gawk/gawk-4.1.0.tar.gz}. + +@item +GCC: @uref{http://ftpmirror.gnu.org/gcc/gcc-4.7.3/gcc-4.7.3.tar.bz2}. + +@item +Gdbm: @uref{http://ftp.gnu.org/gnu/gdbm/gdbm-1.11.tar.gz}. + +@item +Gettext: @uref{http://ftpmirror.gnu.org/gettext/gettext-0.18.3.1.tar.gz}. + +@item +Glibc: @uref{http://ftpmirror.gnu.org/glibc/glibc-2.18.tar.bz2}. + +@item +Gmp: @uref{http://ftpmirror.gnu.org/gmp/gmp-5.1.3.tar.bz2}. + +@item +Grep: @uref{http://ftpmirror.gnu.org/grep/grep-2.15.tar.xz}. + +@item +Groff: @uref{http://ftpmirror.gnu.org/groff/groff-1.22.2.tar.gz}. + +@item +GRUB: @uref{http://ftpmirror.gnu.org/grub/grub-2.00.tar.gz}. + +@item +Gzip: @uref{http://ftpmirror.gnu.org/gzip/gzip-1.6.tar.gz}. + +@item +Iana-Etc: @uref{http://sethwklein.net/iana-etc-2.30.tar.bz2}. + +@item +Inetutils: @uref{http://ftpmirror.gnu.org/inetutils/inetutils-1.9.1.tar.gz}. + +@item +Iproute2: @uref{https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.10.0@/.tar.bz2}. + +@item +Kbd: @uref{http://ftp.altlinux.org/pub/people/legion/kbd/kbd-2.0.1.tar.gz}. + +@item +Kmod: @uref{https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-15.tar.gz}. + +@item +Less: @uref{http://www.greenwoodsoftware.com/less/less-458.tar.gz}. + +@item +Libpipeline: @uref{http://download.savannah.gnu.org/releases/libpipeline/@/libpipeline-1.3.0.tar.gz}. + +@item +Libtasn1: @uref{http://ftpmirror.gnu.org/libtasn1/libtasn1-3.4.tar.gz}. + +@item +Libtool: @uref{http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz}. + +@item +Linux-Libre @footnote{The kernel Linux is shipped with proprietary +firmware. The version called Linux-Libre exists without them, it is +available for download at +@uref{http://www.fsfla.org/ikiwiki/selibre/linux-libre/}.}. +@uref{http://linux-libre.fsfla.org/pub/linux-libre/releases/3.10-gnu/@/linux-libre-3.10-gnu.tar.xz}. + +@item +Lynx: @uref{http://invisible-mirror.net/archives/lynx/tarballs/lynx2.8.8dev.16.tar@/.bz2}. + +@item +M4: @uref{http://ftpmirror.gnu.org/m4/m4-1.4.17.tar.bz2}. + +@item +Make: @uref{http://ftpmirror.gnu.org/make/make-4.0.tar.bz2}. + +@item +Man-db: @uref{http://download.savannah.gnu.org/releases/man-db/man-db-2.6.7.1.tar@/.xz}. + +@item +Man-Pages: @uref{https://www.kernel.org/pub/linux/docs/man-pages/Archive/man-pages-@/3.54.tar.bz2}. + +@item +Mpc: @uref{http://ftpmirror.gnu.org/mpc/mpc-1.0.1.tar.gz}. + +@item +Mpfr: @uref{http://ftpmirror.gnu.org/mpfr/mpfr-3.1.2.tar.bz2}. + +@item +Nano: @uref{http://ftpmirror.gnu.org/nano/nano-2.3.2.tar.gz}. + +@item +Ncurses: @uref{http://ftpmirror.gnu.org/ncurses/ncurses-5.9.tar.gz}. + +@item +Openssl: @uref{ftp://ftp.openssl.org/source/old/1.0.1/openssl-1.0.1i.tar.gz}. + +@item +Patch: @uref{http://ftpmirror.gnu.org/patch/patch-2.7.1.tar.bz2}. + +@item +Perl: @uref{http://www.cpan.org/src/5.0/perl-5.18.1.tar.gz}. + +@item +Procps: @uref{http://procps.sourceforge.net/procps-3.2.8.tar.gz}. + +@item +Psmisc: @uref{https://sourceforge.net/projects/psmisc/files/psmisc/psmisc-22.20.tar@/.gz}. + +@item +Readline: @uref{http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz}. + +@item +Runit: @uref{http://smarden.org/runit/runit-2.1.2.tar.gz} + +@item +Sed: @uref{http://ftpmirror.gnu.org/sed/sed-4.2.2.tar.bz2}. + +@item +Shadow: @uref{https://src.fedoraproject.org/repo/pkgs/shadow-utils/shadow-4.1.4.3@/.tar.bz2/b8608d8294ac88974f27b20f991c0e79/shadow-4.1.4.3.tar.bz2}. + +@item +Sysvinit: @uref{http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf@/.tar.bz2}. + +@item +Tar: @uref{http://ftpmirror.gnu.org/tar/tar-1.27.1.tar.bz2}. + +@item +Texinfo: @uref{http://ftpmirror.gnu.org/texinfo/texinfo-4.13a.tar.gz}. + +@item +Tzcode: @uref{http://www.iana.org/time-zones/repository/releases/tzcode2013h.tar@/.gz}. + +@item +Tzdata: @uref{http://www.iana.org/time-zones/repository/releases/tzdata2013h.tar@/.gz}. + +@item +Udev: @uref{https://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-175.tar.gz}. + +@item +Util-Linux: @uref{https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-@/linux-2.24.tar.bz2}. + +@item +Wireless_tools: @uref{http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz}. + +@item +Wpa_supplicant: @uref{http://w1.fi/releases/wpa_supplicant-2.0.tar.gz}. + +@item +Wget: @uref{http://ftpmirror.gnu.org/wget/wget-1.14.tar.gz}. + +@item +XZ-Utils: @uref{https://tukaani.org/xz/xz-5.0.8.tar.bz2}. + +@item +Zlib: @uref{http://www.zlib.net/fossils/zlib-1.2.8.tar.gz}. +@end itemize + + +@node Patches Download +@subsection Downloading Patches + +Patches and configuration files location: + +@itemize +@item +@uref{http://cjarry.org/gnu-linux/gllfsc/pentium4/gllfsc-pentium4-1.7-patches@/.tar.gz}. After +having downloaded this file under @env{$@{DOWNLOAD_DIR@}}, execute +the following commands to extract its content: + +@verbatim +cd ${DOWNLOAD_DIR} +tar xvf gllfsc-pentium4-1.7-patches.tar.gz +cd +@end verbatim + +@ignore +@item +The page +@uref{http://dev.lemote.com/cgit/linux-official.git/commit/?h=linux-3.6@/&id=94fe1f0a7d2e3042fa7fadfd15da71b9d0c11809} +describes the changes to be made to the kernel in order to add support +for Chinese fonts in console. The patch applies to Linux 3.6. +Be aware though that applying this patch to the kernel may make +characters that are both non-@acronym{CJK} (Chinese Japanese Korean) +and non-ASCII unreadable (accented letters, cyrillic, etc.). + +@item +The page +@uref{http://microcai.gsalex.net/old/archives/2011/01/fbcon_UNICODE_font_support.html} +is useful for users who want support for @acronym{CJK} (Chinese +Japanese Korean) characters under the (non-graphical) terminal. It +gives access to a git@footnote{@uref{http://git-scm.com/}} repository +with kernel patches@footnote{The patches to use with version 3.5 of +the kernel are the first four on +@uref{http://repo.or.cz/w/linux-2.6/cjktty.git/shortlog/refs/heads/3.5-utf8}.} +that permit direct rendering of UTF-8 characters under the framebuffer +environment. Be aware though that applying those CJK patches to the +kernel may make characters that are both non-CJK and non-ASCII +unreadable (accented letters, cyrillic, etc.). +@end ignore + +@item +@uref{http://www.fsfla.org/svn/fsfla/software/linux-libre/lemote/gnewsense/tags/@/2.6.36-libre-lemote_0lxo/100gnu+freedo.patch} +this patch adds a picture of a GNU beside Freedo, Freedo being the +mascot of Linux-Libre. The image can be seen on +@uref{http://www.fsfla.org/ikiwiki/selibre/linux-libre/100gnu+freedo}. + +@item +@uref{http://linux-libre.fsfla.org/pub/linux-libre/releases/3.10.7-gnu/patch-3.10-@/gnu-3.10.7-gnu.xz} +this patch updates linux-libre-3.10 to linux-libre-3.10.7. +@end itemize + + +@node Final Preparations +@section Final Preparations + +@menu +* Target Filesystem Hierarchy Creation:: Creating the directories of + the target system. +* Needed Files Creation:: Creating files for needed + user, groups and log. +@end menu + + +@node Target Filesystem Hierarchy Creation +@subsection Target Filesystem Hierarchy Creation + +@verbatim +cd ${TARGET_DIR} + +# /usr is required for cmake, python and ruby at least +mkdir -v usr +cd usr +mkdir -v bin include lib share src +ln -sv bin sbin +ln -sv lib lib32 +ln -sv lib lib64 +cd .. + +mkdir -v boot dev etc home local mnt proc root run static sys var +mkdir -v cross-tools libexec + +ln -sv usr/bin bin +ln -sv usr/bin sbin +ln -sv usr/include include +ln -sv usr/lib lib +ln -sv usr/lib lib32 +ln -sv usr/lib lib64 +ln -sv usr/share share +ln -sv usr/src src +install -dv -m 0777 tmp + +install -dv -m 1777 var +cd var +mkdir -v cache local lock log mail run spool +mkdir -pv lib/misc lib/locate +cd .. + +install -dv -m 0750 root + +cd local +mkdir -v bin include lib src +ln -sv bin sbin +ln -sv lib lib32 +mkdir -v share +cd share +mkdir -v doc info locale man misc terminfo zoneinfo +mkdir -v man/man{1..8} +cd ../.. +ln -sv share/man man +cd +@end verbatim + +The command @samp{install -dv -m 1777 var} creates the directory +@file{var} with the permissions to read, write and execute for +everyone. The '1' in @samp{1777} is the sticky bit which allows +deletion of the file or directory having this attribute only for the +owner of the file or directory. + +The command @samp{ln -svf lib lib64} creates a symbolic link (option +@option{-s}) with the name @file{lib64} which will point to +@file{lib}. + + +@node Needed Files Creation +@subsection Creating needed user, groups and log files + +@verbatim +cat > ${TARGET_DIR}/etc/passwd << EOF +root::0:0:root:/root:/bin/bash +EOF +@end verbatim + +The file @file{/etc/passwd} contains one line for each user account, +with seven fields delimited by colons. These fields are: + +@itemize +@item +login name; + +@item +optional encrypted password; + +@item +numerical user ID; + +@item +numerical group ID; + +@item +user name or comment field; + +@item +user home directory; + +@item +optional user command interpreter. +@end itemize + + +@verbatim +cat > ${TARGET_DIR}/etc/group << EOF +root:x:0: +bin:x:1: +sys:x:2: +kmem:x:3: +tty:x:4: +tape:x:5: +daemon:x:6: +floppy:x:7: +disk:x:8: +lp:x:9: +dialout:x:10: +audio:x:11: +video:x:12: +utmp:x:13: +usb:x:14: +cdrom:x:15: +EOF +@end verbatim + +The file @file{/etc/group} is a text file which defines the groups on +the system. There is one entry per line, with the following format: +@samp{group_name:password:GID:user_list}. + + +@verbatim +touch ${TARGET_DIR}/var/run/utmp \ + ${TARGET_DIR}/var/log/{btmp,lastlog,wtmp} +chmod -v 664 ${TARGET_DIR}/var/run/utmp \ + ${TARGET_DIR}/var/log/lastlog +@end verbatim + + +@node Building the Cross-Compilation Toolchain +@chapter Building the Cross-Compilation Toolchain + +In this chapter, the cross-compilation toolchain is built as well as +core components of the target system. Those will then be used to build +the target system. + +@menu +* Target Linux-Header:: Linux-Header for target system. +* Cross Binutils:: Binutils for cross-compilation. +* Cross GCC:: GCC for cross-compilation (C support only). +* Target glibc:: glibc for target system. +* Cross GCC CXX:: GCC for cross-compilation (C and C++ support). +@end menu + + +@node Target Linux-Header +@section Target Linux-Header + +In this document, the kernel used is version 3.10.7 of Linux-libre. I +stick to this version because some changes made in the kernel since +3.14 require the non-free firmware of the radeon driver earlier at +boot: without the firmware, the screen will remain blank on a machine +that requires it, making the computer unusable.@footnote{See +@uref{https://bugzilla.kernel.org/show_bug.cgi?id=77861} for details.} +I think version 3.10.7 of Linux-libre is usable on such a machine +without the non-free firmware of the radeon driver. + +You need Patch, Make and GCC on your system to compile this program +from source. Under gNewSense 4.0, try @samp{sudo apt-get install patch +make gcc-4.4} and then @samp{sudo ln -sv gcc-4.4 /usr/bin/gcc}. + +@verbatim +# 14 minutes mostly to compress the kernel with xz +cd ${BUILD_DIR} + +tar xf ${DOWNLOAD_DIR}/linux-libre-3.10-gnu.tar.xz \ + -C ${BUILD_DIR} +cd ${BUILD_DIR}/linux-3.10 +unxz ${DOWNLOAD_DIR}/patch-3.10-gnu-3.10.7-gnu.xz +patch -Np1 -i ${DOWNLOAD_DIR}/patch-3.10-gnu-3.10.7-gnu +cd .. + +# About 2 minutes for the following command (490 MB) +tar -cf linux-libre-3.10.7-gnu.tar linux-3.10 + +# About 12 minutes for the following command (68 MB) +# (requires ~800 MB of RAM) +xz -9 linux-libre-3.10.7-gnu.tar + +mv linux-libre-3.10.7-gnu.tar.xz ${DOWNLOAD_DIR} + +cd linux-3.10 + +make mrproper +make ARCH=i386 headers_check +make ARCH=i386 INSTALL_HDR_PATH=dest headers_install +cp -rv dest/include/* ${TARGET_DIR}/include +cd .. +rm -rf linux-3.10 +cd +@end verbatim + +@samp{14 minutes} is the time it takes to build the package on Dell +Optiplex 745 with a Pentium 4 processor. + +The command @samp{make mrproper} cleans the sources. + +We need to specify @samp{ARCH=i386} as we are cross-compiling. + + +@node Cross Binutils +@section Cross Binutils + +GNU Binutils (GNU binary utilities) is a collection of programs for +manipulating binaries. + +@verbatim +# 4 minutes +tar xf ${DOWNLOAD_DIR}/binutils-2.24.tar.bz2 -C ${BUILD_DIR} +cd $BUILD_DIR/binutils-2.24 +mkdir -pv ../binutils-build +cd ../binutils-build +CC="gcc" AR="ar" \ + ../binutils-2.24/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --enable-64-bit-bfd \ + --with-sysroot=${TARGET_DIR} \ + --disable-nls \ + --enable-shared +make configure-host +make +make install +cp -v ../binutils-2.24/include/libiberty.h \ + ${TARGET_DIR}/include +cd .. +rm -rf binutils-build +rm -rf binutils-2.24 +cd +@end verbatim + +@samp{CC="gcc"} and @samp{AR="ar"} are flags that tell the +@file{configure} script to use the local commands @command{gcc} as the +C compiler and @command{ar} as the program that handles archives. + +@option{--prefix=$@{TARGET_DIR@}/cross-tools} tells the configure +script to install architecture-independant files in +@file{$@{TARGET_DIR@}/cross-tools}. + +The option @option{--enable-64-bit-bfd} enables 64 bit for +@acronym{BFD} (the Binary File Descriptor). + +@option{--with-sysroot=@env{$@{TARGET_DIR@}}} tells Binutils to +consider @env{$@{TARGET_DIR@}} as the root of a tree that contains (a +subset of) the root filesystem of the target operating system. Target +system headers, libraries and run-time object files will be searched +in there. + +The @option{--enable-nls} option enables Native Language Support +(NLS), which lets Binutils output diagnostics in languages other than +American English. Native Language Support is enabled by default if not +doing a canadian cross build. The @option{--disable-nls} option +disables NLS. + +The option @option{--enable-shared} is used to build shared versions +of libraries, if shared libraries are supported on the target +platform. Use @option{--disable-shared} to build only static +libraries. + +@c cp -v ../binutils-2.22/include/libiberty.h \ +@c ${TARGET_DIR}/include + + +@node Cross GCC +@section Cross GCC (C support only) + +GCC is the GNU compiler collection. It can compile many languages, of +which only C and C++ will be enabled in this document. + +In this section, we build a minimal GCC in order to build glibc. + +@quotation Warning +to build GMP (a GCC dependency), you need a version of GCC different +from 4.3.2 on your system@footnote{@uref{https://gmplib.org/#STATUS}}: +@end quotation + +@quotation +GCC 4.3.2 miscompiles GMP on 64-bit machines; please use a different +gcc version (e.g., gcc 4.3.1 and gcc 4.3.3 both work properly). We +have not been able to find any workaround for this gcc bug. +Unfortunately, Debian 5.0 has decided to stay with this trouble gcc +version, resulting in that many users strike this bug. +@end quotation + +I recommend installing @samp{gcc-4.4} on gNewSense 4.0 to avoid this +issue. + +@verbatim +# 20 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/gcc-4.7.3 +tar xf ${DOWNLOAD_DIR}/gmp-5.1.3.tar.bz2 +mv gmp-5.1.3 gmp +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz +mv mpc-1.0.1 mpc +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2 +mv mpfr-3.1.2 mpfr +# Fix undefined reference to `__stack_check_guard' when compiling glibc: +sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure +mkdir -pv ../gcc-build +cd ../gcc-build +../gcc-4.7.3/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --with-sysroot=${TARGET_DIR} \ + --disable-multilib \ + --with-newlib \ + --disable-nls \ + --disable-shared \ + --disable-threads \ + --enable-languages=c \ + --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \ + --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs" \ + --disable-decimal-float +# fixes bid_decimal_globals: fenv.h: No such file or directory + +make all-gcc +make all-target-libgcc +make install-gcc +make install-target-libgcc +cd .. +rm -r gcc-build +rm -r gcc-4.7.3 +cd +@end verbatim + +@option{--disable-multilib} specifies that multiple target libraries +to support different target variants@footnote{Such as different ABI, +for instance n32 and 64.}, calling conventions, etc@:. should not be +built. The default is to build a predefined set of them. + +@option{--with-newlib} specifies that @samp{newlib} is being used as +the target C library. + +@option{--disable-threads} specifies that threading support should be +disabled. + +@option{--enable-languages=c} specifies that only the C compiler and +its runtime libraries should be built. + +@c --with-abi=${MABI} + +@c --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \ +@c --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs" +@c to avoid error: libmpfr not found or uses a different ABI (including static vs shared). + +GCC provides a low-level runtime library, @file{libgcc.a} or +@file{libgcc_s.so.1} on some platforms. GCC generates calls to +routines in this library automatically, whenever it needs to perform +some operation that is too complicated to emit inline code for. This +is built with @samp{make all-target-libgcc} and installed with +@samp{make install-target-libgcc} + + +@node Target glibc +@section Target glibc + +Glibc is the GNU C library. It provides macros, type definitions, and +functions for tasks like string handling, mathematical computations, +input/output processing, memory allocation and several other operating +system services. + +You need Gawk on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install gawk}. + +@verbatim +# 20 minutes +tar xf ${DOWNLOAD_DIR}/glibc-2.18.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/glibc-2.18 +sed -i.orig '4775s/3.79\* | 3.\[89\]\*/& | 4.0/' configure +sed -i.orig "s/ -lgcc_eh\| -lgcc_s//g" Makeconfig +#echo "" > ports/sysdeps/mips/mips64/n64/Makefile +#echo "" > ports/sysdeps/mips/mips64/n32/Makefile +#echo "" > ports/sysdeps/mips/mips32/Makefile +#sed -i "/default) machine=/s/n32/${MABI}/g" \ +# ports/sysdeps/mips/preconfigure +mkdir -pv ../glibc-build +cd ../glibc-build + +cat > config.cache << EOF +libc_cv_c_cleanup=yes +libc_cv_slibdir=/lib +EOF + +cat > configparms << EOF +install_root=${TARGET_DIR} +libdir=/lib +EOF + +BUILD_CC="gcc" \ + CC="${CROSS_TARGET}-gcc -march=${MARCH}" \ + AR="${CROSS_TARGET}-ar" \ + RANLIB="${CROSS_TARGET}-ranlib" \ + ../glibc-2.18/configure \ + --prefix= \ + --libexecdir=/lib/glibc \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --disable-profile \ + --enable-add-ons \ + --with-tls \ + --enable-kernel=3.10 \ + --with-__thread \ + --with-binutils=${TARGET_DIR}/cross-tools/bin \ + --with-headers=${TARGET_DIR}/include \ + --enable-obsolete-rpc \ + --cache-file=config.cache + +make + +make install + +cd .. +rm -rf glibc-build +rm -rf glibc-2.18 +cd + +cat > ${TARGET_DIR}/etc/nsswitch.conf << EOF +# Begin /etc/nsswitch.conf + +passwd: files +group: files +shadow: files + +hosts: files dns +networks: files + +protocols: files +services: files +ethers: files +rpc: files + +# End /etc/nsswitch.conf +EOF + +cat > ${TARGET_DIR}/etc/ld.so.conf << EOF +# Begin /etc/ld.so.conf + +/local/lib + +# End /etc/ld.so.conf +EOF +@end verbatim + +@c @samp{sed -i.orig "s/\ -lgcc_eh\|\ -lgcc_s//g" Makeconfig} + +@c Glibc uses @samp{n32} ABI by default with MIPS. To use @env{MABI} +@c instead, we do the following: +@c +@c @verbatim +@c echo "" > ports/sysdeps/mips/mips64/n64/Makefile +@c echo "" > ports/sysdeps/mips/mips64/n32/Makefile +@c echo "" > ports/sysdeps/mips/mips32/Makefile +@c sed -i "/default) machine=/s/n32/${MABI}/g" \ +@c ports/sysdeps/mips/preconfigure +@c @end verbatim + +@ignore +Contents of the files above. + +cat mips64/n64/Makefile +# `long double' is a distinct type we support. +long-double-fcts = yes + +ifeq ($(filter -mabi=64,$(CC)),) +CC += -mabi=64 +endif + +cat mips64/n32/Makefile +# `long double' is a distinct type we support. +long-double-fcts = yes + +ifeq ($(filter -mabi=n32,$(CC)),) +CC += -mabi=n32 +endif + +cat mips32/Makefile +ifeq ($(filter -mabi=32,$(CC)),) +CC += -mabi=32 +endif + +grep 'default)' preconfigure + + default) machine=mips/mips64/n32 mips_config_abi=n32 ;; + +@end ignore + +The file @file{config.cache} is used to attribute values to variables +of the configure script. + +@samp{libc_cv_forced_unwind=yes} is used to avoid the error message +@samp{error: forced unwind support is required}. + +@samp{libc_cv_c_cleanup=yes} is used to avoid the error message +@samp{error: the compiler must support C cleanup handling}. + +@samp{libc_cv_slibdir=/lib} defines @file{/lib} as the directory in +which the C library of the target system will be installed, instead of +@file{/lib64} or @file{/lib32}. + +You can install glibc somewhere other than where you configured it to +go by setting the @code{install_root} variable on the command line for +@samp{make install}. The value of this variable is prepended to all +the paths for installation. This is useful when setting up a chroot +environment or preparing a binary distribution. The directory should +be specified with an absolute file name. + +Files listed in @samp{install-lib} are installed in the directory +specified by @samp{libdir} in @file{configparms} or @file{Makeconfig}. + +@verbatim +BUILD_CC="gcc" \ + CC="${CROSS_TARGET}-gcc -march=${MARCH}" \ + AR="${CROSS_TARGET}-ar" \ + RANLIB="${CROSS_TARGET}-ranlib" +@end verbatim + +@samp{CC="$@{CROSS_TARGET@}-gcc -march=$@{MARCH@}"} +sets @code{CC} to the cross-compiler for the target's architecture, +processor and ABI we configured the library for. @code{AR} and +@code{RANLIB} are set to cross-compiling versions of @code{ar} and +@code{ranlib} as the native tools are not configured to work with +object files for the target we configured for. + +@option{--prefix=} tells the @file{configure} script to install +glibc in the root directory (@file{/}) of the target system. + +@c @option{--libexecdir=/lib/glibc} tells the configure script to +@c install glibc executables inside @file{/lib/glibc}. + +Unlike previous builds, @option{--host} now equals +@env{$@{CROSS_TARGET@}} instead of @env{$@{CROSS_HOST@}}. This is +because we are building the glibc version that the target system will +use. We won't have to build it later. + +Profiling can be of help to optimize a program by analysing memory +use, the usage of particular instructions, etc. Option +@option{--disable-profile} is used to disable this. + +Option @option{--enable-add-ons} is used to enable all the add-on +packages in the main source directory, which includes the glibc-ports +used to support the MIPS architecture. + +The option @option{--with-tls} tells the configure script to use +@acronym{TLS} (thread-local storage). Thread-local storage is a +computer programming method that uses memory local to a thread. + +The @samp{3.10} parameter given to option @option{--enable-kernel} +describes the smallest version of the Linux kernel the generated +library is expected to support. The higher the version number is, the +less compatibility code is added, and the faster the code gets. + +Option @option{--with-__thread} enables threads in glibc. + +The option @option{--with-binutils=$@{TARGET_DIR@}/cross-tools/bin} +tells the @file{configure} script to use the binutils (assembler and +linker) built in the cross-compilation toolchain process. + +@option{--with-headers=$@{TARGET_DIR@}/include} indicates the +location of the kernel Linux' headers. + +@option{--enable-obsolete-rpc} tells the @file{configure} script to +install remote procedure call (RPC) headers. Those may be required by +some programs. + +@option{--cache-file=config.cache} specifies the file in which cache +variables are listed for @file{configure}. + +The file @file{$@{TARGET_DIR@}/etc/nsswitch.conf} contains the +configuration of @acronym{NSS} (Name Service Switch). NSS is a facility +in Unix-like operating systems that provides a variety of sources for +common configuration databases and name resolution mechanisms. These +sources include local operating system files (such as +@file{/etc/passwd}, @file{/etc/group}, and @file{/etc/hosts}), the +Domain Name System (DNS), the Network Information Service (NIS), and +LDAP. + +@c Purpose of the file @file{$@{TARGET_DIR@}/etc/ld.so.conf} + + +@node Cross GCC CXX +@section Cross GCC (C and C++ support) + +In this section, we build a complete cross-compiler with support for C +and C++ languages. + +@verbatim +# 35 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/gcc-4.7.3 +tar xf ${DOWNLOAD_DIR}/gmp-5.1.3.tar.bz2 +mv gmp-5.1.3 gmp +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz +mv mpc-1.0.1 mpc +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2 +mv mpfr-3.1.2 mpfr +mkdir -v ../gcc-build +cd ../gcc-build +../gcc-4.7.3/configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --build=${CROSS_HOST} \ + --host=${CROSS_HOST} \ + --target=${CROSS_TARGET} \ + --with-sysroot=${TARGET_DIR} \ + --disable-nls \ + --enable-shared \ + --enable-__cxa_atexit \ + --disable-multilib \ + --enable-c99 \ + --enable-long-long \ + --enable-threads=posix \ + --enable-languages=c,c++ \ + --with-mpfr-include="${BUILD_DIR}/gcc-4.7.3/mpfr/src" \ + --with-mpfr-lib="${BUILD_DIR}/gcc-build/mpfr/src/.libs" +make +make install +cd .. +rm -rf gcc-build +rm -rf gcc-4.7.3 +cd +@end verbatim + +@option{--enable-__cxa_atexit} enables @code{__cxa_atexit}, rather +than @code{atexit}, to register C++ destructors for local statics and +global objects. This is essential for fully standards-compliant +handling of destructors, but requires @code{__cxa_atexit} in libc. + +@option{--enable-c99} enables support for the C99 standard. + +@option{--enable-long-long} enables support for @code{long long int} +types. + +@c @option{--enable-threads=posix} + + +@node Building the Cross-Compilation Tools +@chapter Building the Cross-Compilation Tools + +@menu +* Cross File:: File for cross-compilation. +* Cross Groff:: Groff for cross-compilation. +* Cross Shadow:: Shadow for cross-compilation. +* Cross M4:: M4 for cross-compilation. +* Cross Ncurses:: Ncurses for cross-compilation. +* Cross Cleaning:: Cleaning up the cross-compilation toolchain. +@end menu + + +@node Cross File +@section File + +The command @command{file} is used to determine the type of a file: +text, executable or data. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/file-5.16.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/file-5.16 +./configure \ + --prefix=${TARGET_DIR}/cross-tools +make +make install +cd .. +rm -rf file-5.16 +cd +@end verbatim + + +@node Cross Groff +@section Groff + +Groff is the GNU version of the roff document formatting system which +is used to produce man pages. + +You need G++ on your system to compile this program from source. Under +gNewSense 4.0, try @samp{sudo apt-get install g++-4.4} and then +@samp{sudo ln -sv g++-4.4 /usr/bin/g++}. + + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/groff-1.22.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/groff-1.22.2 +PAGE=A4 \ + ./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --without-x +make +make install +cd .. +rm -rf groff-1.22.2 +cd +@end verbatim + +@samp{PAGE=A4} defines the default format of pages for printed output. + +@option{--without-x} disables the dependancy on the X window system. + + +@node Cross Shadow +@section Shadow + +The package contains programs to handle users, groups and passwords in +a secure way: passwords are encrypted. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/shadow-4.1.4.3 +patch -Np1 -i ${DOWNLOAD_DIR}/shadow-4.1.4.3-sysroot_hacks-1.patch +#sed -i.orig \ +# 's/bindir)\/\$\$i/bindir)\/mips64el-unknown-linux-gnu-\$\$i/' \ +# src/Makefile.am +#automake-1.11 +echo "shadow_cv_passwd_dir=${TARGET_DIR}/bin" > config.cache +echo "ac_cv_func_lckpwdf=no" >> config.cache +./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --sbindir=${TARGET_DIR}/cross-tools/bin \ + --sysconfdir=${TARGET_DIR}/etc \ + --disable-shared \ + --without-audit \ + --without-libpam \ + --without-selinux \ + --program-prefix=${CROSS_TARGET}- \ + --cache-file=config.cache +sed -i.orig "/PASSWD_PROGRAM/s/passwd/${CROSS_TARGET}-&/" config.h +make +make install +cd .. +rm -rf shadow-4.1.4.3 +cd +@end verbatim + +@c @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin} +@c @samp{ac_cv_func_lckpwdf=no} + +The patch @file{shadow-4.1.4.3-sysroot_hacks-1.patch} is used so that +shadow can be built with the sysroot method. Because we use this +patch, @samp{shadow_cv_passwd_dir=$@{TARGET_DIR@}/bin} and +@samp{ac_cv_func_lckpwdf=no} have to be added in @file{config.cache} +in order for the @file{configure} script not to test the +functionalities associated. + +@c @option{--sbindir=$@{TARGET_DIR@}/cross-tools/bin} + +@c @option{--sysconfdir=$@{TARGET_DIR@}/etc} + +@option{--without-audit}, @option{--without-libpam} and +@option{--without-selinux} disable support for auditing, @acronym{PAM} +(Pluggable authentication modules) and @acronym{SELinux} +(Security-Enhanced Linux). We do not need those extra features. + +@option{--program-prefix=$@{CROSS_TARGET@}-} prepends the value of +@env{CROSS_TARGET} (that is @samp{i386-unknown-linux-gnu} in this +document) to installed program names for cross-compilation. + +@c @samp{sed -i.orig "/PASSWD_PROGRAM/s/passwd/$@{CROSS_TARGET@}-&/" +@c config.h} is used to avoid the error message + + +@node Cross M4 +@section M4 + +Bison 2.5 requires M4 to be built. + +GNU M4 is a package containing an implementation of the m4 macro +language. GNU M4 is used in GNU Autoconf' @file{configure} files. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/m4-1.4.17.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/m4-1.4.17 +./configure \ + --prefix=${TARGET_DIR}/cross-tools +make +make install +cd .. +rm -rf m4-1.4.17 +cd +@end verbatim + + +@node Cross Ncurses +@section Ncurses + +GNU ncurses contains a library used to write text-based user +interfaces in a terminal-independent manner. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/ncurses-5.9 +./configure \ + --prefix=${TARGET_DIR}/cross-tools \ + --without-shared +make -C include +make -C progs tic +install -m755 progs/tic ${TARGET_DIR}/cross-tools/bin +cd .. +rm -rf ncurses-5.9 +cd +@end verbatim + +@option{--without-shared} is used to avoid building the whole library +as only @command{tic} is installed. + + +@node Cross Cleaning +@section Cleaning up Cross-Compilation Toolchain + +In order to save some space, binaries and libraries of +cross-compilation tools can be stripped out. + +@quotation Warning +incorrect cleaning arguments used against library files can lead to +library files breaking. For this reason, be careful of the command +arguments. If you are not comfortable with this, you can skip this +section as it will have no effect on the process of building the +target system. +@end quotation + + +@verbatim +cd ${TARGET_DIR}/cross-tools +strip --strip-all bin/* +strip --strip-debug lib/* +cd +@end verbatim + +@option{--strip-all} removes all symbols. This command reduces the +size of the @file{bin} directory's content from 26 MB to 9 MB. + +@option{--strip-debug} removes debugging symbols only. This command +reduces the size of the @file{lib} directory's content from 13 MB to +13 MB. + + +@node Building the Target System +@chapter Building the Target System + +After having set up the cross-compilation toolchain and tools, the +operating system for the target machine is built in this chapter. + +@menu +* Environment Setup:: Setting up the environment. +* Man Pages:: Building Man Pages. +* Zlib:: Building Zlib. +* Binutils:: Building Binutils. +* GMP:: Building GMP. +* MPFR:: Building MPFR. +* MPC:: Building MPC. +* GCC:: Building GCC. +* Sed:: Building Sed. +* E2fsprogs:: Building E2fsprogs. +* Coreutils:: Building Coreutils. +* iana-etc:: Building iana-etc. +* M4:: Building M4. +* Bison:: Building Bison. +* Ncurses:: Building Ncurses. +* Procps:: Building Procps. +* Libtool:: Building Libtool. +* Readline:: Building Readline. +* Autoconf:: Building Autoconf. +* Automake:: Building Automake. +* Bash:: Building Bash. +* Bzip2:: Building Bzip2. +* DHCPCD:: Building DHCPCD. +* Diffutils:: Building Diffutils. +* File:: Building File. +* Findutils:: Building Findutils. +* Flex:: Building Flex. +* Gawk:: Building Gawk. +* Gdbm:: Building Gdbm. +* Gettext:: Building Gettext. +* Grep:: Building Grep. +* Groff:: Building Groff. +* Gzip:: Building Gzip. +* Inetutils:: Building Inetutils. +* Iproute2:: Building Iproute2. +* Kbd:: Building Kbd. +* Kmod:: Building Kmod. +* Less:: Building Less. +* Libpipeline:: Building Libpipeline. +* Make:: Building Make. +* Man-db:: Building Man-db. +* Nano:: Building Nano. +* Patch:: Building Patch. +* Psmisc:: Building Psmisc. +* Shadow:: Building Shadow. +* Sysvinit:: Building Sysvinit. +* Tar:: Building Tar. +* Texinfo:: Building Texinfo. +* Udev:: Building Udev. +* Util-Linux:: Building Util-Linux. +* XZ-Utils:: Building XZ-Utils. +* Bootscripts:: Building Bootscripts. +* Kernel:: Building the Kernel. +@end menu + + +@node Environment Setup +@section Setting up the Environment + +Because this chapter is about the build of the target system and not +the build of the cross-compilation toolchain and tools anymore, we +need to update some environment variables. + +For more convenience, we can set environment variables up in the +@file{~/.bashrc} file, so that this setup is preserved when logging +in: + + +@verbatim +cat >> ~/.bashrc << EOF +export CC="${CROSS_TARGET}-gcc -march=${MARCH}" +export CXX="${CROSS_TARGET}-g++ -march=${MARCH}" +export AR="${CROSS_TARGET}-ar" +export AS="${CROSS_TARGET}-as" +export RANLIB="${CROSS_TARGET}-ranlib" +export LD="${CROSS_TARGET}-ld" +export STRIP="${CROSS_TARGET}-strip" +EOF +source ~/.bash_profile +@end verbatim + +@env{CC} is the flag that indicates the C compiler to be used, +@env{CXX} the C++ compiler, @env{AR} the archiver, @env{AS} the +assembler, @env{RANLIB} the archives' index generator, @env{LD} the +linker and @env{STRIP} the program for stripping. + +All the programs to be used are prefixed with +@samp{$@{CROSS_TARGET@}-} in order to use the cross-compilation +toolchain instead of the toolchain of the host. + + +@node Man Pages +@section Man Pages + +The man-pages package documents the kernel Linux and C library's +interfaces that are used by user-space programs. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/man-pages-3.54.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/man-pages-3.54 +make prefix=${TARGET_DIR} install +cd .. +rm -rf man-pages-3.54 +cd +@end verbatim + +The option @option{prefix=$@{TARGET_DIR@}} is used to install the man +pages on the target directory instead of the @file{/usr} directory of +the host. + + +@node Zlib +@section Zlib + +Zlib is a compression/decompression library. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/zlib-1.2.8.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/zlib-1.2.8 +./configure \ + --prefix= +make AR="${AR}" +make prefix=${TARGET_DIR} install +cd .. +rm -rf zlib-1.2.8 +cd +@end verbatim + +In order to build zlib by cross-compilation, the flag @env{AR} has to +be equal to @samp{$@{AR@}}. + + +@node Binutils +@section Binutils + +GNU Binutils (GNU binary utilities) is a collection of programs for +manipulating binaries. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/binutils-2.24.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/binutils-2.24 +mkdir -pv ../binutils-build +cd ../binutils-build +../binutils-2.24/configure \ + --prefix= \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --target=${CROSS_TARGET} \ + --enable-64-bit-bfd \ + --enable-shared +make configure-host +make tooldir= +make DESTDIR=${TARGET_DIR} tooldir= install +cp -v ../binutils-2.24/include/libiberty.h ${TARGET_DIR}/include +cd .. +rm -rf binutils-build +rm -rf binutils-2.24 +cd +@end verbatim + +The option @option{--host} is now set to @env{CROSS_TARGET} because +the host that will run this build will be the target system. + +@c @samp{make tooldir=} +@c @samp{make DESTDIR=$@{TARGET_DIR@} tooldir= install} + + +@node GMP +@section GMP + +@acronym{GMP} (GNU multiple precision arithmetic library) is required +to build GCC. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/gmp-5.1.3.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/gmp-5.1.3 +./configure \ + --host=${CROSS_TARGET} \ + --prefix= \ + --enable-cxx +make +make DESTDIR=${TARGET_DIR} install +rm -v ${TARGET_DIR}/lib/lib{gmp,gmpxx}.la +cd .. +rm -rf gmp-5.1.3 +cd +@end verbatim + +The option @option{--enable-cxx} enables support for the C++ language. + +The files @file{$@{TARGET_DIR@}/lib/lib@{gmp,gmpxx@}.la} are removed +to avoid the following error when building MPFR: +@samp{/lib/libgmp.so: could not read symbols: File in wrong format}. + + +@node MPFR +@section MPFR + +GNU @acronym{MPFR} (Multiple Precision Floating-Point Reliably) is a +portable C library for arbitrary-precision binary floating-point +computation with correct rounding. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/mpfr-3.1.2.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/mpfr-3.1.2 +./configure \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +rm -v ${TARGET_DIR}/lib/libmpfr.la +cd .. +rm -rf mpfr-3.1.2 +cd +@end verbatim + +The file @file{$@{TARGET_DIR@}/lib/libmpfr.la} is removed to avoid the +following error when building MPC: +@samp{/lib/libmpfr.so: could not read symbols: File in wrong format}. + + +@node MPC +@section MPC + +GNU @acronym{MPC} (Multiple Precision Complex Library) is a C library +for the arithmetic of complex numbers with arbitrarily high precision +and correct rounding of the result. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/mpc-1.0.1.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/mpc-1.0.1 +./configure \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf mpc-1.0.1 +cd +@end verbatim + + +@node GCC +@section GCC + +GCC is the GNU Compiler Collection. + +@verbatim +# 25 minutes +tar xf ${DOWNLOAD_DIR}/gcc-4.7.3.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/gcc-4.7.3 +sed -i.orig 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in +sed -i.orig 's@\./fixinc\.sh@-c true@' gcc/Makefile.in +mkdir -v ../gcc-build +cd ../gcc-build +../gcc-4.7.3/configure \ + --prefix= \ + --libexecdir=/lib \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --target=${CROSS_TARGET} \ + --enable-shared \ + --enable-threads=posix \ + --enable-__cxa_atexit \ + --enable-c99 \ + --enable-long-long \ + --disable-multilib \ + --enable-clocale=gnu \ + --enable-languages=c,c++ \ + --disable-libstdcxx-pch +make +make DESTDIR=${TARGET_DIR} install +ln -sv gcc ${TARGET_DIR}/bin/cc +cd .. +rm -rf gcc-build +rm -rf gcc-4.7.3 +cd +@end verbatim + +@samp{sed -i.orig 's/install_to_$(INSTALL_DEST) //' +libiberty/Makefile.in} is used as we already installed the library +@file{libiberty.a} with Binutils. + +@c We use @samp{sed -i.orig 's@@\./fixinc\.sh@@-c true@@' +@c gcc/Makefile.in} to avoid using fixincludes that may output errors if +@c headers have been modified. + +Using @option{--enable-clocale=gnu} option ensures that the correct +locale will automatically be chosen. + +Option @option{--disable-libstdcxx-pch} disables support for +precompiled headers (PCH). + +The line @samp{ln -sv gcc $@{TARGET_DIR@}/bin/cc} creates a +symbolic link @file{cc} that points on @file{gcc}. + + +@node Sed +@section Sed + +GNU sed is a stream editor: it is used to perform basic text +transformations on an input stream (a file or input from a pipeline). + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/sed-4.2.2.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/sed-4.2.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --bindir=/bin +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf sed-4.2.2 +cd +@end verbatim + +@c @option{--bindir=/bin} FHS? + + +@node E2fsprogs +@section E2fsprogs + +E2fsprogs is a package that contains tools to handle the ext2, ext3 +and ext4 filesystems. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/e2fsprogs-1.42.8.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/e2fsprogs-1.42.8 +mkdir -v build +cd build +../configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --with-root-prefix="" \ + --enable-elf-shlibs +make +make DESTDIR=${TARGET_DIR} install +make DESTDIR=${TARGET_DIR} install-libs +rm -v ${TARGET_DIR}/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so +cd ../.. +rm -rf e2fsprogs-1.42.8 +cd +@end verbatim + +@option{--with-root-prefix=""} is used to put e2fsprogs binaries +inside @file{/sbin} instead of @file{@var{PREFIX}/sbin} which would be +@file{/sbin}. + +Option @option{--enable-elf-shlibs} enables e2fsprogs shared +libraries. + +@samp{make DESTDIR=$@{TARGET_DIR@} install-libs} is used to install +libraries, those are not installed with @samp{make +DESTDIR=$@{TARGET_DIR@} install}. + +The sequence of commands that follows first removes symbolic links +@file{$@{TARGET_DIR@}/lib/lib@{@/blkid,com_err,e2p,ext2fs,ss,uuid@}.so} +which point on abolute paths +@file{/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so}. In order to +use the libraries of the target operating system, we need to symlink +@file{$@{TARGET_DIR@}/lib/lib@{blkid,com_err,e2p,ext2fs,ss,uuid@}.so} +to their relative paths files. + + +@node Coreutils +@section Coreutils + +GNU coreutils (core utilities) includes the standard programs for text +and file manipulation. + +On gNewSense Parkes, you need to install @file{xz-utils} to extract +the package. + +@verbatim +# 3 minutes +tar xf ${DOWNLOAD_DIR}/coreutils-8.19.tar.xz -C ${BUILD_DIR} +cd ${BUILD_DIR}/coreutils-8.19 +cat > config.cache << EOF +fu_cv_sys_stat_statfs2_bsize=yes +gl_cv_func_mbrtowc_incomplete_state=yes +gl_cv_func_mbrtowc_nul_retval=yes +gl_cv_func_mbrtowc_null_arg=yes +gl_cv_func_mbrtowc_retval=yes +gl_cv_func_btowc_eof=yes +gl_cv_func_wcrtomb_retval=yes +gl_cv_func_wctob_works=yes +gl_cv_func_fstatat_zero_flag=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --enable-install-program=hostname \ + --enable-no-install-program=kill,uptime \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf coreutils-8.19 +cd +@end verbatim + +@c @samp{sed -i.orig '/strftime/s/\ LC_ALL//' man/help2man} + +The variables listed in the file @file{config.cache} are used in order +to avoid that the @file{configure} script evaluate their values: +otherwise the build may fail when cross-compiling. + +We use @option{--enable-install-program=hostname} to install the +command @command{hostname} which is not built by default. + +We use @option{--enable-no-install-program=kill,uptime} in order not +to install commands @command{kill} and @command{uptime}. Those +commands will be installed by the package procps. + + +@node iana-etc +@section iana-etc + +The iana-etc package installs services and protocols using data from +the Internet Assigned Numbers Authority (IANA). + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/iana-etc-2.30.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/iana-etc-2.30 +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf iana-etc-2.30 +cd +@end verbatim + + +@node M4 +@section M4 + +GNU M4 is a package containing an implementation of the m4 macro +language. GNU M4 is used in GNU Autoconf' @file{configure} files. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/m4-1.4.17.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/m4-1.4.17 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf m4-1.4.17 +cd +@end verbatim + + +@node Bison +@section Bison + +GNU bison parser generator. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/bison-2.7.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/bison-2.7 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +echo '#define YYENABLE_NLS 1' >> config.h +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf bison-2.7 +cd +@end verbatim + +@samp{echo '#define YYENABLE_NLS 1' >> config.h} is used to build +@acronym{NLS} (native language support) inside bison. + + +@node Ncurses +@section Ncurses + +@verbatim +# 4 minutes +tar xf ${DOWNLOAD_DIR}/ncurses-5.9.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/ncurses-5.9 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --with-shared \ + --enable-widec \ + --without-debug \ + --without-ada \ + --with-build-cc="gcc -D_GNU_SOURCE" \ + --libdir=/lib +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf ncurses-5.9 +cd +@end verbatim + +Option @option{--enable-widec} enables wide characters support in +ncurses. + +@c Option @option{--without-debug} + +Option @option{--without-ada} disables support for the Ada programming +language inside ncurses. + +@c Option @option{--with-build-cc="gcc -D_GNU_SOURCE"} + +@c Option @option{--libdir=/lib} + +@ignore +@c PROCPS issue: +The command @samp{ln -sfv libncursesw.so $@{TARGET_DIR@}/lib/libncurses.so} +creates the symlink @file{libcurses.so} so that programs that do not +know @file{libncursesw.so} can be linked against it. +@end ignore + +@c ln -sfv ../../share/terminfo ${TARGET_DIR}/lib/terminfo + + +@node Procps +@section Procps + +The procps package contains utilities that give information about +processes using the @file{/proc} filesystem. The package includes the +commands @command{ps}, @command{top}, @command{vmstat}, @command{w}, +@command{kill}, @command{free}, @command{slabtop}, and +@command{skill}. + +@verbatim +# 1 minute +ln -sv ncursesw/curses.h ${TARGET_DIR}/include/curses.h +ln -sv ncursesw/ncurses.h ${TARGET_DIR}/include/ncurses.h +ln -sv ncursesw/term.h ${TARGET_DIR}/include/term.h +ln -sfv libncursesw.so ${TARGET_DIR}/lib/libncurses.so +tar xf ${DOWNLOAD_DIR}/procps-3.2.8.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/procps-3.2.8 + +# From http://lists.gnu.org/archive/html/bug-make/2010-07/msg00153.html +sed '177s,\*/module.mk,proc/module.mk ps/proc.mk,' -i.orig Makefile + +make \ + CPPFLAGS= \ + lib64=lib +make \ + DESTDIR=${TARGET_DIR} \ + lib64=lib \ + ldconfig= \ + install="install -D" \ + install +cd .. +rm -rf procps-3.2.8 +cd +@end verbatim + +@ignore +Option @option{CPPFLAGS= } is used so that the target system's ncurses +library will be used, default value would have been +@option{-I/include/ncurses}. +@end ignore + +Option @option{lib64=lib} makes the directory @file{/lib} the one +where to put 64 bit libraries, default would be @file{/lib64}. + +Option @option{ldconfig= } is used in order not to use current host's +@command{ldconfig}. + +Option @option{install="install -D"} is used so that all the files +installed are owned by the current user. By default, all installed +files are owned by root. + + +@node Libtool +@section Libtool + +GNU libtool is a generic library support script. It hides the +complexity of using shared libraries behind a consistent, portable +interface. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/libtool-2.4.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/libtool-2.4.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf libtool-2.4.2 +cd +@end verbatim + + +@node Readline +@section Readline + +The GNU Readline library provides a set of functions for use by +applications that allow users to edit command lines as they are typed +in. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/readline-6.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/readline-6.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --libdir=/lib +make +make DESTDIR=${TARGET_DIR} install +make DESTDIR=${TARGET_DIR} install-doc +cd .. +rm -rf readline-6.2 +cd +@end verbatim + +@c sed -i 's:^SHLIB_LIBS=:SHLIB_LIBS=-lncursesw:' support/shobj-conf + + +@node Autoconf +@section Autoconf + +GNU autoconf is an extensible package of M4 macros that produce shell +scripts to automatically configure software source code +packages. These scripts can adapt the packages to many kinds of +UNIX-like systems without manual user intervention. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/autoconf-2.69.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/autoconf-2.69 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf autoconf-2.69 +cd +@end verbatim + + +@node Automake +@section Automake + +GNU automake is a tool for automatically generating @file{Makefile.in} +files compliant with the GNU Coding +Standards@footnote{@uref{http://www.gnu.org/prep/standards/}}. + +You need Autoconf on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install autoconf} +(version 2.69 here). + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/automake-1.14.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/automake-1.14 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf automake-1.14 +cd +@end verbatim + + +@node Bash +@section Bash + +GNU @acronym{Bash} (Bourne again shell) is an sh-compatible shell that +incorporates useful features from the Korn shell (ksh) and C shell +(csh). + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/bash-4.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/bash-4.2 +cat > config.cache << EOF +ac_cv_func_mmap_fixed_mapped=yes +ac_cv_func_strcoll_works=yes +ac_cv_func_working_mktime=yes +bash_cv_func_sigsetjmp=present +bash_cv_getcwd_malloc=yes +bash_cv_job_control_missing=present +bash_cv_printf_a_format=yes +bash_cv_sys_named_pipes=present +bash_cv_ulimit_maxfds=yes +bash_cv_under_sys_siglist=yes +bash_cv_unusable_rtsigs=no +gt_cv_int_divbyzero_sigfpe=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --bindir=/bin \ + --cache-file=config.cache \ + --without-bash-malloc \ + --with-installed-readline +make +make \ + DESTDIR=${TARGET_DIR} \ + htmldir=/share/doc/bash-4.2 \ + install +ln -sv bash ${TARGET_DIR}/bin/sh +cd .. +rm -rf bash-4.2 +cd +@end verbatim + +The variables listed in the file @file{config.cache} are used in order +to avoid that the @file{configure} script evaluate their values: +otherwise the build may fail when cross-compiling. + +Option @option{--without-bash-malloc} tells the @file{configure} +script not to use the @code{malloc} function shipped with +Bash. Glibc's version will be used instead. + +Option @option{--with-installed-readline} tells the configure script +to use the installed readline library instead of the one shipped with +Bash. + +@samp{ln -sv bash $@{TARGET_DIR@}/bin/sh} creates a symlink @file{sh} +to @file{bash}. + + +@node Bzip2 +@section Bzip2 + +Bzip2 is a package that contains utilities to compress and decompress +files with a better original size/compressed size ratio than gzip. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/bzip2-1.0.6.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/bzip2-1.0.6 +sed -i -e "/^all:/s/ test//" Makefile +sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile +make \ + -f Makefile-libbz2_so \ + CC="${CC}" \ + AR="${AR}" \ + RANLIB="${RANLIB}" +make clean +make \ + CC="${CC}" \ + AR="${AR}" \ + RANLIB="${RANLIB}" +make \ + PREFIX=${TARGET_DIR} \ + install +cp -av libbz2.so* ${TARGET_DIR}/lib +ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/lib/libbz2.so +rm -v ${TARGET_DIR}/bin/{bunzip2,bzcat,bzip2} +cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2 +ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2 +ln -sv bzip2 ${TARGET_DIR}/bin/bzcat +cd .. +rm -rf bzip2-1.0.6 +cd +@end verbatim + +@samp{sed -i.orig -e "/^all:/s/ test//" Makefile} is used to skip +tests when building. + +@samp{sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile} is used +in order to have relative path symlinks instead of absolute ones. + +Option @option{-f Makefile-libbz2_so} is used to build shared +libraries. + +Flags @env{CC}, @env{AR} and @env{RANLIB} are used so that bzip2 is +built using cross-compilation tools instead of the host's ones. + +@samp{make clean} is used to clean up temporary files. + +The second build commands are used to build static libraries. + +@ignore +cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2 +cp -av libbz2.so* ${TARGET_DIR}/lib +ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/lib/libbz2.so +rm -v ${TARGET_DIR}/bin/{bunzip2,bzcat,bzip2} +ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2 +ln -sv bzip2 ${TARGET_DIR}/bin/bzcat +@end ignore + + +@node DHCPCD +@section DHCPCD + +DHCPCD is a wrapper for the @acronym{DHCP} (Dynamic Host Configuration +Protocol) client daemon. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/dhcpcd-6.1.0.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/dhcpcd-6.1.0 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --bindir=/sbin \ + --sysconfdir=/etc \ + --dbdir=/var/lib/dhcpcd \ + --libexecdir=/lib/dhcpcd +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf dhcpcd-6.1.0 +cd +@end verbatim + +@c Option @option{--bindir=/sbin} is used to comply with FHS? +@c @option{--sysconfdir=/etc} @file{/etc} instead of ? +@c @option{--dbdir=/var/lib/dhcpcd} @file{/var/lib/dhcpcd} instead of? +@c @option{--libexecdir=/lib/dhcpcd} @file{/lib/dhcpcd} instead of ? + + +@node Diffutils +@section Diffutils + +GNU Diffutils is a package of several programs related to finding +differences between files. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/diffutils-3.3.tar.xz -C ${BUILD_DIR} +cd ${BUILD_DIR}/diffutils-3.3 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf diffutils-3.3 +cd +@end verbatim + + +@node File +@section File + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/file-5.16.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/file-5.16 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf file-5.16 +cd +@end verbatim + + +@node Findutils +@section Findutils + +The GNU Find Utilities are typically used to provide directory search +and file locating capabilities. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/findutils-4.4.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/findutils-4.4.2 +cat > config.cache << EOF +gl_cv_func_wcwidth_works=yes +gl_cv_header_working_fcntl_h=yes +ac_cv_func_fnmatch_gnu=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --libexecdir=/lib/locate \ + --localstatedir=/var/lib/locate \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf findutils-4.4.2 +cd +@end verbatim + +@c --libexecdir=/lib/locate +@c --localstatedir=/var/lib/locate + + +@node Flex +@section Flex + +Flex is a tool for generating scanners. A scanner, sometimes called a +tokenizer, is a program which recognizes lexical patterns in text. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/flex-2.5.37.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/flex-2.5.37 +# From http://sourceforge.net/p/flex/bugs/151/ +sed '1s/$/\n#undef malloc\n#undef realloc/' \ + -i.orig lib/realloc.c +cat > config.cache << EOF +ac_cv_path_M4="/bin/m4" +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +ln -sv libfl.a ${TARGET_DIR}/lib/libl.a +cd .. +rm -r flex-2.5.37 +cd + +cat > ${TARGET_DIR}/bin/lex << EOF +#!/bin/sh +exec /bin/flex -l \$@ +EOF +chmod -v 755 ${TARGET_DIR}/bin/lex +@end verbatim + +@file{config.cache} forces flex to use @file{/bin/m4} instead of +@file{/gllfsc/cross-tools/bin/m4} on the target machine. + +For compatibility issues, we create the symlink @file{libl.a}. + +We then create target system's @file{/bin/lex} that will execute +@command{flex} with option @option{-l} in order to behave with maximal +compatibility like @command{lex}. + +@ignore +@samp{sed -i.orig "s/-I@@includedir@@//g" Makefile.in} is used in +order not to use host's headers in @file{/include} during +cross-compilation. +@end ignore + +@c Variables @samp{ac_cv_func_malloc_0_nonnull=yes} and +@c @samp{ac_cv_func_realloc_0_nonnull=yes} are used to get rid of +@c error message: @samp{}. + +@c We use option @option{-fPIC} passed to the cross-compiler in order to +@c generate position-independent code (PIC). + + +@node Gawk +@section Gawk + +GNU awk (Gawk) is a program used to select particular records in a +file and perform operations upon them. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/gawk-4.1.0.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/gawk-4.1.0 +sed -i.orig \ + '/check-recursive all-recursive/s/ check-for-shared-lib-support//' \ + extension/Makefile.in +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --libexecdir=/lib +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -r gawk-4.1.0 +cd +@end verbatim + +The sed expression is used to avoid the error @samp{Building the +extensions is not supported on this platform}. + + +@node Gdbm +@section Gdbm + +GNU dbm is a library of database functions. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/gdbm-1.11.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/gdbm-1.11 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -r gdbm-1.11 +cd +@end verbatim + + +@node Gettext +@section Gettext + +GNU gettext utilities are a set of tools that provides a framework to +help packages produce multi-lingual messages. + +@verbatim +# 7 minutes +tar xf ${DOWNLOAD_DIR}/gettext-0.18.3.1.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/gettext-0.18.3.1 +cat > config.cache << EOF +am_cv_func_iconv_works=yes +gl_cv_func_wcwidth_works=yes +gt_cv_func_printf_posix=yes +gt_cv_int_divbyzero_sigfpe=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --cache-file=config.cache +make +#cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i} +#cp gettext-tools/src/.libs/libgettextsrc.la{,i} +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf gettext-0.18.3.1 +cd +@end verbatim + +@c cp gettext-tools/gnulib-lib/.libs/libgettextlib.la{,i} ? +@c cp gettext-tools/src/.libs/libgettextsrc.la{,i} ? + + +@node Grep +@section Grep + +GNU @command{grep} command searches one or more input files for lines +containing a match to a specified pattern. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/grep-2.15.tar.xz -C ${BUILD_DIR} +cd ${BUILD_DIR}/grep-2.15 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --bindir=/bin \ + --disable-perl-regexp +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf grep-2.15 +cd +@end verbatim + +Option @option{--disable-perl-regexp} disables support of Perl-style +regular expressions (regexp). + + +@node Groff +@section Groff + +Groff is the GNU version of the roff document formatting system which +is used to produce man pages. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/groff-1.22.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/groff-1.22.2 +PAGE=A4 \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make \ + TROFFBIN=troff \ + GROFFBIN=groff \ + GROFF_BIN_PATH= +make prefix=${TARGET_DIR} install +ln -sv soelim ${TARGET_DIR}/bin/zsoelim +ln -sv eqn ${TARGET_DIR}/bin/geqn +ln -sv tbl ${TARGET_DIR}/bin/gtbl +cd .. +rm -rf groff-1.22.2 +cd +@end verbatim + +The variables @env{TROFFBIN=troff} and @env{GROFFBIN=groff} tell +@command{make} to use @command{troff} and @command{groff} commands +installed in the @ref{Building the Cross-Compilation Tools} to build +documentation. + +The variable @env{GROFF_BIN_PATH} before @env{PATH} is checked for +programs @command{groff} is calling (preprocessors, @command{troff}, +and output devices). If not set, it defaults to the directory where +the @file{groff} binary is located. + +The symlinks are used for compatibility. + + +@node Gzip +@section Gzip + +GNU Gzip is a data compression program. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/gzip-1.6.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/gzip-1.6 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf gzip-1.6 +cd +@end verbatim + + +@node Inetutils +@section Inetutils + +Inetutils is a collection of common network programs. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/inetutils-1.9.1.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/inetutils-1.9.1 +sed -i '/gets is a security hole/d' lib/stdio.in.h +sed -i -e '/PATH_PROCNET_DEV/s/\ no//' paths +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf inetutils-1.9.1 +cd +@end verbatim + +@samp{sed -i.orig '/gets is a security hole/d' lib/stdio.in.h} is used +to fix the following error when issuing @samp{make}: +@samp{./stdio.h:1030:1: error: 'gets' undeclared here (not in a +function)}. + +@c It deletes the following line in lib/stdio.in.h: +@c _GL_WARN_ON_USE (gets, ``gets is a security hole - use fgets instead''); + +@samp{sed -i.orig -e '/PATH_PROCNET_DEV/s/\ no//' paths} is used to +fix the following error when issuing @samp{make}: +@samp{'PATH_PROCNET_DEV' undeclared (first use in this function)}. + + +@node Iproute2 +@section Iproute2 + +Iproute2 is a collection of utilities for controlling TCP and UDP IP +networking and traffic. + +You need Bison and Flex on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install bison flex}. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/iproute2-3.10.0.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/iproute2-3.10.0 +sed -i.orig '/^TARGETS/s@arpd@@g' misc/Makefile +make \ + DESTDIR=${TARGET_DIR} \ + CC="${CC}" \ + DOCDIR=/share/doc/iproute2 \ + MANDIR=/share/man +make \ + DESTDIR=${TARGET_DIR} \ + DOCDIR=/share/doc/iproute2 \ + MANDIR=/share/man \ + install +cd .. +rm -rf iproute2-3.10.0 +cd +@end verbatim + +@samp{sed -i.orig '/^TARGETS/s@@arpd@@@@g' misc/Makefile} is used to +disable the build of @command{arpd} as it requires Berkeley DB to be +installed. + +@env{DOCDIR} and @env{MANDIR} indicate the location in which the +documentation and the manual pages will be installed, +respectively. Those are no absolute paths but use the value of +@env{DESTDIR} as a prefix. + + +@node Kbd +@section Kbd + +Kbd contains keytable files and keyboard utilities. + +You need Check on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install check}. + +@verbatim +# 3 minutes +tar xf ${DOWNLOAD_DIR}/kbd-2.0.1.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/kbd-2.0.1 + +# Do not check for CHECK: +sed '14s/^/#/' -i.orig configure.ac +autoconf configure.ac > configure + +sed -i.orig '/^SUBDIRS/s/ tests//' Makefile.am +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --disable-vlock +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf kbd-2.0.1 +cd +@end verbatim + +@samp{sed -i.orig '/SUBDIRS/s/ tests//' Makefile.in} is used to +prevent files in the @file{tests} directory to be built. + +Option @option{--disable-vlock} disables the build of vlock. vlock +needs PAM library headers to be present on the build system and is not +necessary for us, so we do not build it. + + +@node Kmod +@section Kmod + +Kmod (previously known as module-init-tools) provide userspace-side +assistance in loading kernel modules and their dependencies. + +You need Xsltproc on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install xsltproc}. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/kmod-15.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/kmod-15 +zlib_CFLAGS="-I${TARGET_DIR}/include" \ + zlib_LIBS="-L${TARGET_DIR}/lib -lz" \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --with-zlib +make +make \ + DESTDIR=${TARGET_DIR} \ + INSTALL=install \ + install +cd .. +rm -rf kmod-15 +cd + +# For bootscripts: +ln -sv kmod ${TARGET_DIR}/bin/lsmod +ln -sv kmod ${TARGET_DIR}/bin/depmod +ln -sv kmod ${TARGET_DIR}/bin/insmod +ln -sv kmod ${TARGET_DIR}/bin/modprobe +ln -sv kmod ${TARGET_DIR}/bin/modinfo +ln -sv kmod ${TARGET_DIR}/bin/rmmod +@end verbatim + +@samp{zlib_CFLAGS} and @samp{zlib_LIBS} are defined to avoid the error +message: @samp{The pkg-config script could not be found or is too +old. Make sure it is in your PATH or set the PKG_CONFIG environment +variable to the full path to pkg-config. Alternatively, you may set +the environment variables zlib_CFLAGS and zlib_LIBS to avoid the need +to call pkg-config.} + +@option{--with-zlib} enables support for modules compressed with +zlib. + +By default, installation uses @env{INSTALL=install-with-care} which +checks if old utilities have not been destroyed. To avoid this check, +we use @env{INSTALL=install}. + + +@node Less +@section Less + +Less is a file pager: it is used to view the content of a text file. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/less-458.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/less-458 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make prefix=${TARGET_DIR} install +cd .. +rm -rf less-458 +cd +@end verbatim + + +@node Libpipeline +@section Libpipeline + +Libpipeline is a C library for manipulating pipelines of subprocesses +in a flexible and convenient way. + +@verbatim +tar xf ${DOWNLOAD_DIR}/libpipeline-1.3.0.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/libpipeline-1.3.0 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make prefix=${TARGET_DIR} install +cd .. +rm -rf libpipeline-1.3.0 +cd +@end verbatim + + +@node Make +@section Make + +GNU @command{make} utility determines automatically which pieces of a +large program need to be recompiled, and issues the commands to +recompile them. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/make-4.0.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/make-4.0 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf make-4.0 +cd +@end verbatim + + +@node Man-db +@section Man-db + +Man-db is an implementation of the standard Unix documentation system +accessed using the man command. It uses a Berkeley DB database in +place of the traditional flat-text whatis databases. + +@verbatim +# fix /lib/libpipeline.so: error adding symbols: File in wrong format +rm ${TARGET_DIR}/lib/libgdbm.la +rm ${TARGET_DIR}/lib/libpipeline.la + +tar xf ${DOWNLOAD_DIR}/man-db-2.6.7.1.tar.xz -C ${BUILD_DIR} +cd ${BUILD_DIR}/man-db-2.6.7.1 +libpipeline_CFLAGS="-I${TARGET_DIR}/include" \ + libpipeline_LIBS="-L${TARGET_DIR}/lib -lpipeline" \ + ./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf man-db-2.6.7.1 +cd + +sed -i 's/#\(DEFINE.*pager.*\)less -s/\1 less -isRc/' \ + ${TARGET_DIR}/etc/man_db.conf +@end verbatim + +@samp{libpipeline_CFLAGS} and @samp{libpipeline_LIBS} are defined to +avoid the error message: @samp{The pkg-config script could not be +found or is too old. Make sure it is in your PATH or set the +PKG_CONFIG environment variable to the full path to +pkg-config. Alternatively, you may set the environment variables +libpipeline_CFLAGS and libpipeline_LIBS to avoid the need to call +pkg-config.} + +The @command{sed} command is used to replace default pager with +@command{less}. Option @option{-c} will cause @command{less} to +display man pages faster as this option disables scrolling. Option +@option{-R} will cause @command{less} to render colors in the man +pages. + + +@node Nano +@section Nano + +GNU nano is a lightweight text editor. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/nano-2.3.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/nano-2.3.2 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +sed -i.orig -e \ + '/CPPFLAGS/s@/usr/include/ncursesw@${TARGET_DIR}/include@' \ + `find . -iname 'Makefile'` +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf nano-2.3.2 +cd +@end verbatim + +The sed expression is used to replace @file{/usr/include/ncursesw} +with @file{$@{TARGET_DIR@}/include} in every file named +@file{Makefile} in order to overcome the error +@samp{/usr/include/ncursesw/ncurses.h:60:34: fatal error: +ncursesw/ncurses_dll.h: No such file or directory}. + +@quotation Note +commands in nano are displayed as in `^X'. The `^' character means +@key{CTRL} key, so `^X' means @kbd{CTRL-X}. +@end quotation + + +@node Patch +@section Patch + +GNU patch takes a patch file containing a difference listing produced +by the @command{diff} program and applies those differences to one or +more original files, producing patched versions. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/patch-2.7.1.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/patch-2.7.1 +cat > config.cache << EOF +ac_cv_path_ed_PROGRAM=ed +ac_cv_func_strnlen_working=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --cache-file=config.cache +make +make prefix=${TARGET_DIR} install +cd .. +rm -rf patch-2.7.1 +cd +@end verbatim + + +@node Psmisc +@section Psmisc + +This package contains utilities that use the proc filesystem. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/psmisc-22.20.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/psmisc-22.20 +cat > config.cache << EOF +ac_cv_func_malloc_0_nonnull=yes +ac_cv_func_realloc_0_nonnull=yes +EOF +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --cache-file=config.cache +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf psmisc-22.20 +cd +@end verbatim + + +@node Shadow +@section Shadow + +@verbatim +# 4 minutes +tar xf ${DOWNLOAD_DIR}/shadow-4.1.4.3.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/shadow-4.1.4.3 +#automake +echo "ac_cv_func_setpgrp_void=yes" > config.cache +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --libdir=/lib \ + --sysconfdir=/etc \ + --enable-shared \ + --without-audit \ + --without-libpam \ + --without-selinux \ + --cache-file=config.cache \ + --enable-man +sed -i.orig '/man_MANS/s/$(man_nopam) //' man/ru/Makefile +sed -i.orig 's/groups$(EXEEXT) //' src/Makefile +for mkf in $(find man -name Makefile) + do + sed -i.orig -e '/groups.1.xml/d' -e 's/groups.1 //' ${mkf} + done +make +make DESTDIR=${TARGET_DIR} install +sed -i.orig -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \ + -e 's@/var/spool/mail@/var/mail@' \ + ${TARGET_DIR}/etc/login.defs +${CROSS_TARGET}-pwconv +${CROSS_TARGET}-grpconv +cd .. +rm -rf shadow-4.1.4.3 +cd +@end verbatim + +@c echo "ac_cv_func_setpgrp_void=yes" > config.cache + +The option @option{--enable-man} is used to generate man pages. + +The first call of @command{sed} removes @var{$(man_nopam)} on the line +with man_MANS in @file{man/ru/Makefile.am} in order for @samp{make +install} to complete. + +The second call of @command{sed} disables the build of command +@command{groups}, as coreutils already installed it. + +The last call of @command{sed} enables support for MD5 encrypted +passwords and changes the mail default directory from +@file{/var/spool/mail} to @file{/var/mail}. + +The @command{pwconv} command creates @file{shadow} file from file +@file{passwd} and an optionally existing @file{shadow} file. + +The @command{grpconv} command creates @file{gshadow} file from file +@file{group} and an optionally existing @file{gshadow} file. + + +@node Sysvinit +@section Sysvinit + +Sysvinit is the system-V style init process. Init is the first process +started during booting. It is started by the kernel. Init continues +running as a daemon until the system is shut down. It is the direct or +indirect ancestor of all other processes and automatically adopts all +orphaned processes. + + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/sysvinit-2.88dsf.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/sysvinit-2.88dsf +sed -i.orig -e 's@/dev/initctl@$(ROOT)&@g' \ + -e 's@\(mknod \)-m \([0-9]* \)\(.* \)p@\1\3p; chmod \2\3@g' \ + -e '/^ifeq/s/$(ROOT)//' \ + -e 's@/usr/lib@$(ROOT)/lib@' \ + src/Makefile +make -C src clobber +make -C src ROOT=${TARGET_DIR} CC="${CC}" +make -C src ROOT=${TARGET_DIR} INSTALL="install" install +cd .. +rm -rf sysvinit-2.88dsf +cd + +cat > ${TARGET_DIR}/etc/inittab << EOF +# Begin /etc/inittab + +id:3:initdefault: + +si::sysinit:/etc/rc.d/init.d/rc sysinit + +l0:0:wait:/etc/rc.d/init.d/rc 0 +l1:S1:wait:/etc/rc.d/init.d/rc 1 +l2:2:wait:/etc/rc.d/init.d/rc 2 +l3:3:wait:/etc/rc.d/init.d/rc 3 +l4:4:wait:/etc/rc.d/init.d/rc 4 +l5:5:wait:/etc/rc.d/init.d/rc 5 +l6:6:wait:/etc/rc.d/init.d/rc 6 + +ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now + +su:S016:once:/sbin/sulogin + +1:2345:respawn:/sbin/agetty --noclear tty1 9600 +2:2345:respawn:/sbin/agetty tty2 9600 +#3:2345:respawn:/sbin/agetty tty3 9600 +#4:2345:respawn:/sbin/agetty tty4 9600 +#5:2345:respawn:/sbin/agetty tty5 9600 +#6:2345:respawn:/sbin/agetty tty6 9600 + +#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100 + +# End /etc/inittab +EOF +@end verbatim + +The first call of @command{sed} replaces @file{/dev/initctl} with +@file{$(ROOT)/dev/initctl}, and @file{/usr/lib} with +@file{$(ROOT)/lib} among other things in order to install sysvinit +on the target system. + +@samp{make -C src clobber} is used to clean up the @file{src} +directory. + +Then, we create the @file{inittab} file that describes which processes +are started at bootup and during normal operation. + +The line @samp{#c0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100} is +commented out (with @code{#}) in order to avoid the message: +@samp{INIT: Id "c0" respawning too fast: disabled for 5 minutes} on +the target system. + + +@node Tar +@section Tar + +GNU tar is an archiving utility: it stores and extracts files from a +tape or disk archive. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/tar-1.27.1.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/tar-1.27.1 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf tar-1.27.1 +cd +@end verbatim + + +@node Texinfo +@section Texinfo + +GNU Texinfo is a documentation system that can produce both online +information and a printed manual from a single source. + +You need Ncurses headers on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install +libncurses5-dev}. + +@verbatim +# 10 minutes +tar xf ${DOWNLOAD_DIR}/texinfo-4.13a.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/texinfo-4.13 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make -C tools/gnulib/lib +make -C tools +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf texinfo-4.13 +cd + +cd ${TARGET_DIR}/share/info +rm dir +for f in * + do install-info $f dir 2>/dev/null +done +cd +@end verbatim + +The first three calls of @command{make} make it possible to build +Texinfo by cross-compilation. + +For Info to work, the @file{info} directory must contain a file that +serves as a top level directory for the Info system. By convention, +this file is called @file{dir}. We update this file for the target +system. + + +@node Udev +@section Udev + +Udev is the dynamic device management of the kernel Linux. + +You need Gperf on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install gperf}. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/udev-175.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/udev-175 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= \ + --with-rootlibdir=/lib \ + --libexecdir=/lib/udev \ + --docdir=/share/doc/udev-175 \ + --disable-introspection \ + --with-pci-ids-path=no \ + --with-usb-ids-path=no \ + --disable-gudev +make +make DESTDIR=${TARGET_DIR} install +install -dv ${TARGET_DIR}/lib/firmware +ln -sv ../lib/udev/udevd ${TARGET_DIR}/sbin/udevd +cd .. +rm -rf udev-175 +cd +@end verbatim + + +@node Util-Linux +@section Util-Linux + +util-linux is a random collection of utilities for use with the kernel +Linux. + +@quotation Warning +If you have trouble building util-linux, try to uninstall the package +named libtinfo-dev. Then remove @file{$@{BUILD_DIR@}/util-linux-2.24} +and build it again. +@end quotation + +@verbatim +# 5 minutes +# fix /lib/libudev.so: error adding symbols: File in wrong format +rm ${TARGET_DIR}/lib/libudev.la + +tar xf ${DOWNLOAD_DIR}/util-linux-2.24.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/util-linux-2.24 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --enable-partx \ + --disable-wall \ + --enable-write \ + --disable-makeinstall-chown +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -r util-linux-2.24 +cd +@end verbatim + +Option @option{--enable-partx} enables the build and installation of +the @command{addpart}, @command{delpart} and @command{partx} commands. + +Option @option{--disable-wall} disables the build of the +@command{wall} command which is already provided by sysvinit. + +Option @option{--enable-write} enables the build and installation of +the @command{write} command. + +Option @option{--disable-makeinstall-chown} disables the change of +owner to root for installed programs. + + +@node XZ-Utils +@section XZ-Utils + +XZ Utils is a general-purpose data compression software with high +compression ratio. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/xz-5.0.8.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/xz-5.0.8 +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf xz-5.0.8 +cd +@end verbatim + + +@node Bootscripts +@section Bootscripts + +The bootscript archive contains scripts that manage services during +system's bootup and shutdown. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/bootscripts-cross-lfs-2.0.0.tar.xz \ + -C ${BUILD_DIR} +cd ${BUILD_DIR}/bootscripts-cross-lfs-2.0-pre2 +make DESTDIR=${TARGET_DIR} install-bootscripts +make DESTDIR=${TARGET_DIR} install-network +cd .. +rm -rf bootscripts-cross-lfs-2.0-pre2 +cd +@end verbatim + +This installs basic bootscripts required for bootup and shutdown, and +network-related bootscripts. + + +@node Kernel +@section The Kernel + +Linux is a kernel aimed towards POSIX and Single UNIX Specification +compliance. + +You need Bc and Lzma on your system to compile this program from +source. Under gNewSense 4.0, try @samp{sudo apt-get install bc lzma}. + +@ignore +@quotation Warning +You may need to install the package libncurses5-dev to build the +Kernel. +@end quotation +@end ignore + +@verbatim +# 35 minutes +tar xf ${DOWNLOAD_DIR}/linux-libre-3.10.7-gnu.tar.xz \ + -C ${BUILD_DIR} +cd ${BUILD_DIR}/linux-3.10 +make mrproper +@end verbatim + +The @command{sed} expression is used to avoid waiting 60 seconds for +the binary-blob firmware to load at boot time, as those have been +removed by the @file{deblob} script. + +Then: + +@verbatim +cp arch/x86/configs/i386_defconfig .config +#patch -Np1 -i ${DOWNLOAD_DIR}/100gnu+freedo.patch +@end verbatim + +Then, if you want to change the configuration: + +@verbatim +make ARCH=i386 CROSS_COMPILE=${CROSS_TARGET}- menuconfig +@end verbatim + +@quotation Note +In order for GLLFSC to boot properly, you have to activate the two options +below: + +@verbatim +Device Drivers + > Generic Driver Options + > [*] Maintain a devtmpfs fs to mount on /dev + > [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs. +@end verbatim + +@ignore +The second option is for runit + +You can also disable bootup logos in +_D_evice drivers > _G_raphics support > _B_ootup logo. + +# _F_ile systems : stay with ext4 even with an ext3 partition +@end ignore +@end quotation + +Then: + +@verbatim +make \ + ARCH=i386 \ + CROSS_COMPILE=${CROSS_TARGET}- +make \ + ARCH=i386 \ + CROSS_COMPILE=${CROSS_TARGET}- \ + INSTALL_MOD_PATH=${TARGET_DIR} \ + modules_install +cp arch/x86/boot/bzImage ${TARGET_DIR}/boot/vmlinuz-3.10.7-gnu +cp System.map ${TARGET_DIR}/boot/System.map +cp .config ${TARGET_DIR}/boot/config +cd .. +cd +@end verbatim + +@quotation Tip +because future compilation may need kernel sources, the compilation +directory of the kernel should be preserved. +@end quotation + + +@node Configuration Files +@chapter Creating Required Configuration Files for the New System + +@menu +* Time Setup File:: File for time setup. +* Bash Keyboard Setup:: Setting up keyboard function keys + for the Shell. +* Bash Startup Files:: Setting up Bash shell startup files. +* Localhost Setup:: Setting up localhost. +* hosts Setup:: Setting up @file{hosts} file. +* Network Address Setup:: Setting up network address. +* DNS Setup:: Setting up DNS. +* fstab File Creation:: Creating @file{fstab} file. +@end menu + + +@node Time Setup File +@section File for Time Setup + +@verbatim +#mkdir ${TARGET_DIR}/etc/sysconfig +cat > ${TARGET_DIR}/etc/sysconfig/clock << EOF +# Begin /etc/sysconfig/clock + +UTC=1 + +# End /etc/sysconfig/clock +EOF +@end verbatim + +If you have trouble with the clock behaviour, do: + +@verbatim +mv ${TARGET_DIR}/etc/rc.d/rcsysinit.d/S15setclock \ + ${TARGET_DIR}/etc/rc.d/rcsysinit.d/K15setclock +@end verbatim + + +@node Bash Keyboard Setup +@section Setting up Keyboard Function keys for the Shell + +Readline default configuration file is set: + +@verbatim +cat > ${TARGET_DIR}/etc/inputrc << EOF +set bell-style none +set convert-meta Off +set horizontal-scroll-mode Off +set input-meta On +set output-meta On +"\eOd": backward-word +"\eOc": forward-word +"\e[1~": beginning-of-line +"\e[4~": end-of-line +"\e[5~": beginning-of-history +"\e[6~": end-of-history +"\e[3~": delete-char +"\e[2~": quoted-insert +"\eOH": beginning-of-line +"\eOF": end-of-line +"\e[H": beginning-of-line +"\e[F": end-of-line +EOF +@end verbatim + +If @option{convert-meta} is set to @samp{on}, Readline will convert +characters with the eighth bit set to an @sc{ascii} key sequence by +stripping the eighth bit and prefixing an @key{ESC} character, +converting them to a meta-prefixed key sequence. + +@option{horizontal-scroll-mode} set to @samp{off} means that the text +of the lines being edited will be wrapped onto a new screen line when +they are longer than the width of the screen, instead of being +scrolled horizontally on a single screen line. + +@c set meta-flag On + +@option{input-meta} If set to @samp{on}, Readline will enable +eight-bit input (it will not clear the eighth bit in the characters it +reads), regardless of what the terminal claims it can support. + +If @option{output-meta} is set to @samp{on}, Readline will display +characters with the eighth bit set directly rather than as a +meta-prefixed escape sequence. + +@ignore +"\eOd": backward-word +"\eOc": forward-word +"\e[1~": beginning-of-line +"\e[4~": end-of-line +"\e[5~": beginning-of-history +"\e[6~": end-of-history +"\e[3~": delete-char +"\e[2~": quoted-insert +"\eOH": beginning-of-line +"\eOF": end-of-line +"\e[H": beginning-of-line +"\e[F": end-of-line +@end ignore + + +@node Bash Startup Files +@section Setting up Bash Shell Startup Files + +@verbatim +cat > ${TARGET_DIR}/etc/profile << 'EOF' +# Begin /etc/profile + +export LANG=en_US.UTF-8 +export INPUTRC=/etc/inputrc +export PS1='\[\e[31m\]\A-\W\[\e[00m\]# ' + +# End /etc/profile +EOF +@end verbatim + +The environment variable @env{LANG} defines the default language that +should be used on the system. @samp{en_US.UTF-8} means ``english'' +language, country ``US'' and @acronym{UTF-8} (UCS Transformation +Format—8-bit) encoding (Unicode). + +@c For a full list, see??? + +For explanations on @env{PS1}, @pxref{Environment Variables Setup}. + + +@node Localhost Setup +@section Localhost Setup + +@verbatim +echo "HOSTNAME=gllfsc" > ${TARGET_DIR}/etc/sysconfig/network +@end verbatim + + +@node hosts Setup +@section Setting up @file{hosts} File + +@verbatim +cat > ${TARGET_DIR}/etc/hosts << EOF +# Begin /etc/hosts + +127.0.0.1 gllfsc localhost + +# End /etc/hosts +EOF +@end verbatim + + +@node Network Address Setup +@section Setting up Network Address + +You can choose to have a network static or dynamic address. + +@menu +* Network Static Address Setup:: Setting up Network Static Address. +* Network Dynamic Address Setup:: Setting up Network Dynamic + Address. +@end menu + + +@node Network Static Address Setup +@subsection Setting up Network Static Address + +@verbatim +cd ${TARGET_DIR}/etc/sysconfig/network-devices +mkdir -v ifconfig.eth0 +cat > ifconfig.eth0/ipv4 << EOF +ONBOOT=yes +SERVICE=ipv4-static +IP=192.168.1.1 +GATEWAY=192.168.1.2 +PREFIX=24 +BROADCAST=192.168.1.255 +EOF +cd +@end verbatim + +@quotation Warning +@code{IP}, @code{GATEWAY}, @code{BROADCAST} addresses are set up +according to one's situation. +@end quotation + + +@node Network Dynamic Address Setup +@subsection Setting up Network Dynamic Address + +@verbatim +cd ${TARGET_DIR}/etc/sysconfig/network-devices +mkdir -v ifconfig.eth0 +cat > ifconfig.eth0/dhcpcd << EOF +ONBOOT=yes +SERVICE=dhcpcd +DHCP_START="-q" +DHCP_STOP="-k" +EOF +cd +@end verbatim + + +@node DNS Setup +@section Setting up DNS + +@verbatim +cat > ${TARGET_DIR}/etc/resolv.conf << EOF +# Begin /etc/resolv.conf + +nameserver your-main-DNS-address +nameserver your-secondary-DNS-address + +# End /etc/resolv.conf +EOF +@end verbatim + + +@node fstab File Creation +@section @file{fstab} File Creation + +The file @file{/etc/fstab} is used at boot to mount partitions under +the requested directories. + +@verbatim +cat > ${TARGET_DIR}/etc/fstab << EOF +# Begin /etc/fstab + +# file system mount-point type options dump fsck order + +/dev/sda1 / ext3 defaults 0 0 +#/dev/sda7 /home ext3 defaults 0 0 +/dev/sda5 swap swap pri=1 0 0 +devtmpfs /dev dev defaults 0 0 +proc /proc proc defaults 0 0 +tmpfs /run run defaults 0 0 +sysfs /sys sysfs defaults 0 0 +devpts /dev/pts devpts gid=4,mode=620 0 0 +shm /dev/shm tmpfs defaults 0 0 + +# End /etc/fstab +EOF +@end verbatim + +@quotation Warning +the name of the hard drive and the name of filesystem used here have +to be modified to reflect @emph{your} real situation. +@end quotation + + +@node Before Booting GLLFSC +@chapter Before Booting GLLFSC + +@menu +* Archiving:: All the system archived in one + package. +* Recommendations:: Some tips. +@end menu + + +@node Archiving +@section Archiving the System + +After the system has been completed, we use the command @command{exit} +to logout as the @emph{gllfsc} user. + +Now, login as the @emph{root} user. + +Then fix the permissions on the new system: + +@verbatim +export TARGET_DIR=/gllfsc +cd ${TARGET_DIR} +mknod -m 600 dev/console c 5 1 +mknod -m 666 dev/null c 1 3 +cp -a dev/{console,null} lib/udev/devices/ +#chown -R root:root * +chown -R root:root \ + bin boot dev etc home include lib* local man mnt proc root run \ + sbin share src static sys tmp usr var +@end verbatim + +Also copy packages to be built after reboot: + +@verbatim +export DOWNLOAD_DIR="${TARGET_DIR}/download" +for FILE in \ + tzcode2013h.tar.gz \ + tzdata2013h.tar.gz \ + runit-2.1.2.tar.gz \ + openssl-1.0.1i.tar.gz \ + wpa_supplicant-2.0.tar.gz \ + wireless_tools.29.tar.gz \ + wget-1.14.tar.gz \ + perl-5.18.1.tar.gz \ + libtasn1-3.4.tar.gz \ + lynx2.8.8dev.16.tar.bz2 \ + certdata.txt \ + inetutils-1.9.1.tar.gz \ + man-db-2.6.7.1.tar.xz; do +cp -v ${DOWNLOAD_DIR}/$FILE ${TARGET_DIR}/src +done +@end verbatim + +We archive the entire system by using the following command: + +@verbatim +# 8 minutes +tar -cjf gllfsc-pentium4-1.7.tar.bz2 \ + bin boot dev etc home include lib* local man mnt proc root run \ + sbin share src static sys tmp usr var +@end verbatim + +It is then simple to copy the archive to the target machine and extract +it. + + +@node Recommendations +@section Some Recommendations + +We recommend extracting the system to an empty partition. Moreover, +the filesystem of the chosen partition has to be a filesystem +supported by the kernel you compiled. Finally, this partition has to +be consistent with the system description in the file +@file{/etc/fstab} you created during setup (@pxref{fstab File +Creation}). + +@ignore + +extlinux +lilo + +@verbatim +# ? minute +tar xf ${DOWNLOAD_DIR}/grub-2.00.tar.gz \ + -C ${BUILD_DIR} +cd ${BUILD_DIR}/grub-2.00 +sed -i '/gets is a security hole/d' grub-core/gnulib/stdio.in.h +./configure \ + --build=${CROSS_HOST} \ + --host=${CROSS_TARGET} \ + --prefix= +make +make DESTDIR=${TARGET_DIR} install +cd .. +rm -rf grub-2.00 +cd + +mkdir ${TARGET_DIR}/boot/grub +@end verbatim +@end ignore + +Then, you will have to edit the GRUB configuration file of the target +machine: @file{/boot/grub/grub.cfg}. + +@c ?This file has to be put on the first partition of the hard drive. + +@c GRUB sur /dev/sda1 >= 1MB +@c mount ... /mnt/boot && grub-install --boot-directory=/mnt/boot /dev/sda +@c grub-script-check + +@ignore +@quotation Note +?On the Yeeloong 8133, vmlinuz @emph{must} be on the first primary +partition to be able to boot. +@end quotation + +# Install in the MBR +#grub-install /dev/sda +# Install in the OS partition +grub-install /dev/sda1 +@end ignore + +A minimal @file{/boot/grub/grub.cfg} could be: + +@verbatim +insmod ext2 +set default=0 +set root=(hd0,1) +set timeout=5 + +menuentry 'GLLFSC 1.7' { + echo 'Loading linux-libre-3.10.7-gnu...' + linux (hd0,1)/boot/vmlinuz-3.10.7-gnu root=/dev/sda1 quiet +} +@end verbatim + +@c Or use grub-mkconfig -o /boot/grub/grub.cfg + + +@node After Booting GLLFSC +@chapter After Booting GLLFSC + +Some system configuration and package installation can only be made +after booting onto the new system. + +@menu +* Login:: Login onto GLLFSC. +* Locales:: Configure the language of GLLFSC. +* Timezone:: Building Tzcode, Tzdata and choosing timezone. +* Runit:: Building Runit. +* Perl:: Building Perl. +* OpenSSL:: Building OpenSSL. +* Wpa_supplicant:: Building Wpa_supplicant. +* Wireless_tools:: Building Wireless_tools. +* Wget:: Building Wget. +* Libtasn1:: Building Libtasn1. +* Lynx:: Building Lynx. +* CA-Certificates:: Building CA-Certificates. +* Inetutils 2:: Building Inetutils under GLLFSC. +* Man-db 2:: Building Man-db under GLLFSC. +* Archiving Complete System:: Archiving the Complete System. +* Add User:: Creating a New User Account. +* Halting Computer:: Halting the Computer +@end menu + + +@node Login +@section Login + +To login as @emph{root}, just type @samp{root} when the system asks +for your @samp{login:}. Then, update your bash profile: + +@quotation Note +To use the french keyboard layout, type @samp{loadkeys -q fr}. +@end quotation + +@verbatim +cat > ~/.bash_profile << EOF +export BUILD_DIR=/tmp +export DOWNLOAD_DIR=/src +EOF + +source ~/.bash_profile +@end verbatim + + +@node Locales +@section Locales + +You may want to have your new system display messages in your native +language. If you desire to have a system supporting german, US +english, french and China mainland's chinese: + +@verbatim +mkdir /lib/locale + +#localedef -i de_DE -f UTF-8 de_DE +localedef -i en_US -f UTF-8 en_US +#localedef -i fr_FR -f UTF-8 fr_FR +#localedef -i zh_CN -f UTF-8 zh_CN +@end verbatim + +Other locales are available: + +@itemize +@item +For available charmaps, see the content of @file{/share/i18n/charmaps}. + +@item +For available locales, see the content of @file{/share/i18n/locales}. + +@end itemize + + +@node Timezone +@section Timezone + +In order to have the time and date corresponding to the area where you +live, you should build tzcode, tzdata and define your timezone. + +@verbatim +mkdir ${BUILD_DIR}/tz +tar xf ${DOWNLOAD_DIR}/tzcode2013h.tar.gz -C ${BUILD_DIR}/tz +tar xf ${DOWNLOAD_DIR}/tzdata2013h.tar.gz -C ${BUILD_DIR}/tz +cd ${BUILD_DIR}/tz + +make \ + TOPDIR=/ \ + TZDIR=/share/zoneinfo \ + ETCDIR=/bin + +for TZ in africa antarctica asia australasia europe northamerica \ + southamerica pacificnew etcetera backward systemv factory \ + solar87 solar88 solar89; do + zic -y "sh yearistype.sh" \ + -d /share/zoneinfo \ + -L /dev/null $TZ +done + +zic -y "bash yearistype.sh" \ + -d /share/zoneinfo \ + -l GMT \ + -p America/New_York + +cp iso3166.tab zone.tab /share/zoneinfo +cd .. +rm -rf tz +cd +@end verbatim + +Then, we define our timezone, in this case @file{Europe/Paris}: + +@verbatim +cp -v --remove-destination \ + /share/zoneinfo/Europe/Paris \ + /etc/localtime +@end verbatim + + +@node Runit +@section Runit + +runit is a cross-platform Unix init scheme with service supervision, a +replacement for sysvinit, and other init schemes. + + +@verbatim +tar xf ${DOWNLOAD_DIR}/runit-2.1.2.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/admin/runit-2.1.2 + +# On GLLFSC, sleep is not under /bin: +sed -i 's,/bin/sleep,sleep,' etc/debian/ctrlaltdel + +cd src + +make +make check + +install -s -m0755 \ + chpst runit runit-init runsv runsvchdir runsvdir sv svlogd utmpset \ + /sbin + +install -m0644 ../man/* \ + /share/man/man8 + +cd .. + +mkdir /etc/runit + +mkdir /service + +cp etc/debian/ctrlaltdel /etc/runit/ + +mv /sbin/init /sbin/init.sysv +ln -sv runit-init /sbin/init + +cd ../.. +rm -rf admin +cd +@end verbatim + +The init-related programs have been installed. We need to create the +boot scripts too: @file{/etc/runit/1} to boot the system, +@file{/etc/runit/2} to launch 2 ttys and the service logging daemon +and @file{/etc/runit/3} to halt or reboot the system. + +@verbatim +cat > /etc/runit/1 << 'EOF' +#!/bin/sh +# system one time tasks + +# Exit on error: +set -e + +PATH=/bin + +echo -n '16. Mounting kernel-based file systems:' +echo -n ' /proc' +mount -n -o nosuid,noexec,nodev -t proc proc /proc +echo -n ' /sys' +mount -n -o nosuid,noexec,nodev -t sysfs sys /sys +echo ' /run' +mount -n -o mode=0755,nosuid,nodev -t tmpfs run /run + +echo -n '15. Creating directories:' +echo -n ' /run/lock' +mkdir -m 1777 /run/lock +echo -n ' /dev/pts' +mkdir -p /dev/pts +echo ' /dev/shm' +mkdir -p /dev/shm + +echo '14. Mounting root file system in read-write mode.' +mount -n -o remount,rw / >/dev/null + +# Remove fsck-related system watermarks. +rm -f /fastboot /forcefsck + +echo '13. Recording existing mounts in /etc/mtab.' +> /etc/mtab +mount -f / +mount -f /proc +mount -f /sys +mount -f /run +mount -f /dev + +echo '12. Mounting remaining file systems.' +mount -a -r >/dev/null + +echo '11. Cleaning file system /tmp.' +cd /tmp && find . -xdev -mindepth 1 ! -name lost+found -delete + +echo '10. Creating /var/run/utmp.' +if grep -q '^utmp:' /etc/group; then + chmod 664 /var/run/utmp + chgrp utmp /var/run/utmp +fi + +echo '9. Starting udevd...' +echo '' > /sys/kernel/uevent_helper + +/lib/udev/udevd --daemon + +echo '8. Performing Coldplugging...' +/sbin/udevadm trigger --action=add --type=subsystems +/sbin/udevadm trigger --action=add --type=devices + +/sbin/udevadm settle + +echo '7. Activating all swap files/partitions...' +swapon -a + +echo '6. Setting Font...' +setfont LatArCyrHeb-16 -C /dev/tty2 +setfont LatArCyrHeb-16 -C /dev/tty3 + +echo '5. Setting keymap to UTF-8...' +dumpkeys | loadkeys --unicode + +echo '4. Enabling Multibyte input...' +kbd_mode -u + +echo '3. Setting up US Keymap...' +loadkeys -q us + +echo '2. Setting encoding to UTF-8...' +echo -ne $'\033%G' > /dev/tty2 +echo -ne $'\033%G' > /dev/tty3 + +echo '1. Bringing up the loopback interface...' +ip addr add 127.0.0.1/8 label lo dev lo +ip link set lo up + +echo '0. Setting hostname to gllfsc...' +hostname gllfsc + +echo +echo To login, remember: +echo your login is root +echo with no password +echo +echo You can now login through tty2 by pressing simultaneously +echo Ctrl, Alt and F2 keys +echo +echo You can then come back to this screen \(tty1\) by pressing +echo simultaneously Ctrl, Alt and F1 keys +echo +echo Edit /etc/runit/1 if you want to remove this message +echo + +touch /etc/runit/stopit +chmod 0 /etc/runit/stopit + +exit 0 +EOF + +chmod +x /etc/runit/1 +@end verbatim + +@verbatim +cat > /etc/runit/2 << EOF +#!/bin/sh + +PATH=/bin + +exec env -i PATH=/bin \ +runsvdir -P /service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................' +EOF + +chmod +x /etc/runit/2 +@end verbatim + +@verbatim +cat > /etc/runit/3 << EOF +#!/bin/sh + +# Exit on error: +set -e + +exec 2>&1 + +PATH=/bin + +echo '4. Waiting for services to stop...' +sv down /service/* + +echo '3. Exiting services...' +sv exit /service/* + +echo '2. Deactivating all swap files/partitions...' +swapoff -a + +# Unmount everything but /: +echo -n '1. Unmounting filesystems: /home' +umount -r /home +echo -n ' /proc' +umount -r /proc +echo -n ' /sys' +umount -r /sys +echo -n ' /dev/pts' +umount -r /dev/pts +echo ' /dev/shm' +umount -r /dev/shm + +echo '0. Shutdown...' + +exit 0 +EOF + +chmod +x /etc/runit/3 +@end verbatim + +We now create useful services: + +@verbatim +mkdir /etc/sv +mkdir /etc/sv/getty-2 + +cat > /etc/sv/getty-2/run << EOF +#!/bin/sh +exec /sbin/agetty tty2 9600 +EOF +chmod +x /etc/sv/getty-2/run + +cat > /etc/sv/getty-2/finish << EOF +#!/bin/sh +exec utmpset -w tty2 +EOF +chmod +x /etc/sv/getty-2/finish + +ln -sv /etc/sv/getty-2 /service/getty-2 + + +mkdir -p /etc/sv/getty-3 + +cat > /etc/sv/getty-3/run << EOF +#!/bin/sh +exec /sbin/agetty tty3 9600 +EOF +chmod +x /etc/sv/getty-3/run + +cat > /etc/sv/getty-3/finish << EOF +#!/bin/sh +exec utmpset -w tty3 +EOF +chmod +x /etc/sv/getty-3/finish + +ln -sv /etc/sv/getty-3 /service/getty-3 + + +mkdir /etc/sv/svlogd + +cat > /etc/sv/svlogd/run << EOF +#!/bin/sh +exec svlogd +EOF +chmod +x /etc/sv/svlogd/run + +ln -sv /etc/sv/svlogd /service/svlogd +@end verbatim + + +@node Perl +@section Perl + +Perl is a high-level programming language. + +@quotation Note +You may have to type @samp{exit} twice during the configure phase of +the Perl installation. +@end quotation + +@verbatim +tar xf ${DOWNLOAD_DIR}/perl-5.18.1.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/perl-5.18.1 +sh Configure -ds -e -Dprefix= +make +make install +cd .. +rm -rf perl-5.18.1 +cd +@end verbatim + + +@node OpenSSL +@section OpenSSL + +OpenSSL is a toolkit implementing the Transport Layer Security (TLS) +and Secure Sockets Layer (SSL) protocols as well as a cryptography +library. + +@verbatim +tar xf ${DOWNLOAD_DIR}/openssl-1.0.1i.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/openssl-1.0.1i +./config \ + --prefix=/usr \ + --openssldir=/etc/ssl \ + shared +make -j1 +# Install without the documentation: +make install_sw +cd .. +rm -rf openssl-1.0.1i +cd +@end verbatim + + +@node Wpa_supplicant +@section Wpa_supplicant + +Wpa_supplicant is a user space IEEE 802.1X/WPA supplicant (wireless +client) for many wireless drivers. + +@verbatim +# 2 minutes +tar xf ${DOWNLOAD_DIR}/wpa_supplicant-2.0.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/wpa_supplicant-2.0/wpa_supplicant + +cat > .config << EOF +CONFIG_DRIVER_HOSTAP=y +CONFIG_DRIVER_WEXT=y +#CONFIG_DRIVER_NL80211=y +#CONFIG_DRIVER_WIRED=y + +#CONFIG_PKCS12=y +#CONFIG_SMARTCARD=y + +CONFIG_CTRL_IFACE=y + +CONFIG_BACKEND=file +CONFIG_PEERKEY=y +#CONFIG_IEEE80211W=y + +CONFIG_TLS=openssl + +#CONFIG_IEEE80211N=y +EOF + +sed -i.orig 's@local/@@g' Makefile +make +make install +cd ../.. +rm -rf wpa_supplicant-2.0 +cd + +cat > /etc/wpa_supplicant.conf << EOF +network={ + ssid="MYESSID" + key_mgmt=WPA-PSK + pairwise=TKIP + group=TKIP + psk="MYPASSWORD" +} +EOF +chmod 600 /etc/wpa_supplicant.conf +@end verbatim + + +@node Wireless_tools +@section Wireless_tools + +The Wireless Tools is a set of tools allowing to manipulate the +Wireless Extensions. + +@verbatim +# 1 minute +tar xf ${DOWNLOAD_DIR}/wireless_tools.29.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/wireless_tools.29 +make +make PREFIX= install +cd .. +rm -rf wireless_tools.29 +cd +@end verbatim + + +@ignore +Launch wireless connection: + +ifconfig wlan0 up +iwconfig wlan0 essid MYESSID +sleep 10s +dhcpcd wlan0 +@end ignore + + +@node Wget +@section Wget + +GNU wget is an utility for downloading network data. + +@verbatim +# 5 minutes +tar xf ${DOWNLOAD_DIR}/wget-1.14.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/wget-1.14 +sed -i.orig 's/item $thing/item C<$thing>/' doc/texi2pod.pl +./configure \ + --prefix= \ + --with-ssl=openssl +make +make install +cd .. +rm -rf wget-1.14 +cd +@end verbatim + + +@node Libtasn1 +@section Libtasn1 + +GNU libtasn1 is a ASN.1 library. + +@verbatim +tar xf ${DOWNLOAD_DIR}/libtasn1-3.4.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/libtasn1-3.4 +./configure \ + --prefix= +make +make install +cd .. +rm -rf libtasn1-3.4 +cd +@end verbatim + + +@node Lynx +@section Lynx + +Lynx is a text web browser. + +@verbatim +tar xf ${DOWNLOAD_DIR}/lynx2.8.8dev.16.tar.bz2 -C ${BUILD_DIR} +cd ${BUILD_DIR}/lynx2-8-8 +./configure \ + --prefix= \ + --with-ssl=/lib \ + --enable-nls \ + --with-screen=ncursesw +make +make install +cd .. +rm -rf lynx2-8-8 + +# Stop asking questions about certificates: +sed -i s/#FORCE_SSL_PROMPT:PROMPT/FORCE_SSL_PROMPT:yes/ \ + /etc/lynx.cfg + +# Display non-ascii characters: +sed -i s/#CHARACTER_SET:iso-8859-1/CHARACTER_SET:utf-8/ \ + /etc/lynx.cfg + +# I don't want cookies: +sed -i 's/#SET_COOKIES:TRUE/SET_COOKIES:FALSE/' \ + /etc/lynx.cfg +sed -i 's/#ACCEPT_ALL_COOKIES:FALSE/ACCEPT_ALL_COOKIES:FALSE/' \ + /etc/lynx.cfg +sed -i 's/#PERSISTENT_COOKIES:FALSE/PERSISTENT_COOKIES:FALSE/' \ + /etc/lynx.cfg +cd +@end verbatim + + +@node CA-Certificates +@section CA-Certificates + +CA-Certificates are used for https web pages. + +@verbatim +# Inspired from +# http://linuxfromscratch.org/blfs/view/stable/postlfs/cacerts.html + +cp ${DOWNLOAD_DIR}/certdata.txt ${BUILD_DIR} +cd ${BUILD_DIR} + +cat > /bin/make-cert.pl << 'EOF' +#!/bin/perl -w + +# Used to generate PEM encoded files from Mozilla certdata.txt. +# Run as ./make-cert.pl > certificate.crt +# +# Parts of this script courtesy of RedHat (mkcabundle.pl) +# +# This script modified for use with single file data (tempfile.cer) +# extracted from certdata.txt, taken from the latest version in the +# Mozilla NSS source. +# mozilla/security/nss/lib/ckfw/builtins/certdata.txt +# +# Authors: DJ Lucas +# Bruce Dubbs +# +# Version 20120211 + +my $certdata = './tempfile.cer'; + +open( IN, "cat $certdata|" ) + || die "could not open $certdata"; + +my $incert = 0; + +while ( ) +{ + if ( /^CKA_VALUE MULTILINE_OCTAL/ ) + { + $incert = 1; + open( OUT, "|openssl x509 -text -inform DER -fingerprint" ) + || die "could not pipe to openssl x509"; + } + + elsif ( /^END/ && $incert ) + { + close( OUT ); + $incert = 0; + print "\n\n"; + } + + elsif ($incert) + { + my @bs = split( /\\/ ); + foreach my $b (@bs) + { + chomp $b; + printf( OUT "%c", oct($b) ) unless $b eq ''; + } + } +} +EOF + +chmod +x /bin/make-cert.pl + + + +cat > /bin/make-ca.sh << 'EOF' +#!/bin/sh +# Begin make-ca.sh +# Script to populate OpenSSL's CApath from a bundle of PEM formatted +# CAs +# +# The file certdata.txt must exist in the local directory +# Version number is obtained from the version of the data. +# +# Authors: DJ Lucas +# Bruce Dubbs +# +# Version 20120211 + +certdata="certdata.txt" + +if [ ! -r $certdata ]; then + echo "$certdata must be in the local directory" + exit 1 +fi + +REVISION=$(grep CVS_ID $certdata | cut -f4 -d'$') + +if [ -z "${REVISION}" ]; then + echo "$certfile has no 'Revision' in CVS_ID" + exit 1 +fi + +VERSION=$(echo $REVISION | cut -f2 -d" ") + +TEMPDIR=$(mktemp -d) +TRUSTATTRIBUTES="CKA_TRUST_SERVER_AUTH" +BUNDLE="BLFS-ca-bundle-${VERSION}.crt" +CONVERTSCRIPT="/bin/make-cert.pl" +SSLDIR="/etc/ssl" + +mkdir "${TEMPDIR}/certs" + +# Get a list of starting lines for each cert +CERTBEGINLIST=$(grep -n "^# Certificate" "${certdata}" | cut -d ":" -f1) + +# Get a list of ending lines for each cert +CERTENDLIST=$(grep -n "^CKA_TRUST_STEP_UP_APPROVED" "${certdata}" \ + | cut -d ":" -f 1) + +# Start a loop +for certbegin in ${CERTBEGINLIST}; do + for certend in ${CERTENDLIST}; do + if test "${certend}" -gt "${certbegin}"; then + break + fi + done + + # Dump to a temp file with the name of the file as the beginning + # line number + sed -n "${certbegin},${certend}p" "${certdata}" \ + > "${TEMPDIR}/certs/${certbegin}.tmp" +done + +unset CERTBEGINLIST CERTDATA CERTENDLIST certbegin certend + +mkdir -p certs +rm -f certs/* # Make sure the directory is clean + +for tempfile in ${TEMPDIR}/certs/*.tmp; do + # Make sure that the cert is trusted... + grep "CKA_TRUST_SERVER_AUTH" "${tempfile}" | \ + egrep "TRUST_UNKNOWN|NOT_TRUSTED" > /dev/null + + if test "${?}" = "0"; then + # Throw a meaningful error and remove the file + cp "${tempfile}" tempfile.cer + perl ${CONVERTSCRIPT} > tempfile.crt + keyhash=$(openssl x509 -noout -in tempfile.crt -hash) + echo "Certificate ${keyhash} is not trusted! Removing..." + rm -f tempfile.cer tempfile.crt "${tempfile}" + continue + fi + + # If execution made it to here in the loop, the temp cert is trusted + # Find the cert data and generate a cert file for it + + cp "${tempfile}" tempfile.cer + perl ${CONVERTSCRIPT} > tempfile.crt + keyhash=$(openssl x509 -noout -in tempfile.crt -hash) + mv tempfile.crt "certs/${keyhash}.pem" + rm -f tempfile.cer "${tempfile}" + echo "Created ${keyhash}.pem" +done + +# Remove blacklisted files +# MD5 Collision Proof of Concept CA +if test -f certs/8f111d69.pem; then + echo "Certificate 8f111d69 is not trusted! Removing..." + rm -f certs/8f111d69.pem +fi + +# Finally, generate the bundle and clean up. +cat certs/*.pem > ${BUNDLE} +rm -r "${TEMPDIR}" +EOF + +chmod +x /bin/make-ca.sh + + + +cat > /bin/remove-expired-certs.sh << 'EOF' +#!/bin/sh +# Begin /bin/remove-expired-certs.sh +# +# Version 20120211 + +# Make sure the date is parsed correctly on all systems +mydate() +{ + local y=$( echo $1 | cut -d" " -f4 ) + local M=$( echo $1 | cut -d" " -f1 ) + local d=$( echo $1 | cut -d" " -f2 ) + local m + + if [ ${d} -lt 10 ]; then d="0${d}"; fi + + case $M in + Jan) m="01";; + Feb) m="02";; + Mar) m="03";; + Apr) m="04";; + May) m="05";; + Jun) m="06";; + Jul) m="07";; + Aug) m="08";; + Sep) m="09";; + Oct) m="10";; + Nov) m="11";; + Dec) m="12";; + esac + + certdate="${y}${m}${d}" +} + +OPENSSL=/bin/openssl +DIR=/etc/ssl/certs + +if [ $# -gt 0 ]; then + DIR="$1" +fi + +certs=$( find ${DIR} -type f -name "*.pem" -o -name "*.crt" ) +today=$( date +%Y%m%d ) + +for cert in $certs; do + notafter=$( $OPENSSL x509 -enddate -in "${cert}" -noout ) + date=$( echo ${notafter} | sed 's/^notAfter=//' ) + mydate "$date" + + if [ ${certdate} -lt ${today} ]; then + echo "${cert} expired on ${certdate}! Removing..." + rm -f "${cert}" + fi +done +EOF + +chmod +x /bin/remove-expired-certs.sh + + +make-ca.sh +remove-expired-certs.sh certs + + +install -d /etc/ssl/certs +cp -v certs/*.pem /etc/ssl/certs +c_rehash +install BLFS-ca-bundle*.crt /etc/ssl/ca-bundle.crt +ln -sfv ../ca-bundle.crt /etc/ssl/certs/ca-certificates.crt + +rm BLFS-ca-bundle*.crt +rm certdata.txt +rm -rf certs + +cd +@end verbatim + + +@node Inetutils 2 +@section Inetutils 2 + +Installed @samp{ifconfig} may hang. Reinstalling under GLLFSC to fix this: + +@verbatim +tar xf ${DOWNLOAD_DIR}/inetutils-1.9.1.tar.gz -C ${BUILD_DIR} +cd ${BUILD_DIR}/inetutils-1.9.1 +sed -i '/gets is a security hole/d' lib/stdio.in.h +#sed -i -e '/PATH_PROCNET_DEV/s/\ no//' paths +./configure \ + --prefix= +make +make DESTDIR= install +cd .. +rm -rf inetutils-1.9.1 +cd +@end verbatim + + +@node Man-db 2 +@section Man-db 2 + +Installed @samp{man} is buggy. Reinstalling under GLLFSC to fix this: + +@verbatim +tar xf ${DOWNLOAD_DIR}/man-db-2.6.7.1.tar.xz -C ${BUILD_DIR} +cd ${BUILD_DIR}/man-db-2.6.7.1 +libpipeline_CFLAGS="-I/include" \ + libpipeline_LIBS="-L/lib -lpipeline" \ + ./configure \ + --prefix= +make +make DESTDIR= install +cd .. +rm -rf man-db-2.6.7.1 +cd +@end verbatim + + +@node Archiving Complete System +@section Archiving the Complete System + +@verbatim +# Clean up: +rm /src/* +rm /root/* +rm /root/.bash* +rm -rf /share/doc +mv /share/man/man* /share +rm -rf /share/man/* +mv /share/man[1-8] /share/man + +# Strip binaries +# 109 MB before, 36 MB after +strip --strip-all /bin/* + +# To be done outside GLLFSC: +tar -cjf gllfsc-pentium4-1.7-completed.tar.bz2 \ + bin boot dev etc home include lib* local man mnt proc root run \ + sbin service share src sys tmp usr var +@end verbatim + + +@node Add User +@section Add User + +To create a new user, without root rights: + +@verbatim +useradd -m USER +@end verbatim + +This will create a new user named @samp{USER}, with group +@samp{USER} and user's home at @file{/home/USER}. + +To give a password to this user: + +@verbatim +passwd USER +@end verbatim + +You may want to change the color of this user's prompt: + +@verbatim +cat > /home/USER/.bash_profile << EOF +export PS1='\[\e[32m\]\A-\W\[\e[00m\]$ ' +EOF +chown USER:USER /home/USER/.bash_profile +@end verbatim + + +@node Halting Computer +@section Halting the Computer + +In order to halt the computer after this build process, type: + +@verbatim +init.sysv 0 +@end verbatim + +If you prefer to reboot instead type: + +@verbatim +init.sysv 6 +@end verbatim + +The next time you use GLLFSC, runit will be the default init system +and you will have to type @samp{init 0} to halt the operating system +and @samp{init 6} to reboot. + + +@node Further Readings +@chapter Further Readings + +On my personal website at +@uref{http://cjarry.org/gnu-linux/gllfsc@//gllfsc.en.html}, +there is some information on how to extend GLLFSC, for instance +instructions on how to build Xorg and programs on top of it. + +Haiyong Sun's website (in Chinese): +@uref{http://blog.chinaunix.net/uid/436750.html}. It includes documents on building a +GNU/Linux system for Loongson and a GNU/Hurd system for x86. + +Cross [GNU/]Linux from scratch: @uref{http://www.clfs.org} (PDF +files may be downloaded from @uref{http://clfs.org/files/BOOK/}). +Includes a lot of documentation to build a GNU/Linux system by +cross-compilation on a variety of hardware, no information (yet) for +cross-compiling with sysroot on MIPS though. There is also a +Community-driven Beyond [GNU/]Linux From Scratch on +@uref{http://cblfs.clfs.org/index.php/Main_Page}. It documents +the building of Xorg and TeXLive among other things. + +@c Some patches from the above project are available for download on +@c @uref{http://svn.clfs.org/svn/repos/patches/}. + +@uref{http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_@/man.txt} +documents an interesting way of managing packages. Quotation from the +file: + +@quotation +DESCRIPTION: +@itemize + +@item +You want to know which packages your files belong to? + +@item +You want to deinstall software that doesn't have make uninstall? + +@item +You are bothered by programs installed setuid root behind your back? + +@item +You don't like packages quietly overwriting files from other packages? + +@item +You don't like package managers like RPM? + +@item +YOU WANT TOTAL CONTROL USING ONLY UNIX BUILTINS? +@end itemize +@end quotation + +The suckless team@footnote{@uref{http://suckless.org}} is a group of +programmers that share the following +philosophy@footnote{@uref{http://suckless.org/philosophy}}: + +@quotation +Focus on simplicity, clarity and frugality. Our philosophy is about +keeping things simple, minimal and usable. We believe this should +become the mainstream philosophy in the IT sector. Unfortunately, the +tendency for complex, error-prone and slow software seems to be +prevalent in the present-day software industry. We intend to prove the +opposite with our software projects. +@end quotation + +The simple and lightweight programs released by this team are +interesting for everyone who like small, reactive and reliable +programs. + + +@ignore +@node Thanks +@chapter Thanks + +I thank Lemote and particularily the CEO, Fuxin Zhang, for offering me +a Yeeloong 8133, Huacai Chen and Haiyong Sun for their help in fixing +the bugs I found in the deblobbed kernel. + +I am particularily grateful to Haiyong Sun for having shared his +knowledge on building a free operating system for Loongson 2F +machines, this document is heavily based on this. +@end ignore + + +@node GNU Free Documentation License +@appendix GNU Free Documentation License +@include fdl-1.3.texi + + +@node GNU General Public License +@appendix GNU General Public License +@include gpl.texi + +@bye diff --git a/gpl.txt b/gpl.txt new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/gpl.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +.