5

I'm following the directions on the Using Check with the Autotools page in an attempt to build in support for unit test in a (currently) small C project. Although I am using Cgreen instead of Check.

I'm having trouble with step 9, which is causing automake to emit a warning about the use of `%'-style pattern rules being a GNU make extension.

The particular make rule is:

check_%.$(OBJEXT) : $(srcdir)/%.c
    $(COMPILE) -DCHECKING -c -o $@ $^

I'm wondering if there is an equivalent way of specifying this rule that does not rely on gnu make extensions.

Wes
  • 2,166
  • 1
  • 20
  • 22

2 Answers2

7

Portable make rules can only use different suffixes, the prefixes should be the same.

.c.o:
        $(COMPILE) -DCHECKING -c -o $@ $<

The suffix does not necessarily starts with a dot, however. (In that case you have to tell Automake what your suffixes are, because it cannot guess.) So for instance you could have something as follows if you rename check_showdns.o to showdns_check.o:

SUFFIXES = _check.o 
check_libapdns_LDADD        = @CHECK_LIBS@ showdns_check.o
.c_check.o:
        $(COMPILE) -DCHECKING -c -o $@ $<
adl
  • 15,627
  • 6
  • 51
  • 65
  • Great suggestion. Fixes the problem. I ended up using a _test prefix instead of _check. – Wes Apr 21 '09 at 03:17
-3

I'd rather try to disable the warning or just ignore it. GNU make exists for all relevant Unix-like platforms; there is no practical reason to spend time maintaining makefile portability. GNU make is also feature-wise superior to most other make dialects.

JesperE
  • 63,317
  • 21
  • 138
  • 197
  • That's true but it would be nice not have to require installation of an additional tool when the host OS provides one out of the box. – Wes Apr 20 '09 at 23:15
  • But consider the time you have to spend maintaining a portable makefile. If you target GNU make only, you will make it *much* easier to write your makefiles, and get more time over improving your application and fix bugs. – JesperE Apr 21 '09 at 06:43
  • 1
    Nice story, do you name all your Makefiles GNUMakefile like you should if you target GNU Make only? Requiring everyone's 'make' to be GNU Make and not indicating your desire to break compatibility with standard make by using GNUMakefile is standard practice now thanks to the "don't waste your time maintaining a portable makefile" attitude – MkV Jul 31 '13 at 06:51
  • Unfortunately I cannot downvote my own post, but to my defense I wrote it almost 10 years ago. The OP explicitly asked for a solution not requiring gnu make, so my comment was rather silly. – JesperE Sep 04 '18 at 04:42