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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:53:53+00:00 2026-06-07T06:53:53+00:00

Some days ago I posted an answer in stack overflow about how to write

  • 0

Some days ago I posted an answer in stack overflow about how to write a hierarchical make (http://stackoverflow.com/questions/1498213/make-hierarchical-make-file). The answer was deleted, therefore I assume that it was completely wrong or off topic (or both).

I would like to know how to write hierarchical Makefile. This is a Makefile that calls several Makefiles in sub-directories. I assume a directory structure like:

- project
  |--module1
      |--Makefile
      |--...
  |--module2
     |--Makefile
     |--module2.1
     |--module2.2  
     |--...
  |--module3
     |--Makefile
     |--...
  |--etc

I also assume that the project members have only agreed only upon a minimal set of makefile targets like: all (default), clean, install, and so. So, the following commands including make flags will be propagate to the modules:

cd project
make clean  
make -k
make install
#etc

What is wrong with the following project Makefile:

PACKAGES = \
    module1 \
    module2 \
    emodule3

VIRTUAL_PACKAGES = $(addsuffix /.virtual.Makefile,${PACKAGES})

TARGETS=clean install all

.PHONY: $(TARGETS)
default: all

FLAGS = $(ifeq $(MAKEFLAGS) "","",-$(MAKEFLAGS))

$(TARGETS): $(VIRTUAL_PACKAGES)

$(VIRTUAL_PACKAGES): 
    $(MAKE) $(FLAGS) -C $(@D) $(MAKECMDGOALS)

yes, the $VIRTUAL_PACKAGES in the Makefile looks odd. The alternative of mixing a for loop is a bit shorter but I am not sure if it is better (as I need to rely on bash):
PACKAGES = \
module1 \
module2 \
emodule3

TARGETS=clean install all

.PHONY: $(TARGETS)
default: all

FLAGS = $(ifeq $(MAKEFLAGS) "","",-$(MAKEFLAGS))

$(TARGETS): 
    for p in $(PACKAGES) ; do $(MAKE) $(FLAGS) -C $$p $@ || break; done

Thanks!

  • 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-07T06:53:55+00:00Added an answer on June 7, 2026 at 6:53 am

    There are “dragons” here. It can be done, but the implications can be tricky.

    Google, “Recursive Make Considered Harmful”. You will get very good (simple) illustrations of exactly what you want (e.g., hierarchical-make), plus good explanations of the pitfalls/concerns. Some of the “responses” will discuss possible “best-practices”, and ways to mitigate problems. Then, you can decide if the issues raised are compelling for your application or not.

    The original paper:

    http://miller.emu.id.au/pmiller/books/rmch/

    Some other links:

    http://c2.com/cgi/wiki?RecursiveMakeConsideredHarmful

    http://dbaspot.com/configuration-management/194597-thoughts-recursive-make-considered-harmful.html

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

Sidebar

Related Questions

I posted some days ago this question: How to intersect multiple polygons? . Now
Some days ago I asked a question about tagging differencies in 2 text files,
Some days ago I started using partitioning to make it possible to work with
My Eclipse is downloaded some days ago from http://www.eclipse.org/downloads/ and the type is Eclipse
some days ago i've posted a question for a win32 API stacktrace implementation with
Some days ago, I decided that it would be fun to write a streambuf
i created this ticked some days ago. http://trac.symfony-project.org/ticket/8922#preview I'm interested in creating a patch
This post is closely related to another one I posted some days ago .
I posted this question a few days ago, and I have some follow up
Some days ago I asked a question about my problem and I was advised

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.