Changeset 6efdfbe
- Timestamp:
- 07/02/2023 11:33:10 AM (12 months ago)
- Branches:
- 12.0, 12.1, kea, ken/TL2024, ken/tuningfonts, lazarus, plabs/newcss, python3.11, rahul/power-profiles-daemon, renodr/vulkan-addition, trunk, xry111/llvm18, xry111/xf86-video-removal
- Children:
- 9b61265
- Parents:
- cbffe27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
introduction/important/building-notes.xml
rcbffe27 r6efdfbe 24 24 <para>While you can keep the source files anywhere you like, we assume that 25 25 you have unpacked the package and changed into the directory created by the 26 unpacking process (the 'build'directory). We also assume you have27 uncompressed any required patches and they are in the directory immediately28 above the 'build'directory.</para>26 unpacking process (the source directory). We also assume you have 27 uncompressed any required patches and they are in the directory 28 immediately above the source directory.</para> 29 29 30 30 <para>We can not emphasize strongly enough that you should start from a … … 75 75 <screen><userinput>bzcat filename.tar.bz2 | tar -xv</userinput></screen> 76 76 77 <para>Finally, you sometimes need to be able to unpack patches which are 78 generally not in <filename class='extension'>.tar</filename> format. The 79 best way to do this is to copy the patch file to the parent of the 'build' 80 directory and then run one of the following commands depending on whether 81 the file is a <filename class='extension'>.gz</filename> or <filename 82 class='extension'>.bz2</filename> file:</para> 83 84 <screen><userinput>gunzip -v patchname.gz 85 bunzip2 -v patchname.bz2</userinput></screen> 77 <para> 78 Finally, sometimes we have a compressed patch file in 79 <filename class='extension'>.patch.gz</filename> or 80 <filename class='extension'>.patch.bz2</filename> format. 81 The best way to apply the patch is piping the output of the 82 decompressor to the <command>patch</command> utility. For example: 83 </para> 84 85 <screen><userinput>gzip -cd ../patchname.patch.gz | patch -p1</userinput></screen> 86 87 <para> 88 Or for a patch compressed with <command>bzip2</command>: 89 </para> 90 91 <screen><userinput>bzcat ../patchname.patch.bz2 | patch -p1</userinput></screen> 86 92 87 93 </sect2> … … 218 224 219 225 <para> 220 but for ninja, the default number of jobs is <N>+2, where <N> 221 is the number of processors available, so that using the above commands 222 is rather for limiting the number of jobs (see below for why this could 223 be necessary). 226 but for ninja, the default number of jobs is N + 2, if 227 the number of logical processors N is greater than 2; or N + 1 if 228 N is 1 or 2. The reason to use a number of jobs slightly greater 229 than the number of logical processors is keeping all logical 230 processors busy even if some jobs are performing I/O operatations. 224 231 </para> 225 232 226 233 <para>Generally the number of processes should not exceed the number of 227 cores supported by the CPU . To list the processors on your234 cores supported by the CPU too much. To list the processors on your 228 235 system, issue: <userinput>grep processor /proc/cpuinfo</userinput>. 229 236 </para> 230 237 231 <para>In some cases, using multiple processes may result in a 'race'238 <para>In some cases, using multiple processes may result in a race 232 239 condition where the success of the build depends on the order of the 233 240 commands run by the <command>make</command> program. For instance, if an … … 239 246 240 247 <para>If this occurs, the best way to proceed is to drop back to a 241 single processor build. Adding '-j1' to a make command will override242 the similar setting in the <envar>MAKEFLAGS</envar> environment243 variable.</para>244 248 single processor build. Adding <option>-j1</option> to a make command 249 will override the similar setting in the <envar>MAKEFLAGS</envar> 250 environment variable.</para> 251 <!-- outdated 245 252 <note><para>When running the package tests or the install portion of the 246 253 package build process, we do not recommend using an option greater than … … 248 255 have not been validated using parallel procedures and may fail with issues 249 256 that are difficult to debug.</para></note> 250 257 --> 251 258 <important> 252 259 <para> … … 293 300 redirection so that the program uses the data in the file as the answers to 294 301 the questions.</para> 295 302 <!-- outdated 296 303 <para>Building the <application>CUPS</application> package is a good 297 304 example of how redirecting a file as input to prompts can help you automate … … 303 310 304 311 <screen><userinput>make check < ../cups-1.1.23-testsuite_parms</userinput></screen> 305 312 --> 306 313 <para>This effectively makes the test suite use the responses in the file 307 314 as the input to the questions. Occasionally you may end up doing a bit of … … 382 389 example. First, issue the command:</para> 383 390 384 <screen><userinput>ls -l /usr/bin | more</userinput></screen>391 <screen><userinput>ls -l /usr/bin | less</userinput></screen> 385 392 386 393 <para>Of course, you'll be required to view the output one page at a time 387 because the <command> more</command> filter was used. Now try the same394 because the <command>less</command> filter was used. Now try the same 388 395 command, but this time redirect the output to a file. The special file 389 396 <filename>/dev/null</filename> can be used instead of the filename shown, 390 397 but you will have no log file to examine:</para> 391 398 392 <screen><userinput>ls -l /usr/bin | more> redirect_test.log 2>&1</userinput></screen>399 <screen><userinput>ls -l /usr/bin | less > redirect_test.log 2>&1</userinput></screen> 393 400 394 401 <para>Notice that this time the command immediately returned to the shell … … 407 414 <literal>#!/bin/bash 408 415 409 ls -l /usr/bin | more416 ls -l /usr/bin | less 410 417 411 418 echo -n -e "\n\nDid you enjoy reading this? (y,n) " … … 703 710 the issues caused by some choices (typically slow execution or 704 711 unexpected use of, or omission of, optimizatons) by starting with 705 the CFLAGS and CXXFLAGS environment variables. There are also some 706 programs which use rust. 707 </para> 708 709 <para> 710 Most LFS and BLFS builders are probably aware of the basics of CFLAGS 711 and CXXFLAGS for altering how a program is compiled. Typically, some 712 form of optimization is used by upstream developers (-O2 or -O3), 713 sometimes with the creation of debug symbols (-g), as defaults. 714 </para> 715 716 <para> 717 If there are contradictory flags (e.g. multiple different -O values), 712 the <envar>CFLAGS</envar>, <envar>CXXFLAGS</envar>, and 713 <envar>LDFLAGS</envar> environment variables. There are also some 714 programs which use Rust. 715 </para> 716 717 <para> 718 Most LFS and BLFS builders are probably aware of the basics of 719 <envar>CFLAGS</envar> and <envar>CXXFLAGS</envar> for altering how a 720 program is compiled. Typically, some form of optimization is used by 721 upstream developers (<option>-O2</option> or <option>-O3</option>), 722 sometimes with the creation of debug symbols (<option>-g</option>), 723 as defaults. 724 </para> 725 726 <para> 727 If there are contradictory flags (e.g. multiple different 728 <option>-O</option> values), 718 729 the <emphasis>last</emphasis> value will be used. Sometimes this means 719 730 that flags specified in environment variables will be picked up before 720 731 values hardcoded in the Makefile, and therefore ignored. For example, 721 where a user specifies '-O2' and that is followed by '-O3' the build will722 use '-O3'.732 where a user specifies <option>-O2</option> and that is followed by 733 <option>-O3</option> the build will use <option>-O3</option>. 723 734 </para> 724 735 725 736 <para> 726 737 There are various other things which can be passed in CFLAGS or 727 CXXFLAGS, such as forcing compilation for a specific microarchitecture 728 (e.g. -march=amdfam10, -march=native) or specifying a specific standard 729 for C or C++ (-std=c++17 for example). But one thing which has now come 730 to light is that programmers might include debug assertions in their 731 code, expecting them to be disabled in releases by using -DNDEBUG. 732 Specifically, if <xref linkend="mesa"/> is built with these assertions 733 enabled, some activities such as loading levels of games can take 734 extremely long times, even on high-class video cards. 738 CXXFLAGS, such as allowing using the instruction set extensions 739 available with a specific microarchitecture (e.g. 740 <option>-march=amdfam10</option> or <option>-march=native</option>), 741 tune the generated code for a specific microarchitecture (e. g. 742 <option>-mtune=tigerlake</option> or <option>-mtune=native</option>, 743 if <option>-mtune=</option> is not used, the microarchitecture from 744 <option>-march=</option> setting will be used), or specifying a 745 specific standard for C or C++ (<option>-std=c++17</option> for 746 example). But one thing which has now come to light is that 747 programmers might include debug assertions in their code, expecting 748 them to be disabled in releases by using <option>-DNDEBUG</option>. 749 Specifically, if <xref linkend="mesa"/> is built with these 750 assertions enabled, some activities such as loading levels of games 751 can take extremely long times, even on high-class video cards. 735 752 </para> 736 753 … … 738 755 739 756 <para> 740 This combination is often described as 'CMMI' (configure, make, make 741 install) and is used here to also cover the few packages which have a 742 configure script that is not generated by autotools. 757 This combination is often described as <quote>CMMI</quote> 758 (configure, make, make install) and is used here to also cover 759 the few packages which have a configure script that is not 760 generated by autotools. 743 761 </para> 744 762 … … 760 778 761 779 <para> 762 In most CMMI packages, running 'make' will list each command and run 763 it, interspersed with any warnings. But some packages try to be 'silent' 764 and only show which file they are compiling or linking instead of showing 765 the command line. If you need to inspect the command, either because of 766 an error, or just to see what options and flags are being used, adding 767 'V=1' to the make invocation may help. 768 </para> 780 In most CMMI packages, running <command>make</command> will list 781 each command and run it, interspersed with any warnings. But some 782 packages try to be <quote>silent</quote> and only show which file 783 they are compiling or linking instead of showing the command line. 784 If you need to inspect the command, either because of an error, or 785 just to see what options and flags are being used, adding 786 <option>V=1</option> to the make invocation may help. 787 </para> 769 788 770 789 <bridgehead renderas="sect3" id="cmake-info">CMake</bridgehead> 771 790 772 791 <para> 773 CMake works in a very different way, and it has two backends which can 774 be used on BLFS: 'make' and 'ninja'. The default backend is make, but 792 CMake works in a very different way, and it has two backends which 793 can be used on BLFS: <command>make</command> and 794 <command>ninja</command>. The default backend is make, but 775 795 ninja can be faster on large packages with multiple processors. To 776 use ninja, specify '-G Ninja' in the cmake command. However, there are 777 some packages which create fatal errors in their ninja files but build 778 successfully using the default of Unix Makefiles. 796 use ninja, specify <option>-G Ninja</option> in the cmake command. 797 However, there are some packages which create fatal errors in their 798 ninja files but build successfully using the default of Unix 799 Makefiles. 779 800 </para> 780 801 … … 789 810 Perhaps the most-important thing about CMake is that it has a variety 790 811 of CMAKE_BUILD_TYPE values, and these affect the flags. The default 791 is that this is not set and no flags are generated. Any CFLAGS or 792 CXXFLAGS in the environment will be used. If the programmer has coded 793 any debug assertions, those will be enabled unless -DNDEBUG is used. 794 The following CMAKE_BUILD_TYPE values will generate the flags shown, 795 and these will come <emphasis>after</emphasis> any flags in the 796 environment and therefore take precedence. 812 is that this is not set and no flags are generated. Any 813 <envar>CFLAGS</envar> or <envar>CXXFLAGS</envar> in the environment 814 will be used. If the programmer has coded any debug assertions, 815 those will be enabled unless -DNDEBUG is used. The following 816 CMAKE_BUILD_TYPE values will generate the flags shown, and these 817 will come <emphasis>after</emphasis> any flags in the environment 818 and therefore take precedence. 797 819 </para> 798 820 … … 845 867 details of the defines that you may wish to change you can look at 846 868 <filename>meson_options.txt</filename> which is usually in the 847 869 top-level directory. 848 870 </para> 849 871 … … 872 894 <listitem> 873 895 <para>plain : no added flags. This is for distributors to supply their 874 own CLFAGS, CXXFLAGS and LDFLAGS. There is no obvious reason to use 896 own <envar>CFLAGS</envar>, <envar>CXXFLAGS</envar> and 897 <envar>LDFLAGS</envar>. There is no obvious reason to use 875 898 this in BLFS.</para> 876 899 </listitem> 877 900 <listitem> 878 <para>debug : '-g' - this is the default if nothing is specified879 in either <filename>meson.build</filename> or the command line.880 However it results large and slow binaries, so we should override881 it in BLFS.</para>901 <para>debug : <option>-g</option> - this is the default if 902 nothing is specified in either <filename>meson.build</filename> 903 or the command line. However it results large and slow binaries, 904 so we should override it in BLFS.</para> 882 905 </listitem> 883 906 <listitem> 884 <para>debugoptimized : '-O2 -g' : this is the default specified in 885 <filename>meson.build</filename> of some packages.</para> 907 <para>debugoptimized : <option>-O2 -g</option> - this is the 908 default specified in <filename>meson.build</filename> of some 909 packages.</para> 886 910 </listitem> 887 911 <listitem> 888 <para>release : '-O3 -DNDEBUG' (but occasionally a package will force 889 -O2 here)</para> 912 <para>release : <option>-O3</option> (occasionally a package will 913 force <option>-O2</option> here) - this is the buildtype we use 914 for most packages with Meson build system in BLFS.</para> 890 915 </listitem> 891 916 </itemizedlist> 892 917 893 <para> 894 Although the 'release' buildtype is described as enabling -DNDEBUG, and all 895 CMake Release builds pass that, it has so far only been observed (in 896 verbose builds) for <xref linkend="mesa"/>. That suggests that it might 897 only be used when there are debug assertions present. 898 </para> 899 900 <para> 901 The -DNDEBUG flag can also be provided by passing 902 <command>-Db_ndebug=true</command>. 918 <!-- From https://mesonbuild.com/Builtin-options.html#core-options: 919 b_ndebug: Default value = false, Possible values are 920 true, false, if-release. Some packages sets it to if-release 921 so we mistakenly believed if-release had been the default. --> 922 <para> 923 The <option>-DNDEBUG</option> flag is implied by the release 924 buildtype for some packages (for example <xref linkend='mesa'/>). 925 It can also be provided explicitly by passing 926 <option>-Db_ndebug=true</option>. 903 927 </para> 904 928 905 929 <para> 906 930 To see the details of the commands which are being run in a package using 907 meson, use 'ninja -v'.931 meson, use <command>ninja -v</command>. 908 932 </para> 909 933 … … 915 939 and then download them as necessary. These packages are built using 916 940 <command>cargo --release</command>. In theory, you can manipulate the 917 RUSTFLAGS to change the optimize-level (default is 3, like -O3, e.g. 918 <literal>-Copt-level=3</literal>) or to force it to build for the 919 machine it is being compiled on, using 920 <literal>-Ctarget-cpu=native</literal> but in practice this seems to 941 RUSTFLAGS to change the optimize-level (default for 942 <option>--release</option> is 3, i. e. 943 <option>-Copt-level=3</option>, like <option>-O3</option>) or to 944 force it to build for the machine it is being compiled on, using 945 <option>-Ctarget-cpu=native</option> but in practice this seems to 921 946 make no significant difference. 922 947 </para> 923 948 924 949 <para> 925 If you find an interesting rustc program which is only provided as 926 unpackaged source, you should at least specify 927 <literal>RUSTFLAGS=-Copt-level=2</literal> otherwise it will do an 928 unoptimized compile with debug info and run <emphasis>much</emphasis> 929 slower. 930 </para> 931 932 <para> 933 The rust developers seem to assume that everyone will compile on a 934 machine dedicated to producing builds, so by default all CPUs are used. 935 This can often be worked around, either by exporting 936 CARGO_BUILD_JOBS=<N> or passing --jobs <N> to cargo. For 937 compiling rustc itself, specifying --jobs <N> on invocations of 938 x.py (together with the <envar>CARGO_BUILD_JOBS</envar> environment 939 variable, which looks like a "belt and braces" approach but seems to be 940 necessary) mostly works. The exception is running the tests when building 941 rustc, some of them will nevertheless use all online CPUs, at least as of 942 rustc-1.42.0. 950 If you are compiling a standalone Rust program (as an unpackaged 951 <filename class='extension'>.rs</filename> file) by running 952 <command>rustc</command> directly, you should specify 953 <option>-O</option> (the abbreviation of 954 <option>-Copt-level=2</option>) or <option>-Copt-level=3</option> 955 otherwise it will do an unoptimized compile and run 956 <emphasis>much</emphasis> slower. If are compiling the program 957 for debugging it, replace the <option>-O</option> or 958 <option>-Copt-level=</option> options with <option>-g</option> to 959 produce an unoptimized program with debug info. 960 </para> 961 962 <para> 963 Like <command>ninja</command>, by default <command>cargo</command> 964 uses all logical processors. This can often be worked around, 965 either by exporting 966 <envar>CARGO_BUILD_JOBS=<replaceable><N></replaceable></envar> 967 or passing 968 <option>--jobs <replaceable><N></replaceable></option> to 969 <command>cargo</command>. 970 For compiling rustc itself, specifying 971 <option>--jobs <replaceable><N></replaceable></option> for 972 invocations of <command>x.py</command> 973 (together with the <envar>CARGO_BUILD_JOBS</envar> environment 974 variable, which looks like a <quote>belt and braces</quote> 975 approach but seems to be necessary) mostly works. The exception is 976 running the tests when building rustc, some of them will 977 nevertheless use all online CPUs, at least as of rustc-1.42.0. 943 978 </para> 944 979 … … 950 985 <para> 951 986 Many people will prefer to optimize compiles as they see fit, by providing 952 CFLAGS or CXXFLAGS. For an introduction to the options available with gcc953 and g++ see <ulink987 <envar>CFLAGS</envar> or <envar>CXXFLAGS</envar>. For an 988 introduction to the options available with gcc and g++ see <ulink 954 989 url="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html"/> and <ulink 955 990 url="https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html"/> … … 959 994 960 995 <para> 961 Some packages default to '-O2 -g', others to '-O3 -g', and if CFLAGS or 962 CXXFLAGS are supplied they might be added to the package's defaults, 963 replace the package's defaults, or even be ignored. There are details 964 on some desktop packages which were mostly current in April 2019 at 996 Some packages default to <option>-O2 -g</option>, others to 997 <option>-O3 -g</option>, and if <envar>CFLAGS</envar> or 998 <envar>CXXFLAGS</envar> are supplied they might be added to the 999 package's defaults, replace the package's defaults, or even be 1000 ignored. There are details on some desktop packages which were 1001 mostly current in April 2019 at 965 1002 <ulink url="https://www.linuxfromscratch.org/~ken/tuning/"/> - in 966 particular, README.txt, tuning-1-packages-and-notes.txt, and 967 tuning-notes-2B.txt. The particular thing to remember is that if you 968 want to try some of the more interesting flags you may need to force 969 verbose builds to confirm what is being used. 1003 particular, <filename>README.txt</filename>, 1004 <filename>tuning-1-packages-and-notes.txt</filename>, and 1005 <filename>tuning-notes-2B.txt</filename>. The particular thing to 1006 remember is that if you want to try some of the more interesting 1007 flags you may need to force verbose builds to confirm what is being 1008 used. 970 1009 </para> 971 1010 … … 974 1013 profile it and perhaps recode some of it if it is too slow. But for 975 1014 building a whole system that approach is impractical. In general, 976 -O3 usually produces faster programs than -O2. Specifying 977 -march=native is also beneficial, but means that you cannot move the 978 binaries to an incompatible machine - this can also apply to newer 979 machines, not just to older machines. For example programs compiled for 980 'amdfam10' run on old Phenoms, Kaveris, and Ryzens : but programs 981 compiled for a Kaveri will not run on a Ryzen because certain op-codes 982 are not present. Similarly, if you build for a Haswell not everything 983 will run on a SandyBridge. 984 </para> 1015 <option>-O3</option> usually produces faster programs than 1016 <option>-O2</option>. Specifying 1017 <option>-march=native</option> is also beneficial, but means that 1018 you cannot move the binaries to an incompatible machine - this can 1019 also apply to newer machines, not just to older machines. For 1020 example programs compiled for <literal>amdfam10</literal> run on 1021 old Phenoms, Kaveris, and Ryzens : but programs compiled for a 1022 Kaveri will not run on a Ryzen because certain op-codes are not 1023 present. Similarly, if you build for a Haswell not everything will 1024 run on a SandyBridge. 1025 </para> 1026 1027 <note> 1028 <para> 1029 Be careful that the name of a <option>-march</option> setting 1030 does not always match the baseline of the microarchitecture 1031 with the same name. For example, the Skylake-based Intel Celeron 1032 processors do not support AVX at all, but 1033 <option>-march=skylake</option> assumes AVX and even AVX2. 1034 </para> 1035 </note> 985 1036 986 1037 <para> … … 992 1043 <para> 993 1044 If building Perl or Python modules, or Qt packages which use qmake, 994 in general the CFLAGS and CXXFLAGS used are those which were used by 995 those 'parent' packages. 1045 in general the <envar>CFLAGS</envar> and <envar>CXXFLAGS</envar> 1046 used are those which were used by those <quote>parent</quote> 1047 packages. 996 1048 </para> 997 1049
Note:
See TracChangeset
for help on using the changeset viewer.