Next: , Previous: , Up: Conditional Subdirectories   [Contents][Index] Subdirectories with AM_CONDITIONAL

One method of conditional subdirectories is for configure to output the Makefile for all directories unconditionally, using AC_CONFIG_FILES. configure will also define an Automake conditional under which opt/ should be built. (See Conditionals.)

AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])

Then SUBDIRS can be defined in the top-level as follows.

  MAYBE_OPT = opt

In this case Automake will define ‘DIST_SUBDIRS = src opt’ automatically, because it knows that MAYBE_OPT can contain ‘opt’.

Running make will recurse into src/, and possibly opt/ as well, depending on the value of the conditional. Running ‘make dist’ will recurse into both src/ and opt/ directories because ‘make dist’, unlike ‘make all’, uses the DIST_SUBDIRS variable instead of the SUBDIRS variable. In all cases, the make recursion works because the subdirectories have been configured.