Reputation: 12963
My configure.ac lets the user specify --enable-monitor
. In a subdirectory, I have a Makefile.in which contains a certain number of targets to build. I would like some of them to be only available when the user has specified --enable-monitor
Put differently, I want the user to be only able to run make monitor
when ./configure
has been run with --enable-monitor
.
How can I do that?
Upvotes: 1
Views: 242
Reputation: 212404
It should be sufficient to put this in configure.ac
:
AC_ARG_ENABLE([monitor],[help string],[use_monitor=yes])
AM_CONDITIONAL([USE_MONITOR],[test "$use_monitor" = yes])
and this in Makefile.am:
if USE_MONITOR
bin_PROGRAMS = monitor
else
monitor:
@echo Target not supported >&2 && exit 1
endif
The else clause with an explicit monitor target is used to override and default rules that Make might otherwise use. Note that "help string" ought to be more useful and constructed using AS_HELP_STRING
, but those details have been omitted for brevity.
--EDIT--
Since automake is not being used, you can replace the AM_CONDITIONAL
line in configure.ac with something like:
AC_SUBST([USE_MONITOR],[$use_monitor])
and then do checks in Makefile.in
like:
monitor:
@if test "@USE_MONITOR@" = yes; then \
... ; \
else \
echo Target not supported >&2 && exit 1; \
fi
Upvotes: 1