Using configuration files

By default, Cook doesn't need any configuration file. But if you want to use other compiler than DMD, or specify path to compiler and linker, it is essential to write proper *.conf file.


Cook automatically detects and loads a configuration file. It should reside in project directory and have a name of the main module + ".conf" extension:

 Main module/target: main

 Main module file: main.d

 Configuration file: main.conf

Configuration is a bunch of simple identifier/value pairs. Identifier is separated from value with a colon (:), pairs are separated from each other with semicolons (;). For values that include spaces, string syntax is supported ("some text").


 identifier1: value1;
 identifier2: "some text here";

Built-in identifiers

Cook has a number of identifiers that it understands internally:

 source.language - language of the project. Default value is "d". This identifier is reserved for future use;

 source.ext - extension for source files, including the dot. Default value is ".d";

 compiler - compiler to use. Default value is "dmd";

 linker - linker to use. Default value is "dmd";

 librarian - librarian to use. Default value is "lib" under Windows and "dmd" under Linux;

 cflags - compiler flags;

 lflags - linker flags;

 obj.path - where to store object files. Default value is "o_windows/" under Windows or "o_linux/" under Linux;

 obj.ext - extension for source files. Default value is ".obj" under Windows or ".o" under Linux;

 target - override default target name;

 rc - specify resource file;

 project.compile - override compilation command with your own one; - override linking command with your own one;

 project.linklib - override library linking command with your own one.

 More identifiers could be added in future.


You can introduce any new identifiers you want. This is useful when using so called patterns. They allow you to use identifiers as "variables" directly in a value. Current syntax for this is %id%:

 compiler: "gdc";
 linker: "gdc";
 cflags: "-fversion=Tango -fversion=Posix";
 lflags: "";
 project.compile: "%compiler% %cflags% -c %source% -o %object%"; "%linker% %lflags% -o %target% %objects%";

"source", "object" and "objects" are built-in identifiers representing current source file, object file and all object files list accordingly. They are meant to be read-only.

Platform-specific identifiers

It is a quite common case when compilation parameters are not the same under different operating systems. Cook deals with it by supporting platform-specific identifiers that override "default" ones. They are preceded by platform specifier ("windows." and "linux.")

Here's the example - using custom path to DMD under Windows and Linux:

 linux.compiler_dir: "/opt/dmd2-2.065.0/linux";
 windows.compiler_dir: "C:/D/dmd2/windows";

 linux.compiler: "%compiler_dir%/bin32/dmd";
 linux.linker: "%compiler_dir%/bin32/dmd";

 windows.compiler: "%compiler_dir%/bin/dmd";
 windows.linker: "%compiler_dir%/bin/dmd";

 linux.obj.path: "o_linux_dmd/";
 windows.obj.path: "o_windows_dmd/";

 cflags: "-O -release -inline -noboundscheck";
 linux.project.compile: "%compiler% %cflags% -c %source% -of%object%";
 windows.project.compile: "%compiler% %cflags% -c %source% -of%object%";