This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: if construct doesn't work in makefile


> -----Original Message-----
> From: cygwin-owner On Behalf Of Prasad, Kanuparthi
> Sent: 11 November 2004 11:16

>   In my make file I am trying to check whether a directory 
> exists or not
> then set a path differently if doesn't exist.
>   I am using cygwin installed on windows 2000.
>   The if construct I have is as follows.
> 
>   if test [-dc:/tools]; then DRIVE = c:/tools; else DRIVE = 
> c:/altTools; fi


  Oh, and by the way, another way you can do this, using only makefile syntax so
it doesn't involve the shell at all, is to use the $(wildcard ...) function with
a full filename to see if it exists, and then use that in a $(if ...) test.
Like so:

DRIVE=$(if $(wildcard c:/tools), c:/tools, c:/altTools)

This technique has the advantage of working whether you're using make in --win32
or --unix mode:

dk@mace /tmp/bgcc> ls -la C:/tools
ls: C:/tools: No such file or directory
dk@mace /tmp/bgcc> cat makefoo

DRIVE=$(if $(wildcard c:/tools), c:/tools, c:/altTools)

all:
        echo drive is ${DRIVE}

dk@mace /tmp/bgcc> make -f makefoo
echo drive is  c:/altTools
drive is c:/altTools
dk@mace /tmp/bgcc> make --win32 -f makefoo
echo drive is  c:/altTools
drive is  c:/altTools
dk@mace /tmp/bgcc> mkdir C:/tools
dk@mace /tmp/bgcc> make -f makefoo
echo drive is  c:/tools
drive is c:/tools
dk@mace /tmp/bgcc> make --win32 -f makefoo
echo drive is  c:/tools
drive is  c:/tools
dk@mace /tmp/bgcc>

since it depends only on the cygwin dll's path-handling abilities, and not on
the nature of the shell that is being used to execute the commands.




    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]