Makefile make忽略我的python bash别名

Makefile make忽略我的python bash别名,makefile,bash,Makefile,Bash,我的CentOS 5.5服务器同时安装了Python 2.4和Python 2.7(到/opt/python2.7.2)。在我的~/.bash_配置文件中有两个别名指向我的Python 2.7安装和我的路径配置为: alias python=/opt/python2.7.2/bin/python alias python2.7=/opt/python2.7.2/bin/python PATH=$PATH:/opt/python2.7/bin 令我惊讶的是,我发现调用的是Python 2.4,而不

我的CentOS 5.5服务器同时安装了Python 2.4和Python 2.7(到
/opt/python2.7.2
)。在我的
~/.bash_配置文件中
有两个别名指向我的Python 2.7安装和我的
路径
配置为:

alias python=/opt/python2.7.2/bin/python alias python2.7=/opt/python2.7.2/bin/python PATH=$PATH:/opt/python2.7/bin 令我惊讶的是,我发现调用的是Python 2.4,而不是Python 2.7

我必须明确指定
python2.7

pythonbuild: python2.7 setup.py build pythonbuild: python2.7 setup.py构建
bash别名是否被
make
忽略?我猜
make
使用
PATH
来定位第一个
python
可执行文件(碰巧是python 2.4?

别名通常仅由交互式shell使用

请注意,我认为
make
并不总是调用shell 最好的办法是从
bash(1)
中明确说明要使用的路径:

虽然您可以在
Makefile
中使用类似于
SHELL=/bin/bash-O expand\u alias
的东西,但我认为在
Makefile
中保持对较新Python的显式依赖要比在用户
~/.bash\u配置文件中隐藏依赖要好得多

相反,将
PYTHON=/opt/python2.7/bin/PYTHON
放入您的
Makefile
,然后您就可以使用:

pythonbuild:
    $(PYTHON) setup.py build
按照你的规则

最好的部分是,您可以轻松更改在命令行上使用的Python解释器:

make PYTHON=/tmp/python-beta/bin/python pythonbuild

如果您将其部署到另一个站点,则只需更新
Makefile
中的一行。

使用grep和awk的解决方法:

此解决方案的优点是,如果我在~/.bash_profil或~/.bashrc中更改别名,我的makefile也会自动采用它

说明:

我想在我的makefile中使用别名lcw,它的定义与我的~/.bashrc文件类似

.bashrc

...
alias lcw='/mnt/disk7/LCW/productiveVersion/lcw.out'
...
我还使用了其他解决方案中给出的变量的定义,但我使用grep和awk直接从bashrc读取它的值

makefile

LCW= $(shell grep alias\ lcw= ~/.bashrc | awk -F"'" '{print $$2}')

.PHONY: std
std:
    $(LCW)
如您所见,lcw别名由makefile中的命令
$(lcw)
调用

注意:


我的解决方案假定bashrc中的别名定义在“”个字符内。

我很欣赏,并将此技术保留在find中。
make PYTHON=/tmp/python-beta/bin/python pythonbuild
...
alias lcw='/mnt/disk7/LCW/productiveVersion/lcw.out'
...
LCW= $(shell grep alias\ lcw= ~/.bashrc | awk -F"'" '{print $$2}')

.PHONY: std
std:
    $(LCW)