Thread: Compiling serious C projects

  1. #1
    Registered User MartinR's Avatar
    Join Date
    Dec 2013
    Posts
    183

    Lightbulb Compiling serious C projects

    I wonder how to write clever makefile for serious C project. This task which may seems to be trivial is actually not so easy, here is why (IMHO):

    1. We can compile all source files by seraching for *.c, *.cpp, *.c. Looks like this quick and nice sloution however what if we later one decide that some or all components have "variants" - now we are in trap. This solution have also obvious disadvantage of compilling files that may not even be used.
    2. The soultion to above problem would be to create a small makefiles in each module/folder which defines what needs to be compiled. But this solution also have drawback, if we change compiler or sth else system level then we need to change maybe 1000 makefiles.

    So, what good practices are recomended for such a case?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,615
    2. The soultion to above problem would be to create a small makefiles in each module/folder which defines what needs to be compiled. But this solution also have drawback, if we change compiler or sth else system level then we need to change maybe 1000 makefiles.
    I still recommend this solution.

    I understand make to be a general purpose program: as long as the compiler, or toolchain, can be invoked on the command line, you can set up a make file.
    CC= allows you to name the C compiler
    CXX= allows you to name the C++ compiler

    You can set flags as well like this. GNU make: Implicit Variables

    So, in general, I don't really understand the complaint. Make-fu should be able to solve it as long as you put variables to judicious use.


    Maybe it's time to use an IDE and shift to a project-oriented workflow.
    Last edited by whiteflags; 05-03-2018 at 03:33 PM.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,729
    We are told to avoid nested makefiles because it's hard to correctly pass environment variables around and makes multitasking at the same level (meaning while the other Makefile is running) impossible.

    I don't share that opinion though. I think a separate makefile is necessary when you want to build multiple executables. My general rule is one executable (or linking) per makefile.

    To answer your question, if you're concerned about having to change compiler or system you either need to use implicit variables as whiteflags suggested, use the classic ./configure script or use a wrapper program such as cmake.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's everyone up to? Projects?
    By Epy in forum General Discussions
    Replies: 18
    Last Post: 04-11-2017, 08:31 PM
  2. big projects
    By Krewella in forum C Programming
    Replies: 1
    Last Post: 06-19-2016, 09:45 AM
  3. Replies: 11
    Last Post: 05-25-2007, 04:39 PM
  4. Projects
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 05-01-2002, 12:40 PM
  5. projects
    By iain in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 12-28-2001, 02:46 PM

Tags for this Thread