I've got some 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 just has a very simple Makefile and doesn't rely on autotools at all).
It looks like using gnulib would be a good way to be able to compile this for Windows under MinGW and I've started out in that direction, but it seems that if you're not very familiar with autotools you get into the deep weeds really quickly.
So here's what I've tried:
$ gnulib-tool --import getsockname,getsockopt,setsockopt,socket,socketlib,sockets,socklen,sys_socket,arpa_inet,inet_ntop,inet_pton,netinet_in
It runs 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.
Ok, I had no configure.ac nor a 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
And...
$ 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 assume that you're intimately familiar with autotools, so they leave out all of the instructions for what you need to do with autotools next.
From what I've been able to figure out from reading various forums, it seems that the next steps are to run:
$ aclocal
$ autoconf
$ automake
$ configure
However... when I ran 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: to configure.ac' and run
autoconf' again.
Hmmm... Ok that's probably just some stuff I'm missing in my Makefile.am (because I'm not entirely sure what should go into a Makefile.am)... so going back a step... I should be able to run the configure file that got 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've read by googling around it seems like the gl_EARLY and gl_INIT should be take care of by the line added to the Makefile.am file ( ACLOCAL_AMFLAGS = -I m4), but at this point I'm not entirely sure that I'm doing the autotools part of this correctly. Can anyone point out what I'm doing wrong here?
AC_CONFIG_MACRO_DIR([m4])
to configure.ac
and it will find gnulib macros in m4
directoryAM_INIT_AUTOMAKE
AC_CONFIG_FILES
should contain not only gnulib Makefile, but your Makefile tooautoreconf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With