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

The Archive Base Latest Questions

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

I have a very simple Makefile that isn’t doing what I expect it would

  • 0

I have a very simple Makefile that isn’t doing what I expect it would do. The ultimate goal is that it should call itself recursively, including the appropriate file each time, resulting in a build specific to what was included (I’m building several projects that all share the same code base, but utilize different combinations of the source files). I’ve never really dealt with recursive calls to make, so I must be missing something obvious. At the moment, I only have one .mk file in the same folder as my Makefile. It’s a simple one-liner just for the purposes of this test. It will eventually contain various per-project settings.

Makefile:

SHELL = /bin/sh

ifdef MYFILE
include $(MYFILE)
PROGRAM = $(basename $(MYFILE))
endif

all: $(wildcard *.mk)

dummy:
        @echo -- Entering dummy stub ... why do I need this?

%.mk: dummy
        @echo Calling $(MAKE) MYFILE=$@ $*
        $(MAKE) MYFILE=$@ $*

$(PROGRAM): objs
        @echo Time to link!

objs:
        @echo Building objs!

test.mk

SOMEVAR = SomeValue

I have the following two problems:

Problem 1

If I remove the dummy prerequisite from my pattern rule, the pattern rule never gets called (I get the dreaded ‘Nothing to be done for all’ error). Is there a way I can get the recipes under the %.mk rule to run without needing that dummy prerequisite?

Problem 2

Given the two aforementioned files, I would expect make to do the following:

  1. make[1] starts and hit the all rule
  2. make[1] jumps down to the %.mk pattern rule
  3. make[1] calls itself recursively (the call would look like make MYFILE=test.mk test)
  4. make[2] starts, includes the test.mk file, and sets up the PROGRAM variable
  5. make[2] jumps down to the $(PROGRAM) rule (since we were explicitly called with that target)
  6. make[2] jumps to the objs rule, runs the recipes, and returns back up the chain

In actuality, make gets stuck on the %.mk pattern rule and enters an infinite loop. I don’t understand why it’s insisting on hitting the pattern rule, when I explicitly told it to build test in my first recursive call (which should correspond to the $(PROGRAM) target). What am I missing here?

  • 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-03T13:57:04+00:00Added an answer on June 3, 2026 at 1:57 pm

    Problem 0:
    This is overdesigned. You don’t need to use recursive Make here.

    Problem 1:
    The reason Make doesn’t try to rebuild test.mk (without a dummy preq) is that test.mk is up to date. A better approach is to switch to a static pattern rule and use PHONY:

    MKS = $(wildcard *.mk)
    .PHONY: $(MKS)
    
    $(MKS): %.mk:
        @echo Calling $(MAKE) MYFILE=$@ $*
        $(MAKE) MYFILE=$@ $*
    

    An even better approach is not to use the name of a real file as a target of a rule that doesn’t rebuild (or even “touch”) that file.

    Problem 2:
    In make[2], the makefile includes test.mk. If a makefile includes another file, Make will attempt to rebuild that file before doing anything else. If there is a rule for that file (which there is) and if it succeeds (which it does) Make then reinvokes itself.

    You should reconsider this design from the ground up. There are many ways to get the behavior you’re looking for, depending on the specifics (how many variable will be defined in a foo.mk? do you really want to manage the build by manually moving those files around? and so on).

    P.S. Here’s one kludge that springs to mind. Whether it suits your case depends on the specifics:

    makefile:

    # includes nothing
    
    %.mk: dummy
            @echo Calling $(MAKE) MYFILE=$@ -f $@ $*
            $(MAKE) MYFILE=$@ -f $@ $*
    

    test.mk:

    SOMEVAR = SomeValue
    include makefile
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple python script that should scan a text file, which
I have a very simple makefile, that basically does the following: # Pre-compiled header
Hopefully this is a very simple question. I have a makefile pattern rule that
I have a very simple webforms app that will allow field techs to order
I have a very simple Setup project that copies three dlls into the GAC.
I have a very simple iPhone app that requires a random integer from 1-100.
I have a very simple Mac Cocoa app that just has a Web View
I have two very simple, identical UITableViews in my app that are populated with
I have very simple query that calls a UDF which splits a field by
I have a very simple makefile: all: @for i in 1 2 3;\ do

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.