How to include/import shell vars/exports in a Makefile (GNU/Make)
See https://unix.stackexchange.com/questions/235223/makefile-include-env-file and others.
How to include/import shell vars/exports in a Makefile (GNU/Make)
See https://unix.stackexchange.com/questions/235223/makefile-include-env-file and others.
#!/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')) |