5

I am new to autotools and have managed to create a, for the moment, satisfying configure.ac. Now I would like to specify somewhere (configure.ac, Makefile.am, or wherever) that after a successfull "make", a short note is printed. Something like "Make sure that you have also included the correct path in you LD_LIBRARY_PATH".

However, when I specify it in Makefile.in, executing "automake" overwrites this file (as expected). So I have not found how to extend e.g. Makefile.am to include an "echo Make sure that you have also included the correct path in you LD_LIBRARY_PATH" upon termination of compilation of one of the targets. ATM I only have one target (bin_PROGRAMS = myprog). Besides this, compiling etc. works fine. But as an information for the possibly "un"experienced user, I really would like to print out some final advice.

Is there a way to achieve this?

Thank you and best regards.

P.S. I know about cmake and have not yet used it and, for the moment, I want to work with autotools and automake.

Shadow
  • 1,042
  • 2
  • 15
  • 23
  • While the answers and comments of Edwin Buck were a great help, I realized that it is not so simple to induce a print upon a pure "make". So I changed over to specifying what to print for the main-target. This has some drawbacks (need to define for _every_ new main-target, time-of-appearance unknown in parallel builds, etc.). Thus, my personal recommendation would be to include this also for the install-exec-hook, especially if the reports/warnings/notes are very crucial for the user to know and not to rely on her/him to read documentation;) – Shadow Feb 15 '11 at 08:38

2 Answers2

7

----Edited as install-exec-hook is useful, but here's the 100% answer ----

Extend your Makefile, by replacing the "install:" target in the Makefile.am

Add the following to "Makefile.am"

install: install-am
        echo "Don't forget to set your LD_LIBRARY_PATH"

For this to work, you must first find the install target in the generated Makefile and copy it to the Makefile.am. This ensures that you don't break how automake's targets depend on each other.

Then you add commands under the target much as you would any Makefile. Note that this is done in Makefile.am, so when automake builds it's Makefile.in and Makefile, it will source your target over the defaults it normally provides.

This will get your "warning" closer to the end on non-parallel builds. The dangers are that you will have to ensure that your override of the "install" target remains consistent with automake's requirements.

Also, if they run "make install-exec" your warning will not report. If you decide to make it report in "make install-exec" then you should

  1. Remove the reporting customization for "make install" (to avoid double-reporting).
  2. Add the reporting customization for "make install-exec" (to report the library add warning).
  3. Customize install-am target to install the data before installing the executables.

Example with install customization removed

// note the lack of install: override int Makefile.am
install-exec: install-exec-am
        echo "Be sure to update your LD_LIBRARY_PATH"

install-am: all-am
    @${MAKE} $(AM_MAKEFLAGS) install-data install-exec

---- Original post follows ----

Your report really should be made at install time. There's two install targets in the autotools platform, install-data and install-exec. A shared-library properly goes under the "exec" category.

Add an install-exec-hook to the makefile.am

Basically it would look a bit like:

install-exec-hook:
        echo "Be sure to set your LD_LIBRARY_PATH!"

install-data, install-exec, uninstall, dist, and distcheck all support "-hook" extensions.

As far as guaranteeing it runs at the end of the build, it's a bit more difficult. Make / Automake is constructed to allow parallel builds, and that interferes with a guarantee it will run at the end of a build.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • Thank you. This is an interesting point. Actually, I agree with you, that this is rather related to install time. Nevertheless, is there also a similar way to do this after a _pure_ "make"? Locally, I experience very often that users only want to build but not to install, so this would be a helpful report for those. Although we could of course argue that it is not best practice to do so... – Shadow Feb 14 '11 at 16:22
  • A pure make will call "make all" as it is the first target in an automake generated file. If you want to extend that, follow the procedure similar to above, but override the "all:" target to depend on "all-am" with your added message as a step below. – Edwin Buck Feb 14 '11 at 16:41
  • Thank you for the clarification. Unfortunately, I get an error: src/Makefile.am:17: user target `install' defined here... /usr/share/automake-1.11/am/install.am: ... overrides Automake target `install' defined here autoreconf-2.65: automake failed with exit status: 1 when I do it as you suggest. – Shadow Feb 14 '11 at 16:53
  • Sorry, added a few "-am"s where not appropriate. It's been edited. To make sure it is correct for your system, remove the customizations from Makefile.am and the rerun automake. Look at the generated targets, copy them into Makefile.am and then customize as necessary. Don't forget about tabs in the target! Cheers, – Edwin Buck Feb 14 '11 at 17:15
  • No problem. Besides the root-dir Makefile.am, I have includes/Makefile.am and src/Makefile.am. Everything works fine when I do not try to override the install-target. When I integrate "install: install-am echo "Don't forget to set your LD_LIBRARY_PATH"" into src/Makefile.am it still complains with the error. I have double-checked and I used tabs in the target-rule. Any ideas? – Shadow Feb 14 '11 at 17:31
  • I've done it, and it works for me. I then double-checked all three of the above solutions in cygwin, and they all work. Try "autoreconf" to see if you have a stale config somewhere. Make sure you don't have spaces / stuff before the target. Make sure the colon is just after the target. Make sure one target doesn't interfere with another. I'm using automake version 1.11.1. Odds are high you have a typo somewhere. How do your customized targets stack up to the uncustomized targets? – Edwin Buck Feb 14 '11 at 18:33
  • I found out what was causing the behavior. I used "AM_INI_AUTOMAKE([forgein -Wall -Werror])" and the "-Wall" seems to be the origin as it works, when I remove it. Thank you very much for your support so far! – Shadow Feb 15 '11 at 07:59
  • Ok, that makes a lot of sense. -Wall turns on all warnings, and -Werror makes all enabled warnings into errors. Both are generally good options, except the combination will raise a warning that you are overriding the makefile target, which will then become an error. In your case, that's not desirable. – Edwin Buck Feb 15 '11 at 11:04
  • Replacing automake's install rule is a really bad idea, as it may lock you in to a particular version of automake, and it's way more work than is necessary. – William Pursell Feb 22 '11 at 10:54
  • @William, I agree that it can lock you into a particular version of automake, but there's really not a lot of ways to report an automake build at the end of the build without chaining it from the makefile. Too bad there isn't such a thing as a "make listener" which would have callbacks for each expanded make target. That would be nice for solving this kind of problem. – Edwin Buck Feb 22 '11 at 15:31
4

Just add a local hook in the top level Makefile.am:

all-local:
        @echo 'Make sure...'
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • Thanks for the pointer to all-local, it's a better (and more maintainable) solution if you want the reminder to print during every build. Of course, that's overkill as setting LD_LIBRARY_PATH should only be done after an install, so calls to "make install" might not print out the message. – Edwin Buck Feb 22 '11 at 15:38