Chris
Chris

Reputation: 932

Allow automake to generate optional compile rules

I have made changes to a program which are part of a much larger project which use the Intel Performance Primitives. It turns out my recent changes use calls which are only available on the newest version of IPP, while a number of the users still use older versions. The program in question is not essential, so I want make it optional rather than back porting to the oldest versions of IPP (IPP has had a lot of API changes over the years).

We use automake/autoconf for generation of Makefiles. Ideally my particular program (single source file in C) would not be compiled by default, unless someone specifically runs "make myprog".

Is there a way to do this or do I have to support a "--with-myprog" option for the configure script?

The Makefile.am currently has (I think this is all that is relevant)

bin_PROGRAMS = \
    stripVDIF \
    {snip}
    generateVDIF 

generateVDIF_SOURCES = \
    generateVDIF.c

generateVDIF_LDADD = $(IPP_LIBS) $(LDADD)

My program is generateVDIF

Upvotes: 1

Views: 250

Answers (2)

Diego Elio Pettenò
Diego Elio Pettenò

Reputation: 3240

If you do not want it to be installed you can simply declared it as EXTRA_PROGRAMS rather than bin_PROGRAMS and that should do exactly what you want (only works with make myprog).

If you want it to be installed, you'll have to use AC_ARG_WITH and AM_CONDITIONAL in configure.ac and then have something like

bin_PROGRAMS = ....

if ENABLE_MYPROG
  bin_PROGRAMS += myprog
endif

and the rest remains the same.

Upvotes: 1

Mike Kinghan
Mike Kinghan

Reputation: 61232

The right way to do this is to place the build of your optional program under the control of a ./configure option, so that ./configure can manage it appropriately. See e.g. how to add configure options

If that sounds too much like hard work you could exploit the fact that additional make code within a Makefile.am is simply passed through to the generated Makefile.

So, e.g. if the following is the Makefile.am for target foo:

EXTRA_DIST = README 
bin_PROGRAMS = foo
foo_SOURCES = foo.c

and you want to add an unmanaged target bar, a program built from bar.c, then you can extend the Makefile.am to:

EXTRA_DIST = README bar.c
bin_PROGRAMS = foo
foo_SOURCES = foo.c

bar: bar.o
    $(CC) $(LDFLAGS) -o$@ $< $(LDLIBS)

The autotooled package will then support make bar, and you could document this fact for the user, with the appropriate caveats - notably including the absence of the usual autotooled install and uninstall.

Obviously, this shortcut would detract from a knowledgeable user's impression of your professional chops.

Upvotes: 0

Related Questions