romeovs
romeovs

Reputation: 5943

Function in makefile

I have a function in my .profile which I need in a makefile (one of the first ones I ever made). As far as I can tell make doesn't allow for interactively defined functions or aliases

How can I still make use of the function? This is defined in my .profile:

matlabs(){
    /Applications/Matlab.app/bin/matlab -nodesktop -nosplash -nojvm -r "disp('MATLAB:');${1}; quit();" | tail -n +11
}

And I would like to do this in the makefile:

num.txt : finance.m
    matlabs finance

Upvotes: 0

Views: 240

Answers (1)

Fred Foo
Fred Foo

Reputation: 363547

Makefiles aren't shell scripts. What you can do is make a shell script out of your matlabs function; put the following in an executable file matlabs somewhere in your PATH:

#!/bin/sh
/Applications/Matlab.app/bin/matlab -nodesktop -nosplash -nojvm \
   -r "disp('MATLAB:');${1}; quit();" \
  | tail -n +11

Alternatively, if you don't want the Makefile to depend on an external script and you need to do this transformation often, you can define an implicit Makefile rule for it:

%.txt : %.m
        @/Applications/Matlab.app/bin/matlab -nodesktop -nosplash -nojvm \
            -r "disp('MATLAB:'); $<; quit();" \
            | tail -n +11 > "$@"

Upvotes: 1

Related Questions