How to detect shell used in GNU make?

2019-07-27 02:24发布

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条回答
▲ chillily
2楼-- · 2019-07-27 02:34

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})        
查看更多
登录 后发表回答