Subdir-objects option for automake not working

After reading autotools mythbuster , I tried to write a small example of a non-recursive makefile using subdir objects to have my binary in my source directory.

Here is my organization :

/
   autogen.sh
   configure.ac
   Makefile.am
   src/
      main.c

      

autogen.sh :

#!/bin/sh
echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS || exit 1
echo "Running autoheader..." ; autoheader || exit 1
echo "Running autoconf..." ; autoconf || exit 1
echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
./configure "$@"

      

configure.ac :

AC_PREREQ([2.69])
AC_INIT([test], [0.0.1], [devel@hell.org])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC
AM_INIT_AUTOMAKE([1.14 foreign subdir-objects])
AM_MAINTAINER_MODE([enable])
AC_OUTPUT(Makefile)

      

Makefile.am :

MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.h.in configure depcomp install-sh missing compile
bin_PROGRAMS=toto
toto_SOURCES=src/main.c

      

I will compile everything with:

./autogen.sh
make

      

I thought the toto binary would be created in the src directory using the subdir-objects options, but this option seems to have no effect and the toto binary is always generated in the root directory.

I also tried to pass this parameter to Makefile.am using AUTOMAKE_OPTIONS = subdir attributes, but with success.

+3


source to share


1 answer


This is not what the subdir-objects option does. It places the intermediate build results, especially the object files *.o

, in the same directory as the sources from which they are generated. In particular, you should find it main.o

there and not in the top directory.

The end result of a build, on the other hand, should be what and where you specify in your Automake. If you want to toto

go into the directory too src/

, use this one Makefile.am

:



MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.h.in configure depcomp install-sh missing compile
bin_PROGRAMS=src/toto
src_toto_SOURCES=src/main.c

      

+3


source







All Articles