Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What on earth is configure,make,make install doing in Linux?

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Under Linux, it is often necessary to install and deploy some software packages or tools. After taking a look at the installation package, it is easy to do it with configure,make and make install.

Sometimes I wonder, what does this congigure,make, make install mean? configure is a test feature that exists, and then make starts compiling and make install generates the corresponding executable. But a tool only remembers the spelling or basic concepts, but knows very little about the principle and needs to be made up.

Several commands to build, compile and hide

To start with the compilation and installation process, using the command aclocal generates an M4 file, and aclocal is essentially a perl script. First mention M4, M4 is a macro processor, it is part of the POSIX standard. Why is it called M4? the full name is macro,m followed by four letters. It is said to be so, . Excerpt a description of M4: from Turing's point of view, M4, input stream and output stream can be connected to form an infinitely extended paper tape, M4 is the read and write head of this tape, so M4 is a Turing machine. The computing power of M4 is the same as that of any programming language, and the difference only lies in the programming efficiency and the running efficiency of the program written.

Then there is autoconf, which generates configure files. Configure is a script that can set up source programs to adapt to different operating system platforms and generate appropriate Makefile according to different systems, so that your source code can be compiled on different operating system platforms.

Finally, automake is used to generate Makefile.in files.

To sum up, this compilation process involves several command tools, and the general function points are as follows.

Aclocal # generates aclocal.m4

Autoconf # generate configure from configure.in

Automake-- add-missing # generate Makefile.in based on Makefile.am

I found a well-summarized picture on the Internet, very comprehensive.

Build process environment preparation

Let's write a simple Hello world to understand the whole process.

I wrote a very simple c program, so I'll just make do with it. The file is main.c

# include

Int main (int argc, const char * argv [])

{

Printf ("Hello world, a new test\ n")

Return 0

}

As you can see, the output of the program after running is Hello world,a new test

Let's look at how to simulate this process according to the specification in building a GNU program.

We create a file configure.ac, which contains some macros, which are processed by the next two autoconf, and then handed over to automake to process, and finally complete the check.

AC_INIT ([helloworld], [0.1], [xxx@xxx.com])

AM_INIT_AUTOMAKE

AC_PROG_CC

AC_CONFIG_FILES ([Makefile])

AC_OUTPUT

For example, AC_INIT ([helloworld], [0.1], [xxx@xxx.com]) means the name of the autoconf generation package, version (which can be defined by yourself), and feedback mailbox.

AM_INIT_AUTOMAKE is a tool to check when automake tries Makefile, AC_PROG_CC is compiler detection, and AC_CONFIG_FILES is automake to build .in-like files.

Then there is the Makefile file, which we set to Makefile.am, which is closely related to the above configuration.

[root@oel64 tmp] # cat Makefile.am

AUTOMAKE_OPTIONS=foreign

Bin_PROGRAMS = helloworld

Helloworld_SOURCES = main.c

Automake offers three software levels: foreign, gnu, and gnits. The default level is gnu. Here AUTOMAKE_OPTIONS uses foreign, which means that only necessary files are detected.

Bin_PROGRAMS defines the name of the execution file to be generated, here we define it as helloworld

File_SOURCES defines file, the dependent file of the executing program, in which the first part of "file" in "file_SOURCES" is to be rewritten to the executable file name, that is, the name is the same as the name defined by bin_PROGRAMS. Here is helloworld. If you have more than one executable, define the corresponding file_SOURCES.

Construction process practice

So far, we have created three files, main.c,configure.ac,Makefile.am

[root@oel64 c] # ll

-rwxr-xr-x. 1 root root 108 Sep 13 12:13 configure.ac

-rw-r--r--. 1 root root 105 Sep 13 12:13 main.c

-rw-r--r--. 1 root root 79 Sep 13 12:13 Makefile.am

First use aclocal to get the M4 file. Two files are generated here, one is aclocal.m4 and the other is cache file autom4te.cache

[root@oel64 c] # aclocal

[root@oel64 c] # ll

Total 56

-rw-r--r--. 1 root root 34611 Sep 13 12:14 aclocal.m4

Drwxr-xr-x. 2 root root 4096 Sep 13 12:14 autom4te.cache

-rwxr-xr-x. 1 root root 108 Sep 13 12:13 configure.ac

-rw-r--r--. 1 root root 105 Sep 13 12:13 main.c

-rw-r--r--. 1 root root 79 Sep 13 12:13 Makefile.am

Then use autoconf to get the configure file

[root@oel64 c] # autoconf

[root@oel64 c] # ll

-rw-r--r--. 1 root root 34611 Sep 13 12:14 aclocal.m4

Drwxr-xr-x. 2 root root 4096 Sep 13 12:14 autom4te.cache

-rwxr-xr-x. 1 root root 135288 Sep 13 12:14 configure

-rwxr-xr-x. 1 root root 108 Sep 13 12:13 configure.ac

-rw-r--r--. 1 root root 105 Sep 13 12:13 main.c

-rw-r--r--. 1 root root 79 Sep 13 12:13 Makefile.am

Then use automake to build the module

[root@oel64 c] # automake-- add-missing

Configure.ac:2: installing `. / install-sh'

Configure.ac:2: installing `. / missing'

Makefile.am: installing `. / depcomp'

After the whole process is completed, it is what we usually do.

The result of executing configure is as follows:

[root@oel64 c] #. / configure

Checking for a BSD-compatible install... / usr/bin/install-c

Checking whether build environment is sane... Yes

Checking for a thread-safe mkdir-p. / bin/mkdir-p

Checking for gawk... Gawk

Checking whether make sets $(MAKE)... Yes

Checking for gcc... Gcc

Checking for C compiler default output file name... A.out

Checking whether the C compiler works... Yes

Checking whether we are cross compiling... No

Checking for suffix of executables...

Checking for suffix of object files... O

Checking whether we are using the GNU C compiler... Yes

Checking whether gcc accepts-g. Yes

Checking for gcc option to accept ISO C89... None needed

Checking for style of include used by make... GNU

Checking dependency style of gcc... Gcc3

Configure: creating. / config.status

Config.status: creating Makefile

Config.status: executing depfiles commands

[root@oel64 c] #

Then there is make, and in this process you can clearly see that gcc begins to compile.

[root@oel64 c] # make

Gcc-DPACKAGE_NAME=\ "helloworld\"-DPACKAGE_TARNAME=\ "helloworld\"-DPACKAGE_VERSION=\ "0.1\"-DPACKAGE_STRING=\ "helloworld\ 0.1\"-DPACKAGE_BUGREPORT=\ "xxx@xxx.com\"-DPACKAGE=\ "helloworld\"-DVERSION=\ "0.1\"-I. -g-O2-MT main.o-MD-MP-MF .deps / main.Tpo-c-o main.o main.c

Mv-f .deps / main.Tpo .deps / main.Po

Gcc-g-O2-o helloworld main.o

Finally, there is make install, with executable program files.

[root@oel64 c] # make install

Make [1]: Entering directory `/ root/c'

Test-z "/ usr/local/bin" | | / bin/mkdir-p "/ usr/local/bin"

/ usr/bin/install-c helloworld'/ usr/local/bin'

Make [1]: Nothing to be done for `install-data-am'.

Make [1]: Leaving directory `/ root/c'

For example, the compiled main.o, if you use strings to view the content is the result of execution.

[root@oel64 c] # strings main.o

Hello world, a new test

If you look at the contents of the executable program helloworld, there is a corresponding stack inside.

[root@oel64 c] # strings helloworld

/ lib64/ld-linux-x86-64.so.2

_ _ gmon_start__

Libc.so.6

Puts

_ _ libc_start_main

GLIBC_2.2.5

Fff.

Do it by hand.

[root@oel64 c] #. / helloworld

Hello world, a new test

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 207

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report