Skip to content

Instantly share code, notes, and snippets.

@mcous
Last active June 10, 2020 17:23
Show Gist options
  • Save mcous/f384f8aba72bc05cca97e597ef1d3a21 to your computer and use it in GitHub Desktop.
Save mcous/f384f8aba72bc05cca97e597ef1d3a21 to your computer and use it in GitHub Desktop.
Makefile PATH bug on macOS 10.14 and later

Makefile PATH bug on macOS 10.14 and later

The make utility included in macOS 10.14 and later exhibits strange behavior that was not present in earlier versions of macOS and is also not present in newer versions of GNU make (e.g. the version installable via brew).

The shell spawned by tasks is unable to find executables in its $PATH. You can verify that the executable is in $PATH for the shell by using env or which. For some reason, if you chain any commands with &&, subsequent commands work.

reproduction

Clone this repository, and:

/usr/bin/make setup

broken in built-in make

/usr/bin/make broken

#> env
#> ...
#> PATH=.:/other/paths
#> ...
#> shell-script
#> make: shell-script: No such file or directory
#> make: *** [broken] Error 1
/usr/bin/make also_broken

#> which shell-script
#> ./shell-script
#> shell-script
#> make: shell-script: No such file or directory
#> make: *** [also_broken] Error 1

./shell-script is in the PATH, but make's shell can't find it, unless you:

weirdly working

/usr/bin/make works

#> env && shell-script
#> ...
#> PATH=.:/other/paths
#> ...
#> shell script success!

also weirdly working

/usr/bin/make also_works

#> sleep 0 && shell-script
#> shell script success!

workaround

Credit to @henrynash via Opentrons/opentrons#4809

PATH := .:$(PATH)
SHELL := env PATH=$(PATH) /bin/bash

# ...
SHELL := /bin/bash
PATH := .:$(PATH)
.PHONY: broken
broken:
env
shell-script
.PHONY: also_broken
also_broken:
which shell-script
shell-script
.PHONY: works
works:
env && shell-script
.PHONY: also_works
also_works:
sleep 0 && shell-script
.PHONY: setup
setup:
chmod +x ./shell-script
#!/usr/bin/env bash
echo "shell script success!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment