tags:

views:

139

answers:

4

Hi,

I have a very large code, a lot of which is legacy code. I want to know which of all these files are taking part in the compilation. The code is written in GNU compilers and mostly in C/C++, but some in other programs too. Any advice will be highly appreciated.

Thanks,

Moshe.

I am compiling under linux with a mix of scripts/makefiles. I want to somehow 'wrap' this build with a tool which will give an output of all the source files used in the build, preferably with absolute path names.

What do you say?

A: 
  1. How do you build the application? I.e. what do you type at the terminal to build it?
  2. Depending on your answer to (1), find the relevant program used for the build (i.e. make, scons, etc.)
  3. Now find the input file(s) to that build program, like Makefile, SConstruct, etc.
  4. Look into this build file and other build files used by it to figure out which source files go into the build
Eli Bendersky
Hi Eli, your solution can surely work. Yet, as much of the code is legacy code (including many of the make files etc.), I would prefer finding a "wrapper" program of some sort which might be able to filter the data for me. Thanks Moshe.
Moshe
+5  A: 

If you want to show included headers then whether that's supported and how to do it depends on the compiler.

E.g.,

C:\test> (g++ --help --verbose 2>&1) | find "header"
  -print-sysroot-headers-suffix Display the sysroot suffix used to find headers
  --sysroot=<directory>    Use <directory> as the root directory for headers
  -H                          Print the name of header files as they are used
  -MG                         Treat missing header files as generated files
  -MM                         Like -M but ignore system header files
  -MMD                        Like -MD but ignore system header files
  -MP                         Generate phony targets for all headers
  -Wsystem-headers            Do not suppress warnings from system headers
  -print-objc-runtime-info    Generate C header of platform-specific features
  -ftree-ch                   Enable loop header copying on trees

C:\test> (cl /? 2>&1) | find "include"
/FI<file> name forced include file      /U<name> remove predefined macro
/u remove all predefined macros         /I<dir> add to include search path
/nologo suppress copyright message      /showIncludes show include file names

C:\test> _

In the above you can see the relevant options for respectively g++ and Visual C++.

Cheers & hth.,

– Alf

Alf P. Steinbach
+1  A: 

Two options come to mind.

  1. Parse the compilation log

    Run a build, save the log, and then search in the log.

  2. Find the files that are opened during the compilation time.

    A way to do that might be to use a system tracing tool like strace or library tracing tool like ltrace and then look out for file open calls.

    See also http://stackoverflow.com/questions/880263/how-can-i-detect-file-accesses-in-linux

ArunSaha
A: 

For a given compilation unit, e.g. foo.cpp, add the flags -E -g3 to the call of g++. This gives you the preprocessed code. There you can look which things are included.

swegi