Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect shell used in GNU make?

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.

like image 794
Vit Bernatik Avatar asked Oct 20 '25 13:10

Vit Bernatik


1 Answers

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})        
like image 200
Vit Bernatik Avatar answered Oct 23 '25 09:10

Vit Bernatik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!