makefile question

This is a discussion on makefile question within the Tech Board forums, part of the Community Boards category; Can I verify in a makefile that a directory exists ? For example if the dir already exists and I ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    makefile question

    Can I verify in a makefile that a directory exists ?
    For example if the dir already exists and I do mkdir <dir> it gives me an error. and the scripts execution ends. I don't want that. Can I do the verification in the makefile?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Two ways...
    Code:
    default:
       - mkdir bin
       - mkdir bin
       - mkdir bin
    Attempt to make the directory, but do not exit the makefile on error.


    Code:
    default:
       if [ ! -d bin ]; then mkdir bin; fi;
       if [ ! -d bin ]; then mkdir bin; fi;
       if [ ! -d bin ]; then mkdir bin; fi;
    Test for the directory before attempting to make it.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Another way of doing it (which should be more portable than QuestionC's second method) is to set each directory as a target:

    Code:
    default: dirA dirB
    
    dirA:
       mkdir dirA
    
    dirB:
       mkdir dirB
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,252
    Quote Originally Posted by spank View Post
    Can I verify in a makefile that a directory exists ?
    For example if the dir already exists and I do mkdir <dir> it gives me an error. and the scripts execution ends. I don't want that. Can I do the verification in the makefile?
    Who cares about verifying if it's there. Use "mkdir -p", which won't fail if the directory already exists.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Compilation Question
    By chacham15 in forum C Programming
    Replies: 10
    Last Post: 10-12-2008, 08:15 PM
  2. A question about an interesting Makefile
    By meili100 in forum Tech Board
    Replies: 2
    Last Post: 08-12-2008, 03:56 PM
  3. about Makefile and Macro
    By tom_mk in forum C++ Programming
    Replies: 1
    Last Post: 09-18-2003, 01:07 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Makefile Newbie: Inheritance Question
    By Ashes999 in forum C++ Programming
    Replies: 2
    Last Post: 07-10-2003, 02:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21