can return values be trapped in a makefile

can return values be trapped in a makefile

Post by rava.. » 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 return values be trapped in a makefile

Post by Reinier Pos » Thu, 13 Jan 2000 04:00:00



>t1 and t2 do the flollowing
>t1 -i <input_file_to_reverse> -o <output_file_reversed>
>t2 -i <reversed_file> -o <decoded_file>

This is what pipes were invented for.  t1 and t2 should produce output
to stdout, period.  If they can't, complain to the vendor.

--
Reinier

 
 
 

can return values be trapped in a makefile

Post by Heiner Steve » Thu, 13 Jan 2000 04:00:00


[...]

> #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 I understood your problem correctly, it is as follows:

 o  You call the diff command from a Makefile
 o  If the diff command returns nonzero, you want to continue with
    the next command in the make rule (the default behaviour of "make"
    is to exit)
 o  If the diff command returns zero, you want to terminate the
    command of the make rule (the default behaviour of "make" is
    to continue)

In other words: you want to "reverse" the exit code of the "diff"
command.

The following could work:

        target: dependency
                if diff a b; then false; else true; fi

Heiner
--
 ___ _                          

\__ \  _/ -_) V / -_) ' \    UNIX Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.oase-shareware.org/shell/

 
 
 

can return values be trapped in a makefile

Post by Ken Pizzi » Fri, 14 Jan 2000 04:00:00



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

In the strictest sense, that can't be done --- none of the
commands executed by make are a part of make, after all.
But since all commands "executed" by make are actually passed
on to an instance of the shell, you can just make use of that
fact and use shell conditionals and flow-control...

Quote:>Question:
># How do i check return values and branch off appropriately in
>makefiles?

For simple pass/fail tests:
   if command; \
   then echo success; \
   else echo fail; \
   fi
For more detailed exit code analysis:
   command; \
   case $$? in \
     23) echo twenty-three ;; \
     42) echo the answer ;; \
     0)  echo success ;; \
     *)  echo other ;; \
   esac

(You need all of those terminating backwacks in order to
instruct make to send _all_ of the lines in question down
to the shell.  You also need to punctuate the commands with
the assumption that the <\><newline> pairs will be translated
to spaces by make --- for example, the ;s in the above if
statment above would not be required in a normal multi-line
shell script, but are required here.

Quote:># How can I Change macro values based on execution of tools?

Oh... that's what you're after?  Macro values are assigned at
makefile-compilation time, before program execution begins.
With some make implementations (such as GNU's) there are
mechanisms which might be usable (e.g., the $(shell ...)
construct in a := clause), but there is no universal mechanism
which can be used for this, and this is still done before any
dependency-based program execution.

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

There's always recursive makefile techniques --- have your
top-level makefile invoke another instance of $(MAKE) with
arguments which depend on the results of invoked tools.

                --Ken Pizzini

 
 
 

1. can makefile trap the return values

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. test

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

4. frame value too large by ifconfig!!!!

5. HELP:Trapping return values

6. Verisign: are they having reliability problems?

7. The `who am i` does not return a value

8. aio methods for block devices

9. set a variable to commandline return value in makefile

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

11. HELP! I am trapped inside of XDM!!!

12. Q: Routing problem: I am trapped!

13. trapping and exit values