如何包括与通用Autoconf宏宏?

问题描述 投票:0回答:1

Background

我管理建设固件和库约半打不同的主板,它们都使用相同的嵌入式处理器。因为所有的板都使用相同的处理器,则可以是显著公共配置(CCCXXCPPFLAGSCFLAGSCXXFLAGSLDFLAGS等)和食谱。对于固件,我使用自定义的makefile包括定义所有常见的配置和配方的通用配置文件。为了简化开发人员的计算机上安装库和头,我用使用GNU自动为库。但是,自定义makefile和GNU自动文件之间显著重复的配置,所以我迁移固件升级到GNU Autotools的。

Objective

我希望能有尽可能少的样板越好。一种用于板configure.ac可能看起来像下面这样:

AC_INIT([mppt], [0.1.0])
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AC_PROG_CC
AM_PROG_CC_C_O
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

一种用于图书馆configure.ac可能看起来像下面这样:

AC_INIT([gcc-arm-none-eabi-samples], [4.7+])
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CXX='arm-none-eabi-g++ -specs=nosys.specs'}
AC_PROG_CXX
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AM_PROG_AS
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_RANLIB
AC_PROG_CXX_C_O
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

有很多这些文件之间的共同配置。我想有一个定义与普通Autoconf宏宏本地include目录中的一个文件:

AC_DEFUN([TIVASDK],
[AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AC_PROG_CC
: ${CXX='arm-none-eabi-g++ -specs=nosys.specs'}
AC_PROG_CXX
AM_PROG_AS
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_RANLIB
AM_PROG_CC_C_O
AC_PROG_CXX_C_O
AC_CONFIG_FILES([Makefile])])

然后,我希望能够在第一个例子简化为以下几点:

AC_INIT([mppt], [0.1.0])
TIVASDK
AC_OUTPUT

这有很多的,除了简单的优点。如果,例如,MPPT开发者介绍C ++到固件目前完全用C写的,那么他们还是我不会有更新他们configure.ac。如果我要做出改变的工具链,我将只需要更新推到一个存储库,而不是差不多十。

Problem

Autoconf的不理解宏为我所期望的。有几个不同的失效机理。

expanded before it was required

this answer

我有我使用的测试骨架项目。它非常简单qa​​zxswpoi指定Makefile.am

ACLOCAL_AMFLAGS

ACLOCAL_AMFLAGS = -I "$TIVASDK_HOME"/include noinst_PROGRAMS = skel.axf skel_axf_SOURCES = \ src/main.cpp \ src/abort.cpp TIVASDK_HOME定义。

~/.profile。它this question使用宏:

configure.ac

AC_INIT([skel], [0.1.0]) m4_define([TIVASDK_HOME], [esyscmd([printf "$TIVASDK_HOME"])]) AC_CONFIG_MACRO_DIR(TIVASDK_HOME[/include]) TIVASDK AC_OUTPUT 构建出的树在autogen.sh

build

运行#!/bin/sh autoreconf -vfi .. && \ ../configure --prefix="$TIVASDK_HOME" --host=arm-none-eabi 产生如下:

autogen.sh

$ ./autogen.sh autoreconf: Entering directory `..' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force -I /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include/tivasdk.m4:1: TIVASDK is expanded from... configure.ac:4: the top level configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include/tivasdk.m4:1: TIVASDK is expanded from... configure.ac:4: the top level autoreconf: configure.ac: tracing configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required aclocal.m4:1173: TIVASDK is expanded from... configure.ac:4: the top level autoreconf: configure.ac: not using Libtool autoreconf: running: /usr/bin/autoconf --force configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required aclocal.m4:1173: TIVASDK is expanded from... configure.ac:4: the top level autoreconf: configure.ac: not using Autoheader autoreconf: running: automake --add-missing --copy --force-missing configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required aclocal.m4:1173: TIVASDK is expanded from... configure.ac:4: the top level configure.ac:4: installing './compile' configure.ac:4: installing './install-sh' configure.ac:4: installing './missing' Makefile.am: installing './depcomp' autoreconf: Leaving directory `..' checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for arm-none-eabi-strip... arm-none-eabi-strip checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for style of include used by make... GNU checking for arm-none-eabi-gcc... arm-none-eabi-gcc checking whether we are using the GNU C compiler... no checking whether arm-none-eabi-gcc accepts -g... no checking for arm-none-eabi-gcc option to accept ISO C89... unsupported checking whether arm-none-eabi-gcc understands -c and -o together... yes checking dependency style of arm-none-eabi-gcc... gcc3 checking for arm-none-eabi-gcc... (cached) arm-none-eabi-gcc checking whether the C compiler works... no configure: error: in `/home/matthew/gatech.edu/sp2019/vip4602/tmp/skel/build': configure: error: C compiler cannot create executables See `config.log' for more details

我有command not found扩大一些Autoconf宏出于某种原因预感。我替换AC_DEFUNAC_DEFUN

m4_define

运行m4_define([TIVASDK], [AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror]) : ${CC='arm-none-eabi-gcc -specs=nosys.specs'} AC_PROG_CC : ${CXX='arm-none-eabi-g++ -specs=nosys.specs'} AC_PROG_CXX AM_PROG_AS AM_PROG_CC_C_O AC_PROG_CXX_C_O AC_CONFIG_FILES([Makefile])]) 产生如下:

autogen.sh

看来,$ ./autogen.sh autoreconf: Entering directory `..' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force -I /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include autoreconf: configure.ac: tracing autoreconf: configure.ac: not using Libtool autoreconf: running: /usr/bin/autoconf --force autoreconf: configure.ac: not using Autoheader autoreconf: configure.ac: not using Automake autoreconf: Leaving directory `..' ../configure: line 1678: TIVASDK: command not found configure: creating ./config.status 并没有扩张的。我试着用TIVASDK更换m4_define无济于事。

Minimal working example

简单地把在define宏定义修复该问题:

configure.ac

运行m4_define([TIVASDK], [AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror]) : ${CC='arm-none-eabi-gcc -specs=nosys.specs'} AC_PROG_CC : ${CXX='arm-none-eabi-g++ -specs=nosys.specs'} AC_PROG_CXX AM_PROG_AS AM_PROG_CC_C_O AC_PROG_CXX_C_O AC_CONFIG_FILES([Makefile])]) AC_INIT([skel], [0.1.0]) TIVASDK AC_OUTPUT 产生如下:

autogen.sh

TL;DR

  • 为什么$ ./autogen.sh autoreconf: Entering directory `..' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force -I /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include autoreconf: configure.ac: tracing autoreconf: configure.ac: not using Libtool autoreconf: running: /usr/bin/autoconf --force autoreconf: configure.ac: not using Autoheader autoreconf: running: automake --add-missing --copy --force-missing configure.ac:12: installing './compile' configure.ac:12: installing './install-sh' configure.ac:12: installing './missing' Makefile.am: installing './depcomp' autoreconf: Leaving directory `..' checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for arm-none-eabi-strip... arm-none-eabi-strip checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for arm-none-eabi-gcc... arm-none-eabi-gcc -specs=nosys.specs checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... yes checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether arm-none-eabi-gcc -specs=nosys.specs accepts -g... yes checking for arm-none-eabi-gcc -specs=nosys.specs option to accept ISO C89... none needed checking whether arm-none-eabi-gcc -specs=nosys.specs understands -c and -o together... yes checking for style of include used by make... GNU checking dependency style of arm-none-eabi-gcc -specs=nosys.specs... gcc3 checking whether we are using the GNU C++ compiler... yes checking whether arm-none-eabi-g++ -specs=nosys.specs accepts -g... yes checking dependency style of arm-none-eabi-g++ -specs=nosys.specs... gcc3 checking dependency style of arm-none-eabi-gcc -specs=nosys.specs... gcc3 checking whether arm-none-eabi-g++ -specs=nosys.specs understands -c and -o together... yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: executing depfiles commands 努力扩大AC_DEFUN
  • 为什么宏定义由AC_PROG_CC似乎不扩大?
  • 为什么在m4_define中定义的宏行为不同于在另一个文件中定义,包括宏?
autotools autoconf
1个回答
0
投票
  • 为什么AC_DEFUN努力扩大AC_PROG_CC?

我无法解释你的错误的原因。我与你的代码复制,但无法与我最初尝试类似的代码。似乎有多种因素参与,其中两个configure.ac的存在和AC_PROG_CC在一起。

但是,从您最初的尝试,在“问题”的标题上面的问题提出,并从到其错误消息指网上的Autoconf手册页的信息化,我可以通过调用AC_PROG_CXX间接通过AC_PROG_CC根本解决问题而不是直接:

AC_REQUIRE

我发现,顺便说一下,有没有道理,至少在骨架项目,定义或使用AC_DEFUN([TIVASDK], [ AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror]) : ${CC='arm-none-eabi-gcc -specs=nosys.specs'} # HERE: AC_REQUIRE([AC_PROG_CC]) : ${CXX='arm-none-eabi-g++ -specs=nosys.specs'} AC_PROG_CXX # ... 宏。在TIVASDK_HOME定义的ACLOCAL_AMFLAGS显然是不够的。

我不太受使用环境变量来定义所需的宏的位置包括目录的想法迷恋,以及为什么这是非常有用的例子不说清楚我的,但如果你继续与那我鼓励你

  • 使用Makefile.in记录该变量,使之珍贵,
  • 的确做删除同名的宏。
  • 为什么宏定义由m4_define似乎不扩大?

我相信,这将是因为外部宏观文件不能直接使用,而是通过加工来AC_ARG_VAR生成文件aclocal,这是被包括在内。我想你会发现,直接aclocal.m4,出现任何的Autoconf宏定义的范围之外,并没有得到复制。

  • 为什么在configure.ac中定义的宏行为不同于在另一个文件中定义,包括宏?

我不认为它。但在m4_define定义的M4宏肯定不会行为不同于其他地方的一个,而不是定义包括在内。

© www.soinside.com 2019 - 2024. All rights reserved.