What is your vision of ideal build system script?

Programming, for all ages and all languages.
Post Reply
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

What is your vision of ideal build system script?

Post by Griwes »

I'm going to create my very own build system for my project, and I don't want to do it in SCons-style or Waf-style way, i.e. not with build scripts as Python or any other language files. I had few ideas of my own format, few that understood what .c or .cpp file is, few that didn't, few that were just obfuscated versions of Makefile, few that weren't, and I can't really come up with easy to learn and use format for it.

The build system is meant to require Makefile-like files, but providing sane way to call filesystem functions (no moar $(shell) hell), to get current architecture/OS, to access command line switches and allow users to write `if-else` blocks in it. I want something like this:

Code: Select all

if (linux and -rose) // we are cross-compiling on Linux for ReaverOS
// command line: build -rose .
{
    CXX = /usr/reaver/cross/bin/clang++ // or: load_preset(/usr/reaver/cross) or something like that
}

if (linux and -exclude includes builder)
// command line: build -exclude=builder ., but also build -exclude=builder,kernel,utilities
{
    // ...
}
Those are meant just to show how I'd like to get switch handling and architecture handling done; I know there isn't much in this example, but I want to get some opinions from you.


So: how would your "ideal" Makefile-ish file format look like?

---------

Edit: I know Brendan will say something like "In my perfect world, you don't need build scripts"; yet I'm asking about opinions of us, non-perfect-worlders ;)
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: What is your vision of ideal build system script?

Post by Brendan »

Hi,
Griwes wrote:Edit: I know Brendan will say something like "In my perfect world, you don't need build scripts"; yet I'm asking about opinions of us, non-perfect-worlders ;)
You're right.

Think of it as a big compromise between 2 very different extremes. At one extreme there's "nothing" where you have to manually type commands into a shell in a precise order each time you want to build anything. This is extremely tedious. At the other extreme there's "nothing" (my perfect world), where the hassle of building is minimised to the point where you don't need to write or maintain anything that describes how things are built.

The question is, how far can you get from the first extreme (or, how much hassle can you avoid) without inventing your own world?

Bash/python/whatever scripts are an obvious first step. Something like makefiles (which are basically just scripts in a language intended to be more suitable) are a slightly better second step. I don't think you can go much further than this; as going further means avoiding the need for languages and files/scripts to describe what to do, which is the beginning of inventing your own world.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: What is your vision of ideal build system script?

Post by Love4Boobies »

An optimal build system cannot exist by itself; it needs to be tightly integrated with the compiler (make and other tools are designed to be compiler-independent and do not care about the language the code was written in). The reason for this is that these legacy tools work on a file basis when dependencies actually happen within translation units. This causes unnecessary work. E.g., consider the following:

Code: Select all

// foo.h

void hello(void);
void world(void);

// foo.c

#include <foo.h>

void bar(void)
{
    hello();
}
If you were to change the return type of world to int, the build system should not rebuild foo.c. But not only will it do that; it will also rebuild everything that depends on either it or foo.h. A whole tree of extra rebuilding follows.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: What is your vision of ideal build system script?

Post by bluemoon »

I use shell script to generate Makefile, It's portable and easy (ie. it works on Linux and Mac, and perhaps cygwin)

To process argument it's simple:

Code: Select all

for i in $*
do
  case $i in
      --arch=i586   )
          ARCH=i586
      ;;
      --arch=x86_64 )
          ARCH=x86_64
      ;;
  esac
done
To detect the host platform:

Code: Select all

case $(uname -a) in
    *BSD* )
        PLATFORM=BSD
    ;;
    *Linux* )
        PLATFORM=LINUX
    ;;
    *Darwin\ Kernel* )
        PLATFORM=MACOSX
    ;;
    *SunOS* )
        PLATFORM=SOLARIS
    ;;
esac
*Note: You might be actually using darwin instead of Mac OS, but it is practically working for me.

The script can setup parameters for Makefile, scan entries of drivers and output their entry on Makefile, etc
And like the Makefile itself, once it's done you never need to care it again.
Post Reply