Date: Tue, 27 Oct 1998 20:14:38 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: bowman cc: djgpp AT delorie DOT com Subject: Re: Recursive make: portable technique? In-Reply-To: <36337F9D.12147CDB@montana.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com On Sun, 25 Oct 1998, bowman wrote: > I'm really getting confused here. If command.com never sees the cd > command, in v3.77, what breaks when bash isn't present? Nothing breaks; it's a feature, not a bug. Here's a somewhat lengthy explanation. The current working directory in DOS/Windows is a global notion (on Windows it is global to the current virtual machine, aka DOS box). So when Make calls `chdir' (actually, DJGPP's `system' does that when it gets "cd foo"), the new directory is now global for all programs, until it is explicitly changed by another `chdir'. In contrast, on Unix, the current working directory is local to the program that calls `chdir'. So when the commands invoked by Make exit, the previous working directory is automagically ``restored''. Since there's no such magic on DOS/Windows, Make must chdir back when the commands it invoked exit, if it wants to restore the original directory. The DJGPP port of Make indeed does that, but only when Make itself is about to exit (so you wind up in the same place where you invoked Make); that is why "make -C foo" works in recursive sub-makes. However, the DJGPP port does NOT restore the original directory after running each command line in the rules. This is done on purpose, because most other DOS-based Make's don't support multiple commands on a single line like the DJGPP's port does. The only way to have some command run on DOS in another directory without having such a feature is like this: foo: bar cd bardir run-program-which-makes-foo If our Make would restore the directory after each line in the rules exits, Makefiles which use this (and there are a lot of them) will all break. So we don't do this. When Bash is your shell, Bash itself restores the directory when the command it runs exits (this is a special feature of the DJGPP port of Bash, since on Unix Bash doesn't have to care about this). So every command that needs a shell to run will preserve the directory when Bash is the shell (a line which calls `cd' will call the shell, since make knows that `cd' is an internal shell command).