Search code examples
autotoolsautoconfautomake

How to propagate an configure option in an autotools project?


I have an autotools projet. I can define a custom option to my top configure.ac (a "--enable-XX" option , using AC_ARG_ENABLE and AM_CONDTIONNAL). This is ok.

But now, i want to propagate this option to all my subdirectories.

How do i do ? :

Do i have to define the AC_ARG_ENABLE/AM_CONDTIONAL in every subdirectories configure.ac ?

//// Edit ////

Here is a schema of my working directory :

Project
  | configure.ac
  | Makefile.am
  | Component_1
      | configure.ac
      | Makefile.am (*)
      | src
          | Makefile.am
  | Component_2
      | configure.ac
      | Makefile.am (*)
      | src
          | Makefile.am

(*) SUBDIRS = src

Solution

  • Using subdirectories does not require creating subprojects.

    In a typical Autotools project, only the top-level directory has a configure.ac or a configure script. If there are makefiles or other artifacts to configure in subdirectories, then this is all handled by the one top-level script. With such an arrangement, your question is moot -- there is nowhere to propagate the options to, and no reason to want to propagate them.

    On the other hand, occasionally one project will incorporate a separate complete project. If that incorporated project is an Autotools project then it will have its own configure script that should be run when the top-level project's is run. This is arranged by use of the AC_CONFIG_SUBDIRS macro in the top-level project's configure.ac. The configure script in each designated subdirectory will be run with the same command-line arguments that the top-level configure was run with; you don't need to do anything else to forward the options.

    It is a separate question, however, whether forwarding any particular option to a sub-project configure script makes sense. The meanings, if any, of custom configure options are specific to each configure script. If you have a subproject that you want to react in a specific way to a particular custom option, then it needs its own AC_ARG_ENABLE / AC_ARG_WITH and whatever else needs to go with it. But if you feel at liberty to modify a subproject to add such things then maybe it ought not to be a subproject at all, but instead fully integrated, so that it is configured directly by the top-level script.