Given a source package that uses GNU Automake, the typical build goes like this:

cd ${srcdir}

To build a single file rather than everything, make would normally accept this:

$ make path/to/file

However, that returns an error:

make: *** No rule to make target 'path/to/file'. Stop.

The required file is in a subdirectory that contains its own makefile. It's possible to go into that subdirectory and do ./configure && make file there, work out missing dependencies each time make fails, doing a similar thing to provide those dependencies and repeating the process until make successfully generates the required file.

But surely there must be an easier way...?

So, assuming a typical Linux package that builds cleanly by GNU Automake, is it possible to tell it to build a single file (specifically, a binary executable) ?

  • How about building the corresponding target that lists that particular file? Although other dependent files would also be built alongside. – Barun Sep 26 '16 at 16:46

If there's a makefile in the subdirectory, you probably need to invoke that makefile instead.

make -C path/to file
  • Doing that will kick off the build of file (similar to what I said in my question) but it does not build the dependencies (which may be in other subdirectories). I'm looking for a solution that can be launched at the top level which will build file and whatver it depends upon (as would happen with a top level make of the whole package). – starfry Sep 27 '16 at 8:21
  • @starfry There's no generic solution for this. You have to read the toplevel makefile and figure out what makes it go into the subdirectories. It's not uncommon for this to be a loop (for loop in a shell command) that goes into several subdirectories and where the order of the loop matters — many projects that use make recursively aren't clean with respect to dependencies. – Gilles Sep 27 '16 at 9:19
  • Funny, that's exactly how I did it. I should write it up as an answer. – starfry Sep 27 '16 at 10:18

The best I've been able to come up with is to use a for loop to build dependent subdirectories and then built the file from within its directory:

for lib in dependency1 dependency2 dependency3
  cd ${srcdir}/libs/${lib}
  ./configure --prefix=/usr
  make LDFLAGS+=-lstdc++

cd ${srcdir}/libs/directory

./configure --prefix=/usr
  --localstatedir=/var \
make LDFLAGS+=-lstdc++ file

This doesn't answer the question, but I fear it's as good as it gets...

Your Answer

