Configure script: Difference between revisions

Content deleted Content added
Kuromedayo (talk | contribs)
m delete unnecessary newline
 
(7 intermediate revisions by one other user not shown)
Line 1:
{{Short description|ExecutableShell script usedfor whengenerating buildingbuild programsconfiguration files on a Unix-like environment}}
{{Lowercase title}}
When installing a package on a [[Unix]] or [[Unix-like]] environment, a '''configure script''' is a [[shell script]] that generates [[software build|build]] configuration files for a [[codebase]] to facilitate cross-platform support. It generates files tailoring for the host system {{endash}} the environment on which the codebase is built and run.
[[Image:Autoconf-automake-process.svg|thumb|280px|Flow diagram including configure, [[autoconf]] and [[automake]], three tools in the GNU Build System]]
A '''configure script''' is an executable script designed to aid in developing a [[computer program|program]] to be run on a wide number of different computers. It matches the [[Library (computer science)|libraries]] on the user's computer, with those required by the program before [[compiler|compiling]] it from its [[source code]].
 
Even though there are no standards for such a script, the pattern is so ubiquitous that many developers are familiar with and even expect a script named ''configure'' that has this functionality. The script can be and originally was hand-coded. Today, multiple tools are available for generating a configure script based on special configuration files. One commonly used tool is [[Autotools]] which generates a [[Bash (Unix shell)|Bash]] script.
As a common practice, all configure scripts are named <code>configure</code>. Usually, configure scripts are written for the [[Bourne shell]], but they may be written for execution in any desired shell.
 
Obtaining a software package as [[source code]] and [[compiler|compiling]] it locally is a common scenario on [[Unix]] and [[Unix-like]] environments. Typically, this process involves the following steps:
== Usage ==
 
Obtaining software directly from the source code is a common procedure on [[Unix]] computers, and generally involves the following three steps: configuring the [[makefile]], compiling the code, and finally installing the executable to standard locations. A configure script accomplishes the first of these steps. Using configure scripts is an automated method of generating [[makefile]]s before compilation to tailor the software to the system on which the executable is to be compiled and run. The final executable software is most commonly obtained by executing the following commands in a shell that is currently pointing to the directory containing the source code:
# Generate build configuration files
# Build the code
# Install the result to an accessible ___location
 
A configure script accomplishes the first step by generating a [[makefile]] that is configured for the host system. This includes using the [[Library (computer science)|libraries]] of the host as required by the codebase.
 
== UsageUse ==
 
OneAfter must type <code>./configure</code> rather than simply <code>configure</code> to indicate to the shell that the script is in the current directory. This is because, asnavigating a security precaution,command-line [[UnixShell (computing)|shell]] configurations don't searchto the current directory forthat executables.contains the So,source to execute programs in that directorycode, onethe mustfollowing explicitlycommands specifyare theirtypically ___location.executed:<ref>{{cite web |url=http://www.control-escape.com/linux/lx-swinstall-tar.html |title=Compiling Linux Software from Source Code |publisher=Control-Escape's Linux Help Engine |access-date=20 November 2010}}</ref>
 
<syntaxhighlight lang="sh">
Line 15 ⟶ 23:
</syntaxhighlight>
 
For the Autotools, the configure script logs status and errors to file ''config.log'', and the command <code>./configure --help</code> outputs command line help information.
One must type <code>./configure</code> rather than simply <code>configure</code> to indicate to the shell that the script is in the current directory. This is because, as a security precaution, [[Unix]] configurations don't search the current directory for executables. So, to execute programs in that directory, one must explicitly specify their ___location.<ref>{{cite web |url=http://www.control-escape.com/linux/lx-swinstall-tar.html |title=Compiling Linux Software from Source Code |publisher=Control-Escape's Linux Help Engine |access-date=20 November 2010}}</ref>
 
Often, a document with instructions is included. with Thisthe cancodebase; beoften helpfulin ifa file named <code>configureINSTALL</code> fails. It Thiscan filebe ishelpful commonlyif namedthe <code>INSTALL</code>configure script fails.
Upon its completion, <code>configure</code> prints a report to <code>config.log</code>. Running <code>./configure --help</code> gives a list of command line arguments, for enabling or disabling additional features such as:
 
== Generating <code>configure</code> ==
<syntaxhighlight lang="sh">
./configure --libs="-lmpfr -lgmp"
./configure --prefix=/home/user/local
</syntaxhighlight>
 
SoftwareAutotools developerssimplifies simplifysome of the challengechallenges of [[cross-platform software]] development by using [[GNU Autotools]].<ref>{{cite web |url=https://www.gnu.org/software/autoconf/ |title=Autoconf - GNU Project - Free Software Foundation (FSF) |publisher=GNU Operating System |access-date=20 November 2010}}</ref> These scriptstools query the host system on which they run for environment settings, platform architecture, and the existence and ___location of required build and runtime dependencies. They store the gathered information in <code>configure.ac</code> or the now deprecated <code>configure.in</code> to be read by <code>configure</code> during the installation phase.
The first line includes the <code>mpfr</code> and <code>gmp</code> libraries. The second line tells <code>[[make (software)|make]]</code> to install the final version in <code>/home/user/local</code>.
 
In new development, library dependency checking hascan beenbe doneaccomplished in great part usingvia [[pkg-config]] via the [[M4 (computer language)|m4]] macro, PKG_CHECK_MODULES. Before pkg-config gained popularity, separate m4 macros were created to locate files known to be included in the distribution of libraries depended upon.
Often, a document with instructions is included. This can be helpful if <code>configure</code> fails. This file is commonly named <code>INSTALL</code>.
 
== Generating <code>configure</code> ==
Software developers simplify the challenge of [[cross-platform software]] development by using [[GNU Autotools]].<ref>{{cite web |url=https://www.gnu.org/software/autoconf/ |title=Autoconf - GNU Project - Free Software Foundation (FSF) |publisher=GNU Operating System |access-date=20 November 2010}}</ref> These scripts query the system on which they run for environment settings, platform architecture, and the existence and ___location of required build and runtime dependencies. They store the gathered information in <code>configure.ac</code> or the now deprecated <code>configure.in</code> to be read by <code>configure</code> during the installation phase.
 
== Dependency checking ==
In new development, library dependency checking has been done in great part using [[pkg-config]] via the [[M4 (computer language)|m4]] macro, PKG_CHECK_MODULES. Before pkg-config gained popularity, separate m4 macros were created to locate files known to be included in the distribution of libraries depended upon.
 
== History ==
The first program to come with a configure script was [[rn (newsreader)|rn]] by [[Larry Wall]] in 1984. The script was written by hand and produced a jocular running commentary when executed. It still survives as part of the build system of the '''trn''' program.<ref>{{cite web |url=https://github.com/acli/trn/blob/613a7e97aca06dd807fb225990fa804e8c744574/Configure|title= Configure script of trn |publisher=GitHub |access-date=10 December 2020}}</ref>
 
Since then, an ecosystem of programstools hashave grownbeen updeveloped to automate the creation of configure scripts as far as possible, of which the most common is the [[Autoconf|GNU Autoconf]] system.
 
== See also ==
* [[Autoconf]]
* [[Software build]]
* [[GNU Build System]]
 
== References ==