What about dependencies?

If you've used Make, you're used to creating Makefiles. In them, you manually build this immense graph where all of the parts hopefully add up to a working program.

# Sample Makefile

all: prog1 prog2
prog1: prog1.o lib1.o lib2.o
prog2: prog2.o lib1.o lib3.o
prog1.o: prog1.cc prog1.h
prog2.o: prog2.cc prog1.h
lib1.o: lib1.cc lib1.h
lib2.o: lib2.cc lib2.h
lib3.o: lib3.cc lib3.h

That's so messy! It's also completely unnecessary since your source code already lists its dependencies explicitly. How does it work? #include directives!

// prog1.cc

#include "lib1.h"     // this...
#include "lib2.h"     // ... and this!

int main() {
  // ... do stuff ...
  return 0;

This is where your world is turned upside-down

Tell the build tool to build a target in your depot. It will sniff out all of the objects which also need to be built to make it work, and it will build them first. Once everything exists, it will link it all together into a binary -- assuming it has a main()!

If you're just building a library, then it will compile everything and will drop an object file for you instead. No linking will occur unless your target has a function matching "int main(".

What about system libraries with weird flags?

When you encounter a new system library dependency, you add it to your .build.conf file and give the compiler and linker flags for how to use it. You can use pkg-config to help find those flags if your system has that installed.

Here's what a few .build.conf hints look like...

system_header {
  name: "gnuradio"
  name_type: DIRECTORY
  cflag: "-I/usr/local/include/gnuradio"

system_header {
  name: "microhttpd.h"
  ldflag: "-lmicrohttpd"

system_header {
  name: "mysql/mysql.h"
  ldflag: "-L/usr/lib64/mysql"
  ldflag: "-lmysqlclient"

In this case, any source file which did #include <microhttpd.h> would automatically pick up the -lmicrohttpd flag when linking. This even works if that source file is buried deep within your final program. It all "bubbles up" and just works.

So what's the catch? »