I rewrote my makefile a while back to get the benefit of greedily searching for and compiling all sources under some root folder. I'm very happy with it except for the fact that the source libraries I include as submodules tend to have a lot of junk files, e.g. examples, tests, or other sources I don't need... and the make process chokes on these. This is where I am at currently.

So I've come back around to seeing why it can be better to explicitly list sources. The problem with that is that one must always remember to amend the Makefile whenever new sources are added to the tree. That's tedious, and the reason I went initially with the above.

I'm now beginning to wonder if there isn't some method to allow a mix of the two. For example, what if certain folders had a manifest in them that specified certain files to compile, while other folders without a manifest caused the makefile to default to "compile all herein"?

I'm newish to make, so does this sound wise or unwise? Advice on how to set it up? Pitfalls?

P.S. I've considered sparse checkout of submodules to solve the matter without changing my current makefile, but SourceTree does not support this yet, and I rely heavily on it for my use of git.


You are asking for a technological solution to a non-technological problem.

You have these constraints:

  • All files with certain extensions below a directory are source code files that are part of the project.
  • Except people randomly make additional files that violates the first constraint.
  • Except some random additional files do not violate the first constraint.

Your options include:

  • Teach people to use a naming convention for temporary files.
  • Ignore the file system and compile the source code control system.
  • Compile only what compiled last time and ask about new files.
  • Make lots of different combinations of compilations and keep only the ones that compile.
  • Figure out how to compile quickly enough that it doesn't matter. (The Go language has this as a design constraint.)

There is really no way to completely have your cake and fully eat is as well.

  • It's not a "can't do". It is a "when you do this, you break something". You can optimistically link the combinatorial set of all successfully compilation units. You cannot guess the intent of what should be included given no information. – Charles Merriam Sep 26 '15 at 19:29
  • It is a worthwhile perspective in any case. +1. – Engineer Sep 26 '15 at 19:30

A hybrid solution was indeed the final outcome.

My makefile now contains two separate variables:

  1. a list of directories which may be searched both exhaustively AND recursively for sources to compile - this is used for the main application code over which I have control and which also changes very often, thus I need not explicitly add/remove sources to/from the makefile whenever I add/remove to/from the application's source tree;
  2. a list of explicit, cherry-picked sources - this used for libraries over which I have no control and where I thus must pick individual sources in order to avoid compiling unwanted sources like tests and examples.

...By combining these two into a single list, I now have my full source list to pass to $CC, with greater control and only marginally less convenience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.