无法在makefile内调用bash函数
我有一种印象,我可以在GNU makefile中调用bash函数,但似乎是错误的。这是一个简单的测试,我定义了这个函数:无法在makefile内调用bash函数,makefile,gnu-make,Makefile,Gnu Make,我有一种印象,我可以在GNU makefile中调用bash函数,但似乎是错误的。这是一个简单的测试,我定义了这个函数: >type lsc lsc is a function lsc () { ls --color=auto --color=tty } 这是我的Makefile: >cat Makefile all: lsc 以下是我在跑步中得到的: >make lsc make: lsc: Command not found make: *** [a
>type lsc
lsc is a function
lsc ()
{
ls --color=auto --color=tty
}
这是我的Makefile:
>cat Makefile
all:
lsc
以下是我在跑步中得到的:
>make
lsc
make: lsc: Command not found
make: *** [all] Error 127
我的印象不对吗?或者是否存在任何环境设置问题?我可以在命令行中运行“lsc”。是否使用“export-f”导出函数
bash是Makefile的shell还是sh?不能在Makefile中调用bash函数或别名,只能调用二进制文件和脚本。但是,您可以调用交互式bash并指示它调用您的函数或别名:
all:
bash -i -c lsc
例如,如果在
.bashrc
中定义了lsc
,请在BASH脚本中使用$*
:
函数。sh
_my_function() {
echo $1
}
# Allows to call a function based on arguments passed to the script
$*
Makefile
test:
./functions.sh _my_function "hello!"
运行示例:
$ make test
./functions.sh _my_function "hello!"
hello!
如果从问题中使用此选项,则可以从shell文件导入所有shell脚本函数 如果您愿意,您甚至可以不使用
.ONESHELL
,只需使用冒号,就可以在一行中完成所有操作代码>在导入shell脚本之后:
my_target: dependency
. ./shell_script.sh; my_imported_shell_function "String Parameter"
假设compile是您.bash\u配置文件中的一个函数
.bash_简介
compile(){
...
}
生成文件
ACTIVE_ENV=source ~/.bash_profile
default:
$(ACTIVE_ENV) && compile boot_sect_simple.asm c
另一条信息:当我尝试复制此命令时,我将命令typelsc
添加到规则中,它给出了正确的答案——但是命令lsc
仍然失败。是的,我尝试了“export-f”,而不是帮助。不确定你的第二个问题的意思是,我的shell是bash,我在其中运行make。你设置了shell变量了吗?请参见此处:“如果未在makefile中设置此变量,则程序/bin/sh将用作shell。”
ACTIVE_ENV=source ~/.bash_profile
default:
$(ACTIVE_ENV) && compile boot_sect_simple.asm c