can makefile trap the return values

can makefile trap the return values

Post by ravad.. » Thu, 13 Jan 2000 04:00:00



Hi,
Can any one out there please help me. I'm desperate for a solution.

Problem:
t1 and t2 are 2 tools to be connected in series.
T1 takes in an input file and produces an output
T2 takes t1's input and produces an output
Assume:
t1 and t2 do the flollowing
t1 -i <input_file_to_reverse> -o <output_file_reversed>
t2 -i <reversed_file> -o <decoded_file>

Assume also
an <expected_output_file_reversed> exists.
A diff script exists that will be invoked after t1 runs
that is
diff -i1 <output_file_reversed> -i2 <expected_output_file_reversed>
-o<diff_file>
if the files are identical diff returns 0
else it returns 23

Now t1, the diff script and t2 have to be run in series.

t2's input should be t1's output if diff returns 0
or
t2's input is the expected_output_file if diff returns 23.

Consider further if this has to be done using a makefile (only).

#makefile:
###########################  macros ###############################
t1_expected_output=expected_reversed_data.dat

t1_input_file=input.dat
t1_output_file=reversed_output.dat

t2_input_file=$(t1_output_file)
t2_output_file=decoded_file.dat

###########################  end macros ###############################

$(t2_output_file) : $(t2_input_file) diff_file.dat
        t2 -i $(t2_input_file) -o $(t2_output_file);

diff_file.dat : $(t1_output_file) $(t1_expected_output)
        diff -i1 $(output_file_reversed) -i2
$(expected_output_file_reversed)

#
# what i need is to check the return status of diff and then proceed.
#
# return = diff -i1 <output_file_reversed> -i2
<expected_output_file_reversed> -o <diff_file>
# if test $return -ne 0
# then
#     t2_input_file=t1_expected_output
# fi
# How do i check return values and branch off appropriately?
#
#
$(t1_expected_output) $(t1_input_file):
        echo dummy;

$(t1_output_file) : $(t1_input_file)
        t1 -i $(t1_input_file) -o $(t1_output_file);

Question:
# How do i check return values and branch off appropriately in
makefiles?
# How can I Change macro values based on execution of tools?

If there is no support in makefile for doing this? is there any
workaround for my problem?

thanks in advance.

regards
linus

Please reply to


Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

can makefile trap the return values

Post by Paul D. Smit » Fri, 14 Jan 2000 04:00:00


  rt> Problem:
  rt> t1 and t2 are 2 tools to be connected in series.
  rt> T1 takes in an input file and produces an output
  rt> T2 takes t1's input and produces an output
  rt> Assume:
  rt> t1 and t2 do the flollowing
  rt> t1 -i <input_file_to_reverse> -o <output_file_reversed>
  rt> t2 -i <reversed_file> -o <decoded_file>

  rt> How do i check return values and branch off appropriately in
  rt> makefiles?

You can't.  Make is not a procedural language.  You construct a
dependency graph, choose a starting point, and go.

Assuming you don't need the intermediate files for other processing, you
should put all the above into _one_ rule and use the shell to handle any
tests, etc.

If you do need them, you can break it up into two parts: t1 in one rule
and the diff and t2 in the other rule.

  rt> How can I Change macro values based on execution of tools?

You can't change a make macro value from within the execution of a
rule.

  rt> Consider further if this has to be done using a makefile (only).

A requirement like this makes this sound suspiciously like a homework
problem.  I'm feeling mellow so I'll give you a hint anyway: recursion.

--
-------------------------------------------------------------------------------

 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.

 
 
 

1. can return values be trapped in a makefile

Hi,
Can any one out there please help me. I'm desperate for a solution.

Problem:
t1 and t2 are 2 tools to be connected in series.
T1 takes in an input file and produces an output
T2 takes t1's input and produces an output
Assume:
t1 and t2 do the flollowing
t1 -i <input_file_to_reverse> -o <output_file_reversed>
t2 -i <reversed_file> -o <decoded_file>

Assume also
an <expected_output_file_reversed> exists.
A diff script exists that will be invoked after t1 runs
that is
diff -i1 <output_file_reversed> -i2 <expected_output_file_reversed>
-o<diff_file>
if the files are identical diff returns 0
else it returns 23

Now t1, the diff script and t2 have to be run in series.

t2's input should be t1's output if diff returns 0
or
t2's input is the expected_output_file if diff returns 23.

Consider further if this has to be done using a makefile (only).

#makefile:
###########################  macros ###############################
t1_expected_output=expected_reversed_data.dat

t1_input_file=input.dat
t1_output_file=reversed_output.dat

t2_input_file=$(t1_output_file)
t2_output_file=decoded_file.dat

###########################  end macros ###############################

$(t2_output_file) : $(t2_input_file) diff_file.dat
        t2 -i $(t2_input_file) -o $(t2_output_file);

diff_file.dat : $(t1_output_file) $(t1_expected_output)
        diff -i1 $(output_file_reversed) -i2
$(expected_output_file_reversed)

#
# what i need is to check the return status of diff and then proceed.
#
# return = diff -i1 <output_file_reversed> -i2
<expected_output_file_reversed> -o <diff_file>
# if test $return -ne 0
# then
#     t2_input_file=t1_expected_output
# fi
# How do i check return values and branch off appropriately?
#
#
$(t1_expected_output) $(t1_input_file):
        echo dummy;

$(t1_output_file) : $(t1_input_file)
        t1 -i $(t1_input_file) -o $(t1_output_file);

Question:
# How do i check return values and branch off appropriately in
makefiles?
# How can I Change macro values based on execution of tools?

If there is no support in makefile for doing this? is there any
workaround for my problem?

thanks in advance.

regards
linus

Please reply to


Sent via Deja.com http://www.deja.com/
Before you buy.

2. Printing help needed

3. ksh: if I trap on exit to rm tmp files, how do I save return value ?

4. Please , help with manual on web.

5. HELP:Trapping return values

6. 2.4.19-pre8 breaks apm=power-off on Asus A7M266-D

7. set a variable to commandline return value in makefile

8. TCP Port Reservation!!!

9. Default return value for when return() is not explicitly used on SC5.0

10. trapping and exit values

11. Return codes in trap handlers in ksh

12. What is this supposed to return: "trap 'exit ' 0; exit"?

13. expansion immunity for values in Makefile assignments?