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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:47:11+00:00 2026-06-02T01:47:11+00:00

Assume I have a make rule: .PHONY:gen gen: auto.template generate-sources auto.template that creates a

  • 0

Assume I have a make rule:

.PHONY:gen
gen: auto.template
        generate-sources auto.template

that creates a bunch of files, for example auto1.src, auto2.src, auto3.src and so on.

If I now have rules to build targets from *.src files, like this:

$(patsubst %.src,%.target,$(wildcard *.src)): %.target: %.src
        build $< > $@

How can I tell make to first execute the gen rule and then expand the preconditions for the second rule template? GNU extensions are welcome.

Note: I would like to keep it in one make invocation; A trivial solution to this would be to put the second rule in a secondary Makefile.secondrun and call $(MAKE) -f Makefile.secondrun after gen was processed. But I was wondering if there is a better option.

  • 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-02T01:47:12+00:00Added an answer on June 2, 2026 at 1:47 am

    Building off Beta’s answer, here’s how you can do it using makefile remaking in GNU make, which is not the same thing as recursive make. Rather, it updates an included makefile using a rule in the main makefile, then restarts the original make instance. This is how *.d dependency files are typically generated and used.

    # Get the list of auto-generated sources.  If this file doesn't exist, or if it is older 
    # than auto.template, it will get built using the rule defined below, according to the 
    # standard behavior of GNU make.  If autosrcs.mk is rebuilt, GNU make will automatically 
    # restart itself after autosrcs.mk is updated.
    
    include autosrcs.mk
    
    # Once we have the list of auto-generated sources, getting the list of targets to build 
    # from them is a simple pattern substitution.
    
    TARGETS=$(patsubst %.src,%.target,$(AUTO_SRCS))
    
    all: $(TARGETS)
    
    # Rule describing how to build autosrcs.mk.  This generates the sources, then computes 
    # the list of autogenerated sources and writes that to autosrcs.mk in the form of a 
    # make variable.  Note that we use *shell* constructs to get the list of sources, not
    # make constructs like $(wildcard), which could be expanded at the wrong time relative
    # to when the source files are actually created.
    
    autosrcs.mk: auto.template
            ./generate-sources auto.template
            echo "AUTO_SRCS=`echo *.src`" > autosrcs.mk
    
    # How to build *.target files from *.src files.
    
    %.target: %.src
            @echo 'build $< > $@'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have had to make changes to a trigger and assumed that running an
Assume I have a application that stores data,gets data and processes data and stores
Let's assume I have two Rails ActiveRecord models, CarType (make/model of car) and Car
Assume I have a histogram script that builds a 960 500 svg graphic. How
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
Assume I have a file at http://mysite.com/myscript.sh that contains: #!/bin/bash echo Hello $1 From
Lets assume i have a function that takes 32bit integer in, and returns random
I have a rule that works for one direction but, not the other. A
Assume I have encoded the natural numbers in Haskell types, and that I have
Assume I have three simple tables. How do I make the tables be inline

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.