I have C code that was written for Linux and relies on sockets and arpa / inet.h, as well as libusb.h, and I want to compile this for Windows under MinGW. (Note that the current project has a very simple Makefile and does not rely on autotools at all).
It seems that using gnulib would be a good way to compile this for Windows under MinGW, and I started working in that direction, but it seems that if you are not very familiar with autotools, you get into deep weeds very quickly.
So here is what I tried:
$ gnulib-tool --import getsockname,getsockopt,setsockopt,socket,socketlib,sockets,socklen,sys_socket,arpa_inet,inet_ntop,inet_pton,netinet_in
It starts up and gives me the following message at the end:
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.
Well, I did not have configure.ac and Makefile.am, so I created them as follows (as per the instructions above):
$ cat Makefile.am SUBDIRS = lib ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = m4/gnulib-cache.m4
A...
$ cat configure.ac AC_INIT([configure.ac]) AC_CONFIG_FILES([lib/Makefile]) AC_PROG_CC gl_EARLY gl_INIT
Now at this point, the gnulib docs seem to suggest that you are familiar with autotools, so they disregard all the instructions for what you need to do with autotools next.
From what I was able to figure out from reading various forums, it seems that the following steps should be followed:
$ aclocal $ autoconf $ automake $ configure
However ... when I started automake, I got:
$ 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: until configure.ac' and run autoconf' again.
Hmmm ... Well, that might just be something I miss in my Makefile.am (because I'm not quite sure what to do in Makefile.am) ... so back to the step. .. I have to run the configuration file that was created above in the autoconf step:
$ ./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
From what I read in googling around, it looks like gl_EARLY and gl_INIT should take care of the line added to the Makefile.am file (ACLOCAL_AMFLAGS = -I m4), but at the moment I'm not completely sure that I am doing the auto-part part correctly . Can someone point out what I'm doing wrong here?