如何检测GNU make中使用的shell?

时间:2016-11-22 20:28:42

标签: makefile gnu-make

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

  • linux
  • windows
  • 使用cygwin的窗口(请注意,在使用cygwin的windows上,make使用cygwin shell)

然后我想在OS上独立检测系统中是否存在gcc。

1 个答案:

答案 0 :(得分:1)

到目前为止,我提出了这个解决方案:

# 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

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

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