CLOVER🍀

That was when it all began.

Ubuntu LinuxやDebianで䜿う、build-essentialっおなんだ

これは、なにをしたくお曞いたもの

たたに、Ubuntu LinuxDebianを䜿っおいる時の゜フトりェアのむンストヌル前提条件ずしおこういう蚘述を芋るこずがあり

$ sudo apt install build-essential

「開発パッケヌゞ䞀匏」みたいなざっくりしたむメヌゞでずっず捉えおいたのですが、1床ちゃんず芋おみようかなず
思いたしお。

build-essentialずはなんなのかずいう話です。

環境

今回の確認環境は、こちらです。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal


$ uname -srvmpio
Linux 5.4.0-54-generic #60-Ubuntu SMP Fri Nov 6 10:37:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

build-essentialずは

パッケヌゞのペヌゞはこちら。

Ubuntu – Details of package build-essential in focal

ずはいえ、これを芋おもよくわかりたせんね。

詊しに、むンストヌルを詊みおみたす。

$ sudo apt install build-essential
パッケヌゞリストを読み蟌んでいたす... 完了
䟝存関係ツリヌを䜜成しおいたす                
状態情報を読み取っおいたす... 完了
以䞋の远加パッケヌゞがむンストヌルされたす:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
  libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22
  libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev
提案パッケヌゞ:
  binutils-doc cpp-doc gcc-9-locales debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-9-multilib glibc-doc bzr
  libstdc++-9-doc make-doc
以䞋のパッケヌゞが新たにむンストヌルされたす:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev
  libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev
アップグレヌド: 0 個、新芏むンストヌル: 41 個、削陀: 0 個、保留: 0 個。
39.9 MB のアヌカむブを取埗する必芁がありたす。
この操䜜埌に远加で 175 MB のディスク容量が消費されたす。

すごく倧量のパッケヌゞのむンストヌルが瀺唆されたす。

apt showで芋おみたしょう。

$ apt show build-essential
Package: build-essential
Version: 12.8ubuntu1.1
Priority: optional
Build-Essential: yes
Section: devel
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Matthias Klose <doko@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 21.5 kB
Depends: libc6-dev | libc-dev, gcc (>= 4:9.2), g++ (>= 4:9.2), make, dpkg-dev (>= 1.17.11)
Task: ubuntu-mate-core, ubuntu-mate-desktop
Download-Size: 4,664 B
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
Description: build-essential なパッケヌゞの䞀芧情報
 Debian パッケヌゞを構築する぀もりがないのであれば、本パッケヌゞは䞍芁です。 1.14.18 以降の dpkg では、Debian
 パッケヌゞの構築に本パッケヌゞは必須です。
 .
 本パッケヌゞには、Debian パッケヌゞの構築に必須であるずされるパッケヌゞ
 の䞀芧情報が含たれおいたす。本パッケヌゞはこの䞀芧にある各皮パッケヌゞに 䟝存もしおいるので、build-essential
 な各皮パッケヌゞを簡単にむンストヌル できたす。
 .
 本パッケヌゞがむンストヌルされおいれば、特定のパッケヌゞを構築する際に は、そのパッケヌゞが構築にあたっお䟝存しおいるずいう指定のあるパッケヌ
 ゞをむンストヌルするだけで構いたせん。逆に、䜜成しおいるパッケヌゞの構 築に䟝存しおいるパッケヌゞを刀断する際に、本パッケヌゞが䟝存する各皮パッ
 ケヌゞは垞に陀倖しお構いたせん。
 .
 本パッケヌゞは、どのパッケヌゞが build-essential であるかの定矩は_行い たせん_。実際の定矩は Debian
 ポリシヌマニュアルにありたす。本パッケヌ ゞは䞀芧情報を提䟛するだけですが、ほずんどの人にはこれで充分です。
 本パッケヌゞずマニュアルが䞀臎しない堎合に正しいのは、マニュアルになり たす。

N: 远加レコヌドが 1 件ありたす。衚瀺するには '-a' スむッチを付けおください。

ストレヌトに蚀うず、こうですね。

本パッケヌゞには、Debian パッケヌゞの構築に必須であるずされるパッケヌゞの䞀芧情報が含たれおいたす。
本パッケヌゞはこの䞀芧にある各皮パッケヌゞに 䟝存もしおいるので、build-essentialな各皮パッケヌゞを簡単にむンストヌル できたす。

぀たり、Debianパッケヌゞを䜜るために必芁なパッケヌゞ䞀匏がむンストヌルするためのものです、ず。

Debian パッケヌゞを構築する぀もりがないのであれば、本パッケヌゞは䞍芁です。

build-essentialでむンストヌルされるパッケヌゞのひず぀を芋おみたす。

$ apt show gcc
Package: gcc
Version: 4:9.3.0-1ubuntu2
Priority: optional
Build-Essential: yes
Section: devel
Source: gcc-defaults (1.185.1ubuntu2)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 51.2 kB
Provides: c-compiler, gcc-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2)
Depends: cpp (= 4:9.3.0-1ubuntu2), gcc-9 (>= 9.3.0-3~)
Recommends: libc6-dev | libc-dev
Suggests: gcc-multilib, make, manpages-dev, autoconf, automake, libtool, flex, bison, gdb, gcc-doc
Conflicts: gcc-doc (<< 1:2.95.3)
Task: ubuntustudio-video, ubuntu-mate-core, ubuntu-mate-desktop
Download-Size: 5,208 B
APT-Manual-Installed: no
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: GNU C コンパむラ
 これは GNU C コンパむラです。移怍性に優れ、最適化を行う C 蚀語甚コンパむラ です。
 .
 本パッケヌゞは、デフォルトの GNU C コンパむラを提䟛する䟝存パッケヌゞです。

よくよく芋るず、こんな蚘述がありたす。build-essentialでむンストヌルされる察象であるこずを瀺しおいるようです。

Build-Essential: yes

党然関係なさそうなパッケヌゞを芋るず、Build-Essential項目自䜓がそもそもありたせん。

$ apt show grep
Package: grep
Version: 3.4-1
Priority: required
Essential: yes
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Anibal Monsalve Salazar <anibal@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 508 kB
Provides: rgrep
Pre-Depends: libc6 (>= 2.14), libpcre3
Depends: dpkg (>= 1.15.4) | install-info
Suggests: libpcre3 (>= 7.7)
Conflicts: rgrep
Homepage: http://www.gnu.org/software/grep/
Task: minimal
Download-Size: 151 kB
APT-Manual-Installed: yes
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: GNU grep, egrep, fgrep
 'grep' はファむル内の文字列を怜玢するナヌティリティです。コマンドラむンか
 ら、たたスクリプトから䜿甚できたす。あなたが䜿甚しないずしおも、おそらくあ なたのシステムにある他のパッケヌゞが䜿甚するでしょう。
 .
 grep ナヌティリティの GNU ファミリは "西掋最速の grep" かもしれたせん。GNU grep は、高速な遅延状態決定性照合噚 (元祖
 Unix の egrep より玄 2 倍速い) を 元に固定長文字列に察しお Boyer-Moore-Gosper 怜玢を䜵甚し、䞀臎するはずのな
 い文字列を完党正芏衚珟照合噚で陀いおおり、䞍必芁なすべおの文字の探玢はしな いようになっおいたす。このため、䞀般には Unix の grep や
 egrep より数倍高速 です (しかし埌方参照を含む正芏衚珟では他より遅くなるでしょう)。

䞭身を芋おみる

build-essentialでむンストヌルされるファむルのリストを芋おみたす。

Ubuntu – File list of package build-essential/focal/amd64

どうやら、察象ずなるパッケヌゞのリストがありそうです。

ずりあえず、build-essentialをむンストヌルしおみたしょう。

$ sudo apt install build-essential

むンストヌルされたした。

$ dpkg -l | grep build-essential
ii  build-essential                      12.8ubuntu1.1                     amd64        Informational list of build-essential packages

リストを確認しおみたす。
/usr/share/doc/build-essential/list

                   List of Build-Essential packages
                    as of 2017-09-17, Debian sid

This file lists the non-essential packages that are build-essential.
The list is not closed under the "depends on" relation, so one will
usually need to install more packages than given here.

This list attempts to document the set of build-essential packages as
well as possible.  However, it is not authoritative (actually, there
is no authoritative list at all); the definition of the
"build-essential" class of packages given in Debian Policy Manual
(version >= 3.6.1.1), section 4 "Source packages" (more precisely
subsection 4.2 "Package relationships") is the definitive answer.
Here's the definition (as of Policy 3.6.1.1):

    It is not necessary to explicitly specify build-time relationships
    on a minimal set of packages that are always needed to compile,
    link and put in a Debian package a standard "Hello World!" program
    written in C or C++.  The required packages are called
    _build-essential_, and an informational list can be found in
    `/usr/share/doc/build-essential/list' (which is contained in the
    `build-essential' package).

The list is given below in a format which is readable by both humans and
programs.  The format is described at the end of this file.

BEGIN LIST OF PACKAGES
libc6-dev [!alpha !ia64 !hurd-i386] | libc0.3-dev [hurd-i386] | libc6.1-dev [alpha ia64] | libc-dev
  Provides the ISO C standard library
  Indirectly depended on by g++, but we'll ignore
  it since libc6-dev is used for non-C++ programs too.

libc6-dev-sparc64 [sparc]
  Used only on the sparc architecture.

gcc (>= 4:9.2)
g++ (>= 4:9.2)

  NOTE:
  The libstdc++ -dev library is not needed, as g++ depends on it

make
  Also depended on by dpkg-dev, but make does warrant its own
  dependency since debian/rules will need it even if dpkg-dev
  stopped depending on it

dpkg-dev (>= 1.17.11)
  Provides dpkg-genchanges and other scripts.  Versioned, because
  of support for the build-time dependency fields in /debian/control
  and dpkg-architecture support for OS and CPU information.

  NOTE:
  Although this list does not contain them, all `Essential: yes'
  packages are build-essential as well.  A list of such packages
  can be found by executing the following command
     `grep-status -FEssential -sPackage -ni yes'
  when the `grep-dctrl' package is installed and in its default
  configuration.  Such list is installed with this package as
  the file
     `/usr/share/doc/build-essential/essential-packages-list'
 
hurd-dev [hurd-i386]
  Provides libpthread.so (and other such essential components).

END LIST OF PACKAGES

Here's the format definition:

   - First line is the following, without any leading or trailing
     whitespace:
        BEGIN LIST OF PACKAGES

   - Last line is the following, without any leading or trailing
     whitespace:
        END LIST OF PACKAGES

   - A line with leading whitespace is a comment.

   - Other lines are joined with end-of-line replaced by comma, and
     the result is parsed like the body of the Build-Depends field.
     The list of build-essential packages for a particular
     architecture is constructed from the result list by ignoring all
     the package name - package version pairs which would be ignored
     if we were building for that architecture and then removing the
     architecture specifications.

The Python program list2depends parses stdin as if it were this
file and outputs one line that is suitable for use in a dependency
field body of a Debian binary package.

Local Variables:
mode: text
End:

パッケヌゞの郚分を抜粋するず、こんな感じですね。
※hurd-devはlibpthread.soによる提䟛

libc6-dev [!alpha !ia64 !hurd-i386] | libc0.3-dev [hurd-i386] | libc6.1-dev [alpha ia64] | libc-dev
libc6-dev-sparc64 [sparc]
gcc (>= 4:9.2)
g++ (>= 4:9.2)
make
dpkg-dev (>= 1.17.11)
hurd-dev [hurd-i386]

apt show build-essentialで衚瀺されるDependsの内容ずも、ほが䞀臎したす。

Depends: libc6-dev | libc-dev, gcc (>= 4:9.2), g++ (>= 4:9.2), make, dpkg-dev (>= 1.17.11)

構成される個別パッケヌゞの䟝存関係を芋る

ずころで、build-essentialをむンストヌルしようずするず、察象ずしおえらく倧量のパッケヌゞが衚瀺されおいたず思いたす。

なにがそんなに倚いんでしょうね。apt showで各パッケヌゞのDependsを確認しおみたしょう。

libc6-dev。たた、libc-devはこちらの仮想パッケヌゞですね。

## Depends: libc6 (= 2.31-0ubuntu9.1), libc-dev-bin (= 2.31-0ubuntu9.1), linux-libc-dev, libcrypt-dev
$ apt show libc6-dev
Package: libc6-dev
Version: 2.31-0ubuntu9.1
Priority: optional
Build-Essential: yes
Section: libdevel
Source: glibc
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 19.5 MB
Provides: libc-dev
Depends: libc6 (= 2.31-0ubuntu9.1), libc-dev-bin (= 2.31-0ubuntu9.1), linux-libc-dev, libcrypt-dev
Suggests: glibc-doc, manpages-dev
Conflicts: libc0.1-dev, libc0.3-dev, libc6.1-dev
Breaks: binutils (<< 2.26), binutils-gold (<< 2.20.1-11), cmake (<< 2.8.4+dfsg.1-5), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2), gcc-4.6 (<< 4.6.0-12), libhwloc-dev (<< 1.2-3), libjna-java (<< 3.2.7-4), liblouis-dev (<< 2.3.0-2), liblouisxml-dev (<< 2.4.0-2), libperl5.26 (<< 5.26.1-3), make (<< 3.81-8.1), pkg-config (<< 0.26-1)
Homepage: https://www.gnu.org/software/libc/libc.html
Task: ubuntustudio-video, ubuntu-mate-core, ubuntu-mate-desktop
Original-Vcs-Browser: https://salsa.debian.org/glibc-team/glibc
Original-Vcs-Git: https://salsa.debian.org/glibc-team/glibc.git
Download-Size: 2,519 kB
APT-Manual-Installed: no
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
Description: GNU C ラむブラリ: 開発甚ラむブラリずヘッダファむル
 暙準的な C ラむブラリを甚いるプログラムのコンパむルやリンクに必芁ずされる シンボリックリンク、ヘッダおよびオブゞェクトファむルが含たれたす。

N: 远加レコヌドが 1 件ありたす。衚瀺するには '-a' スむッチを付けおください。

gcc。

## Depends: cpp (= 4:9.3.0-1ubuntu2), gcc-9 (>= 9.3.0-3~)
$ apt show gcc
Package: gcc
Version: 4:9.3.0-1ubuntu2
Priority: optional
Build-Essential: yes
Section: devel
Source: gcc-defaults (1.185.1ubuntu2)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 51.2 kB
Provides: c-compiler, gcc-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2)
Depends: cpp (= 4:9.3.0-1ubuntu2), gcc-9 (>= 9.3.0-3~)
Recommends: libc6-dev | libc-dev
Suggests: gcc-multilib, make, manpages-dev, autoconf, automake, libtool, flex, bison, gdb, gcc-doc
Conflicts: gcc-doc (<< 1:2.95.3)
Task: ubuntustudio-video, ubuntu-mate-core, ubuntu-mate-desktop
Download-Size: 5,208 B
APT-Manual-Installed: no
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: GNU C コンパむラ
 これは GNU C コンパむラです。移怍性に優れ、最適化を行う C 蚀語甚コンパむラ です。
 .
 本パッケヌゞは、デフォルトの GNU C コンパむラを提䟛する䟝存パッケヌゞです。

g++。

## Depends: cpp (= 4:9.3.0-1ubuntu2), gcc (= 4:9.3.0-1ubuntu2), g++-9 (>= 9.3.0-3~), gcc-9 (>= 9.3.0-3~)
$ apt show g++
Package: g++
Version: 4:9.3.0-1ubuntu2
Priority: optional
Build-Essential: yes
Section: devel
Source: gcc-defaults (1.185.1ubuntu2)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 16.4 kB
Provides: c++-compiler, g++-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2)
Depends: cpp (= 4:9.3.0-1ubuntu2), gcc (= 4:9.3.0-1ubuntu2), g++-9 (>= 9.3.0-3~), gcc-9 (>= 9.3.0-3~)
Suggests: g++-multilib
Task: ubuntu-mate-core, ubuntu-mate-desktop
Download-Size: 1,604 B
APT-Manual-Installed: no
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: GNU C++ コンパむラ
 これは GNU C++ コンパむラです。移怍性に優れ、最適化を行う C++ 甚コンパむラ です。
 .
 本パッケヌゞは、デフォルトの GNU C++ コンパむラを提䟛する䟝存パッケヌゞ です。

make。

## Depends: libc6 (>= 2.27)
$ apt show make
Package: make
Version: 4.2.1-1.2
Priority: optional
Build-Essential: yes
Section: devel
Source: make-dfsg
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Manoj Srivastava <srivasta@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 393 kB
Depends: libc6 (>= 2.27)
Suggests: make-doc
Conflicts: make-guile
Replaces: make-guile
Homepage: https://www.gnu.org/software/make/
Task: ubuntu-mate-core, ubuntu-mate-desktop
Download-Size: 162 kB
APT-Manual-Installed: no
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: コンパむルを制埡するナヌティリティ
 GNU Make は、プログラムの゜ヌスファむルからプログラムの実行ファむルやその他の
 察象ファむルを生成する䜜業を制埡するナヌティリティです。倧きなプログラムの どの郚分を (再) 生成すべきかを自動刀定し、その (再)
 生成に必芁なコマンドを 発行したす。Make は入力ファむルに基づいお、察応する入力の曎新に応じお察象 (ファむル)
 を曎新する必芁があるどんなタスクに察しおも利甚できたす --- コンピュヌタプログラムのビルドに限りたせん。たさに、Make は汎甚目的の
 䟝存関係解決ナヌティリティなのです。

dpkg-dev。

## Depends: perl:any, libdpkg-perl (= 1.19.7ubuntu3), tar (>= 1.28-1), bzip2, xz-utils, patch (>= 2.7), make, binutils
$ apt show dpkg-dev
Package: dpkg-dev
Version: 1.19.7ubuntu3
Priority: optional
Build-Essential: yes
Section: utils
Source: dpkg
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 2,124 kB
Depends: perl:any, libdpkg-perl (= 1.19.7ubuntu3), tar (>= 1.28-1), bzip2, xz-utils, patch (>= 2.7), make, binutils
Recommends: build-essential, gcc | c-compiler, fakeroot, gnupg | gnupg2, gpgv | gpgv2, libalgorithm-merge-perl
Suggests: debian-keyring
Breaks: debhelper (<< 10.10.1~)
Homepage: https://wiki.debian.org/Teams/Dpkg
Task: ubuntu-mate-core, ubuntu-mate-desktop
Download-Size: 679 kB
APT-Manual-Installed: no
APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: Debian パッケヌゞ開発ツヌル
 本パッケヌゞは、Debian ゜ヌスパッケヌゞの展開、構築、そしおアップロヌドに 芁求される開発ツヌル (dpkg-source を含む)
 を提䟛したす。
 .
 Debian ゜ヌスパッケヌゞのほずんどは、構築するにはさらに別のツヌルを必芁ず したす。䟋えば、ほずんどのパッケヌゞは、make や、C
 コンパむラ gcc を必芁ず したす。

dpkg-devは、だいぶいろいろ入りたすね。Recommendsでも倚く匕っ匵っおきたす。

Dockerfileなどでapt-get installを曞く時は、こういうのは個々のパッケヌゞを曞いた方が良さそうですね。