簡體   English   中英

什么是 Makefile.am 和 Makefile.in?

[英]What are Makefile.am and Makefile.in?

這兩個文件多見於開源項目。

它們是做什么用的,它們是如何工作的?

Makefile.am是一個程序員定義的文件,並且用於通過automake以生成Makefile.in文件( .am代表一個UTOAKE)。 通常在源 tarball 中看到的configure腳本將使用Makefile.in生成Makefile

configure腳本本身是從名為configure.acconfigure.in (已棄用)的程序員定義的文件生成的。 我喜歡.ac對於反對派çONF),因為它從產生區別它Makefile.in文件,這樣我可以有規則,如make dist-clean它運行rm -f *.in 由於它是生成的文件,因此通常不會存儲在 Git、SVN、Mercurial 或 CVS 等修訂系統中,而是.ac文件。

閱讀更多關於GNU Autotools 的信息 首先閱讀makeMakefile ,然后了解automakeautoconflibtool等。

簡單的例子

無恥地改編自: http : //www.gnu.org/software/automake/manual/html_node/Creating-amhello.html並在 Ubuntu 14.04 Automake 1.14.1 上測試。

生成文件

SUBDIRS = src
dist_doc_DATA = README.md

自述文件

Some doc.

配置文件

AC_INIT([automake_hello_world], [1.0], [bug-automake@gnu.org])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
 Makefile
 src/Makefile
])
AC_OUTPUT

源代碼/Makefile.am

bin_PROGRAMS = autotools_hello_world
autotools_hello_world_SOURCES = main.c

src/main.c

#include <config.h>
#include <stdio.h>

int main (void) {
  puts ("Hello world from " PACKAGE_STRING);
  return 0;
}

用法

autoreconf --install
mkdir build
cd build
../configure
make
sudo make install
autotools_hello_world
sudo make uninstall

這輸出:

Hello world from automake_hello_world 1.0

筆記

  • autoreconf --install生成幾個應該由 Git 跟蹤的模板文件,包括Makefile.in 它只需要第一次運行。

  • make install安裝:

    • 二進制文件到/usr/local/bin
    • README.md/usr/local/share/doc/automake_hello_world

在 GitHub 上供您試用。

開發人員運行autoconfautomake

  1. autoconf -- 創建可交付的配置腳本
    (安裝程序稍后將運行以制作Makefile
  1. automake - 創建可交付的Makefile.in數據文件
    (稍后將讀取配置文件以制作Makefile

安裝程序運行configuremakesudo make install

./configure       # Creates  Makefile        (from     Makefile.in).  
make              # Creates  the application (from the Makefile just created).  

sudo make install # Installs the application 
                  #   Often, by default its files are installed into /usr/local


輸入/輸出映射

下面的符號大致是:輸入 --> 程序 --> 輸出

開發人員運行這些:

configure.ac - >的autoconf - >配置(腳本)---(* AC =一個UTOÇONF。)
configure.in --> autoconf -> configure (script) --- ( configure.in depreciated. Use configure.ac)

Makefile.am - >的automake - > Makefile.in -----------(。*= A UTOAKE)

安裝程序運行這些:

Makefile.in - >配置- (。*放文件=)>的Makefile

Makefile -> make ---------->(將新軟件放在您的下載或臨時目錄中)
Makefile -> make install ->(將新軟件放入系統目錄)


" autoconf是一個可擴展的 M4 宏包,它生成 shell 腳本來自動配置軟件源代碼包。這些腳本可以使包適應多種類 UNIX 系統,而無需用戶手動干預。Autoconf 從一個包創建配置腳本。以 M4 宏調用的形式列出軟件包可以使用的操作系統功能的模板文件。”

automake是一種自動生成符合 GNU 編碼標准的 Makefile.in 文件的工具。Automake 需要使用 Autoconf。”

手冊:

免費在線教程:


例子:

用於構建 LibreOffice 的主要configure.ac代碼超過 12k 行,(但在子文件夾中還有 57 個其他 configure.ac 文件。)

由此我生成的配置超過 41k 行代碼。

Makefile.inMakefile都只有 493 行代碼。 (但是,子文件夾中還有 768 個 Makefile.in。)

參考

Makefile.am -- automake 的用戶輸入文件

configure.in -- 自動配置的用戶輸入文件


autoconf 從 configure.in 生成配置

automake 從 Makefile.am 生成 Makefile.in

configure 從 Makefile.in 生成 Makefile

例如:

$]
configure.in Makefile.in
$] sudo autoconf
configure configure.in Makefile.in ... 
$] sudo ./configure
Makefile Makefile.in

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM