Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3426562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:43:51+00:00 2026-05-18T06:43:51+00:00

According to what I have read about makefiles, a phony target is any target

  • 0

According to what I have read about makefiles, a phony target is any target that does not correspond to an actual filename. My intuition says that a directory as a target would be treated the same as a file.

Why is this important? I have a directory as a target in my makefile. when I have it as a prerequisite to my primary executable, that executable always gets made, whether or not everything is up to date. If I take it out as a prerequisite, my makefile is smart enough to know when things need to be built, but I have the problem of not knowing if the directory needs to be created. According to what I have read about make, any phony targets are not good as prerequisites because make does not know if they are up to date, so they will always rebuild the associated target. Here is an excerpt from my makefile.

$(EXEC_WITH_PATH): ${OBJ_DIR} $(DPEND) $(OBJS)
    @echo "--------------------------------------------";
    @echo "$(THIS_DIR)  $(MACHINE)";
    @echo "Linking Shared Library";
    @echo "ar -rc $(EXEC_WITH_PATH) INSERT::{OBJS}";
    ar -rc $(EXEC_WITH_PATH)  $(OBJS);
    @echo "--------------------------------------------";


# Make dirs for object code and links
${OBJ_DIR} :
        @if [ ! -d ${OBJ_DIR} ]; then \
                mkdir ${OBJ_DIR};    \
        fi;

So in this case, is ${OBJ_DIR}, a directory name, a phony target or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:43:52+00:00Added an answer on May 18, 2026 at 6:43 am

    Edit: This only applies to GNU make – a fair assumption given the “linux” tag.

    Your target is a real target, not a PHONY one. The problem is that the output directory gets updated when you put targets in it so that it is always newer than your target. This means your target will always get built because it is out of date with respect to its dependencies.

    What you need is an order-only prerequisite. These prerequisites allow you to specify that it needs to be built if it does not exist, but not to pay attention to the timestamp. That is, a target will not be out of date with respect to order-only prerequisites.

    You specify it like this:

    $(EXEC_WITH_PATH): $(DPEND) $(OBJS) | ${OBJ_DIR}
    ...
    

    Anything after the vertical bar is an order-only prerequisite.

    You can now make your OBJ_DIR target simpler:

    ${OBJ_DIR} :
            mkdir -p ${OBJ_DIR}
    

    Note: I’ve used the ${OBJ_DIR} syntax instead of $(OBJ_DIR) because that is what you used. Order-only prerequisites do not depend on that syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I have read about that I can write Objective-C app on Linux (using
According to a book I have (Eclipse for Minor Geniuses or something like that),
I have a web application that's branded according to the user that's currently logged
I have read about windows workflow foundation where people use this to model a
All articles I've read about localization of a WinForms application assume that I already
I am planning an informational site on php with mysql. I have read about
I have lately been trying to read about how everything with strings and encodings
I'm fairly new to DDD and have read a few articles about the concept
There's something I just don't get about guice: According to what I've read so
I am creating a database based on a ERD i have designed according to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.