8

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.

icedwater
  • 4,701
  • 3
  • 35
  • 50
RajSanpui
  • 11,556
  • 32
  • 79
  • 146

2 Answers2

11

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

Patrick B.
  • 11,773
  • 8
  • 58
  • 101
  • :Let me try both the ways and quickly tell you the results. – RajSanpui Aug 09 '11 at 11:05
  • Sorry, this is what happened. export EF_ERRTRACK_START=3 export EF_ERRTRACK_END=5 ./time-interval-measurement-test /bin/sh: line 0: export: `./time-interval-measurement-test': not a valid identifier make: *** [test] Error 1 – RajSanpui Aug 09 '11 at 11:06
  • Testing Electric Fence. After the last test, it should print that the test has PASSED. ./eftest Electric Fence 2.1 Copyright (C) 1987-1998 Bruce Perens. ./tstheap 3072 Electric Fence 2.1 Copyright (C) 1987-1998 Bruce Perens. export EF_ERRTRACK_START=3 export EF_ERRTRACK_END=5 ./time-interval-measurement-test /bin/sh: line 0: export: `./time-interval-measurement-test': not a valid identifier make: *** [test] Error 1 -bash-3.2# make test – RajSanpui Aug 09 '11 at 11:08
  • Thanks it worked, i forgot to remove the `export` before the variable name. – RajSanpui Aug 09 '11 at 11:10
2

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

Community
  • 1
  • 1
Kamath
  • 4,461
  • 5
  • 33
  • 60
  • Thanks, Yes, using the semicolon also works..upvote for you. Came to know of a new method apart from the first one. – RajSanpui Aug 09 '11 at 11:17