Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print something after successfull make in Makefile.am

Tags:

automake

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.

like image 882
Shadow Avatar asked Dec 22 '22 17:12

Shadow


1 Answers

----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.

like image 127
Edwin Buck Avatar answered Feb 04 '23 14:02

Edwin Buck