在MinGW上开始使用gnulib并且不熟悉(足够)使用autotools

ane*_*eal 6 mingw autotools gnulib

我有一些为Linux编写的C代码,依赖于套接字和arpa/inet.h以及libusb.h,我想在MinGW下为Windows编译.(请注意,当前项目只有一个非常简单的Makefile,并且根本不依赖于autotools).

看起来使用gnulib是一个很好的方法,能够在MinGW下为Windows编译这个并且我已经从那个方向开始了,但是看起来如果你对autotools不是很熟悉,你真的会深入杂草很快.

所以这就是我尝试过的:

$ gnulib-tool --import getsockname,getsockopt,setsockopt,socket,socketlib,sockets,socklen,sys_socket,arpa_inet,inet_ntop,inet_pton,netinet_in
Run Code Online (Sandbox Code Playgroud)

它运行并在最后给我以下消息:

Don't forget to
  - add "lib/Makefile" to AC_CONFIG_FILES in ./configure.ac,
  - mention "lib" in SUBDIRS in Makefile.am,
  - mention "-I m4" in ACLOCAL_AMFLAGS in Makefile.am,
  - mention "m4/gnulib-cache.m4" in EXTRA_DIST in Makefile.am,
  - invoke gl_EARLY in ./configure.ac, right after AC_PROG_CC,
  - invoke gl_INIT in ./configure.ac.
Run Code Online (Sandbox Code Playgroud)

好的,我没有configure.ac也没有Makefile.am,所以我按如下方式创建它们(按照上面的说明):

$ cat Makefile.am
SUBDIRS = lib
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = m4/gnulib-cache.m4
Run Code Online (Sandbox Code Playgroud)

和...

$ cat configure.ac
AC_INIT([configure.ac])
AC_CONFIG_FILES([lib/Makefile])
AC_PROG_CC
gl_EARLY
gl_INIT
Run Code Online (Sandbox Code Playgroud)

现在,在这一点上,gnulib文档似乎假设您非常熟悉autotools,因此他们忽略了接下来需要对autotools做什么的所有说明.

从我从阅读各种论坛中得出的结论来看,接下来的步骤似乎是:

$ aclocal
$ autoconf
$ automake
$ configure
Run Code Online (Sandbox Code Playgroud)

但是......当我运行automake时,我得到了:

$ automake
configure.ac: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal).
lib/Makefile.am:30: library used but `RANLIB' is undefined
lib/Makefile.am:30:   The usual way to define `RANLIB' is to add  `AC_PROG_RANLIB
Run Code Online (Sandbox Code Playgroud)

'lib/Makefile.am:30:configure.ac' and run再次autoconf'.

嗯......好吧,这可能只是我在Makefile.am中遗漏的一些东西(因为我不完全确定应该进入Makefile.am)...所以回去一步......我应该是能够在autoconf步骤中运行上面创建的配置文件:

$ ./configure

checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
./configure: line 2497: gl_EARLY: command not found
./configure: line 2498: gl_INIT: command not found
rm: cannot lstat `conftest.exe': Permission denied
Run Code Online (Sandbox Code Playgroud)

从我通过谷歌搜索看到的,似乎gl_EARLY和gl_INIT应该由添加到Makefile.am文件(ACLOCAL_AMFLAGS = -I m4)的行来处理,但在这一点上我不完全确定我正确地做了autotools的一部分.谁能指出我在这里做错了什么?

vit*_*ter 3

  1. 添加AC_CONFIG_MACRO_DIR([m4])到目录configure.ac中就会发现gnulib宏m4
  2. 添加AM_INIT_AUTOMAKE
  3. AC_CONFIG_FILES不仅应该包含 gnulib Makefile,还应该包含你的 Makefile
  4. 您可以通过一次调用重新生成所有内容autoreconf