Autoconf 和 ./configure 变量

And*_*dna 1 automake autoconf

我对 autoconf 有点问题,我知道您可以使用 configure.ac 向 configure.h 添加一些定义,但是有没有办法做这样的事情:

在我的一个标题中,我有

#ifndef SIZE
#define SIZE 4
#endif
Run Code Online (Sandbox Code Playgroud)

现在我想要一个选项,如果我调用

./configure
Run Code Online (Sandbox Code Playgroud)

它创建 makefile 并且大小为 4,但是当有人这样做时

./configure --block-size=num
Run Code Online (Sandbox Code Playgroud)

SIZE 将设置为 num,最好我想在没有 config.h 的情况下执行此操作,我只是希望他向 makefile 添加一些内容,因此将调用编译

-DSIZE=num
Run Code Online (Sandbox Code Playgroud)

jør*_*sen 5

# configure.ac
AC_ARG_WITH([blocksize],
            AS_HELP_STRING([The desired blocksize [[default: 4]]]),
            [blocksize="$withval"], [blocksize=4])
my_CPPFLAGS="-DSIZE=$blocksize"
AC_SUBST([my_CPPFLAGS])
Run Code Online (Sandbox Code Playgroud)

非常简单。

# Makefile.am
AM_CPPFLAGS = ${my_CPPFLAGS}
Run Code Online (Sandbox Code Playgroud)