如何设置 automake 和 autoconf 以有条件地构建程序(测试或其他)

发布于 2024-07-27 22:26:40 字数 881 浏览 11 评论 0原文

目前我的 autotoolset 项目中有 10 个测试。 每当我对 src/ 文件之一进行更改并重新编译时,每个测试都会重新构建并链接。 这开始对我的开发时间产生相当大的影响。

使用 GNU 自动工具集有条件地构建二进制程序、测试或其他程序的最佳方法是什么? 例如,如果我正在 test/check_curl_requestheaders.cc 中工作,并且我进行了更改,我只想重新编译该库,然后重新编译该测试,而不编译其他二进制文件。

我看到一些提到使用 automake 条件(如 WANTS_XXX),但我不能 100% 确定这就是我正在寻找的,也不确定 autoconf 将如何配置它。

我有点希望最终会像这样:

./configure
make test/check_curl_requestheaders

./configure --only-build=test/check_curl_requestheaders
make

指针?

编辑 我不会在每次制作之前进行配置。 如果我对 check_curl_requestheaders 进行更改,则只有 check_curl_requestheaders 会按照预期重建。 问题是,如果我正在处理库的 RequestHeaders 部分,并对 src/curl/requestheaders.cc 进行更改,则所有测试和其他二进制文件都会重建,而不仅仅是 check_curl_requestheaders花费的时间太长,而这正是我试图避免的。 如果我有十几个二进制文件,有没有办法只重建其中一个?

I currently have 10 tests in my autotoolset project. Any time I make a change to one of my src/ files and recompile, each test is rebuilt and linked. This is starting to have a considerable impact on my development time.

What is the best way to conditionally build binary programs, tests or otherwise, with GNU autotoolset? For instance, if I'm working in test/check_curl_requestheaders.cc, and I make a change, I am only going to want to recompile the library and then that one test and none of the other binaries.

I saw some mention of using automake conditionals (like WANTS_XXX) but I am not 100% certain that is what I'm looking for nor am I sure how that would be configured by autoconf.

I am sort of hoping for something that will end up looking like this:

./configure
make test/check_curl_requestheaders

or

./configure --only-build=test/check_curl_requestheaders
make

Pointers?

EDIT I'm not doing a configure before every make. If I make changes to check_curl_requestheaders, only check_curl_requestheaders is rebuilt as one would expect. The problem is that if I'm working on the RequestHeaders part of the library, and make a change to say, src/curl/requestheaders.cc, all of the the tests and other binaries are rebuilt, not just the check_curl_requestheaders. That is taking far too long, and that is what I am trying to avoid. If I have a dozen binaries, is there a way to rebuild only one of them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怪我入戏太深 2024-08-03 22:26:40

我很困惑。 在我参与过的任何项目中,从 ${top_builddir} 或 ${top_builddir}/tests/ 运行“make”将不会重建或运行任何测试。 测试仅针对“make check”而构建和执行。 您是否在 Makefile.am 中使用 check_PROGRAMS ?

一般来说,条件编译是通过 automake 条件和 Makefile.am 片段来处理的,例如:

if WANT_FOO
bin_PROGRAMS += foo
endif

但我确信这不是您正在寻找的。 听起来您在 Makefile.am 中指定了虚假依赖项,您应该发布它/它们的最小版本。

PS:在你的shell脚本中,你可以这样做

export OUT
...
(cd src && make >> $OUT) || exit 3

I'm confused. In any project I've ever worked on, running 'make' from either ${top_builddir} or from ${top_builddir}/tests/ will not rebuild or run any tests. Tests are only built and executed for 'make check'. Are you using check_PROGRAMS in your Makefile.am?

In general, conditional compilation is handled with automake conditionals and Makefile.am snippets like:

if WANT_FOO
bin_PROGRAMS += foo
endif

but I'm certain this is not what you are looking for. It sounds like you have specified bogus dependencies in a Makefile.am, and you should post a minimal version of it/them.

PS: in your shell script, you can just do

export OUT
...
(cd src && make >> $OUT) || exit 3
静若繁花 2024-08-03 22:26:40

当您更改某些源文件时,您根本不必重新配置。 只需再次运行 make,它应该只重建那些实际受更改影响的二进制文件。 因此,当您更改 test/check_curl_requestheaders 时,然后执行简单的 make,那么无论如何,只应重建 test/check_curl_requestheaders 。 如果还重建了其他任何内容,则说明您的 makefile 中存在错误。

当然,如果您首先进行配置(您不应该这样做),则重建更多内容也就不足为奇了。

编辑:如果您更改库,然后只想重建单个测试,那么

make test/check_curl_requestheaders

应该足够了。 这需要您在顶级 makefile 中有一个名为 test/check_curl_requestheaders 的目标。 该目标可能看起来像是

test/%:    library
    make -C test $*

假设您在测试目录中有一个单独的 makefile,并且假设该 makefile 假定该库已经构建。

When you change some source file, you should not have to reconfigure at all. Just run make again, and it should only rebuild those binaries that are actually affected by the change. So when you change test/check_curl_requestheaders, then do a plain make, then only test/check_curl_requestheaders should be rebuilt, anyway. If anything else gets rebuilt also, you have a bug in your makefile.

Of course, if you do configure first (which you should not), it is not surprising that more stuff gets rebuilt.

Edit: If you change the library, and then only want to rebuild a single test, then

make test/check_curl_requestheaders

should be sufficient. This would require you to have a target named test/check_curl_requestheaders in your toplevel makefile. That target may look like

test/%:    library
    make -C test $*

assuming you have a separate makefile in the test directory, and assuming that this makefile assumes that the library has already been built.

一个人的旅程 2024-08-03 22:26:40

我不确定这是最好的方法,但事实证明我的测试文件夹中的程序确实有自己独特的 make 目标。 然而,也存在一些问题。

  1. 如果我在顶层发出 make,则构建所有 src/ 和 test/
  2. 如果我在 test/ 级别发出 make,则不会拾取对 src/ 的更改

为了解决此问题,我编写了一个执行以下操作的 shell 脚本:

  1. 输入src,并构建它。 (如果 src/ 发生更改,则重新构建 src/)
  2. 输入 test,并构建特定的二进制文件。 (如果特定的二进制文件已更改,这将重建它,并且将重新链接 src/ 中的代码已通过上一步更新)

代码如下所示:

#!/bin/sh

TYPE="$1"
WHICH="$2"
OUT="`readlink -f ./buildandrun.out`"

rm -rf $OUT

if test ! -n "$WHICH"
then
    echo "Please specify which type to build"
    exit 1
fi

if test ! -n "$WHICH"
then
    echo "Please specify which $TYPE to build"
    exit 2
fi

RV=0

echo "" >> $OUT
echo "Building src" >> $OUT
echo "" >> $OUT

cd src
make >> $OUT || RV=3
cd ..

if test $RV != 0; then exit $RV; fi

echo "" >> $OUT
echo "Building $TYPE/$WHICH" >> $OUT
echo "" >> $OUT

cd $TYPE
make "$WHICH" >>  $OUT || RV=4
cd ..

if test $RV != 0; then exit $RV; fi

echo "" >> $OUT
echo "Running $TYPE/$WHICH" >> $OUT
echo "" >> $OUT

$TYPE/$WHICH || RV=5

exit $RV

这让我可以执行以下操作:

./buildandrun.sh test check_curl_requestheaders

希望最终有人可以展示我对这个问题有一个更优雅的解决方案,最好使用 autoconf 和 automake。 我有一种感觉,这可能是这些工具开箱即用的功能,只是我还没有发现它。

I'm not sure this is the best way to do this, but it turns out that the programs in my test folder did have their own unique make targets. However, there were some issues.

  1. If I issue make at the top level, all of src/ and test/ are built
  2. If I issue make at test/ level, changes to src/ won't be picked up

To solve this, I wrote a shell script that does the following:

  1. Enter src, and build it. (if changes to src/ have happened, src/ is rebuilt)
  2. Enter test, and build a specific binary. (this will rebuild the specific binary if it has changed and will relink of the code in src/ has been updated by the previous step)

The code is listed below:

#!/bin/sh

TYPE="$1"
WHICH="$2"
OUT="`readlink -f ./buildandrun.out`"

rm -rf $OUT

if test ! -n "$WHICH"
then
    echo "Please specify which type to build"
    exit 1
fi

if test ! -n "$WHICH"
then
    echo "Please specify which $TYPE to build"
    exit 2
fi

RV=0

echo "" >> $OUT
echo "Building src" >> $OUT
echo "" >> $OUT

cd src
make >> $OUT || RV=3
cd ..

if test $RV != 0; then exit $RV; fi

echo "" >> $OUT
echo "Building $TYPE/$WHICH" >> $OUT
echo "" >> $OUT

cd $TYPE
make "$WHICH" >>  $OUT || RV=4
cd ..

if test $RV != 0; then exit $RV; fi

echo "" >> $OUT
echo "Running $TYPE/$WHICH" >> $OUT
echo "" >> $OUT

$TYPE/$WHICH || RV=5

exit $RV

This lets me do the following:

./buildandrun.sh test check_curl_requestheaders

Hopefully there will eventually be someone who can show me a more elegant solution to this problem, preferably using autoconf and automake. I have a feeling that this is probably something that these tools do out of the box and I just haven't discovered it yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文