5

Is there an option to output the "preprocessed" makefile, something equivalent to the GCC's -E option?

I have a project comprised of an hierarchy of dozens of modules, each with its makefile. The build is invoked from a master makefile. That master makefile contains includes, variable definitions, command line option dependent variables, etc.

So, essentially, I am looking for the processed makefile, including all substitutions.

ysap
  • 7,723
  • 7
  • 59
  • 122

1 Answers1

4

Not that I'm aware of. The closest thing you can get to this is the output from make -qp (or similar) which will dump the make database out at you.

Part of the problem with this request is that many of the substitutions/etc. happen as targets are processed and the list of targets isn't necessarily known without actually attempting a build (at least to an extent) so it isn't necessarily possible to fully expand/etc. a makefile in-place.

The make -d output is also useful for certain incidental information related to how make has processed the makefiles but doesn't contain makefile contents directly.

Remake might also be able to provide some extra useful information.

If you are looking for the computed value of some assembled/etc. global make variable then this blog post by Eric Melski is likely to be very helpful.

tl;dr It adds a target like this to the Makefile (though there's more magic in the blog post so I suggest reading it).

print-%:
    @echo '$*=$($*)'
    @echo '  origin = $(origin $*)'
    @echo '  flavor = $(flavor $*)'
    @echo '   value = $(value  $*)'

Though in personal use I replaced that first line with something more like this

@echo '$*=$(subst ','\'',$($*))'

to keep the quoting of the result correct.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • Thanks. There was a lot of information (moer than 3,000 lines of output), and it requires some digging-into, but I guess that with enough time spent on it, one can figure out the required information. – ysap Jun 29 '15 at 20:05
  • @ysap What, specifically, are you trying to find out? There may be simpler ways to do it. (Actually, I'll add one often useful method I just remembered to the answer now.) – Etan Reisner Jun 29 '15 at 20:07
  • Basically, to reverse engineer a project, in order to create an IDE (Eclipse) based project. There are many modules, making a couple of libraries, and many are not compiled/linked into the final binary. There are module selection variables (switches) in one of the common makefile modules. – ysap Jun 29 '15 at 20:10