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

Getting started with gnulib on MinGW and not familiar (enough) with autotools

我有一些为 Linux 编写的 C 代码,依赖于套接字和 arpa/inet.h 以及 libusb.h,我想为 Windows 在 MinGW 下。 (请注意,当前项目只有一个非常简单的 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

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

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.

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

$ cat Makefile.am
SUBDIRS = lib
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = m4/gnulib-cache.m4

还有...

$ cat configure.ac
AC_INIT([configure.ac])
AC_CONFIG_FILES([lib/Makefile])
AC_PROG_CC
gl_EARLY
gl_INIT

此时,gnulib 文档似乎假设您非常熟悉 autotools,因此他们省略了您接下来需要使用 autotools 做什么的所有说明。

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

$ aclocal
$ autoconf
$ automake
$ configure

但是...当我 运行 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

' lib/Makefile.am:30: 再次 configure.ac' and runautoconf'。

嗯...好的,这可能只是我在 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

根据我通过谷歌搜索阅读的内容,似乎 gl_EARLY 和 gl_INIT 应该由添加到 Makefile.am 文件的行处理(ACLOCAL_AMFLAGS = -I m4), 但在这一点上我不完全确定我是否正确地完成了自动工具部分。谁能指出我在这里做错了什么?

  1. AC_CONFIG_MACRO_DIR([m4])添加到configure.ac,它将在m4目录
  2. 中找到gnulib宏
  3. 添加AM_INIT_AUTOMAKE
  4. AC_CONFIG_FILES 不仅应该包含 gnulib Makefile,还应该包含您的 Makefile
  5. 您只需调用 autoreconf
  6. 即可重新生成所有内容