title: Getting started with gnulib on MinGW and not familiar (enough) with autotools
body: <p>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). </p>
  
  <p>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.</p>
  
  <p>So here's what I've tried:</p>
  
  <pre><code>$ gnulib-tool --import getsockname,getsockopt,setsockopt,socket,socketlib,sockets,socklen,sys_socket,arpa_inet,inet_ntop,inet_pton,netinet_in
  </code></pre>
  
  <p>It runs and gives me the following message at the end:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Ok, I had no configure.ac nor a Makefile.am, so I created them as follows (as per the instructions above):</p>
  
  <pre><code>$ cat Makefile.am
  SUBDIRS = lib
  ACLOCAL_AMFLAGS = -I m4
  EXTRA_DIST = m4/gnulib-cache.m4
  </code></pre>
  
  <p>And...</p>
  
  <pre><code>$ cat configure.ac
  AC_INIT([configure.ac])
  AC_CONFIG_FILES([lib/Makefile])
  AC_PROG_CC
  gl_EARLY
  gl_INIT
  </code></pre>
  
  <p>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.</p>
  
  <p>From what I've been able to figure out from reading various forums, it seems that the next steps are to run:</p>
  
  <pre><code>$ aclocal
  $ autoconf
  $ automake
  $ configure
  </code></pre>
  
  <p>However... when I ran automake I got:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>'
      lib/Makefile.am:30:   to <code>configure.ac' and run</code>autoconf' again.</p>
  
  <p>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:</p>
  
  <pre><code>$ ./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
  </code></pre>
  
  <p>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?</p>