Linux uses Automake, autoconf to generate configure files __linux

Source: Internet
Author: User
Tags perl script automake
the diagram of the documents in the process of generating configure

second, Detailed introduction

AutoScan: Scan the source code to search for common portability issues, such as checking compilers, libraries, headers, etc., generate file Configure.scan, it is a prototype of CONFIGURE.AC.

Aclocal: Macros in user-defined macros and ACINCLUDE.M4 files are defined in the file aclocal.m4 by the macros that are required by the Configure.ac file, depending on the macros that are already installed. Aclocal is a Perl script that is defined as: "Aclocal-create aclocal.m4 by scanning configure.ac"

Automake: Create makefile.in the structure defined in makefile.am, and configure script converts the generated makefile.in file to makefile. If you define a special macro in configure.ac, such as Ac_prog_libtool, it will call libtoolize, otherwise it will generate config.guess and config.sub

Autoconf: Expands the macros in CONFIGURE.AC to generate configure scripts. This process may be used to use macros defined in ACLOCAL.M4. Iii. Examples 1. Test code (define two files Hello.h and hello.c)

/*hello.c*/
#include <iostream>
#include "hello.h"

using namespace std;

int main ()
{
    Chello A;
    return 0;
}
/*hello.h*/
#ifndef __hello_h__
#define __HELLO_H__

#include <iostream>
using namespace std;

Class Chello
{public
:
    Chello () {cout<< "hello!" <<endl;}
    ~chello () {cout<< "bye!" <<endl;}
;

#endif
2. Operation Steps (1) Installation of dependent packages
[Root@bogon autoconfig]# yum-y Install Automake autoconf

Automake include: aclocal, Automake, etc.

Autoconf include: AutoScan, autoconf, etc. (2) AutoScan

[Root@bogon autoconfig]# ll
-rw-r--r--1 root  4 hello.cpp
-rw-r--r--1 root 189 June  4 hello.h
[Root@bogon autoconfig]# autoscan
[root@bogon autoconfig]# ll Total
-rw-r--r--1 root  Root   0 June  4 autoscan.log
-rw-r--r--1 root root 481 June  4 Configure.scan
-rw-r--r--1 root root  4 Hello.cpp
-rw-r--r--1 root root 189 June  4 hello.h
(3) aclocal
[Root@bogon autoconfig]# mv Configure.scan configure.ac [Root@bogon autoconfig]# vim configure.ac/* Modify the Red bold section below/* * -*-autoconf-*-# Process This file and autoconf to produce a configure scrip T. ac_prereq ([2.69])ac_init (Hello, 1.0, admin@163.com)
am_init_automake (Hello, 1.0)Ac_config_srcdir ([hello.cpp]) ac_config_headers ([config.h]) # Checks for programs.
Ac_prog_cxx AC_PROG_CC # Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics. # Checks for library functions.ac_output (Makefile)
[Root@bogon autoconfig]# aclocal [root@bogon autoconfig]# ll total 52-rw-r--r--1 root 37794 June 4 aclocal.m4 drwx R-xr-x 2 Root 4 autom4te.cache-rw-r--r--1 root 0 June 4 autoscan.log-rw-r--r--1 root root 4 4 configure.ac-rw-r--r--1 root root June 4 hello.cpp-rw-r--r--1 root root 189 June 4 Hello.h

The following is a brief description of the file (all the behavior notes starting with "#"):
the &NBSP;AC_PREREQ&NBSP Macro declares the autoconf version required by this file, and this example uses a version of 2.59.
· AC_INIT&NBSP macros are used to define information such as the name and version of the software, "Full-package-name" is the package name, "version" is the software version number, "Bug-report-address" Address the bug report (typically the software author's email address).
· Ac_config_srcdir   Macros are used to detect the existence of the specified source file to determine the validity of the source directory. Here is the hello.c under the current directory.
· Ac_config_header   Macros are used to generate config.h files for autoheader use.
· AC_PROG_CC   is used to specify the compiler and, if not specified, the default gcc is selected.
· AC_OUTPUT&NBSP is used to set the file to be generated by the configure, and if it is makefile,configure will bring the result that it checks out into the makefile.in file to produce the appropriate makefile. When using Automake, you need some additional parameters, which are generated by the Aclocal tool. (3) autoconf

[Root@bogon autoconfig]# autoconf
[root@bogon autoconfig]# ll Total
204
-rw-r--r--1 root root  37794 June  4 Aclocal.m4
drwxr-xr-x 2 root root     bayi June  4 Autom4te.cache
-rw-r--r--1 root root      0 jun
  4 Autoscan.log
-rwxr-xr-x 1 root 154727 June  4 Configure
-rw-r--r--1 root root    492 June  4 Configure.ac
-rw-r--r--1 root root    June  4 hello.cpp
-rw-r--r--1 root root    189 June  4 Hello.h

At this point you can see that the Configure (4) has been generated Autoheader

[Root@bogon autoconfig]# autoheader
[root@bogon autoconfig]# ll Total
-rw-r--r--1 root root  37794 June  4 Aclocal.m4
drwxr-xr-x 2 root root     bayi June  4 Autom4te.cache
-rw-r--r--1 root root      0 jun
  4 Autoscan.log
-rw-r--r--1 root    625 June  4 config.h.in
-rwxr-xr-x 1 root root 154727 June  4 Configure
-rw-r--r--1 root root    492 June  4 configure.ac
-rw-r--r--1 root    June  4 Hello.cpp
-rw-r--r--1 root    189 June  4 hello.h

Autoheader generates configure.h.in if Ac_config_header is defined in Configure.ac, then this file is required; (5) makefile.am

[Root@bogon autoconfig]# vim makefile.am
[Root@bogon autoconfig]# cat makefile.am 
automake_options=foreign 
Bin_programs=hello 
hello_sources=hello.cpp hello.h

· AUTOMAKE_OPTIONS&NBSP the option to set Automake. Since the GNU has strict specifications for its own release of software, such as the need for a license declaration file copying, etc., otherwise automake execution will be an error. Automake offers 3 software levels: foreign, GNU, and gnits for users to choose from, with the default level of GNU. In this case, the foreign level is required, which detects only the necessary files. The
bin_programs   Defines the execution file name to be generated. If you want to produce multiple execution files, each file name is separated by a space. The
hello_sources  defines the original files required by the "Hello" executable program. If the "Hello" program is generated by multiple original files, you must list all the original files it uses and separate them with spaces. For example, if the target body "Hello" requires "hello.c", "hello.h" two dependent files, define HELLO_SOURCES=HELLO.C hello.h. (6) Automake

[Root@bogon autoconfig]# automake--add-missing configure.ac:6: Warning:am_init_automake:two-and three-arguments  Forms are deprecated. For more info, See:configure.ac:6: Http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT _005fautomake-invocation configure.ac:6: Installing './install-sh ' configure.ac:6: Installing './missing ' [Root@bogon autoconfig]# ll total 236-rw-r--r--1 root root 37794 June 4 aclocal.m4 drwxr-xr-x 2 root root and Bayi June 4 Autom4te. cache-rw-r--r--1 Root 0 June 4 autoscan.log-rw-r--r--1 root root 625 June 4 Config.h.in-rwxr-xr-x 1 ro  OT Root 154727 June 4 configure-rw-r--r--1 root root 492 June 4 configure.ac-rw-r--r--1 root root June 4 hello.cpp-rw-r--r--1 root 189 June 4 Hello.h lrwxrwxrwx 1 root root June 4 Install-sh->/usr/share/ automake-1.13/install-sh-rw-r--r--1 root 4 makefile.am-rw-r--r--1 root root 22227 June 4 Makefile. In lrwxrwxrwx 1 roOT root June 4 missing->/usr/share/automake-1.13/missing 

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.