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 9158361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:13:41+00:00 2026-06-17T13:13:41+00:00

I am trying to get make to automatically build some generated headers and then

  • 0

I am trying to get make to automatically build some generated headers and then create the depency (.d) files automatically. However I am not sure how to get make to do both targets correctly and in the right order.

Here is what I have so far:

all: test

test: test.o
    g++ test.o -o test

test.o: test.cc test.d external-headers
    g++ test.cc -c -o test.o

test.d: test.cc external-headers
    g++ -MM -MT $@ $< -o $@

external/some_header.hh:
    mkdir -p external
    touch external/some_header.hh

.PHONY: external-headers

-include test.d

external-headers: external/some_header.hh

Looking at the dependencies this looks correct, because I have to make the external header before I can create any .d file. Also if the external-headers are missing they will have to be regenerated. However this small Makefile causes GNU make to go into an endless loop. I used the debugging option, to find out, why it does this.

What I could see was, that make keeps restarting itself each time it recreates any included file. This is ok and what I would expect. However upon each restart, it recreates the external-headers target because it is phony. However although it does not have to create anything in the subsequent targets, this means a dependent target for the inclues has been rebuilt since the last invocation, so it rebuilds it’s includes and then restarts.

Is there a good solution to this problem? The simplest idea I had was to make the .d files dependent on the header external/some_header.hh directly and skip the target in between. When tested this works fine. However in the real situation, i have a whole bunch of generated headers, and I want to easily be able to rebuild all of them at once.

Another Idea I had, was to add a file somewhere which is actually called external-headers and touch this file each time this target is called. This way make could store when it last rebuilt the target and actually notice it won’t have to do anything.

Is there a better way to handle something like this?

  • 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-06-17T13:13:42+00:00Added an answer on June 17, 2026 at 1:13 pm

    The kludge around this is to generate the file as file.tmp, and replace file with file.tmp if they differ. That way make doesn’t see a new file, and doesn’t restart everything. Look at the Makefiles autotools creates with the ./configure dance, it uses that extensively.

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

Sidebar

Related Questions

I'm trying to make a simple ListView with optimistic concurrency. It uses the VS-automatically-generated
I'm trying to get a iOS client to make use of Yammer's Oauth2 to
I've been trying to get input with IUP to make a small pong game.
I have been trying to get yui-css grid system to make a three column
I am trying to get a list together of tools/libraries that make me more
I am trying to get the access key but I cannot make it work.
I get this error when trying to make the executable, the code compiles correctly
Trying to make a floating css menu. How do I get the floating div
I'm trying to make a query to get rush hours for everyday on a
I am trying to make an ajax GET request to a WCF web service

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.