Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a makefile dependency / inheritance tree

Apologies if I explain this badly or am asking something bleeding obvious but I'm new to the Linux kernel and kinda in at the deep end...

We have an embedded-linux system which arrives with a (very badly documented) SDK containing hundreds of folders of stuff, most folders containing a rules.make, make, make.config or some variation of... and the root folder containing a "master" makefile & rules.make which mean that you can, from the root folder, type "make sysall" and it builds the entire package.

So far so good, but trying to debug it is a bit of an issue as the documentation will say something like:

"To get the kernel to output debug messages, just define #outputdebugmessagesplz"

OK, but some of these things are defined in the "master" make/rules file, some of these are defined in the child make/rules/config files, some are in .h files... and of course it's far nicer to turn these things on/off from the "top" make.config rather than modifying individual .h files and then having to remember to turn them off again.

So I thought it would be a useful thing to recursively build a tree, starting from the master "make" file and following everything it does, everything that gets defined or re-defined, etc... but there doesn't seem to be a simple way of doing that?

I assume I am missing a "make" option here that spits this info out, or a usage of the makefile/config that will just work?

like image 939
John U Avatar asked Jan 28 '13 13:01

John U


1 Answers

Your situation is not uncommon. When developing for embedded systems, you might encounter many custom systems that solve a problem in a specific way. As people already commented on your question, there's no easy way to generate a dependency graph for your makefile structure/framework. But there are some things you can try, and I'll try to base my suggestions based on your situation. Since you've said:

Im new to the Linux kernel and kinda in at the deep end...

and

We have an embedded-linux system which arrives with a (very badly documented) SDK containing hundreds of folders of stuff

You could try the following things:

  • If your SDK is provided by a third-party vendor, try contacting them and get some support.
  • SDK's usually provide an abstraction to work with several components without a deep understanding of how each one of them really works. Try to pinpoint your problem, like if you want to customize only the kernel configuration, you could find the linux kernel folder on your SDK (assuming your SDK is composed of a set of folders with things like libraries, source code of applications and stuff, one of them might be the kernel one) and run make menuconfig. This will open a ncurses-based configuration GUI that you can navigate and choose kernel options.
  • As people already pointed out, you can try to run make -n and check the output. You could also try to run make -p | less and inspect the output, but I don't recommend this since it will only print the data base (rules and variable values) that results from reading the makefiles. You would have to parse this output to find out what you want in it.

Basically, you should try to pinpoint what you want to customize and see how this interacts with your SDK. If it's the kernel, then working only with it will give you a starting point. The linux kernel has its own makefile-build system, named kbuild. You can find more information about it at the kernel's Documentation folder.

Besides that, trying to understand how makefiles work will help you if you have a complex makefile structure controlling several components. The following are good resources to learn about makefiles:

GNU Make official documentation

O'Reilly's Open Book "Managing Projects with GNU Make"

Also, before trying to build your own tool, you can check if there's an open source project that does what you want. A quick search on google gave me this:

  • makegrapher

Also, check this question and this one. You might find useful information from people that had the same problems as you did.

Hope it helps!

like image 142
Daniel Noguchi Avatar answered Sep 17 '22 12:09

Daniel Noguchi