程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> C/C++ makefile自動生成工具(comake2,autotools,linux),希望能為開源做點微薄的貢獻!,comake2autotools

C/C++ makefile自動生成工具(comake2,autotools,linux),希望能為開源做點微薄的貢獻!,comake2autotools

編輯:C++入門知識

C/C++ makefile自動生成工具(comake2,autotools,linux),希望能為開源做點微薄的貢獻!,comake2autotools


  序         在linux下C或C++項目開發,Makefile是必備的力氣,但是發現手寫很麻煩。   在百度有個comake2工具,用於自動生成Makefile工具,而在外邊本想找一個同類工具,但發現很難做到,只發現有個類似的智能生成工具autotools,但是操作比較麻煩,奔著“一人學習,大家共享”的原則,手動寫了一個工具類,幫助自己和大家生成現成的c或者cpp框架。   代碼比較簡單,希望我們能一起改善下。         git路徑:https://github.com/chuanshanjia/ccpp/blob/master/frame.sh   git說明:https://github.com/chuanshanjia/ccpp/blob/master/README.md     我也希望大家提出更多好的思路(比如名字、功能),我們一起改進下這個工具,煩請大家留下評論,我收集下。           使用方式    部署:
[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 autotools
configure.ac:6: installing `./install-sh'
configure.ac:6: installing `./missing'
...
[jack@localhost ccpp]$ ls
aclocal.m4  autom4te.cache  ChangeLog  config.h.in  config.status  configure.ac  depcomp   include  install-sh  Makefile.am  missing  README  stamp-h1
AUTHORS     autoscan.log    config.h   config.log   configure      COPYING       frame.sh  INSTALL  Makefile    Makefile.in  NEWS     src

  

 清理:
[jack@localhost ccpp]$ sh frame.sh clear
[jack@localhost ccpp]$ ls
frame.sh
[jack@localhost ccpp]$ 

 

愉快的操作吧^_^

頭文件位置:

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

main文件位置: 

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

編譯運行:

[jack@localhost ccpp]$ make
make  all-am
make[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.cpp
mv -f .deps/demo.Tpo .deps/demo.Po
g++  -g -O2   -o demo demo.o  
make[1]: Leaving directory `/home/jack/tool/ccpp'
[jack@localhost ccpp]$ ./demo 
hello,demo
[jack@localhost ccpp]$ 

  

  

  

以下內容可作為參考學習,幫助理解工具產生的過程,如非必要,可不進行閱讀。網上有很多類似內容,可以在百度搜索“autotools"就能看到整個過程。  

    工具准備(參考)    autoscan aclocal autoheader  automake autoconf automake

 

 

 

 

准備Makefile.am文件

INCLUDES=-I./include -I./src/include
UTOMAKE_OPTIONS=foreign
bin_PROGRAMS=test
test_SOURCES=src/test.cpp 

  

 

  

使用智能化工具(參考)   

autoscan

 當我們利用autoscan工具生成confiugre.scan文件時,我們需要將confiugre.scan重命名為confiugre.ac文件。confiugre.in調用一系列autoconf宏來測試程序需要的或用到的特性是否存在,以及這些特性的功能。

具體使用如下:

 

[jack@localhost tool]$ autoscan 
[jack@localhost tool]$ ls
autoscan.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

  

修改點:

 

 

一氣呵成

aclocal
autoconf
autoheader
automake --add-missing
automake --add-missing
touch NEWS README  AUTHORS  ChangeLog
automake --add-missing
./configure

  

 

 

 

  參考手冊     confiugre.in文件的一般布局:  
AC_INIT
 測試程序
 測試函數庫
 測試頭文件
 測試類型定義
 測試結構
 測試編譯器特性
 測試庫函數
 測試系統調用
AC_OUTPUT

  

 
表 1Makefile.am一般格式
表 1Makefile.am一般格式  
表 2 Makefile.am中可用的全局變量
表 2 Makefile.am中可用的全局變量

在Makefile.am中盡量使用相對路徑,系統預定義了兩個基本路徑:

表 3Makefile.am中可用的路徑變量
表 3Makefile.am中可用的路徑變量     參考文獻     1、http://www.ibm.com/developerworks/cn/linux/l-makefile/ 2、https://www.gnu.org/software/autoconf/manual/autoconf-2.61/html_node/Autoconf-Language.html#Autoconf-Language 3、http://www.gnu.org/software/automake/manual/automake.pdf  

 

推薦  

 

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved