I have an impression that I can call bash function inside GNU makefile, but seems wrong. Here is a simple test, I have this function defined:
>type lsc
lsc is a function
lsc ()
{
ls --color=auto --color=tty
}
Here is my Makefile:
>cat Makefile
all:
lsc
Here is what I get in running make:
>make
lsc
make: lsc: Command not found
make: *** [all] Error 127
Is my impression wrong? Or is there any env setup issue? I can run "lsc" at the command line.
Use $*
in your BASH script:
functions.sh
_my_function() {
echo $1
}
# Allows to call a function based on arguments passed to the script
$*
Makefile
test:
./functions.sh _my_function "hello!"
Running example:
$ make test
./functions.sh _my_function "hello!"
hello!
You cannot call bash functions or aliases in a Makefile, only binaries and scripts. What you can do however, is calling an interactive bash and instruct it to call your function or alias:
all:
bash -i -c lsc
if lsc
is defined in your .bashrc
, for example.
Did you export your function with "export -f"?
Is bash the shell of your Makefile, or is is sh?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With