Use autotools for project management

zhaozj2021-02-16  66

MARK ZHONG's HOMGPAGE? Home Other languages: English Articles: Autotools Used ... More Books Resources: Autotools ... More Give me email ??

Using Autotools Configuration Management Cross-Platform Items? First, Introduction 1. Cross-platform for programming ???? Developers can run on a variety of different platforms are a work that requires many techniques and efforts. There must be a variety of platforms. Just create programs that can run on a variety of different * NIX systems must also do a lot of work. First, the code itself must be portable, the portable code is rarely assumed to the hardware of the runtime and the software library that can be used. Developers must have enough understanding of the compilation and operational environment of different systems, and even hardware system structures. GNU software in GNU / Linux, although there are also many other operating systems and hardware platforms, but this is not the operating system. In addition, there may be the following:

The compiler may not follow the ISO standard library may miss the key feature operating system API may have different file systems. Therefore, the developers under Linux have to write a universal makefile, and tell the user How to edit this Makefile file to accommodate the native environment. The source code of the general open source project and GNU project is compiled by generating makefile through the configure command. If you want to make your project more professional, you want to save the trouble of makefile, if you want to manage a project of source code. Then this article is very suitable for you. 2. The composition and history of Outotools In fact, GNU / Autotools consists of a set of command line tools, including: AutoConf, Automake, LibTool, etc. They are just a group of unix shell script. More detailed information, you can access GNU Manual. 3. How do they work? The following figure is the entire autotools workflow and architectural diagram: the Chinese word color is the green file is the executable file under Linux. The following detailed introduces this process for you. Makefile is the final document that does not exist when the source package is released, which is generally generated by the user on its own platform. To complete the work, you must first prepare configure.in, makefile.am, aclocal.m4, if you need to prepare config.h.in. Configure.IN can be created manually or can be renamed by the template file generated by the AutoScan command. AutoScan only needs to run at a source of the source tree root. Aclocal.m4 is generated by the ACLOCAL program. AutoConf can be run only when you are ready configure.in and aclocal.m4 to generate configure executables. After you are ready for the makefile.am file, you can run Automake to generate the makefile.in file, and finally run configure, check the system and generate makefile before compiling. Then make Make, make install :), below we will use a C source program as an example of this process as this process. Second, actual combat and analysis 1. actual combat hello.cpp

#include

#include "config.h"

Using namespace std;

Int main (void)

{

Cout << "Hello, World" << Endl;

}

Run the AutoScan, CONFIGURE.SCAN will be generated under the directory:

dnl Process this file with autoconf to produce a configure script. AC_INIT (hello.cpp) AM_INIT_AUTOMAKE (hello, 1.0) dnl Checks for programs.AC_PROG_CXX dnl Checks for libraries. dnl Checks for header files. dnl Checks for typedefs, structures, and compiler CHARACTERISTICS. DNL CHECKS for library function ac_output (makefile) where the am_init_automake macro and the last line of Makefile are hand-made. After the modification is complete, rename the configure.scan to configure.in. Aclocal.m4 files are generated in the current directory of the ACLOCAL. Aclocal must run when configure.in files. Running AutoHeader Current Directory Generate config.h.in:/* config.h.in. Generated automatic origism configure.in by autoheader. * / / * Name of package * / # undef package / * version number of package * / #undef version Now you have to add a file to makefile.am:

Automake_options = foreign bin_progrmas = hellohello_sources = Hello.cpp runs automake -add-missing, which will generate makefile.in in the directory. Run AutoConf and create a Configure script in the directory. All jobs have been done now. Try to run: ./ Configuremakemake install is very professional, very cool? 2. Analysis 2.1 Analysis Configu.in We modified configure.in in the actual combat above (this file can complete our large cross-platform settings and check, or customize the behavior of compilation and link) and manually created Makefile. AM. The Configure.in file must call the AC_INIT macro before starting all the work, and call the AC_OUTPUT macro after all work. And in fact, there is only two macros to be a configure.in file. The ac_init syntax is as follows: ac_init (unique_file_in_source_dir) unique_file_in_source_dir is a file in the source code directory, generates a shell command to the AC_INIT's call in the generated configuration script file, by checking the unique_file_source_dir whether or not to verify that the current directory is correct. AC_OUTPUT Create an output file named makefile or other name, whose syntax is as follows: ac_output ([File ... [, extra_cmds [, init_cmds]]] Where File is a list of output files separated by spaces, by copying file.in File to generate these files. Extra_cmds is a list of commands that are attached after config.status, which will be used when regenerating configuration scripts, and init_cmds will also insert into config.status, but their location is before extra_cmds. The structure of the Configure.in file is as follows:

AC_INIT Test Program Test Function Library Test Header File Test Type Definition Test Structure Test Compiler Behavior Test Library Function Test System Call Ac_Output The above order is not necessary. For example, the existence of the library directly affects whether or not the corresponding header file is included, so the inspection of the header file is written after the function library is checked. In the Configure.in file, usually every macro should take a separate line, because most autoconf macro requires a new row to end the command. These variables can be placed on the same line when using macros to read or set an environment variable. A multi-parameter macro adjustment can exceed the rules of each macro. At this time, '/' should be used to renew and all parameters can be enclosed in parentheses that can be identified by M4. Examples are as follows: ac_Check_Headers ([UnisTd.h Termios.h Termio.h sgtty.h / sys / time.h ]) AC_CHECK_HEADERS (Unistd.h Termios.h Termio.h SGTTY.H SYS / TIMER.H) Two definition methods is equivalent. The second example is to write the entire macro in the same line. The first line in Configure.in is a comment DNL Process this file with autoc to produce a configure script.dnl is a comment symbol of M4. You can also use the # as a comment symbol 2.2 Analysis Makefile.AMAUTOMAKE generates makefile.in in configure.in in Configure.in. Automake_Options Sets the option of Automake. Automake is mainly helping software developer's supporting documentation. When executing Automake, there is a file that should have in a standard software document in the directory, such as "news", "install", "ChangeLog", etc. When set to Foreign, no check is performed. BIN_PROGRAMS defines the executable document name you want to generate. If you want to generate multiple executable documents, each document name is separated by spaces. Hello_sources defines this source program for Hello to perform documents and the header files to depend on. If there are multiple executable documents, each executable document must have a corresponding filename_soruces. If you are in your directory tree, the source code is placed in ./src / subdirectory, use the Subdirs macro to specify the subdirectory, in the subdirectory, you want to put a usual makefile.am file. Third, Autotools uses advanced 3.1 Several commonly used autoconf macro ac_prog_cc decides which C compiler, and set the output variable ccac_prog_cxx to determine which C compiler, and set the output variable ccac_prog_cc_c_o to determine if the compiler accepts the -c or -o option. If not accepted, define NO_MINUS_C_MINUS_OAC_CHECK_LIB (lib, function [, action_if_found [, action_if_no_found, [, ire), determine whether there is a specified function in the lib library by connecting a C program linkage to the library lib library. Execute the shell command section_if_found when testing successfully or when the action_if_found is empty, add -LLIB to the output variable LIB. Action_if_not_found passes the Other_libs option to the link command. This function is the most commonly used in the test macro. Ac_header_stdc If the system supports the ANSI / ISO C header file, define STDC_HEADERS.

Ac_header_sys_wait If the system has POSIX-compatible header file sys / wait.h, define the output variable Have_sys_waitac_header_dirent order check head DIrent.h, sysdir / ndir.h, sys / dir.h and ndir.h are defined in DIR, and according to results Define Have_Dirent_h, have_sys_ndir_h, how_sys_dir_h, or how_ndir_h3.2 A advanced example four, more detailed autoconf reference (some macro introduction) 5, reference ???? ... More Home |

Free think org |

UDBI |

Contact me |

Wjian HomePage

Web content is only for personal opinions

.? 1999-2004 Mark Zhong copyright. All rights reserved

转载请注明原文地址:https://www.9cbs.com/read-20035.html

New Post(0)