11

I am autotoolizing a library project, and this project has some example programs. I want the example programs to be distributed in the dist, but not installed.

Currently the demo programs are organized like thus:

src/*.cpp (library source)
include/*.h (library headers)
demos/demo.cpp (example program)
demos/RunDemo (script to run demo)

It is important that RunDemo be runnable after building the software, without requiring the "install" step.

So far I have been able to build the "demo" exectuable using a noinst_PROGRAMS target. However, after make in a VPATH build, the following is available:

build/src/.libs/libxxx.so  (etc..)
build/demos/demo

As you can see, the RunDemo script needed to execute "demo" is not copied to the $(builddir). I have tried a few things, e.g., adding RunDemo to dist_noinst_SCRIPTS, as well as adding my own copy targets and trying to hook all.. no matter what I try, I always get the output,

$ make RunDemo
make: Nothing to be done for `../../../projects/demo/RunDemo'.

I seem to be unable to create a target in the builddir that says "if this file is not in the builddir, copy it from the srcdir."

Is this possible with automake?

ssk
  • 9,045
  • 26
  • 96
  • 169
Steve
  • 8,153
  • 9
  • 44
  • 91

1 Answers1

9

You can make files accessible in the build tree after the ./configure step using the AC_CONFIG_LINKS macro (provided with autoconf) in your configure.ac script. It will create a symbolic link if possible, otherwise it will copy the file.

In your case it would look like

AC_CONFIG_LINKS([demos/RunDemo:demos/RunDemo])

From the autoconf manual:

Macro: AC_CONFIG_LINKS (dest:source..., [cmds], [init-cmds])

Make AC_OUTPUT link each of the existing files source to the corresponding link name dest. Makes a symbolic link if possible, otherwise a hard link if possible, otherwise a copy. The dest and source names should be relative to the top level source or build directory

Using dist_noinst_SCRIPTS is still necessary for the file to be distributed.

Gavin Smith
  • 3,076
  • 1
  • 19
  • 25
  • Is there a way to do this with directories rather than just files? – Matt Fichman Jan 08 '14 at 00:14
  • 1
    I assume that `AC_CONFIG_LINKS([directory:directory])` doesn't work? I'm not sure why that would be, but you could try writing a command to copy it with `AC_CONFIG_COMMANDS` using the `srcdir` and `builddir` variables. – Gavin Smith Jan 08 '14 at 18:47
  • AC_CONFIG_LINKS really wants to work on filies, but you can do directories if you are careful about how you test for $srcdir -- you have to configure it so you never run AC_CONFIG_LINKS unless you are in a build directory. – Rob Latham Feb 19 '18 at 15:35