Command analysis for compiling and installing software in Win or Linux: configure; make; make install

Original address: http://www.cnblogs.com/Jerry-Chou/archive/2010/12/18/1909843.html

Translating an article, I first learned from this article why installing software from source code on the Linux platform usually requires these three steps: ./configure, make, make install. The translation is as follows:


I always hear people say, usually just use configure, make, make install to make the program work. Unfortunately most people who use computers today have never used a compiler at all, or have written a single line of code. With the emergence of graphical user interface (GUI) and application builder (application builder), many real programmers do not need to configure; make; make install anymore.

All you have to do are three steps, each of which uses an existing program to make a new program ready or running. Configure is used before make, but each step has a different purpose. Next I'll explain the second (make) and third (make install) steps, and then I'll explain configure.

The utility of make has become part of Unix history. The main purpose of designing it is to reduce the programmer's memory burden. Better, I guess, is that it reduces the amount of documentation a programmer needs to write. In any case, once you've established a set of rules that make understands to create a program, you don't have to worry about them anymore.

To make this easy, the make utility has a set of built-in rules, you just tell make the rules it needs to build your program. For example, if you type make love, make will look for some rules based on your input. If you don't create rules at all, they use built-in rules. One of the built-in rules is to run Linker and find the program name .o End file to generate an executable file.

So, make will go to the file named love.o. But make doesn't stop there. Even if it finds .o files, it has a set of rules to make sure .o files are up to date. In other words, it is newer than the source code files. In Linux systems, the most common source code is a file with a .c suffix written in C language.

If make finds both the .c file (love.c) and the .o file, it looks at the timestamps of both to make sure the .o file is more recent, if no .c file is newer, or the .o file doesn't exist, make will build a new .o file from the .c file (using the C compiler) using another set of built-in rules. The same rules apply to other types of programming. Finally, when make is finished running, there will be an up-to-date executable program generated.

By the way, a Unix joke from an early version of make. When make cannot find the required files, such as no source code files in love.o, love.c or other formats, the make program will say:
make: don't know how to make love. Stop.

Back to the topic , usually make uses the Makefile in the current directory. If you have a program source code file, there is a Makefile over there, you can take a look. The content is just plain text. A line followed by a colon is the target, which is what you type right after the make command. make performs a few different actions depending on your input. If you just type make without following any commands, the first target will be executed.

At the beginning of most make files, you're most likely to see assignment-like statements. Each line has many fields, and the fields are connected by an equal sign. They are used to set make's internal variables. Common settings such as the location of the C compiler, the version number of the program, and the like.

Now is the time to go back to configure. The C compiler may be located in different locations on different systems, you may use zsh instead of bash as your shell, the program may need to know your hostname, may use the dbm library, and need to know that the gdbm library is installed on the system, Or the ndbm library, blah, blah, blah. To accomplish these configurations, it is often necessary to modify the Makefile. Another pain for programmers is that any time you want to install software on a new system, you need to re-enumerate the configuration.

As more and more software is developed and more POSIX-compliant systems appear, these configurations are getting harder and harder to do. Then configure appears. It's a shell script (usually written in GNU Autoconf) that looks for the location of some tools, trying to see if they work. Then follow the instructions in the Makefile.in file to generate a Makefile (and possibly other files) that may work in the current system.

Now that the background is out of the way, let's summarize:

    you run configure (usually you type ./configure in the shell), which generates a new Makefile.
    Type the make command to build the program. He will find the first target in the Makefile and build the executable according to the instructions of the first target. The purpose of this step is to generate an executable file.
    Now, as root, type make install. Call make again to find a target named install, and install the software according to the files and directories specified by this target.

This is a simplified explanation, but in most cases, what you know will suffice. Most programs will have a file called INSTALL, this file contains installation steps, and some precautions. For example, provide options to the configure command to change the directory of the final executable. There are also other make targets, such as clean, to perform some cleanup after the installation is complete. Sometimes there is a test target, which allows you to test the generated executable software between the two steps of make and make install.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324942560&siteId=291194637