如何检测GNU make中使用的shell? [英] How to detect shell used in GNU make?

查看:90
本文介绍了如何检测GNU make中使用的shell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测gnu make将使用的shell?我希望我的品牌可以在以下平台上运行:

How can I detect shell that will be used by gnu make? I want my make to be running on following platforms:

  • Linux
  • windows
  • 装有cygwin的Windows(请注意,在装有cygwin的Windows上,make使用cygwin shell)

然后,我想检测gcc是否独立存在于OS上的系统上.

Then I would like to detect if gcc is present on the system independently on OS.

推荐答案

到目前为止,我提出了以下解决方案:

So far I come up with this solution:

# detect what shell is used
ifeq ($(findstring cmd.exe,$(SHELL)),cmd.exe)
$(info "shell Windows cmd.exe")
DEVNUL := NUL
WHICH := where
else
$(info "shell Bash")
DEVNUL := /dev/null
WHICH := which
endif

# detect platform independently if gcc is installed
ifeq ($(shell ${WHICH} gcc 2>${DEVNUL}),)
$(error "gcc is not in your system PATH")
else
$(info "gcc found")
endif

可选地,当我需要检测更多我可以使用的工具时:

optionally when I need to detect more tools I can use:

EXECUTABLES = ls dd 
K := $(foreach myTestCommand,$(EXECUTABLES),\
        $(if $(shell ${WHICH} $(myTestCommand) 2>${DEVNUL} ),\
            $(myTestCommand) found,\
            $(error "No $(myTestCommand) in PATH)))
$(info ${K})        

这篇关于如何检测GNU make中使用的shell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆