34

I've installed mingw and msys by using mingw-get-setup.exe. I've also installed Autotools(autoconf, automake,m4,libtool) into C:\/opt/autotools.

When I run automake, the following error always occurs:

configure.ac:11: error: required file './ltmain.sh' not found

If I copy ltmain.sh from libtool’s installed tree, execution will finish normally.

How can I configuure automake to find ltmain.sh without copying?

buruzaemon
  • 3,847
  • 1
  • 23
  • 44
user1345414
  • 3,745
  • 9
  • 36
  • 56

2 Answers2

68

In an autoconf/automake/libtool project you need to run:

  • libtoolize: this copies/links a few support scripts, including ltmain.sh (which is the main component of libtool).
  • aclocal: this looks up all m4 macros that your configure script will need, and make a local copy for easier access.
  • autoheader: optional, if you want to use config.h/AC_CONFIG_HEADERS, otherwise all the test result macros will be inlined when you call the compiler.
  • autoconf: to expand all the macros used by configure.ac into the configure script.
  • automake: to convert all the Makefile.am into Makefile.in templates. You probably want to invoke this with --add-missing so additional support scripts can be linked/copied to your project (such as compile, missing, depcomp, test-driver, etc).

Don't worry about running each tool. Just invoke autoreconf -i and it'll run the tools that are needed. Add -v if you want to see what tools is being executed. To avoid mistakes, just put a script like this at the root of your project:

#!/bin/bash -x
mkdir -p m4
exec autoreconf --install "$@"

Users that checkout/clone the project directly from the source repository will need to run this ./bootstrap script at least once. This is not needed if the user got a tarball distribution.

Automake can take fairly good care of itself; it'll re-invoke the above tools when needed, when you run make. But if you generate a broken Makefile, you'll need to invoke ./bootstrap and ./configure again to generate new Makefiles.

DanielKO
  • 4,422
  • 19
  • 29
  • 4
    very helpful thanks a lot just had to "sudo libtoolize && sudo aclocal && sudo autoheader && sudo autoconf && sudo automake --add-missing" – Mitermayer Reis Feb 08 '15 at 04:57
  • 1
    @MitermayerReis If you need `sudo` then you don't have write permission to the directory and/or files. Are the files owned by another user? – DanielKO Feb 08 '15 at 15:26
  • @Mitermayer, I think you should add your comment as a solutions. Thank you ! – ransh Sep 22 '16 at 13:17
  • 4
    @ransh `sudo` is not meant to be used indiscriminately, for the same reason you should not use a *nix system always logged in as root. Compiling software is not an administrative task, it should not require escalated privileges. – DanielKO Sep 23 '16 at 16:46
  • Where can I find more information about steps needed and it's correct order? (libtoolize, autconf, automake, autoreconf, etc) – Vadim Kotov Mar 16 '17 at 11:21
  • @VadimKotov It's a bit messy. The documentation doesn't spell it out explicitly, but you can gather this from [autoreconf's source code](http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=bin/autoreconf.in;hb=HEAD): invoking libtoolize or gettext might import new macros, so aclocal might need to be called afterwards. The general recommendation these days is to use `autoreconf -i` unless you need something special (and the vast majority of projects don't.) – DanielKO Mar 17 '17 at 15:25
  • A gigantic set of tools for reading makefiles and producing makefiles from the input makefiles. I'm a senior software engineer and I'm not getting it. –  Feb 16 '21 at 18:17
  • And what when libtoolize doesn't create ltmain.sh? I run it as "libtoolize --force --automake". – Carlo Wood Mar 28 '21 at 10:31
  • @FrankPuck How do you package your software for distribution? Does it obey the conventions on what variables or environment characteristics should affect its build or installation? Do you even track dependencies when building? Is testing part of the build and distribution process? Because all of these things take an enormous amount of effort to do with a raw Makefile, let alone to do it right. – DanielKO Mar 29 '21 at 20:54
0

As DanielKO stated, ltmain.sh is created by libtoolize.

However, what if it doesn't?

The following requirements need to be met:

  1. configure.ac must exist and contain at least one of: AM_PROG_LIBTOOL,AC_PROG_LIBTOOL,LT_INIT (see function func_require_seen_libtool in /usr/bin/libtoolize)

  2. If configure.ac does not contain a AC_CONFIG_AUX_DIR, libtoolize will look for a file called 'install-sh' or 'install.sh' in ., .. and ../.. and if found use that as "auxdir" and install ltmain.sh there (see function func_require_aux_dir inside libtoolize).

In my case, I was working on an "example project" in a subdirectory of another project, and the example project did not have a AC_CONFIG_AUX_DIR in its configure.ac; therefore libtoolize found the root of the parent project and installed ltmain.sh there instead of in the example project's root.

Carlo Wood
  • 5,648
  • 2
  • 35
  • 47