I want to define a shell function
#!/bin/sh
test ()
{
do_some_complicated_tests $1 $2;
if something; then
build_thisway $1 $2;
else
build_otherway
Since the question is tagged gnu-make
, you might be happy with Beta's solution, but I think the best solution is to 1) rename the function anything other than test
(avoid names like ls
and cd
as well); for the purpose of discussion let's assume you've renamed it foo
, 2) simply write a script named foo
and invoke it from the Makefile. If you really want to define a shell function in the Makefile, just define it for each rule:
F = foo() { \
do_some_complicated_tests $$1 $$2; \
if something; then \
build_thisway $$1 $$2; \
else \
build_otherway $$1 $$2; \
fi \
}
all: bar
@$(F); foo baz bar
Not that you must have line continuations on each line of the definition of foo
, and the $
are all escaped so that they are passed to the shell.