autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking for built files


From: Benoit SIGOURE
Subject: Re: Checking for built files
Date: Tue, 30 Oct 2007 08:35:38 +0100

On Oct 29, 2007, at 10:25 PM, Andrej Prsa wrote:

Hi,

a program I am working on consists of fortran sources that are compiled
with f2c into their C counterparts, linked into a shared library and
then used in the remainder of the program. To facilitate compiling, I
thought of distributing f2c'd C sources in the tarball so that the
users don't need to have f2c installed to compile the code. However, if
someone did `make distclean`, all built C sources would be deleted and
f2c then must be present on a system. What would be a good way to check
for the existence of built sources and to check for f2c in case these
sources are missing?

Hi Andrej,
you must use BUILT_SOURCES so that automake knows that 1. some sources must be built before the actual build starts and 2. these sources will need to be distributed and as such will not be cleaned by make distclean.

Here is an example project that illustrates this. It requires a `mygen' program to build a source. If the program isn't available but the source is available, the build will succeed. Otherwise the user will get an error saying that a required program wasn't found.

--configure.ac---------------------------------------------------------
AC_INIT([actest], [0.42])
AM_INIT_AUTOMAKE([foreign])

AC_PROG_CC

AM_MISSING_HAS_RUN()
AC_PATH_PROGS([MYGEN], [mygen])
if test x"$MYGEN" = x; then
  MYGEN=${am_missing_run}mygen
fi

AC_CONFIG_FILES([Makefile])

AC_OUTPUT
-----------------------------------------------------------------------
/!\ warning: AM_MISSING_HAS_RUN seems to be an undocumented automake macro which means that automake maintainers can decide to change/ remove this macro at their own will. I doubt this is the sort of macro that will change any time soon, and I think it should be made public and documented, but in the mean time, I'm just warning you ;)

--Makefile.am----------------------------------------------------------
BUILT_SOURCES = foo.c
bin_PROGRAMS = foo
foo_SOURCES = foo.c

foo.c:
        $(MYGEN) $@
-----------------------------------------------------------------------

--mygen----------------------------------------------------------------
#!/bin/sh
echo 'int main(){return 0;}' >"$1"
-----------------------------------------------------------------------

Now, simply run ./configure, you will see:
checking for a BSD-compatible install... /opt/local/bin/ginstall -c
checking whether build environment is sane... yes
[...]
checking for mygen... no
config.status: creating Makefile
config.status: executing depfiles commands

Then, when you run make:
/bin/sh /tmp/ac/missing --run mygen foo.c
/tmp/ac/missing: line 54: mygen: command not found
WARNING: `mygen' is needed, and is missing on your system.
         You might have modified some files without having the
proper tools for further handling them. Check the `README' file, it often tells you about the needed prerequisites for installing this package. You may also peek at any GNU archive site, in case
         some other package would contain this missing `mygen' program.
make: *** [foo.c] Error 1


Now run PATH=.:$PATH make:
/bin/sh /tmp/ac/missing --run mygen foo.c
make  all-am
make[1]: Entering directory `/private/tmp/ac'
gcc [....] -c -o foo.o foo.c
mv -f .deps/foo.Tpo .deps/foo.Po
gcc  -g -O2   -o foo foo.o
make[1]: Leaving directory `/private/tmp/ac'

Cheers,

--
Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory


Attachment: PGP.sig
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]