help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird (and convenient) difference between cygwin and DOS


From: Greg Chicares
Subject: Re: Weird (and convenient) difference between cygwin and DOS
Date: Thu, 24 May 2012 11:58:02 +0000
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 2012-05-24 08:37Z, Mason wrote:
> Eli Zaretskii wrote:
> 
>> Mason wrote:
>>
>>> I'm (grudgingly) running Windows, and I need some Makefile to
>>> work whether it is invoked from a bash shell under cygwin,
>>> or from Microsoft's CMD shell in the "DOS" command-line.
>>>
>>> (I'm using GNU Make 3.82, Built for i686-pc-mingw32)
>>>
>>> I've found a strange way to distinguish between cygwin
>>> and DOS, and I wanted to ask if it works by accident
>>> or by design, and if there is a "better" way (for any
>>> interpretation of "better").
>>>
>>> Right now, I do:
>>>
>>> ifdef windir
>>>   XX = DOS
>>> else
>>>   XX = CYGWIN
>>> endif
>>>
>>> and it seems to work, apparently because DOS keeps the environment
>>> variable in lower case, while CYGWIN sets it to upper case.
>>>
>>> What do you think?

I'd probably do something like this (which makes it easy to distinguish
other POSIX systems, in case the need arises):

uname_result := $(shell uname -s 2>NUL)

ifeq (CYGWIN,$(findstring CYGWIN,$(uname_result)))
  platform := cygwin
else
  platform := probably windows
endif

.PHONY: all
all:
        @echo $(platform)

When run under Cygwin, that has the distressing effect of creating a
'NUL' file that windows can't delete; but you could remove '2>NUL' and
live with "process_begin: CreateProcess(NULL, uname -s, ...) failed"
when running under windows.

>> I think you should use the Cygwin build of Make when you use Cygwin
>> tools and the MinGW build (the one you have) when you work with native
>> Windows tools.  Mixing them is asking for trouble, even though the
>> problems are subtle and may seem non-existent.
> 
> To tell the truth, I am indeed using Cygwin's gmake under Cygwin
> (/usr/bin/make = gmake 3.81 built for i686-pc-cygwin) and the
> i686-pc-mingw32 build under DOS.

BTW, the current Cygwin release is make-3.82.90 .

> But your remark doesn't address my main question: how do people
> create this kind of "portable" (GNU) makefile?
> 
> Right now, I need the test to set the RM command.
> 
> In Cygwin, I set RM = rm -f; In DOS, I set RM = del

CMD.exe and sh are so different that it can become difficult to
write "portable" commands. I tried it years ago, and found that
this idea worked better for me:

  http://lists.gnu.org/archive/html/make-w32/2002-03/msg00007.html
| You could install the ports of Bash and of all the other tools, and
| then do the same as on Unix.

IOW, assuming you can't require a Cygwin installation on every
machine, you can get ported tools from someplace like
http://gnuwin32.sourceforge.net/ .



reply via email to

[Prev in Thread] Current Thread [Next in Thread]