views:

304

answers:

1
+3  Q: 

perfect makefile

I'd like to use make to get a modular build in combination with Continuous Integration, automatic unit testing and multi-platform builds Similar setups are common in Java and .NET, but I'm having a hard time putting this together for make and C/C++. Any thoughts?

My requirements:

  • fast build; non recursive make (stackoverflow what is your experience with non-recursive make)
  • modular system (i.e. minimal dependencies, makefile in subdirectory with components)
  • multiplatform (typically PC for unit testing, embedded target for system integration/release)
  • complete dependency checking
  • ability to perform (automatic) unit tests (Agile engineering)
  • hook into Continuous integration system
  • easy to use

I've started with non-rec make. I still find it a great place to start.

Limitations so far:

  • no integration of unit tests
  • incompatibility of windows based ARM compilers with cygwin paths
  • incompatibility of makefile with windows \ paths
  • forward dependencies

My structure looks like:

    project_root
       /algorithm
                 /src
                     /algo1.c
                     /algo2.c
                 /unit_test
                     /algo1_test.c
                     /algo2_test.c
                 /out
                     algo1_test.exe
                     algo1_test.xml
                     algo2_test.exe
                     algo2_test.xml
             headers.h
       /embunit
       /harnass
   makefile
   Rules.top

I'd like to keep things simple; here the unit tests (algo1_test.exe) depend on both the 'algorithm' component (ok) and the unit test framework (which may or may not be known at the time of building this). However, moving the build rules to the top make does not appeal to me as this would distribute local knowledge of components throughout the system.

As for the cygwin paths: I'm working on making the build using relative paths. This resolves the /cygdrive/c issue (as compilers can generally handle / paths) without bringing in c: (which make dislikes). Any other idea's?

+2  A: 

CMake together with the related tools CTest and CDash seem to answer your requirements. Worth giving it a look.

Bill Hoffman (A lead CMake developer) refers to the Recursive Make Considered Harmful paper in a post at the CMake mailing list:

... since cmake is creating the makefiles for you, many of the disadvantages of recursive make are avoided, for example you should not have to debug the makefiles or even think about how they work. There are other examples of things in that paper that cmake fixes for you as well.

See also this answer for "Recursive Make - friend or foe?" here on stackoverflow.

- http://stackoverflow.com/questions/319764/recursive-make-friend-or-foe

Chen Levy
Thanks; I will give this combination a further look. +1 for your effort.
Adriaan
It's not the answer I was looking for, but I've still accepted it since it may indeed be better to avoid the problem than to solve it in the make files.
Adriaan