配置文件模板来生成makefile文件(configure file template to gen

2019-09-21 12:46发布

几乎在所有的Linux开源的C ++项目有一个“配置”文件创建的源代码之前产生的Makefile。

我从头开始编写一个项目,是有这种“配置”文件中的任何模板?

Answer 1:

在大多数情况下,都不能用手创建的配置文件,但像工具生成的autoconf 。 然而有更现代的替代品,大部分是更容易使用。 看看CMake的 , qmake的 Qt的,或scons的 。

也看看前面的问题,例如C ++构建系统 。



Answer 2:

它是由一个叫做程序产生的Autoconf 。



Answer 3:

configure文件通过从autoconf生成configure.ac文件。 这里是我的最小化的模板configure.ac与C ++:

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 ,而不是随机的工具自己。 这是要猜你需要什么,并运行它。

随时让你知道,如果你需要更多的东西,我会很高兴来解释。



文章来源: configure file template to generate makefile