Is there a better way to source a script, which sets environment variables, from within a makefile?
FLAG ?= 0
ifeq ($(FLAG),0)
export FLAG=1
/bin/myshell -c '<source scripts here> ; $(MAKE) $@'
else
...targets...
endif
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To answer the question as asked: you can’t.
The basic issue is that a child process can not alter the parent’s environment. The shell gets around this by not forking a new process when
source‘ing, but just running those commands in the current incarnation of the shell. That works fine, butmakeis not/bin/sh(or whatever shell your script is for) and does not understand that language (aside from the bits they have in common).Chris Dodd and Foo Bah have addressed one possible workaround, so I’ll suggest another (assuming you are running GNU make): post-process the shell script into make compatible text and include the result:
messy details left as an exercise.