How to detect shell used in GNU make?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 23:24:03

问题


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

  • linux
  • windows
  • windows with cygwin (Note that on windows with cygwin the make uses cygwin shell)

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


回答1:


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})        


来源:https://stackoverflow.com/questions/40751021/how-to-detect-shell-used-in-gnu-make

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!