[英]configure file template to generate makefile
幾乎Linux中的所有opensource c ++項目都有一個'configure'文件,用於在構建源代碼之前生成Makefile。
我正在從頭開始編寫一個項目,這個'configure'文件有沒有模板?
它由一個名為Autoconf的程序生成。
該configure
文件通過從autoconf生成configure.ac
文件。 這是使用C ++的configure.ac
的最小模板:
dnl Minimal autoconf version supported. 2.60 is quite a good bias.
AC_PREREQ([2.60])
dnl Set program name and version. It will be used in output,
dnl and then passed to program as #define PACKAGE_NAME and PACKAGE_VERSION.
AC_INIT([program-name], [program-version])
dnl Keep helpers in build-aux/ subdirectory to not leave too much junk.
AC_CONFIG_AUX_DIR([build-aux])
dnl Enable generation of Makefile.in by automake.
dnl Minimal automake version: 1.6 (another good bias IMO).
dnl foreign = disable GNU rules requiring files like NEWS, README etc.
dnl dist-bzip2 = generate .tar.bz2 archives by default (make dist).
dnl subdir-objects = keep .o files in subdirectories with source files.
AM_INIT_AUTOMAKE([1.6 foreign dist-bzip2 subdir-objects])
dnl Enable silent rules if supported (i.e. CC something.o instead of gcc call)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])
dnl Find a good C++ compiler.
AC_PROG_CXX
dnl Write #defines to config.h file.
dnl You need to generate config.h.in, for example using autoheader.
AC_CONFIG_HEADERS([config.h])
dnl Generate Makefile from Makefile.in.
AC_CONFIG_FILES([Makefile])
dnl This generates fore-mentioned files.
AC_OUTPUT
dnl
行是您的注釋(解釋),您可以從文件中刪除它們。
它假設您正在使用automake來生成Makefile
。 如果您不想這樣,則需要手動准備Makefile.in
(並刪除AM_INIT_AUTOMAKE
行)。
配置結果將寫入config.h
。 你通常包括它:
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
我的Makefile.am
模板(由automake使用):
# Programs which will be compiled and installed to /usr/bin (or similar).
bin_PROGRAMS = myprogram
# Source files for program 'myprogram'.
myprogram_SOURCES = src/f1.cxx src/f2.cxx
# Linked libraries for program 'myprogram'.
myprogram_LDADD = -llib1 -llib2
創建這兩個模板后,通常自己運行autoreconf -vi
而不是隨機工具。 這將猜測你需要什么並運行它。
如果您需要更多的東西,請隨時告訴您,我很樂意解釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.