shell - 如何在 GNU Make 中修改 PATH 并成功使用 $(shell ...) 执行命令?
问题描述
背景:我有一个定制的工具链,应该由 Makefile 使用。工具链被检出(通过 svn:externals)到项目的工作副本中。Makefile 必须适应PATH
变量。否则无法找到工具链二进制文件。在“.bashrc”或“.profile”中调整“PATH”是没有选择的,因为有几个项目使用不同版本的工具链。
请看这个最小的 Makefile,它展示了对交叉编译器 'cc' 的调用,它位于 '/home/edeviser/bin' 中的其他几个工具旁边:
export PATH:=/home/edeviser/bin:$(PATH)$
$(info Compiler used: $(shell which cc))
all:
@echo "Compiler used: $(shell which cc)"
@echo -n "Compiler used: "
@which cc
调用后的输出make
:
Compiler used: /usr/bin/cc
Compiler used: /usr/bin/cc
Compiler used: /home/edeviser/bin/cc
我的期望是:
Compiler used: /home/edeviser/bin/cc
Compiler used: /home/edeviser/bin/cc
Compiler used: /home/edeviser/bin/cc
如何在 GNU Make 中修改 PATH 并成功使用 $(shell ...) 执行命令?
解决方案
您必须编写这样的shell
调用:
$(info Compiler used: $(shell PATH='$(PATH)' which cc))
在shell函数中设置PATH。
推荐阅读
- python - Python - Spark - HiveContext - 找不到表
- php - 如何在 php 7 中的数组中使用追加数据
- maven - 大于 Google 云平台中 [33554432] 的最大允许大小
- c - QuickSort 排序正整数,有时排序后第一个值为负整数
- python - Python - 变量名称中的变量?
- javascript - 数组中的元素似乎未定义,除非记录整个数组
- javascript - 带有圆形填充文本的jQuery画布动画
- java - 单击按钮时删除 ListView 条目 - Android
- javascript - 如何解决 Angular 中的 firebase 登录身份验证的可观察问题
- lilypond - Lilypond:新员工与前员工在同一条垂直线上