2
votes

I'm writing a regression test for our package that is currently using autotools (i.e., autoconf/automake). The following Makefile.am exemplifies the simplest check. When make check is invoked, it compiles tester.c to generate tester and then launches tester.sh that ends up invoking test (among other commands). That works fine.

However, for some tests I need to pass some information gathered at configure time to tester.sh. So is it possible to pass this information as a parameter? The value is available in a variable in the Makefile (i.e. it is AC_SUBSTed) but these variables are not forwarded to child processes spawned by the make command. If that's not possible, would it be feasible to have an extra rule that is executed before tester.sh that generates a file with the parameters that are captured later through tester.sh?

File Makefile.am

check_PROGRAMS = tester
TESTS = tester.sh
tester_SOURCES = tester.c
1

1 Answers

0
votes

Since I'm interested on passing one of the Makefile variables into the test, I have decided to attack this problem by creating an auxiliar program (named pass_variable_PREFIX) that will show the prefix variable defined in the Makefile. This auxiliar program will be later used by the tester.sh to know the value of prefix. I understand that this may not be the best solution, but it works so far.

Here comes the related code:

Makefile.am

check_PROGRAMS = tester pass_variable_PREFIX
TESTS = tester.sh
tester_SOURCES = tester.c
pass_variable_PREFIX_SOURCES = pass_variable_PREFIX.c
pass_variable_PREFIX_CFLAGS  = -DPREFIX="\"$(prefix)\""

pass_variable_PREFIX.c

#include <stdio.h>
int main (int argc, char *argv[])
{
    printf (PREFIX"\n");
    return 0;
}

tester.sh

#!/bin/bash
PREFIX=`./pass_variable_PREFIX`
echo $PREFIX
./tester