source: introduction/important/building-notes.xml@ fabf04f7

10.0 10.1 11.0 11.1 11.2 11.3 12.0 12.1 8.0 8.1 8.2 8.3 8.4 9.0 9.1 basic bdubbs/svn elogind kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts lazarus lxqt perl-modules plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition trunk upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since fabf04f7 was f3429309, checked in by Fernando de Oliveira <fernando@…>, 8 years ago
  • mupdf-1.8: minor reformat.
  • removing spaces from EOL, from Denis Mugnier.
  • BLFS/trunk/BOOK/kde/add/kdepim-runtime.xml: needed to fix to validate the book. One chunck had been removed. Bruce, please check if it is OK, now.

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@16645 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 19.8 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="unpacking">
9 <?dbhtml filename="notes-on-building.html"?>
10
11 <sect1info>
12 <othername>$LastChangedBy$</othername>
13 <date>$Date$</date>
14 </sect1info>
15
16 <title>Notes on Building Software</title>
17
18 <para>Those people who have built an LFS system may be aware
19 of the general principles of downloading and unpacking software. Some
20 of that information is repeated here for those new to building
21 their own software.</para>
22
23 <para>Each set of installation instructions contains a URL from which you
24 can download the package. The patches; however, are stored on the LFS
25 servers and are available via HTTP. These are referenced as needed in the
26 installation instructions.</para>
27
28 <para>While you can keep the source files anywhere you like, we assume that
29 you have unpacked the package and changed into the directory created by the
30 unpacking process (the 'build' directory). We also assume you have
31 uncompressed any required patches and they are in the directory immediately
32 above the 'build' directory.</para>
33
34 <para>We can not emphasize strongly enough that you should start from a
35 <emphasis>clean source tree</emphasis> each time. This means that if
36 you have had an error during configuration or compilation, it's usually
37 best to delete the source tree and
38 re-unpack it <emphasis>before</emphasis> trying again. This obviously
39 doesn't apply if you're an advanced user used to hacking
40 <filename>Makefile</filename>s and C code, but if in doubt, start from a
41 clean tree.</para>
42
43 <sect2>
44 <title>Building Software as an Unprivileged (non-root) User</title>
45
46 <para>The golden rule of Unix System Administration is to use your
47 superpowers only when necessary. Hence, BLFS recommends that you
48 build software as an unprivileged user and only become the
49 <systemitem class='username'>root</systemitem> user when installing the
50 software. This philosophy is followed in all the packages in this book.
51 Unless otherwise specified, all instructions should be executed as an
52 unprivileged user. The book will advise you on instructions that need
53 <systemitem class='username'>root</systemitem> privileges.</para>
54
55 </sect2>
56
57 <sect2>
58 <title>Unpacking the Software</title>
59
60 <para>If a file is in <filename class='extension'>.tar</filename> format
61 and compressed, it is unpacked by running one of the following
62 commands:</para>
63
64<screen><userinput>tar -xvf filename.tar.gz
65tar -xvf filename.tgz
66tar -xvf filename.tar.Z
67tar -xvf filename.tar.bz2</userinput></screen>
68
69 <note>
70 <para>You may omit using the <option>v</option> parameter in the commands
71 shown above and below if you wish to suppress the verbose listing of all
72 the files in the archive as they are extracted. This can help speed up the
73 extraction as well as make any errors produced during the extraction
74 more obvious to you.</para>
75 </note>
76
77 <para>You can also use a slightly different method:</para>
78
79<screen><userinput>bzcat filename.tar.bz2 | tar -xv</userinput></screen>
80
81 <para>Finally, you sometimes need to be able to unpack patches which are
82 generally not in <filename class='extension'>.tar</filename> format. The
83 best way to do this is to copy the patch file to the parent of the 'build'
84 directory and then run one of the following commands depending on whether
85 the file is a <filename class='extension'>.gz</filename> or <filename
86 class='extension'>.bz2</filename> file:</para>
87
88<screen><userinput>gunzip -v patchname.gz
89bunzip2 -v patchname.bz2</userinput></screen>
90
91 </sect2>
92
93 <sect2>
94 <title>Verifying File Integrity Using 'md5sum'</title>
95
96 <para>Generally, to verify that the downloaded file is genuine and complete,
97 many package maintainers also distribute md5sums of the files. To verify the
98 md5sum of the downloaded files, download both the file and the
99 corresponding md5sum file to the same directory (preferably from different
100 on-line locations), and (assuming <filename>file.md5sum</filename> is the
101 md5sum file downloaded) run the following command:</para>
102
103<screen><userinput>md5sum -c file.md5sum</userinput></screen>
104
105 <para>If there are any errors, they will be reported. Note that the BLFS
106 book includes md5sums for all the source files also. To use the BLFS
107 supplied md5sums, you can create a <filename>file.md5sum</filename> (place
108 the md5sum data and the exact name of the downloaded file on the same
109 line of a file, separated by white space) and run the command shown above.
110 Alternately, simply run the command shown below and compare the output
111 to the md5sum data shown in the BLFS book.</para>
112
113<screen><userinput>md5sum <replaceable>&lt;name_of_downloaded_file&gt;</replaceable></userinput></screen>
114
115 </sect2>
116
117 <sect2>
118 <title>Creating Log Files During Installation</title>
119
120 <para>For larger packages, it is convenient to create log files instead of
121 staring at the screen hoping to catch a particular error or warning. Log
122 files are also useful for debugging and keeping records. The following
123 command allows you to create an installation log. Replace
124 <replaceable>&lt;command&gt;</replaceable> with the command you intend to execute.</para>
125
126<screen><userinput>( <replaceable>&lt;command&gt;</replaceable> 2&gt;&amp;1 | tee compile.log &amp;&amp; exit $PIPESTATUS )</userinput></screen>
127
128 <para><option>2&gt;&amp;1</option> redirects error messages to the same
129 location as standard output. The <command>tee</command> command allows
130 viewing of the output while logging the results to a file. The parentheses
131 around the command run the entire command in a subshell and finally the
132 <command>exit $PIPESTATUS</command> command ensures the result of the
133 <replaceable>&lt;command&gt;</replaceable> is returned as the result and not the
134 result of the <command>tee</command> command.</para>
135
136 </sect2>
137
138 <sect2 id="parallel-builds" xreflabel="Using Multiple Processors">
139 <title>Using Multiple Processors</title>
140
141 <para>For many modern systems with multiple processors (or cores) the
142 compilation time for a package can be reduced by performing a "parallel
143 make" by either setting an environment variable or telling the make program
144 how many processors are available. For instance, a Core2Duo can support two
145 simultaneous processes with: </para>
146
147 <screen><userinput>export MAKEFLAGS='-j2'</userinput></screen>
148
149 <para>or just building with:</para>
150
151 <screen><userinput>make -j2</userinput></screen>
152
153 <para>Generally the number of processes should not exceed the number of
154 cores supported by the CPU. To list the processors on your
155 system, issue: <userinput>grep processor /proc/cpuinfo</userinput>.
156 </para>
157
158 <para>In some cases, using multiple processors may result in a 'race'
159 condition where the success of the build depends on the order of the
160 commands run by the <command>make</command> program. For instance, if an
161 executable needs File A and File B, attempting to link the program before
162 one of the dependent components is available will result in a failure.
163 This condition usually arises because the upstream developer has not
164 properly designated all the prerequsites needed to accomplish a step in the
165 Makefile.</para>
166
167 <para>If this occurs, the best way to proceed is to drop back to a
168 single processor build. Adding '-j1' to a make command will override
169 the similar setting in the MAKEFLAGS environment variable.</para>
170
171 </sect2>
172
173 <sect2 id="automating-builds" xreflabel="Automated Building Procedures">
174 <title>Automated Building Procedures</title>
175
176 <para>There are times when automating the building of a package can come in
177 handy. Everyone has their own reasons for wanting to automate building,
178 and everyone goes about it in their own way. Creating
179 <filename>Makefile</filename>s, <application>Bash</application> scripts,
180 <application>Perl</application> scripts or simply a list of commands used
181 to cut and paste are just some of the methods you can use to automate
182 building BLFS packages. Detailing how and providing examples of the many
183 ways you can automate the building of packages is beyond the scope of this
184 section. This section will expose you to using file redirection and the
185 <command>yes</command> command to help provide ideas on how to automate
186 your builds.</para>
187
188 <bridgehead renderas="sect3">File Redirection to Automate Input</bridgehead>
189
190 <para>You will find times throughout your BLFS journey when you will come
191 across a package that has a command prompting you for information. This
192 information might be configuration details, a directory path, or a response
193 to a license agreement. This can present a challenge to automate the
194 building of that package. Occasionally, you will be prompted for different
195 information in a series of questions. One method to automate this type of
196 scenario requires putting the desired responses in a file and using
197 redirection so that the program uses the data in the file as the answers to
198 the questions.</para>
199
200 <para>Building the <application>CUPS</application> package is a good
201 example of how redirecting a file as input to prompts can help you automate
202 the build. If you run the test suite, you are asked to respond to a series
203 of questions regarding the type of test to run and if you have any
204 auxiliary programs the test can use. You can create a file with your
205 responses, one response per line, and use a command similar to the
206 one shown below to automate running the test suite:</para>
207
208<screen><userinput>make check &lt; ../cups-1.1.23-testsuite_parms</userinput></screen>
209
210 <para>This effectively makes the test suite use the responses in the file
211 as the input to the questions. Occasionally you may end up doing a bit of
212 trial and error determining the exact format of your input file for some
213 things, but once figured out and documented you can use this to automate
214 building the package.</para>
215
216 <bridgehead renderas="sect3">Using <command>yes</command> to Automate
217 Input</bridgehead>
218
219 <para>Sometimes you will only need to provide one response, or provide the
220 same response to many prompts. For these instances, the
221 <command>yes</command> command works really well. The
222 <command>yes</command> command can be used to provide a response (the same
223 one) to one or more instances of questions. It can be used to simulate
224 pressing just the <keycap>Enter</keycap> key, entering the
225 <keycap>Y</keycap> key or entering a string of text. Perhaps the easiest
226 way to show its use is in an example.</para>
227
228 <para>First, create a short <application>Bash</application> script by
229 entering the following commands:</para>
230
231<screen><userinput>cat &gt; blfs-yes-test1 &lt;&lt; "EOF"
232<literal>#!/bin/bash
233
234echo -n -e "\n\nPlease type something (or nothing) and press Enter ---> "
235
236read A_STRING
237
238if test "$A_STRING" = ""; then A_STRING="Just the Enter key was pressed"
239else A_STRING="You entered '$A_STRING'"
240fi
241
242echo -e "\n\n$A_STRING\n\n"</literal>
243EOF
244chmod 755 blfs-yes-test1</userinput></screen>
245
246 <para>Now run the script by issuing <command>./blfs-yes-test1</command> from
247 the command line. It will wait for a response, which can be anything (or
248 nothing) followed by the <keycap>Enter</keycap> key. After entering
249 something, the result will be echoed to the screen. Now use the
250 <command>yes</command> command to automate the entering of a
251 response:</para>
252
253<screen><userinput>yes | ./blfs-yes-test1</userinput></screen>
254
255 <para>Notice that piping <command>yes</command> by itself to the script
256 results in <keycap>y</keycap> being passed to the script. Now try it with a
257 string of text:</para>
258
259<screen><userinput>yes 'This is some text' | ./blfs-yes-test1</userinput></screen>
260
261 <para>The exact string was used as the response to the script. Finally,
262 try it using an empty (null) string:</para>
263
264<screen><userinput>yes '' | ./blfs-yes-test1</userinput></screen>
265
266 <para>Notice this results in passing just the press of the
267 <keycap>Enter</keycap> key to the script. This is useful for times when the
268 default answer to the prompt is sufficient. This syntax is used in the
269 <xref linkend="net-tools-automate-example"/> instructions to accept all the
270 defaults to the many prompts during the configuration step. You may now
271 remove the test script, if desired.</para>
272
273 <bridgehead renderas="sect3">File Redirection to Automate Output</bridgehead>
274
275 <para>In order to automate the building of some packages, especially those
276 that require you to read a license agreement one page at a time, requires
277 using a method that avoids having to press a key to display each page.
278 Redirecting the output to a file can be used in these instances to assist
279 with the automation. The previous section on this page touched on creating
280 log files of the build output. The redirection method shown there used the
281 <command>tee</command> command to redirect output to a file while also
282 displaying the output to the screen. Here, the output will only be sent to
283 a file.</para>
284
285 <para>Again, the easiest way to demonstrate the technique is to show an
286 example. First, issue the command:</para>
287
288<screen><userinput>ls -l /usr/bin | more</userinput></screen>
289
290 <para>Of course, you'll be required to view the output one page at a time
291 because the <command>more</command> filter was used. Now try the same
292 command, but this time redirect the output to a file. The special file
293 <filename>/dev/null</filename> can be used instead of the filename shown,
294 but you will have no log file to examine:</para>
295
296<screen><userinput>ls -l /usr/bin | more &gt; redirect_test.log 2&gt;&amp;1</userinput></screen>
297
298 <para>Notice that this time the command immediately returned to the shell
299 prompt without having to page through the output. You may now remove the
300 log file.</para>
301
302 <para>The last example will use the <command>yes</command> command in
303 combination with output redirection to bypass having to page through the
304 output and then provide a <keycap>y</keycap> to a prompt. This technique
305 could be used in instances when otherwise you would have to page through
306 the output of a file (such as a license agreement) and then answer the
307 question of <quote>do you accept the above?</quote>. For this example,
308 another short <application>Bash</application> script is required:</para>
309
310<screen><userinput>cat &gt; blfs-yes-test2 &lt;&lt; "EOF"
311<literal>#!/bin/bash
312
313ls -l /usr/bin | more
314
315echo -n -e "\n\nDid you enjoy reading this? (y,n) "
316
317read A_STRING
318
319if test "$A_STRING" = "y"; then A_STRING="You entered the 'y' key"
320else A_STRING="You did NOT enter the 'y' key"
321fi
322
323echo -e "\n\n$A_STRING\n\n"</literal>
324EOF
325chmod 755 blfs-yes-test2</userinput></screen>
326
327 <para>This script can be used to simulate a program that requires you to
328 read a license agreement, then respond appropriately to accept the
329 agreement before the program will install anything. First, run the script
330 without any automation techniques by issuing
331 <command>./blfs-yes-test2</command>.</para>
332
333 <para>Now issue the following command which uses two automation techniques,
334 making it suitable for use in an automated build script:</para>
335
336<screen><userinput>yes | ./blfs-yes-test2 &gt; blfs-yes-test2.log 2&gt;&amp;1</userinput></screen>
337
338 <para>If desired, issue <command>tail blfs-yes-test2.log</command> to see
339 the end of the paged output, and confirmation that <keycap>y</keycap> was
340 passed through to the script. Once satisfied that it works as it should,
341 you may remove the script and log file.</para>
342
343 <para>Finally, keep in mind that there are many ways to automate and/or
344 script the build commands. There is not a single <quote>correct</quote> way
345 to do it. Your imagination is the only limit.</para>
346
347 </sect2>
348
349 <sect2>
350 <title>Dependencies</title>
351
352 <para>For each package described, BLFS lists the known dependencies.
353 These are listed under several headings, whose meaning is as follows:</para>
354
355 <itemizedlist>
356 <listitem>
357 <para><emphasis>Required</emphasis> means that the target package
358 cannot be correctly built without the dependency having first been
359 installed.</para>
360 </listitem>
361 <listitem>
362 <para><emphasis>Recommended</emphasis> means that BLFS strongly
363 suggests this package is installed first for a clean and trouble-free
364 build, that won't have issues either during the build process, or at
365 run-time. The instructions in the book assume these packages are
366 installed. Some changes or workarounds may be required if these
367 packages are not installed.</para>
368 </listitem>
369 <listitem>
370 <para><emphasis>Optional</emphasis> means that this package might be
371 installed for added functionality. Often BLFS will describe the
372 dependency to explain the added functionality that will result.</para>
373 </listitem>
374 </itemizedlist>
375
376 </sect2>
377
378 <sect2 id="package_updates">
379 <title>Using the Most Current Package Sources</title>
380
381 <para>On occasion you may run into a situation in the book when a package
382 will not build or work properly. Though the Editors attempt to ensure
383 that every package in the book builds and works properly, sometimes a
384 package has been overlooked or was not tested with this particular version
385 of BLFS.</para>
386
387 <para>If you discover that a package will not build or work properly, you
388 should see if there is a more current version of the package. Typically
389 this means you go to the maintainer's web site and download the most current
390 tarball and attempt to build the package. If you cannot determine the
391 maintainer's web site by looking at the download URLs, use Google and query
392 the package's name. For example, in the Google search bar type:
393 'package_name download' (omit the quotes) or something similar. Sometimes
394 typing: 'package_name home page' will result in you finding the
395 maintainer's web site.</para>
396
397 </sect2>
398
399 <sect2 id="stripping">
400 <title>Stripping One More Time</title>
401
402 <para>In LFS, stripping of debugging symbols was discussed a couple of
403 times. When building BLFS packages, there are generally no special
404 instructions that discuss stripping again. It is probably not a good
405 idea to strip an executable or a library while it is in use, so exiting
406 any windowing environment is a good idea. Then you can do:</para>
407
408 <screen><userinput>find /{,usr/}{bin,lib,sbin} -type f -exec strip --strip-unneeded {} \;</userinput></screen>
409
410 <para>If you install programs in other directories such as /opt or /usr/local,
411 you may want to strip the files there too.</para>
412
413 <para>For more information on stripping, see <ulink
414 url="http://www.technovelty.org/linux/stripping-shared-libraries.html"/>.</para>
415
416 </sect2>
417
418 <sect2 id="libtool">
419 <title>Libtool files</title>
420
421 <para>One of the side effects of packages that use Autotools, including
422 libtool, is that they create many files with an .la extension. These
423 files are not needed in an LFS environment. If there are conflicts with
424 pkgconfig entries, they can actually prevent successful builds. You
425 may want to consider removing these files periodically:</para>
426
427 <screen><userinput>find /lib /usr/lib -not -path "*Image*" -a -name \*.la -delete</userinput></screen>
428
429 <para>The above command removes all .la files with the exception of those that have
430 "Image" as a part of the path. These .la files are used by the
431 ImageMagick programs. There may be other exceptions by packages not in BLFS.</para>
432
433 </sect2>
434
435</sect1>
Note: See TracBrowser for help on using the repository browser.