From sources-request at octave dot org Tue Sep 27 13:11:07 2005 Subject: make.m script to facilitate use of make with octave From: "James R. Phillips" To: sources at octave dot org Date: Tue, 27 Sep 2005 13:07:56 -0500 I use octave to perform engineering test data analysis, and have evolved a programming style where the analysis is generally conducted by a loosely coordinated set of scripts (not functions) that must be invoked in the proper order to properly construct a set of output files (typically tables and plots) from a set of input files. This is a perfect scenario for the use of make, which is not restricted to use in software development, but can also be used to automate just about any project where a set of output files depend in a well-defined way on a set of input files. If the makefile is properly constructed, make can be much more efficient than a top-level driver script that runs all lower-level scripts in the proper order, because make can detect which outputs are truly out-of-date, and run the minimum set of commands to bring them up-to-date, without necessarily running the entire analysis. For example, if all the numbers are right, but you want to change the label on a plot, no need to re-run the entire analysis after modifying the plot script - just re-run the plot script. An ancillary benefit of automating a set of octave scripts with a makefile, is that the makefile serves as precise documentation of how to use the scripts. The make.m script below facilitates the use of make with octave. It assumes a makefile named "makefile", and has a default make target of "octave". This allows a makefile to be built with an "octave" target, as well as, for example, a "clean" target which should be executed from the shell instead of inside octave. The script uses the "-n" flag of make to echo commands to an output file ("makeout.m"), and then executes the file. sed is used to comment out any error messages from make prior to execution of "makeout.m" . If the desired make target is not "octave", the variable "make_arg" can be set prior to invoking make.m, to whatever make target is desired. James R. Phillips ---make.m script follows--- you may have to remove extraneous line breaks % MAKE % Script to invoke make, echo output to makeout.m, and invoke makeout.m. % make arguments are in the quoted string make_arg, which will be passed to % make unquoted. sed is used to comment out make messages. % Default make target is "octave". Override default by assigning a value % to make_arg before invoking. make_ifile='makefile'; make_ofile='makeout.m'; if exist('make_arg') ~=1 make_arg='octave'; end system(["make -f ",make_ifile," -n ",make_arg," | sed -e \"/make:/s/^/%/\" > ",make_ofile]); eval(strrep(make_ofile,'.m',''));