# GNU make question

**URL:** <https://boards.straightdope.com/t/gnu-make-question/333093>\
**Category:** Factual Questions\
**Created:** [November 28, 2005, 7:36pm UTC](https://boards.straightdope.com/t/gnu-make-question/333093 "2005-11-28T19:36:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [November 28, 2005, 7:36pm UTC](https://boards.straightdope.com/t/gnu-make-question/333093/1 "2005-11-28T19:36:47Z")

</div>

I’ve got a makefile that needs to make a second makefile, but I’m running into problems using environment variables in the second one. I looked at the make documentation and don’t see anything helpful.

Basically, what I’ve got looks like this:

> [@makefile 1](#):
>
> cd \overhere; $(MAKE)

> [@makefile 2](#):
>
> cd $(foo); bar.exe

Here foo is defined in the machine environment. makefile 2 works just fine if I make it on its own, so I’m pretty sure that it’s a problem communicating between the two. Any ideas?

---

<div class="post-metadata">

**Author:** ![Emerald\_Hawk](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@Emerald\_Hawk](https://boards.straightdope.com/u/Emerald_Hawk)\
**Post date:** [November 28, 2005, 8:51pm UTC](https://boards.straightdope.com/t/gnu-make-question/333093/2 "2005-11-28T20:51:40Z")

</div>

Hmm, make normally should keep you in the same environment. Have you tried adding \> or | or any shell-interpreted symbol to the make command? In your example, you could do:

cd \overhere; $(MAKE) \> /tmp/junk

I think this forces make to pass the command to the shell instead of running it itself, which may help you. Other than that I’m stumped.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [November 28, 2005, 8:53pm UTC](https://boards.straightdope.com/t/gnu-make-question/333093/3 "2005-11-28T20:53:51Z")

</div>

I ended up moving the call to makefile 2 into a .bat file (that I was using anyway for some other stuff), and now everything’s happy. Thanks for the suggestion, though.
