Changeset 6efdfbe


Ignore:
Timestamp:
07/02/2023 11:33:10 AM (12 months ago)
Author:
Xi Ruoyao <xry111@…>
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
Message:

building-notes: Format and update

  • Do not use the single quote "'" for *everything*. Use a proper XML tag if applicable.
  • Don't call the source directory "build" directory because we now often create a subdirectory named "build", so calling the source directory "build" can be puzzling.
  • Update the method to use compressed patch (matching libpng instruction).
  • Explain why ninja attempts to use N+1 or N+2 logical processors.
  • Now we don't run test suites w/o parallel jobs.
  • Use "less" instead of "more" as "less" is actually more powerful.
  • Explain -mtune=.
  • -DNDEBUG is not always implied by --buildtype=release, but it's sometimes implied.
  • Alert that some "Skylake"s are actually not -march=skylake.
  • For Rust, explain "-O" and "-g".
File:
1 edited

Legend:

Unmodified
Added
Removed
  • introduction/important/building-notes.xml

    rcbffe27 r6efdfbe  
    2424  <para>While you can keep the source files anywhere you like, we assume that
    2525  you have unpacked the package and changed into the directory created by the
    26   unpacking process (the 'build' directory).  We also assume you have
    27   uncompressed any required patches and they are in the directory immediately
    28   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>
    2929
    3030  <para>We can not emphasize strongly enough that you should start from a
     
    7575<screen><userinput>bzcat filename.tar.bz2 | tar -xv</userinput></screen>
    7676
    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>
    8692
    8793  </sect2>
     
    218224
    219225    <para>
    220       but for ninja, the default number of jobs is &lt;N&gt;+2, where &lt;N&gt;
    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.
    224231    </para>
    225232
    226233    <para>Generally the number of processes should not exceed the number of
    227     cores supported by the CPU.  To list the processors on your
     234    cores supported by the CPU too much.  To list the processors on your
    228235    system, issue: <userinput>grep processor /proc/cpuinfo</userinput>.
    229236    </para>
    230237
    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
    232239    condition where the success of the build depends on the order of the
    233240    commands run by the <command>make</command> program.  For instance, if an
     
    239246
    240247    <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 override
    242     the similar setting in the <envar>MAKEFLAGS</envar> environment
    243     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
    245252    <note><para>When running the package tests or the install portion of the
    246253    package build process, we do not recommend using an option greater than
     
    248255    have not been validated using parallel procedures and may fail with issues
    249256    that are difficult to debug.</para></note>
    250 
     257-->
    251258    <important>
    252259      <para>
     
    293300    redirection so that the program uses the data in the file as the answers to
    294301    the questions.</para>
    295 
     302<!-- outdated
    296303    <para>Building the <application>CUPS</application> package is a good
    297304    example of how redirecting a file as input to prompts can help you automate
     
    303310
    304311<screen><userinput>make check &lt; ../cups-1.1.23-testsuite_parms</userinput></screen>
    305 
     312-->
    306313    <para>This effectively makes the test suite use the responses in the file
    307314    as the input to the questions. Occasionally you may end up doing a bit of
     
    382389    example. First, issue the command:</para>
    383390
    384 <screen><userinput>ls -l /usr/bin | more</userinput></screen>
     391<screen><userinput>ls -l /usr/bin | less</userinput></screen>
    385392
    386393    <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 same
     394    because the <command>less</command> filter was used. Now try the same
    388395    command, but this time redirect the output to a file. The special file
    389396    <filename>/dev/null</filename> can be used instead of the filename shown,
    390397    but you will have no log file to examine:</para>
    391398
    392 <screen><userinput>ls -l /usr/bin | more &gt; redirect_test.log 2&gt;&amp;1</userinput></screen>
     399<screen><userinput>ls -l /usr/bin | less &gt; redirect_test.log 2&gt;&amp;1</userinput></screen>
    393400
    394401    <para>Notice that this time the command immediately returned to the shell
     
    407414<literal>#!/bin/bash
    408415
    409 ls -l /usr/bin | more
     416ls -l /usr/bin | less
    410417
    411418echo -n -e "\n\nDid you enjoy reading this? (y,n) "
     
    703710      the issues caused by some choices (typically slow execution or
    704711      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),
    718729      the <emphasis>last</emphasis> value will be used. Sometimes this means
    719730      that flags specified in environment variables will be picked up before
    720731      values hardcoded in the Makefile, and therefore ignored.  For example,
    721       where a user specifies '-O2' and that is followed by '-O3' the build will
    722       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>.
    723734    </para>
    724735
    725736    <para>
    726737      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.
    735752    </para>
    736753
     
    738755
    739756      <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.
    743761      </para>
    744762
     
    760778
    761779      <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>
    769788
    770789    <bridgehead renderas="sect3" id="cmake-info">CMake</bridgehead>
    771790
    772791      <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
    775795        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.
    779800      </para>
    780801
     
    789810        Perhaps the most-important thing about CMake is that it has a variety
    790811        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.
    797819      </para>
    798820
     
    845867        details of the defines that you may wish to change you can look at
    846868        <filename>meson_options.txt</filename> which is usually in the
    847          top-level directory.
     869        top-level directory.
    848870      </para>
    849871
     
    872894        <listitem>
    873895          <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
    875898          this in BLFS.</para>
    876899        </listitem>
    877900        <listitem>
    878           <para>debug : '-g' - this is the default if nothing is specified
    879           in either <filename>meson.build</filename> or the command line.
    880           However it results large and slow binaries, so we should override
    881           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>
    882905        </listitem>
    883906        <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>
    886910        </listitem>
    887911        <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>
    890915        </listitem>
    891916      </itemizedlist>
    892917
    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>.
    903927      </para>
    904928
    905929      <para>
    906930        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>.
    908932      </para>
    909933
     
    915939        and then download them as necessary.  These packages are built using
    916940        <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
    921946        make no significant difference.
    922947      </para>
    923948
    924949      <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=&lt;N&gt; or passing --jobs &lt;N&gt; to cargo. For
    937         compiling rustc itself, specifying --jobs &lt;N&gt; 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>&lt;N&gt;</replaceable></envar>
     967        or passing
     968        <option>--jobs <replaceable>&lt;N&gt;</replaceable></option> to
     969        <command>cargo</command>.
     970        For compiling rustc itself, specifying
     971        <option>--jobs <replaceable>&lt;N&gt;</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.
    943978      </para>
    944979
     
    950985      <para>
    951986        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 gcc
    953         and g++ see <ulink
     987        <envar>CFLAGS</envar> or <envar>CXXFLAGS</envar>. For an
     988        introduction to the options available with gcc and g++ see <ulink
    954989        url="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html"/> and <ulink
    955990        url="https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html"/>
     
    959994
    960995      <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
    9651002        <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.
    9701009      </para>
    9711010
     
    9741013        profile it and perhaps recode some of it if it is too slow. But for
    9751014        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>
    9851036
    9861037      <para>
     
    9921043      <para>
    9931044        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.
    9961048      </para>
    9971049
Note: See TracChangeset for help on using the changeset viewer.