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

  • Home
  • SEARCH
  • 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 7883381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:31:00+00:00 2026-06-03T04:31:00+00:00

BACKGROUND We use Makefiles as one part of our regression suite. We have some

  • 0

BACKGROUND

We use Makefiles as one part of our regression suite. We have some default rules:

%.tmp_expect: ...
    @echo "Rule that produces results from the current tool version"

%.tmp_expect_filter: %.tmp_expect
    @echo "Take $*.tmp_expect and remove content specific to the machine/date"

%.tmp_expect_filter_sort: %.tmp_expect_filter
    @echo "Rule to sort $*.tmp_expect_filter"

Then these rules are used by the top level rules:

%.do: %.tmp_expect_filter_sort
    @echo "Create output using current version and diff against expected output"
    @diff $< $*.expect

%.genexpect: %.tmp_expect_filter_sort
    @echo "Generate 'goldstandard' expected output"
    @cp $< $*.expect

The ‘genexpect’ rule is called once for a test case and it generates what we call the ‘goldstandard’ output for the test. As development continues, the ‘do’ rule will check that the current version generates the same output as the ‘goldstandard’.

All of these rules are stored in their own special file “Make.Test” and then we include that file into the Makefiles in the directory with the regression tests.

PROBLEM

Sometimes we need a slightly different output than provided by the default %.tmp_expect. We do this by having the local Makefile implement it’s own %.tmp_expect rule. This works on all platforms we’re interested in: Windows, Linux & Solaris.

If, however, we don’t want the output to be sorted, I would have thought that we could add a rule such as:

%.tmp_expect_filter_sort: %.tmp_expect_filter
    @cp $< $@

This is where things become quite strange. Depending on the platform and if this rule appears before or after the inclusion of the ‘Make.Test’ file, it may or may not be selected.

So my questions are:

  1. How does make decide which rule to use for a given target?
  2. How should I write my rules so that I have control over which ones are selected?
  • 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-03T04:31:02+00:00Added an answer on June 3, 2026 at 4:31 am

    I’ve discovered a way to do this using more recent versions of make (from version 3.81).

    There is a new special target called .SECONDEXPANSION which can be used with a variable to help select between rules.

    The rules can be updated to include a variable expansion as part of the name of the prerequisites:

    %.tmp_expect_filter: %.tmp_expect
        @echo "Take $*.tmp_expect and remove content specific to the machine/date"
    
    
    .SECONDEXPANSION:
    %.tmp_expect_filter_sort: %.tmp_expect_filter$$($$*_FILTER_RULE)
        @cat '$<' | sort -n -t: -k 2 -k 3 > '$@'
    

    My rough understanding of this is that after the target has been determined, the $* is replaced in the prerequisite and it is then expanded a second time.

    For example, the in the target bar.tmp_expect_filter_sort, $* is replaced with bar resulting in %.tmp_expect_filter$(bar_FILTER_RULE). Unless bar_FILTER_RULE is actually set it will expand to nothing and the default rule will be used.

    To have it use a special rule, we can define the variable in our local Makefile:

    bar_FILTER_RULE=_custom
    %.tmp_expect_filter_sort_custom:
        @echo My custom rule here....
    

    The second expansion now results in %.tmp_expect_filter_sort_custom and so the custom rule will be used.

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

Sidebar

Related Questions

I have to design a form with an input inside it. I use background
Background: sometimes I use ps aux | grep process_name to figure out some statistics
Some Background I have been using Git for a while now. The projects that
I have a background method that is called every 5 minutes. That method use
Background: We use github for our project and I work on my own fork
update: some background - i use the xml file to generate a set of
Is it possible to use background and background-color for body in one time? body
I have run into a strange problem. When I use: background-image: url(none); in my
I'm a student new to android, and I have an application which use background
The background I use VS2010, DataGrid (the one delivered with WPF) and I manually

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.