1
votes

I have some problem adding specific rules to an autotools project.

I have this small exemple project :

project/configure.ac :

AC_INIT([myprog], [0.1], [[email protected]])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AM_EXTRA_RECURSIVE_TARGETS([quality])
AC_PROG_CC
AC_SUBST([AM_CFLAGS])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

project/Makefile.am:

SUBDIRS = src

project/src/Makefile.am:

bin_PROGRAMS= myprog

myprog_SOURCES    = myprog.c

QUALITYDIR=$(builddir)/quality
QUALITY_FILE="$(QUALITYDIR)/quality.log"

quality-local: $(QUALITY_FILE)

$(QUALITY_FILE): myprog
    mkdir -p $(QUALITYDIR)
    valgrind ./myprog 2>&1 | tee $(QUALITY_FILE)

CLEANFILES =    $(QUALITY_FILE)

Each time I do :

$ make quality

the valgrind stuff is run, even if "myprog" has not been rebuilt. I expect it shall only be executed when myprog is younger than the quality.log file in build/src/quality .

What do I do wrong ?

1

1 Answers

1
votes

Digging into your generated project/src/Makefile you'll see something like:

.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \
        ... quality-am quality-local ...

A .PHONY target will always be remade, so yes valgrind will always be run (which I also observed).

EDIT:

Forget all that. After running make -d quality (after already having made the log) I noticed:

  Considering target file '"./quality/quality.log"'.
   File '"./quality/quality.log"' does not exist.

So simply changing:

QUALITY_FILE="$(QUALITYDIR)/quality.log"

to

QUALITY_FILE=$(QUALITYDIR)/quality.log

should make it behave as you expect. At least it did for me.