GNU Compiler tool Chain Introduction---antoconf

Source: Internet
Author: User
Tags automake

Everyone in the download a lot of free software to compile the source code, all need to use configure this command, and then Make,make install and so on, here we briefly introduce what is autoconf:

1. Basic Introduction

Autoconf is a program that generates a shell script (or an explanatory script or program on another operating system) that is used to configure the source code based on the compiled environment in which it is built. To give a very simple example, such as I compile the same source on Linux and Mac, the compiled program may be a display of Linux version information, a display of Mac version information, this is the role of autoconf, collecting environmental information, greatly facilitate the user (can imagine, Each time you install a software under the system, you have to configure the system information, the compiler version will be a very troublesome thing.

2. Automake

Introduction autoconf must introduce Automake, as an integral part of the GNU family of two tools, both are complementary in most cases, make the tool is simply to compile the link to build the final target file, if you just write a Hello world, Then use make is sufficient (in fact, even do not), you can directly write a makefile as follows:

Hello:hello.c    

Very simple is it, but in a large-C + + project, there will be many modules, need to introduce a lot of header files, library files and so on, if such a write-dependent, not only inefficient, but also very difficult to manage. Therefore, as an auxiliary tool for make, autoconf came into being, and it often played these roles: Is there a library of engineering dependencies in the search system, and if so, what is the path? The default compiler and its version, and so on.

3. Generate Configure Script

The Configure script is generated by the autoconf program, and Autoconf runs the program under the source path, The program will search for the path under the configure.ac this configuration file, you can also add a test configuration files such as ACLOCAL.M4 and ACSITE.M4, these files can be the specific role of Google, this is not described in detail.

The following figure describes how to build a configuration file

Your source filles--[autoscan*]--[Configure.scan]--.                                   ----x| *-------------- > autoconf*---------> configure[aclocal.m4]   +-------+
| --------x *--------------> [autoheader*]-----> [config.h. in] Makefile. inch

If we use Automake, the following files will play a role.

[ACINCLUDE.M4]----,

[Local macros] ---+-aclocal*---> ACLOCAL.M4
|
Configure.ac ----,

Configure.ac------.
+---> automake*-makefile.in
makefile.am ------,

Configure all of the configuration files that are used in the software process

                                 *----------------> [Config.cache]
configure*----------------------+---------------->config.log
|
[Config.h.in]-. V .-> [Config.h]-.
+-----> config.status* ------+ +-----> make*
makefile.in---, ' Makefile---

As we can see, The final make only needs makefile and config.h two files, then the previous files are what use, a very simple way to understand is that the previous makefile.in is makefile template, configure configuration after the configuration macros written to makefile.in in the form Into the last executable makefile configuration file.

So, how do you write configure.ac?

What we need to know is that configure is nothing more than reading information from various environments, AUTOCONF has provided a lot of macros to read this information. Here, the previous suffix in is the Configure program processing configuration file, and now, it is more recommended to use AC as the suffix of the naming method.

Autoconf is a very robust program that can be compatible with various operating systems, and we don't need to be concerned about this, just write the configuration file in autoconf way, considering that most configure environments are in a UNIX-like environment, so you might say, Why not directly with the shell, anyway is also read various environment variables, theoretically yes, if not autoconf, you can use the shell to initialize the configuration information, and the actual situation is autoconf to avoid our repeated build wheel, has written for us some shell Function reads environment parameters, which is more efficient than writing your own shell, and rarely goes wrong. In fact, careful people know that autoconf is also the CONFIGURE.AC compiled into configure, with the editor open configure will find inside is the shell command.

3.1 Autoconf Configuration language

Autoconf are written using a variety of macro commands, the following describes the specifications for writing these macros:

1. When the macro command has parameters, the macro name and parentheses cannot have spaces

Ac_init ([oops], [1,0]) # Incorrect
Ac_init ([Hello], [1,0]) # correct

2. In general, macro requires the use of brackets, unless it is known that the Macro command can be without brackets, see the following example




[Ac_msg_error ([Sorry, can ' t do anything for you])



[Ac_msg_error ([Sorry, can ' t do anything for you])

Because 1 cannot include macro commands, so you can not use the brackets, the above wording is a very conservative and careful writing, which often makes users more offensive, always add brackets, most people now respected the following wording.




[Ac_msg_error ([Sorry, can ' t do anything for you])

As we can see, stdio.h and Have_stdio_h do not join the brackets, but this is also relatively safe (as long as you do not define the names of the macro, it will not be interpreted wrongly), and then to write a false danger of writing:



Ac_msg_error ([Sorry, can ' t do anything for you])

Why is the above-mentioned notation dangerous? Because

  

  

GNU Compiler tool Chain Introduction---antoconf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.