c++makefileautotoolsautomakeldflags

autotools: Makefile.am: link if file exists


my Makefile.am creates the executable main: "symplerTest" i want to link the files "geometry/source/*.o". Currently im linking it like this:

symplerTest_LDFLAGS = \
    ...
    geometry/source/*.o 

That works. But now in a next step, i want to link only if the files *.o exist. I tried this one:

if ("$(wildcard $(geometry/source/*.o))","")
symplerTest_LDFLAGS += geometry/source/*.o
endif

but get the following error message:

srcUnittest/Makefile.am:81: error: endif without if
srcUnittest/Makefile.am:79: warning: wildcard $(geometry/source/*.o: non-POSIX variable name
srcUnittest/Makefile.am:79: (probably a GNU make extension)

The problem seems to be at ("$(wildcard $(geometry/source/*.o))","")

Thank you!


Solution

  • You are confusing the Automake directive if with the Make directive ifeq,

    The Automake manual at 20 Conditionals emphasises:

    Automake supports a simple type of conditionals.

    These conditionals are not the same as conditionals in GNU Make. Automake conditionals are checked at configure time by the configure script, and affect the translation from Makefile.in to Makefile. They are based on options passed to configure and on results that configure has discovered about the host system. GNU Make conditionals are checked at make time, and are based on variables passed to the make program or defined in the Makefile.

    if is not a Make directive at all. ifeq is a Make directive for which valid arguments may be of the form (arg1, arg2).

    ifeq (arg1, arg2)
    

    means, to Make, if arg1 is equal to arg2.

    Arguments of the form (arg1, arg2) are invalid for the Automake directive if. Valid arguments for the Automake if directive are Automake condition-names, e.g.

    if DEBUG
    

    means, to Automake, if the condition named by DEBUG is true - where DEBUG is a condition name that you have previously created by means of the AM_CONDITIONAL macro.

    Refer to the linked documentation.