KBEA-00035 - How file globbing affects Electric Make builds

Article ID:360032828212
2 minute readKnowledge base


File globbing refers to using the * wildcard to match files on a command line. In a makefile it might take this form:

This link command is run with a list of all objects found by creating a shell process and expanding *.o in it.


Why is file globbing an issue with Electric Make?

Whether or not file globbing works as desired is critically dependent on timing. As long as all required object files are present when *.o is evaluated in the example above, the command succeeds. If the evaluation is made before all objects are created, the link command has an incomplete list of input files and produces bad results. Because Electric Make (emake) runs jobs in parallel, it is possible that the rule that evaluates *.o will run before the rule(s) that create the .o files.

Doesn’t Electric Make detect dependencies and automatically resolve ordering problems?

Electric Make reads dependencies specified in makefiles and then monitors commands as they run to observe which files they touch. The difficulty with file globbing is that if it’s done at the wrong time, neither the dependency rule nor the command specification contain the necessary list of files. Emake has no way to know what is missing. Other parallel build tools will fail, too.

How do I solve file globbing problems?

There are three ways to address file globbing problems.

One possibility is to run parallel builds only with a good history file created from a one-agent build. When you run a build with a maximum of one agent, all jobs run in serial order. This forces the globbing steps to occur in the desired order and allows emake to detect their dependencies. Parallel builds run with the resulting history file will run correctly.

A second solution is to eliminate globbing, replacing it with definite lists of files.

A third solution is to add dependencies to your makefiles to force the steps to happen in the proper order. These are typically simple changes, either adding a dependency to an existing rule or breaking a rule in two to enforce ordering.

Applies to

  • Product versions: All

  • OS versions: All