Skip to content

Instantly share code, notes, and snippets.

@dotmpe
Last active July 9, 2022 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotmpe/3edab10ac041c8fbbeb3c4b6e37109cc to your computer and use it in GitHub Desktop.
Save dotmpe/3edab10ac041c8fbbeb3c4b6e37109cc to your computer and use it in GitHub Desktop.
#!/bin/sh
foo=bar
fnmatch() { case "$1" in $2 ) return ;; esac ; return 1 ; }
#!/usr/bin/make
default:
.PHONY: default install
BASH := $(shell which bash)
export BASH_ENV=env.sh
$(info 0 foo=$(foo) $(shell echo foo=$$foo))
define test
echo 1 foo=$$foo
sh -c 'echo 2.1 foo=$$foo ' || true
sh -l -c 'echo 2.2 foo=$$foo ' || true
bash -c 'echo 3.1 foo=$$foo ' || true
bash -l -c 'echo 3.2 foo=$$foo ' || true
bash --posix -l -c 'echo 3.3 foo=$$foo ' || true
endef
test-1:
@$(call test)
test-2: SHELL := $(BASH)
test-2:
@$(call test)
test-0.0: SHELL := $(BASH)
test-0.0:
type fnmatch
# XXX: This does not work with CYGWIN, but does with Darwin, Linux
test-0.1:
type fnmatch
test-0: test-0.0 test-0.1
test: test-0 test-1 test-2
# This does not work (Darwin, CYGWIN, Linux):
SHELL := $(BASH)
export BASH_ENV=env.sh
$(info 8 foo=$(foo) $(shell echo foo=$$foo))
$(info 8 foo=$(foo) $(shell bash -c 'echo foo=$$foo'))
# But this does..
export foo=bar
$(info 9 foo=$(foo) $(shell echo foo=$$foo))
$(info 9 foo=$(foo) $(shell bash -c 'echo foo=$$foo'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment