views:

401

answers:

2

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.

+2  A: 

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
Great suggestion. Fixes the problem. I ended up using a _test prefix instead of _check.
Wes
+3  A: 

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
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
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