Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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++. How can it be achieved?

My requirements:

  • fast build; non-recursive make (Stack Overflow question What is your experience with non-recursive make?)
  • modular system (that is, 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 ideas?

like image 751
Adriaan Avatar asked Oct 27 '22 03:10

Adriaan


1 Answers

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.

- Recursive Make - friend or foe?

like image 163
Chen Levy Avatar answered Nov 17 '22 22:11

Chen Levy