How to Create a gun C/C ++ Project

Source: Internet
Author: User
Tags automake

1. The module name is used for the top-level directory in the directory structure. Here is the demo.

2. Place the source file in the SRC subdirectory under the module, that is, demo/src. All follow the Convention. When there are multiple sub-modules, the source code of each sub-module is placed in its own directory.

3. Create the source file demo/src/Hello. C.

4. Create a makefile template with the following content:

# Demo/makefile. AM

Subdirs = SRC

 

Subdirs = SRC only has a simple line of code, indicating that there is a SRC subdirectory under it. If there are multiple subdirectories, separate them with spaces.

# Demo/src/makefile. AM

Automake_options = foreign
Subdirs = SRC
Bin_programs = test
Test_sources = test. c

Bin_programs = test test_sources = Main. C indicates that there is an executable file test, 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.

5. Create an Autoconf template. Run autoscan in the demo to generate the file Configure. Scan and rename it Configure. In. The content is as follows:

#-*-Autoconf -*-
# Process this file with Autoconf to produce a configure script.

Ac_prereq (2.59)
Ac_init (full-package-name, version, bug-Report-address)
Ac_config_srcdir ([src/test. C])
Ac_config_header ([config. H])

# Checks for programs.
Ac_prog_cc

# Checks for libraries.

# Checks for header files.
Ac_header_stdc
Ac_check_headers ([String. h unistd. H])

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

Ac_config_files ([src/makefile])
Ac_output

The modified content is as follows:

#-*-Autoconf -*-
# Process this file with Autoconf to produce a configure script.

Ac_prereq (2.59)
Ac_init (test, 0.1, bug-Report-address)
Ac_config_srcdir ([src/test. C])
Ac_config_header ([config. H])
Am_init_automake (test, 0.1)
# Checks for programs.
Ac_prog_cc

# Checks for libraries.

# Checks for header files.
Ac_check_headers ([unistd. H])

# 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 generate makefile files 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 modify ac_init (full-package-name, version, bug-Report-address) to 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 number after the decimal point is the minor version number, and should be upgraded each time it is released. 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, am_init_automake is not required when only data files are generated and files are not compiled.

6. Copy the macros used. Run: As mentioned earlier in aclocal, configure. In is a series of macros, which are carried out by the M4 command. M4 is actually the abbreviation of Macro. 4 indicates that four letters are omitted after M. Similar to i18n (internationalization) and l10n (localization), the numbers represent the number of omitted letters. Macros such as ac_prog_cc are standard macros (or built-in macros) and do not need to be written by ourselves. However, we need to run the aclocal command to configure aclocal. the macros used in are copied to our project. After aclocal is run in the helloworld directory, autom4te. cache appears in the current directory. This is a temporary directory and is only used to accelerate macro development. Aclocal. M4 is the macro definition used in Configure. in. For more information, see.

7. Generate a configuration header file template. Run: The autoheader configuration header file (config. h) 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 we need to provide a template file. This template file can be generated using the command autoheader. After running autoheader in the helloworld directory, config. H. In is generated in the current directory. You do not need to modify it.

8. 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. The latest modification is placed 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

9. Generate makefile. in and the required script. Run the automake-a command to create links to several copying depcomp install-SH missing files pointing to the files in the system. The most important function of automake is to generate the makefile. In file using the makefile. Am template. makefile. In is much more complex than makefile. Am. Fortunately, we don't need to know it.

10. Generate the configure script. Run: 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.

11. Generate the final makefile. Run:./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

12. Compile: Make

13. Install and run: make install

14. Run the released software package: Make Dist or make distcheck; Make distto generate a software package. In this case, a file named test-0.1.tar.gz will be created. Generally, the source code in the source code management system (CVS/SVN/GIT) is under development and is unstable, while the released software package is stable and available to users.

Make distcheck: Generate and test the release package to confirm the correctness of the release package. This operation will automatically unbind the compressed package file, execute the configure command, and execute make to confirm that there is no error in compilation, and finally prompt that your software package is ready and can be released. In actual operations, we can put some of the actions before make into a script file, which is usually named autogen. Sh or Bootstrap.

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.