[ab4fdfc] | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
[61cd9b2] | 2 | <!DOCTYPE chapter 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="la-files" xreflabel="Libtool archive (.la) files">
|
---|
| 9 | <?dbhtml filename="la-files.html"?>
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | <title>About Libtool Archive (.la) files</title>
|
---|
| 13 |
|
---|
| 14 | <!-- section g : 'Others' in longindex.html -->
|
---|
| 15 | <indexterm zone="la-files">
|
---|
| 16 | <primary sortas="g-la-files">Library archive (.la) files</primary>
|
---|
| 17 | </indexterm>
|
---|
| 18 |
|
---|
| 19 | <sect2 role="package">
|
---|
[2c87187] | 20 | <title>Files with a .la extension</title>
|
---|
[61cd9b2] | 21 |
|
---|
| 22 | <para>
|
---|
| 23 |
|
---|
[3334a3d] | 24 | In LFS and BLFS, many packages use an internally shipped libtool copy to
|
---|
[61cd9b2] | 25 | build on a variety of Unix platforms. This includes platforms such as
|
---|
| 26 | AIX, Solaris, IRIX, HP-UX, and Cygwin as well as Linux. The origins of
|
---|
| 27 | this tool are quite dated. It was intended to manage libraries on
|
---|
| 28 | systems with less advanced capabilities than a modern Linux system.
|
---|
[8558044] | 29 |
|
---|
[61cd9b2] | 30 | </para>
|
---|
| 31 |
|
---|
| 32 | <para>
|
---|
| 33 |
|
---|
| 34 | On a Linux system, libtool specific files are generally unneeded.
|
---|
| 35 | Normally libraries are specified in the build process during the link
|
---|
| 36 | phase. Since a linux system uses the <ulink
|
---|
| 37 | url="https://en.wikipedia.org/wiki/Executable_and_Linkable_Format">
|
---|
| 38 | Executable and Linkable Format (ELF)</ulink> for executables and
|
---|
[b3c16f12] | 39 | dynamic libraries, information needed to complete the task is embedded
|
---|
| 40 | in the files. Both the linker and the program loader can query the
|
---|
| 41 | appropriate files and properly link or execute the program.
|
---|
[61cd9b2] | 42 |
|
---|
| 43 | </para>
|
---|
[8558044] | 44 |
|
---|
[61cd9b2] | 45 | <para>
|
---|
[b3c16f12] | 46 | Static libraries are rarely used in LFS and BLFS. And, nowadays most
|
---|
| 47 | packages store the information needed for linking against a static
|
---|
| 48 | library into a .pc file, instead of relying on libtool.
|
---|
| 49 | A <command>pkg-config --static --libs</command> command will output
|
---|
| 50 | the sufficient flags for the linker to link against a static library
|
---|
| 51 | without any libtool magic.
|
---|
| 52 | </para>
|
---|
[61cd9b2] | 53 |
|
---|
[b3c16f12] | 54 | <para>
|
---|
| 55 | The problem is that libtool usually creates one or more text files for
|
---|
| 56 | package libraries called libtool archives. These small files have a
|
---|
| 57 | ".la" extension and contain information that is similar to that embedded
|
---|
| 58 | in the libraries or pkg-config files. When building a package that
|
---|
| 59 | uses libtool, the process automatically looks for these files.
|
---|
| 60 | Sometimes a .la file can contains the name or path of a static library
|
---|
| 61 | used during build but not installed, then the build process will break
|
---|
| 62 | because the .la file refers to something nonexistent on the system.
|
---|
| 63 | Similarly, if a package is updated and no longer uses the .la file,
|
---|
| 64 | then the build process can break with the old .la files.
|
---|
[61cd9b2] | 65 | </para>
|
---|
| 66 |
|
---|
| 67 | <para>
|
---|
| 68 |
|
---|
| 69 | The solution is to remove the .la files. However there is a catch.
|
---|
| 70 | Some packages, such as <xref linkend='imagemagick'/>, use a libtool
|
---|
| 71 | function, lt_dlopen, to load libraries as needed during execution and
|
---|
| 72 | resolve their dependencies at run time. In this case, the .la files
|
---|
[8558044] | 73 | should remain.
|
---|
| 74 |
|
---|
[61cd9b2] | 75 | </para>
|
---|
| 76 |
|
---|
| 77 | <para>
|
---|
| 78 |
|
---|
| 79 | The script below, removes all unneeded .la files and saves them in a
|
---|
| 80 | directory, /var/local/la-files by default, not in the normal library
|
---|
[8558044] | 81 | path. It also searches all pkg-config files (.pc) for embedded
|
---|
| 82 | references to .la files and fixes them to be conventional library
|
---|
| 83 | references needed when an application or library is built. It
|
---|
[61cd9b2] | 84 | can be run as needed to clean up the directories that may be causing
|
---|
| 85 | problems.
|
---|
| 86 |
|
---|
| 87 | </para>
|
---|
[8558044] | 88 |
|
---|
[61cd9b2] | 89 | <screen role="root"><userinput>cat > /usr/sbin/remove-la-files.sh << "EOF"
|
---|
[0949d16] | 90 | <literal>#!/bin/bash
|
---|
| 91 |
|
---|
| 92 | # /usr/sbin/remove-la-files.sh
|
---|
[61cd9b2] | 93 | # Written for Beyond Linux From Scratch
|
---|
| 94 | # by Bruce Dubbs <bdubbs@&lfs-domainname;>
|
---|
| 95 |
|
---|
| 96 | # Make sure we are running with root privs
|
---|
| 97 | if test "${EUID}" -ne 0; then
|
---|
| 98 | echo "Error: $(basename ${0}) must be run as the root user! Exiting..."
|
---|
| 99 | exit 1
|
---|
| 100 | fi
|
---|
| 101 |
|
---|
| 102 | # Make sure PKG_CONFIG_PATH is set if discarded by sudo
|
---|
| 103 | source /etc/profile
|
---|
| 104 |
|
---|
| 105 | OLD_LA_DIR=/var/local/la-files
|
---|
| 106 |
|
---|
| 107 | mkdir -p $OLD_LA_DIR
|
---|
| 108 |
|
---|
| 109 | # Only search directories in /opt, but not symlinks to directories
|
---|
[cc232d3] | 110 | OPTDIRS=$(find /opt -mindepth 1 -maxdepth 1 -type d)
|
---|
[61cd9b2] | 111 |
|
---|
| 112 | # Move any found .la files to a directory out of the way
|
---|
| 113 | find /usr/lib $OPTDIRS -name "*.la" ! -path "/usr/lib/ImageMagick*" \
|
---|
| 114 | -exec mv -fv {} $OLD_LA_DIR \;
|
---|
| 115 | ###############
|
---|
| 116 |
|
---|
[dc436a1] | 117 | # Fix any .pc files that may have .la references
|
---|
[61cd9b2] | 118 |
|
---|
[8558044] | 119 | STD_PC_PATH='/usr/lib/pkgconfig
|
---|
| 120 | /usr/share/pkgconfig
|
---|
| 121 | /usr/local/lib/pkgconfig
|
---|
[61cd9b2] | 122 | /usr/local/share/pkgconfig'
|
---|
| 123 |
|
---|
[4fa85cb8] | 124 | # For each directory that can have .pc files
|
---|
[61cd9b2] | 125 | for d in $(echo $PKG_CONFIG_PATH | tr : ' ') $STD_PC_PATH; do
|
---|
| 126 |
|
---|
| 127 | # For each pc file
|
---|
| 128 | for pc in $d/*.pc ; do
|
---|
| 129 | if [ $pc == "$d/*.pc" ]; then continue; fi
|
---|
| 130 |
|
---|
| 131 | # Check each word in a line with a .la reference
|
---|
| 132 | for word in $(grep '\.la' $pc); do
|
---|
| 133 | if $(echo $word | grep -q '.la$' ); then
|
---|
| 134 | mkdir -p $d/la-backup
|
---|
| 135 | cp -fv $pc $d/la-backup
|
---|
| 136 |
|
---|
| 137 | basename=$(basename $word )
|
---|
| 138 | libref=$(echo $basename|sed -e 's/^lib/-l/' -e 's/\.la$//')
|
---|
[8558044] | 139 |
|
---|
[61cd9b2] | 140 | # Fix the .pc file
|
---|
| 141 | sed -i "s:$word:$libref:" $pc
|
---|
| 142 | fi
|
---|
| 143 | done
|
---|
| 144 | done
|
---|
[b3c16f12] | 145 | done</literal>
|
---|
[61cd9b2] | 146 |
|
---|
| 147 | EOF
|
---|
| 148 |
|
---|
[b3c16f12] | 149 | chmod +x /usr/sbin/remove-la-files.sh</userinput></screen>
|
---|
[61cd9b2] | 150 |
|
---|
| 151 |
|
---|
| 152 | </sect2>
|
---|
| 153 |
|
---|
| 154 | </sect1>
|
---|