I have a large source tree and somewhere inside I have a file with a main function and I want to generate a makefile without resolving all dependencies (include directories and necessary c files) manually. So the tool would need to search starting from the main folder and going up and down the file tree to find the included files that are "closest" to the main file.
3 Answers
Cmake will do partly what you're asking for. You can always start with a strong project template.
I suggest you take a look at c-template.

- 446
- 2
- 11
-
1Thanks I'll have a look at it. – Eltges Sep 09 '15 at 14:09
There is the free tool HWUT, a unit test tool which does the job! HWUT at Sourceforge
HWUT does it out of the motivation to facilitate the setup of unit tests. You might install 'ctags' (hwut will use it automatically). Otherwise, HWUT analyses the code using a compiler's object file output (which is notoriously slow).
Once, you have hwut installed you call it simply with
> hwut sos your.c --root some/root/dir another/root/dir --args -DMyCompilerArg -DAnother Arg --
It will start searching for include files, source files, object files, and libraries in "some/root/dir" and "another/root/dir". Starting from "your.c" file it will search for all required references and headers and generate a nicely formatted Makefile. If the project is still too large, you might specify sets of root directories to search for sources, includes, and libraries separately.
- --root-sources ... for root directories where to search for sources
- --root-includes ... from where to search for include headers
- --root-libraries ... where to search libraries
- --root-objects ... where to search for objects
BTW: There is a 'sols' (safe our laze souls) mode which directly generates test files for all functions in a module, i.e.
hwut sols "module-to-test.c"
will not only generate a Makefile but a battery of test files that serve as a starting point for writing tests.

- 3,182
- 27
- 51
Note, if you already have a gcc
compile line with the appropriate include paths you can have the compiler auto-generate a list of
dependencies for the included .h
files. See the -MM option.

- 11,500
- 2
- 29
- 45
-
1That is not the case, but this is still an interesting option to know. Thanks – Eltges Sep 10 '15 at 07:26