4

I've got a program that's written in C, built using automake/autoconf, and has two test suites. One is a unit test suite also written in C; the other is end-to-end and is (currently) written in Python. I want "make check" to run the unit tests always, and the end-to-end tests only if Python is installed. This is what I have now:

TESTS = unittests
if HAVE_PYTHON
TESTS += tester.py
tester_py_SOURCES = src/test/tester.py.in

tester.py: src/test/tester.py.in Makefile
        $(SED) -e 's,[@]PYTHON[@],$(PYTHON),' < $< > $@
        chmod +x $@
endif

HAVE_PYTHON is set by the configure script with

AM_PATH_PYTHON([2.6],, [:])
AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != ":"])

This works correctly on Unix, but blows up with "no rule to make tester.py.exe" on Windows. Also, the copy-and-substitute technique for getting the #! line right means I can't break up the test suite into multiple modules.

Is there a better way to do this?

zwol
  • 135,547
  • 38
  • 252
  • 361

1 Answers1

5

You must use _SOURCES for compiled things only, so that's why it'a adding $(EXEEXT). Try this:

TESTS = unittests
if HAVE_PYTHON
TESTS += tester.py
# Possibly use += here depending on the rest of your Makefile.am
check_SCRIPTS = tester.py
# I added $(srcdir) here so VPATH builds still work.
tester.py: $(srcdir)/src/test/tester.py.in Makefile
        $(SED) -e 's,[@]PYTHON[@],$(PYTHON),' < $< > $@
        chmod +x $@
endif

Is there any reason you don't just do the substitution via configure.ac?

AS_IF([test "$PYTHON" != ":"], [AC_CONFIG_FILES([src/test/tester.py])])

This will remake the script using config.status and autogenerate rebuild rules.

EDIT 1:

If what you really want to do is run the python tester script as part of make check, I'd do this:

check-local:
if HAVE_PYTHON
        $(PYTHON) $(srcdir)/src/test/tester.py
endif

(I put the check-local outside the if HAVE_PYTHON so that you can define other commands to run as part of check-local, if needed.)

You might prefer writing this, instead:

check-local:
        test "$(PYTHON)" != ":" && $(PYTHON) $(srcdir)/src/test/tester.py

See extending in the automake manual.

Jack Kelly
  • 18,264
  • 2
  • 56
  • 81
  • `check_SCRIPTS`, of course, I shoulda thought of that. As for the other, I thought you couldn't put `AC_CONFIG_FILES` inside an `AS_IF`, but anyway that wouldn't solve the problem of having to put everything in one giant file contra proper Python style. What I really want here is a way to get the `check-TESTS` target to run '`$(PYTHON) $(srcdir)/src/test/tester.py`' instead of just '`./tester.py`'. (I may eventually give up and do a wrapper script, but I'm avoiding that because then I have to deal with more Windows crap.) – zwol Jul 30 '11 at 17:52
  • Yep, check-local seems to be the way to go. Thanks. – zwol Aug 16 '11 at 17:25