On System Programmer growth plan-Engineering Management (2) "target =" _ blank ">
Indicate the source and author's contact information during reprinting.
Article Source: http://www.limodev.cn/blog
Author contact: Li xianjing <xianjimli@gmail.com>
System Programmer growth plan-Engineering Management (2)
Helloworld
Automake is much more complicated than ide. Here we will first write a hello world example, understand the basic concept, and then use it to manage the actual project.
O directory structure
The top-level directory name uses the module name. Here is helloworld.
The source file is placed in the SRC subdirectory under the module, that is, helloworld/src.
This is a convention. When multiple sub-modules exist, the source code of each sub-module is placed in its own directory.
O create source file
Create the source file main. c Under SRC. The content is a simple hello World Program.
O create a makefile Template
Create helloworld/makefile. am with the following content:
SUBDIRS=src
Only a simple line of code indicates that there is a SRC subdirectory under it. If there are multiple subdirectories, separate them with spaces.
Create helloworld/src/makefile. am with the following content:
bin_PROGRAMS=helloworld
helloworld_SOURCES=main.c
This indicates that there is an executable file helloworld, which is compiled from the source file main. C.
Programs indicates the executable file to be generated. When multiple executable files exist, separate them with spaces. Bin indicates the directory to be installed for the executable files.
Sources indicates the source files required to generate executable files. When multiple source files exist, separate them with spaces.
The. Am extension is short for automake, which is a template used by automake to generate the makefile. In file.
O create an Autoconf template.
Run autoscan under helloworld to generate the file Configure. Scan and rename it Configure. In. This is
The Autoconf template file contains the following content:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT
This file is composed of a series of macros which are finally expanded by the command M4 to obtain a script file configure. The main function of configure is to detect system configurations, and then
Generate the makefile based on these configurations. For example, ac_prog_cc
Is used to detect the compiler. ac_config_files and ac_output are used to generate makefile and other data files.
However, this template file cannot be used directly. You need to make the following changes:
Put:
Ac_init (full-package-name, version, bug-Report-address)
Changed:
Ac_init (helloworld, 0.1, xianjimli@hotmail.com)
Full-package-name is the name of the module.
Version
Is the version number of the module. The initial version number is 0.1. Two-level version is enough for a small module. The major version number before the decimal point is used. The major version number is upgraded only when major updates are made. The version number after the decimal point is,
You should upgrade it every time you release it. After upgrading to 0.9, you can continue to upgrade to 0.10 and 0.11.
Bug-Report-address is the email address of the author or maintainer.
Add an automake initialization script:
Am_init_automake (helloworld, 0.1)
Helloworld is the module name.
0.1 is the version number of the module.
Here it is the same as the preceding parameter. ac_init initializes Autoconf and am_init_automake is the initial automake. In some cases
But does not need to compile the file. am_init_automake is not required.
Finally, the following file is obtained:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
AC_INIT(helloworld, 0.1, xianjimli@hotmail.com)
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE(helloworld, 0.1)
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT
O The macro used for copying.
Run: aclocal
As mentioned above, configure. In is a series of macros which are carried out by the M4 command. M4
In fact, it is macro's abbreviation. 4 indicates that four letters are omitted after M. Similarly, i18n (internationalization) and
L10n (localization), where the numbers represent the number of omitted letters.
Ac_prog_cc
A macro like this is a standard macro (or a built-in macro). We don't need to write it by ourselves, but we need to run the command aclocal and aclocal TO USE
The macro program is copied to our project. After aclocal is run in the helloworld directory, the following error occurs in the current directory:
Autom4te. cache is a temporary directory, which is only used to accelerate macro development.
Aclocal. M4 is the macro definition used in Configure. in. For more information, see.
O generate a configuration header file template.
Run: autoheader
The config. h header file is used to define macros that can be referenced in C/C ++ programs, such as the module name and version number. These macros are generated by the configure script, but I
Provide a template file. This template file can be generated using the command autoheader. After running autoheader in the helloworld directory
Generate config. H. In. Generally, you do not need to modify it.
O create several necessary files.
Readme: describes the functions, usage, and precautions of the module.
News: Describes the latest developments in the module.
Authors: the author and contact information of the module.
Changelog: records the modification history of the module. It has a fixed format:
1. Put the latest modification at the top.
2. For each record, the first line is written on the date, modifier, and contact information. The second line starts with a tab, adds an asterisk, and then writes the reason and position of the modification. For example:
2009-03-29 Li XianJing
* Created
O generate makefile. in and the required scripts.
Run: automake-
This command will create copying depcomp install-SH
Missing Links to several files that point to files in the system. Automake uses makefile. am as the template to generate makefile. In.
Makefile. In is much more complex than makefile. Am. Fortunately, we don't need to know about it.
O generate the configure script.
Run: Autoconf
The Autoconf function is to call M4 to expand the macro in configure. In and generate the configure script, which is the final running script.
O generate the final makefile.
Run:./configure
Configure has two common parameters:
-Prefix is used to specify the installation directory. The default installation directory in Linux is/usr/local.
-Host is used for cross-compilation. For example, programs compiled on the arm Board on an X86 PC are used.
For example:./configure-Prefix =/home/lixianjing/work/ARM-root/usr
-Host = arm-Linux
O Compilation
Run: Make
O Installation
Run: make install
O release software packages
Run: Make Dist or make distcheck
Make
Distused to generate a software package, which will contain a file named helloworld-0.1.tar.gz. Usually, the source code management system (CVS/SVN
The source code in/git is under development and is unstable, while the released software package is stable and available for users.
Why? Is it a little dizzy? Here we want to understand the principle. In actual operations, we can put some of the previous actions of make into a script file.
The name is autogen. Sh or Bootstrap.