Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why exported variables in Makefile is not received by executable?

I have a makefile, where i am exporting variables which will be received by an executable, but surprisingly the executable is not receiving the exported values.

Please help me.

31 test:
32         @ echo
33         @ echo "Testing Electric Fence."
34         @ echo "After the last test, it should print that the test has PASSED."
35         ./eftest
36         ./tstheap 3072
37         export EF_ERRTRACK_START=3
38         export EF_ERRTRACK_END=5
39         ./time-interval-measurement-test
40         @ echo
41         @ echo "Electric Fence confidence test PASSED." 
42         @ echo

time-interval-measurement-test is an executable (C program) which should receive the exported variables, but it is not getting. Please help me.

like image 945
RajSanpui Avatar asked Aug 09 '11 10:08

RajSanpui


2 Answers

If I'm not mistaken each line in a Makefile is a separate shell-process. So shell-export does not work for several processes: One way to do it is to put them into one line:

test:
         @ echo
         @ echo "Testing Electric Fence."
         @ echo "After the last test, it should print that the test has PASSED."
         ./eftest
         ./tstheap 3072
         EF_ERRTRACK_START=3 EF_ERRTRACK_END=5 ./time-interval-measurement-test
         @ echo
         @ echo "Electric Fence confidence test PASSED." 
         @ echo

or line-break-escaped with '\'

test:
        [..]
        EF_ERRTRACK_START=3 \
        EF_ERRTRACK_END=5 \
        ./time-interval-measurement-test

Like that the ENV-variables are available to ./time-interval-measrument

like image 103
Patrick B. Avatar answered Sep 28 '22 08:09

Patrick B.


I had asked for a similar question, but its not the exact same scenario how to implement makefile shared variable

Ideally your exported variables should have passed on to the child process, I wonder if your child shell is same as parent.

Try following - export EF_ERRTRACK_START=3; export EF_ERRTRACK_END=5; ./time-interval-measurement-test

like image 39
Kamath Avatar answered Sep 28 '22 08:09

Kamath