User:MGorny/GLEP:EFH

Abstract
This GLEP specifies the install filesystem structure for ebuilds. In particular, it defines recommendations on where specific files are to be installed and can serve as a base for QA checks preventing ebuilds from accidentally installing into incorrect locations. It amends and extends Filesystem Hierarchy Standard as appropriate for Gentoo.

Motivation
While Filesystem Hierarchy Standard was often considered the base definition on how filesystem is used, Gentoo did not fully conform to it. Instead, a semi-normative filesystem policy was published in the Developer Manual Filesystem section, along with a few non-written amendments. This documentation is neither complete, fully correct or up-to-date.

Furthermore, a number of ebuilds over time had various bugs resulting in files being installed in uncommon and incorrect locations. This included stray files and directories in the root directory, home directories, temporary filesystems (i.e. discarded on reboot). It seems quite appropriate to employ additional QA checks that automatically warn developers whenever ebuilds do this.

However, employing proper QA checks requires precise definition on how various directories are to be used. This GLEP serves the purpose of providing a normative reference that can be used both as a source of clear policy on how ebuilds must and must not install files, and a recommendation on how ebuild authors should choose between multiple possible variants.

Directory maintenance
Throughout the directories listed in this specification, specific types of maintenance are listed to describe who is allowed to install files and directories inside the specific directory. The meaning of different types is described in this section.

Ebuild-maintained means that ebuilds are allowed to install files and directories into the specific directory. If a specific directory is not listed as ebuild-maintained, then ebuilds must not install any files there. The only allowed exception is that ebuilds are allowed to create the specific top directory and install a keepfile in order to prevent it from being accidentally removed while pruning empty directories.

User-maintained means that the users (either sysadmin or appropriate users) are allowed to install files and directories into the specific directory. If a specific directory is not listed as user-maintained, then sysadmin should not attempt to install or alter the files inside it. Doing so may result in file collisions and alterations being lost on software installs, unless specified otherwise.

Software-maintained means that various background services and applications can modify the specific directory structure at runtime (i.e. without an explicit request made by user). For software to work correctly, those directories can not be mounted read-only during runtime.

System-maintained means that the contents of the directory may be altered by the operating system kernel. This is the case with special filesystems.

Use of symlinks
The directories listed in this specification can be implemented in terms of symlinks to other directories. The target directories can either be dedicated directories serving no other purpose in this specification, or other directories serving the same purpose.

Hierarchies and hierarchy dependencies
The directories listed in this specification are organized in hierarchies, starting with a well-defined top directory. All subdirectories in a specific hierarchy belong to the hierarchy, unless they form the top directory of another hierarchy.

Each of the hierarchies may depend on other hierarchies. The objects installed into hierarchy A may depend on objects from hierarchy B only if hierarchy A also depends on hierarchy B. In other words, it is disallowed to install objects that depend on objects from a sub-hierarchy into a parent hierarchy.

All hierarchy definitions in this specification are considered complete. Inside a particular hierarchy root, no other subdirectories can exist except for the directories noted and optionally directories specific to a particular operating system.

Hierarchies
The following hierarchies (prefixes) are defined, including their dependencies and short descriptions:

Root directory hierarchy
The following directories are defined in the root directory hierarchy:

/usr directory hierarchy
The following directories are defined for the /usr hierarchy:

/usr/local directory hierarchy
The following directories are defined for the /usr/local hierarchy:

/opt directory hierarchy
The /opt directory hierarchy is used to provide additional binary software packages. Those packages are installed in subdirectories of /opt named by the vendor or software name. The directory structure could be summarized as:

Application executable directories
Applies to: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin, /opt/bin

Application executable directories are intended for storing program executables, scripts and symlinks to them. All of executables stored in those directories should be intended for direct execution by users, and therefore those directories can be added to PATH.

Specific requirements:
 * all files in application executable directories should be executable (+x permission),
 * no subdirectories are allowed in application executable directories.

C/C++ header file directories
Applies to: /usr/include, /usr/local/include

C/C++ header file directories are intended for storing header files for C/C++ libraries. The directory structure of installed files should correspond to desired include paths, as those directories are searched for headers by compilers by default. Alternatively, subdirectories can be used to provide package-specific headers that are explicitly used through -I flags.

It is recommended to store only arch-independent headers in the top header directory structure. Arch-dependent headers should be stored in package subdirectories in library and package data directories. Alternatively, arch-specific subdirectory of header file directory can be used.

Specific requirements:
 * all files should be valid C/C++ header files.

Library and software package directories
Applies to: /lib*, /usr/lib*, /usr/local/lib*

Those directories are considered separately as two kinds of directories:
 * 1) multilib library directories, defined by the profile,
 * 2) native software package lib directory.

Depending on the particular profile, lib can serve the purpose of both a multilib library directory (not necessarily the native one) or a symlink to it, and the native software package directory.

The multilib library directories are used for two purposes:
 * storing shared and static C/C++ libraries,
 * storing architecture-dependent package data (headers, modules…).

The subdirectories of the native software package lib directory can be used for two purposes:
 * storing installed software packages,
 * storing executables and scripts for internal use of installed software.

Specific requirements:
 * all arch-dependent files must correspond to one of the following ABIs:
 * the specific multilib ABI — if the lib* directory corresponds to one,
 * the native ABI — if it is the lib directory,
 * rules for specific subdirectories:
 * pkgconfig subdirectory must contain only valid pkg-config .pc files and no subdirectories.

Internal use executable directories directories
Applies to: /usr/libexec, /usr/local/libexec

Those directories contain executables (and libraries) that are not intended to be called (linked) directly by the user. Instead, they are only used internally by the programs installing them.

Read-only application data directories
Applies to: /usr/share, /usr/local/share

Those directories contain application data that is not modified by the applications at runtime and that is not arch-dependent. Sometimes it is also used to contain internal use scripts (as long as they are not arch-dependent).

Specific requirements:
 * no arch-dependent files can be installed in the directory,
 * rules for specific subdirectories:
 * pkgconfig subdirectory must contain only valid pkg-config .pc files and no subdirectories.

Copyright
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.