Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

automake 快速上手:從 Makefile.am 到 configure.ac 的完整流程

手上已經有一個 Makefile.am,卻不知道怎麼變出可用的 Makefile?其實只要照著 GNU Autotools 的固定套路走一遍就好。

生成 Makefile 的步驟

[root@localhost hello]# autoscan                # 在當前目錄掃描,產生 configure.scan
[root@localhost hello]# cp configure.scan configure.ac
[root@localhost hello]# vi configure.ac       # 編輯設定檔

編輯 configure.ac 時,務必加入 automake 必需的巨集:

AM_INIT_AUTOMAKE(hello,1.0)

接著依序執行:

[root@localhost hello]# aclocal                 # 產生 aclocal.m4
[root@localhost hello]# autoconf                # 產生 configure
[root@localhost hello]# autoheader
[root@localhost hello]# automake --add-missing
[root@localhost hello]# touch NEWS; touch README; touch AUTHORS; touch ChangeLog
[root@localhost hello]# automake --add-missing # 再跑一次
[root@localhost hello]# ./configure            # 生成 Makefile
[root@localhost hello]# make

上述 NEWS、README、AUTHORS、ChangeLog 是 automake 期待存在的標準檔案,若沒有自動產生就手動 touch 一個空的即可,否則 --add-missing 會抱怨。過程中出現一些警告可以暫時忽略。

Makefile.am 範例

AM_LDFLAGS = -lpthread -lc -lm -lrt -ldl
CXXFLAGS = -D__STDC_LIMIT_MACROS -g -Wall -DORDER_SERIALIZE #-O2 -fno-strict-aliasing

bin_PROGRAMS = parser_main

parser_main_SOURCES = parser_main.cpp \
 Parser.cpp \
 Lexer.cpp \
 SelectStmt.cpp \
 InsertStmt.cpp \
 UpdateStmt.cpp \
 DeleteStmt.cpp \
 Stmt.cpp \
 Expr.cpp \
 Identifier.cpp

關鍵只有三塊:bin_PROGRAMS 指定要產出的執行檔名稱,xxx_SOURCES 列出原始碼(用反斜線續行),而 AM_LDFLAGS 與 CXXFLAGS 則統一管理連結參數與編譯選項。

參考資料

https://os.51cto.com/art/201006/207098.htm
https://os.51cto.com/art/201006/207099.htm
https://os.51cto.com/art/201006/207101.htm

Copyright © Linux教程網 All Rights Reserved