Automake Construction Project Engineering Example explanation

Source: Internet
Author: User
Tags manual automake
Automake Construction Project Engineering example explanationCategory: Automake 2011-02-24 21:18 952 People read review (0) Favorite Report makefile Tool script Ubuntu Linux CGI

Construction of Automake environment

"Server Environment"


Linux version: Ubuntu 9.10

Automake version: (GNU automake) 1.11

Autoconf version: (GNU Autoconf) 2.64

Introduced

Although only the Automake and autoconf tools are mentioned above, autoscan,aclocal tools are also required in the actual use process. Which means we need to use it altogether.

Autoscan,aclocal,autoconf,automake these few tools. In Ubuntu, we use the Apt-get Install command and the system automatically installs all the tools for us without having to download them manually. After these commands are executed, the Configure file is generated in the compiled directory, and then we can compile and install the code by using the familiar "./configure", "make", "makes install" commands.

Here are some simple introduction of these tools, online, there are some excerpts from the Internet, in fact, just beginning to learn automake there is no need to fully understand what these tools are, can skip.

AutoScan is used to scan the source code directory for generating Configure.scan files. AutoScan can use directory names as parameters, but if you do not use parameters, then AutoScan will assume that the current directory is being used. AutoScan will scan the source files in the directory you have specified and create a Configure.scan file. Configure.scan contains the basic options for system configuration, which are all macro definitions. In the actual use of the process, we often change the Configure.scan file to configure.in or Configure.ac file.

Note:-note:configure.in is the name used for autoconf files, now deprecated. (from: http://mij.oltrelinux.com/devel/autoconf-automake/) Although the manual is not recommended to change to configure.in, but we can ignore.

Aclocal is a Perl scripting program. Aclocal automatically generates ACLOCAL.M4 files based on the contents of the Configure.in file. The definition of aclocal is: "Aclocal-create aclocal.m4 by scanning configure.ac".

Note: aclocal.m4 file. At that time in study, very tangled in this M4 suffix exactly what meaning, although is a trivial problem, but every time you see this file, always to figure out what this suffix represents a thing. In fact, very simple, M4 is the meaning of macro, that is, there are 4 letters behind M, Daniel's thinking is indeed inconsistent with ordinary people. :)

The autoconf is used to generate configure files. Configure is a script that can set up the source program to accommodate a variety of operating system platforms, and generate the appropriate makefile based on different systems, so that your source code can be compiled on different operating system platforms. The contents of the Configure.in file are macros that, after autoconf processing, become shell scripts that examine system features, environment variables, and the parameters that the software must have. The order of macros in the configure.in file is not specified, but you must add Ac_init macros and Ac_output macros to the front and last sides of all macros.

Automake is used to generate makefile.in files. Those. In files would be used by autoconf scripts to produce the final makefiles (is used to generate makefile files, so it is more important to file)

Overall, the process diagram is like this

(Transferred from HTTP://BLOG.ZQUAN.ME/?TAG=ACLOCAL-M4)

As long as you can see the diagram, the generation of makefile will not be confused about the order.

The following project directory, is my new directory, I based on this directory to explain how to build a compilation project.

"Engineering Catalog"

  

Module NOTES:

Driver: Driver code

Software: module code root directory

-alarm Alarm Module

-common Public Module

-config Configuration Module

-ctrl Main control Module

-lib Store the so dynamic library after compilation

-lib_source source code for third-party libraries

-PTZ gimbal Control Module

-RTP RTP Streaming Media module

-sdkserver SDK Service Module

-server Message Communication Service Module

-storage Storage Module

-webclient CGI Module

-xml Storing XML configuration files

"Execution Process"

Step 1: In the software directory, use AutoScan to scan the current directory (it will automatically scan subdirectories, so you only need to execute once in the root directory), Will generate the Configure.scan file under software, as stated earlier, we need to rename the Configure.scan file to configure.in, otherwise it cannot be recognized by other tools.

1.autoscan

2.MV Configure.scan configure.in

After renaming, we also need to modify the configure.in file according to our actual situation. The version of the tool is different, the generated configure.in file may be different, but we only need to focus on a few parts.

Note: The actual use of the process, you only need to pay attention to my red arrows identified by a few macro commands on it, and other macro commands are many, you need to consult the manual according to the actual situation to obtain the use of the method.

Step 2.

Execute the aclocal command below software to generate the Aclocal.m4 file. (ACLOCAL.M4 file cannot be generated if the autoscan.in file is missing a Ac_init_automake macro)

Step 3.

Execute the autoconf command below software to generate the Configure file.

Note: autoconf is a tool used to generate automatic configuration software source code scripts (configure). Configure scripts can run independently of the autoconf, and in the process of running, without user intervention, to generate configure, must use ACLOCAL.M4.

Step 4.

The Configure script has been created and, if executed at this time, the./configure command will prompt an error, as follows

Config.status:error:cannot Find input file: ' makefile.in '

Because so far, we have not generated the makefile.in file, then how to generate makefile.in it. We first need to write the makefile.am file, look at the suffix. Am, we can know that this makefile.am is for Automake tool use, through the makefile.am file, we put makefile.in generated, and then through. The Configure command reads the execution makefile.in and generates the makefile. Finally, our "make" and "Make Install"

It should be said, Automake as long as the step-by-step, in order to knock a few commands is very easy, the only trouble is to write the makefile.am file, we need to each involved in the compilation of a subdirectory to create a makefile.am file. Although makefile.am is the most tedious step in the entire creation process (considering the possible number of subdirectories), it is much easier than writing each Makefile file yourself.

1. We first create the software/makefile.am file, how to write it.

As you can see, I set two variables in it, Subdirs and automake_options. These are the variables that the system comes with, similar to the variables that come with the system.

Subdirs variable, as the name implies, is the meaning of the subdirectory, should be software is the project root directory, so, we only need to indicate in this makefile.am sub-directory which can be, in the execution process, will automatically go to the sub-directory to find the corresponding makefile.am , so it's quite simple.

Automake_options variable, look at the picture will know, do not explain.

2. Create the root directory of the makefile.am, then the sub-directory is the sub-module of the makefile.am how to write it. Look together.

I chose the SOFTWARE/RTP module as the explanation directory, and its makefile.am is written in this way. Assuming that the file below the RTP module has only one stream.cpp, let's write it like this, as shown in

About Bin_programs also say that, after we make the install, the generated bin file will be copied to the system directory such as/usr/local/bin, if you do not want to copy, to prevent the original file is overwritten, you can use the Noinst_ PROGRAMS Replace Bin_programs (Noinst is not the abbreviation of install, you know)

OK, the other directory of the following makefile.am, you can refer to my above examples, leaf out, very simple.

Step 5.

Once you've finished all the makefile.am, you can execute the automake--add-missing command in the software directory, and the makefile.in file will be automatically generated under each directory after execution. Finally execute the Linux installation file trilogy, "Configure", "make", "made Install", you can do it casually.

The knowledge point in this is only about the very few parts of Automake, want to know more, it is recommended to read more technical articles written by others or look at the Official handbook.

Another good way to do this is to take a few open source code and figure it out for yourself.

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.