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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:26:37+00:00 2026-05-26T20:26:37+00:00

I have a small set of source code files for C. I’m trying to

  • 0

I have a small set of source code files for C. I’m trying to piece together a Makefile for them that builds several different outputs from the same set of source code. Each output is customized using target-specific variables.

(The real-world example is firmware that runs on several different circuit board revisions but is built from the same source code and customized using conditional compilation.)

Here’s an example Makefile illustrating the problems I’ve running into:

CINPUTFILES = Testfile.c

all: v12target v13target

# the same source code is built several different ways depending on a
# list of preset configurations
v12target: lots_of_common_variables = hello
v12target: more_variables = v12_specific
v12target: Rev12Output.mycommontargets

v13target: lots_of_common_variables = hello
v13target: more_variables = v13_specific
v13target: Rev13Output.mycommontargets

# (more vXXtarget targets omitted)

# TODO:  why is @echo required?
%.mycommontargets: %.hex %.elf
    @echo

# TODO: why are these output files deleted?
%.elf: $(CINPUTFILES)
    cp $< $@

%.hex: %.elf
    cp $< $@

# TODO: correct way of adding the dummy mycommontargets to PHONY?
.PHONY : all clean

The idea is that the all target builds several different targets – one for each hardware revision. Because the build process for each is identical except for a list of configuration variables, it calls a number of vXXtarget targets which set variables and then call a common target: %.mycommontargets. This target then sets about generating the actual output files.

Notice the TODO marks…

  1. %.mycommontargets: for some reason, if I remove the @echo I get an error message:

    make: *** No rule to make target `Rev12Output.mycommontargets', needed by `v12target'.  Stop.
    

    Why does this happen and what do I need to do to get rid of it?

  2. If I leave the @echo in place, the build does successfully complete. But then make decides to go ahead and delete the outputs anyway!

    $ make
    cp Testfile.c Rev12Output.elf
    cp Rev12Output.elf Rev12Output.hex
    
    cp Testfile.c Rev13Output.elf
    cp Rev13Output.elf Rev13Output.hex
    
    rm Rev12Output.hex Rev12Output.elf Rev13Output.hex Rev13Output.elf
    

    Why does make do this? What decides when it will do this and when it does not? I never previously realized make even had the capability to delete files like this; it runs counter to the whole idea of incremental builds, which I thought make was supposed to help out with. I’d rather have all intermediate and output files retained…

  3. What’s the correct way of adding the mycommontargets pattern to .PHONY?

I suppose I could just leave @echo in place and then add each target to .PRECIOUS. But even though I don’t have a lot of experience with make, I have a strong feeling that I’m doing it wrong if I have to use a hack like @echo and use a more obscure special target like .PRECIOUS. Just doesn’t feel right.

(Apologies for appearing to ask 3 questions in the space for 1 question, but I have the feeling they are strongly related…)

  • 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-26T20:26:37+00:00Added an answer on May 26, 2026 at 8:26 pm
    1. The problem is that each non-phony target needs a rule to make it. However, you can’t make the targets of pattern rules phony. In your case, I’d advise to leave the @echo (better: replace it by @true to avoid a spurious line of output).
    2. The output files are intermediate files, i.e. not mentioned explicitly in the Makefile, but required by pattern rules. By default, make deletes all intermediate files. The easiest way to disable auto-deletion here is to mention the .SECONDARY target without prerequisites, i.e. add a line somewhere just saying:

      .SECONDARY :

    3. If you really need the .PHONY here, you have to live w/o pattern rules. Which is quite undesirable in your layout, so better let it be.

    Overall, I’d suggest a more orthodox layout here. Normally, you’d leave cross-compiling issues out of the Makefile and give the host board (autotools parlance: the host board is the board the software will run on) as an argument to configure. Let configure generate one build tree per host board from a central source tree, and build in these build trees.

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

Sidebar

Related Questions

I have a small (500kb) swing applet that displays very simple/limited set of small
I have a small project that builds a number of targets from the same
I have a package that imports 7 csv files and loads them into 7
Suppose you have some source code that comes from the unix world. This source
I have a small ajax application built with php. Using phpMyAdmin I have set
In my c# application i have this small form which is used to set
I have small utility that does some processing on a file and changes the
I'm trying to build a small app which allows downloading of multiple files at
I have android code that uses a background process to routinely (e.g. hourly) connect
I have a small dummy project in VS 2008, contains only the following code

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.