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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:13:08+00:00 2026-06-09T02:13:08+00:00

I have a Makefile rule like the following: %.b : %.a [run some commands…]

  • 0

I have a Makefile rule like the following:

%.b : %.a
    [run some commands...]

I’d like to rewrite my Makefile such that all conversions from %.a to %.b are handled by a single execution of the commands rather than once for every file.

I’ve tried the following:

%.b : someDummyFile

someDummyFile : 
    [run some commands]

The problem is that the rule for creating someDummyFile gets executed even when the first rule doesn’t request it, leading to undesirable behavior. I’m guessing that rules without dependencies get executed all the time even when their targets are not used by some other rule?

What am I missing here?


In trying to debug this problem, I removed all references to the second rule. For instance, I insert the following rule into an existing Makefile, why does it get executed even when no other rules make reference to it?

HELLOWORLD :
    echo "# HELLO WORLD! THE NEXT LINE WILL TRIGGER AN ERROR"
    DFASDA
  • 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-09T02:13:10+00:00Added an answer on June 9, 2026 at 2:13 am

    Here’s a quick example that I think does what you’re looking for:

    all: file1.x file2.x
    
    %.x: doWork
        :
    
    doWork:
        touch file1.x
        touch file2.x
    

    The doWork rule will get run once, and then the : (no-op) in the %.x rule gets run twice. You do need the :, or at least something as a recipe for that rule, or else you’ll get an error about there not being a rule to make the .x file. That’s a side effect of the syntax used to cancel a pattern rule being a recipe-less rule.

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

Sidebar

Related Questions

I have a Makefile that looks like this CXX = g++ -O2 -Wall all:
I have the following start on a makefile rule (thanks to help from others),
I have the following implicit rule in a makefile: a1 b1: %: %.o On
I'm using GNU Make 3.81, and I have the following rule in my Makefile:
I have a makefile with something like the following targets: install: do a whole
I have the following makefile which is a slight modification on others that I
So i have a makefile here that looks something like ALL_FILES=$(shell find . -name
I have a Makefile rule that generates an MD5 hash for a file, compares
I currently have the following rule in a Makefile: ../obj/%.o: %.cpp mkdir -p ../obj/$<
So I have a makefile, and in that makefile is a rule that first

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.