C/C ++ makefile Automatic Generation Tool (comake2, autotools, linux), hoping to make a small contribution to open source !, Comake2autotools

Source: Internet
Author: User
Tags automake

C/C ++ makefile Automatic Generation Tool (comake2, autotools, linux), hoping to make a small contribution to open source !, Comake2autotools
Makefile is essential for C or C ++ project development in linux, but it is very troublesome to write. Baidu has a comake2 tool used to automatically generate Makefile. I wanted to find a similar tool outside, but it was difficult to do so. I only found a similar intelligent generation tool, autotools, however, the operation is troublesome.One-person learning, shared by everyone"Principle, manually write a tool class to help you and everyone generate a ready-made c or cpp framework. The code is relatively simple, and we hope we can improve it together. Git path: https://github.com/chuanshanjia/ccpp/blob/master/frame.sh git Description: https://github.com/chuanshanjia/ccpp/blob/master/README.mdI also hope you can come up with better ideas (such as names and functions). Let's improve this tool together. Please leave comments and I will collect them.UsageDeployment:

[jack@localhost ~]$ wget https://github.com/chuanshanjia/ccpp/blob/master/frame.sh[jack@localhost ccpp]$ ls frame.sh[jack@localhost ccpp]$ pwd/home/jack/tool/ccpp[jack@localhost ccpp]$ sh frame.sh autotoolsconfigure.ac:6: installing `./install-sh'configure.ac:6: installing `./missing'...[jack@localhost ccpp]$ lsaclocal.m4  autom4te.cache  ChangeLog  config.h.in  config.status  configure.ac  depcomp   include  install-sh  Makefile.am  missing  README  stamp-h1AUTHORS     autoscan.log    config.h   config.log   configure      COPYING       frame.sh  INSTALL  Makefile    Makefile.in  NEWS     src

  

  Clear:
[jack@localhost ccpp]$ sh frame.sh clear[jack@localhost ccpp]$ lsframe.sh[jack@localhost ccpp]$ 

 

Nice operation! ^_^

Header file location:

[jack@localhost ccpp]$ lsaclocal.m4  autom4te.cache  ChangeLog  config.h.in  config.status  configure.ac  depcomp   include  install-sh  Makefile.am  missing  README  stamp-h1AUTHORS     autoscan.log    config.h   config.log   configure      COPYING       frame.sh  INSTALL  Makefile    Makefile.in  NEWS     src[jack@localhost ccpp]$ vim include/demo.h 

Main file location:

[jack@localhost ccpp]$ vim src/demo.cpp

Compile and run:

[jack@localhost ccpp]$ makemake  all-ammake[1]: Entering directory `/home/jack/tool/ccpp'g++ -DHAVE_CONFIG_H -I. -I/home/jack/tool/ccpp/include -I/home/jack/tool/ccpp/src/include     -g -O2 -MT demo.o -MD -MP -MF .deps/demo.Tpo -c -o demo.o `test -f 'src/demo.cpp' || echo './'`src/demo.cppmv -f .deps/demo.Tpo .deps/demo.Pog++  -g -O2   -o demo demo.o  make[1]: Leaving directory `/home/jack/tool/ccpp'[jack@localhost ccpp]$ ./demo hello,demo[jack@localhost ccpp]$ 

  

  

  

The following content can be used as a reference to help you understand the process of tool generation. If not necessary, do not read it. There are a lot of similar content on the Internet. You can search Baidu for "autotools" to see the entire process.  

Tool preparation (reference) autoscanaclocalautoheader automake Autoconf Automake

 

 

 

 

Prepare the Makefile. am File

INCLUDES=-I./include -I./src/includeUTOMAKE_OPTIONS=foreignbin_PROGRAMS=testtest_SOURCES=src/test.cpp 

  

 

Use intelligent tools (reference)

Autoscan

When we use autoscan to generate the confiugre. scan file, we need to rename confiugre. scan to the confiugre. ac file. Confiugre. in calls a series of autoconf macros to test whether the features required or used by the program exist and the functions of these features.

The specific usage is as follows:

 

[jack@localhost tool]$ autoscan [jack@localhost tool]$ lsautoscan.log  configure.scan  include  src[jack@localhost tool]$ mv configure.scan configure.ac
[jack@localhost tool]$ ls
autoscan.log  configure.in  include  src[jack@localhost tool]$ vim configure.ac

  

Modification point:

 

 

In one breath

aclocalautoconfautoheaderautomake --add-missingautomake --add-missingtouch NEWS README  AUTHORS  ChangeLogautomake --add-missing./configure

  

 

 

 

See the general layout of the confiugre. in document:
AC_INIT test program test function library test header file test Type Definition test structure test compiler features Test Library Function Test System Call AC_OUTPUT

  

Table 1Makefile. am general format Table 2 Global variables available in Makefile. am

Use relative paths in Makefile. am as much as possible. The system predefines two basic paths:

Table 3Makefile. am reference to available PATH variables 1. Example

 

Recommendation

 

 

 

Related Article

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.