歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 使用automake自動生成Makefile

使用automake自動生成Makefile

日期:2017/2/28 15:54:48   编辑:Linux教程
第一回用automake,而不是自己寫makefile,感覺技術高了一個檔次(其實還是老樣子。。。)
我用的電腦主要是 Fedora14 還有Red Ha Enterprise 5...

首先編寫自己需要的源代碼,我的工程是編寫好了server還有client的程序,還有其他要用到的一些自定義的頭文件等等,最終是要生成server和client的可執行程序。

------------------------------------------

運行 autoscan , 自動創建兩個文件: autoscan.log configure.scan
此時狀態如下:
[root@localhost main]# autoscan
[root@localhost main]# ls
autoscan.log configure.scan
...
[root@localhost main]#
------------------------------------------

修改configure.scan的文件名為configure.in

修改:
1.修改AC_INIT裡面的參數: AC_INIT(v1.4,.2.8, [email protected])
2.添加宏AM_INIT_AUTOMAKE, 它是automake所必備的宏,也同前面一樣,PACKAGE是所要產生軟件套件的名稱,VERSION是版本編號。

查看configure.in的內容:
------------------------------------------
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.66])
AC_INIT([v1.4], [2.8] , [email protected])
AC_CONFIG_SRCDIR([soapC.cpp])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(v1.4, 2.8)
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h limits.h locale.h memory.h netdb.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/ioctl.h sys/socket.h sys/time.h sys/timeb.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_FUNC_STRERROR_R
AC_FUNC_STRTOD
AC_CHECK_FUNCS([ftime gethostbyname gettimeofday localtime_r memmove memset select socket strchr strerror strrchr strstr strtoull])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
------------------------------------------
解讀以上的文件:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
# AC_PREREQ:
# 確保使用的是足夠新的Autoconf版本。如果用於創建configure的Autoconf的版
# 本比version 要早,就在標准錯誤輸出打印一條錯誤消息並不會創建configure。
AC_PREREQ()
# 初始化,定義軟件的基本信息,包括設置包的全稱,版本號以及報告BUG時需要用的郵箱地址
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
# 用來偵測所指定的源碼文件是否存在,來確定源碼目錄的有效性
AC_CONFIG_SRCDIR([main.c])
# 用於生成config.h文件,以便autoheader使用
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.
# 創建輸出文件。在`configure.in'的末尾調用本宏一次。
AC_OUTPUT
------------------------------------------
運行 aclocal, 生成一個“aclocal.m4”文件和一個緩沖文件夾autom4te.cache,該文件主要處理本地的宏定義。
此時的狀態是:
[root@localhost main]# aclocal
[root@localhost main]# ls
aclocal.m4 autom4te.cache
autoscan.log configure.in configure.in~ main.c
[root@localhost main]#
------------------------------------------
運行 autoconf, 目的是生成 configure
此時的狀態是:
[root@localhost main]# autoconf
[root@localhost main]# ls
aclocal.m4 autoscan.log configure.in main.c
autom4te.cache configure configure.in~
[root@localhost main]#

------------------------------------------

Copyright © Linux教程網 All Rights Reserved