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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:23:31+00:00 2026-05-30T02:23:31+00:00

I want to create a Makefile (in a parent dir) to call several other

  • 0

I want to create a Makefile (in a parent dir) to call several other Makefiles (in sub dirs) such that I can build several binaries (one per project sub dir) by invoking just the one parent Makefile.

My research has been hampered by finding loads of stuff on recursive Makefiles, but I think this is where you are trying to build several directories Makefiles into a single binary?

Maybe what I want to do is better handled by a shell script perhaps invoking make in each sub directory in turn, but I thought a Makefile might be a more elegant solution?

any pointers gratefully received

PS using linux and the GNU tool chain

  • 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-30T02:23:33+00:00Added an answer on May 30, 2026 at 2:23 am

    The for loop solution given in the first answer above actually shouldn’t be used, as-is. In that method, if one of your sub-makes fails the build will not fail (as it should) but continue on with the other directories. Not only that, but the final result of the build will be whatever the exit code of the last subdirectory make was, so if that succeeded the build succeeds even if some other subdirectory failed. Not good!!

    You could fix it by doing something like this:

    all: 
            @for dir in $(SUBDIRS); \
            do \
                $(MAKE) -C $${dir} $@ || exit $$?; \
            done
    

    However now you have the opposite problem: if you run “make -k” (continue even if there are errors) then this won’t be obeyed in this situation. It’ll still exit on failure.

    An additional issue with both of the above methods is that they serialize the building of all subdirectories, so if you enable parallel builds (with make’s -j option) that will only happen within a single subdirectory, instead of across all subdirectories.

    Eregrith and sinsedrix have solutions that are closer to what you want, although FYI you should never, ever use “make” when you are invoking a recursive make invocation. As in johfel’s example you should ALWAYS use $(MAKE).

    Something like this is what you want:

    SUBDIRS = subdir1 subdir1 subdir3 ...
    
    all: $(addprefix all.,$(SUBDIRS))
    all.%:
            @ $(MAKE) -C '$*' '$(basename $@)'
    .PHONY: $(addprefix all.,$(SUBDIRS))
    

    And of course you can add more stanzas like this for other targets such as “install” or whatever. There are even more fancy ways to handle building subdirectories with any generic target, but this requires a bit more detail.

    If you want to support parallel builds you may need to declare dependencies at this level to avoid parallel builds of directories which depend on each other. For example in the above if you cannot build subdir3 until after both subdir1 and subdir2 are finished (but it’s OK for subdir1 and subdir2 to build in parallel) then you can add something like this to your makefile:

    all.subdir3 : all.subdir1 all.subdir2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a makefile with a rule to build several targets and create a
I want to create a makefile variable that is a multi-line string (e.g. the
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want create an application with animate button? how can i do? after click
I want to create a new field (or two) in my table that is
I want to use a exe that will create a triangle strip. I have
In my Makefile I want to create an environment variable using the current date
I'm currently trying to build a proper Makefile. What I want is full control
Possible Duplicate: Creating makefile Hello, I am trying to create the makefiles and configure

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.