The preprocessor recognizes the following syntaxes:
Import a modular
c
file without using a header
import a from "./awesome.module.c";
All the exported functions/types from awesome.module.c
are now available
under the local namespace a
. So if the function void do(void);
is
exported from awesome.module.c
, after the above import, it can be used
as a.do();
import a from "./awesome.module.c";
-> #include "./awesome.h"
a.do();
-> awesome_do();
Export the symbols of a different module
export * from "dependency.module.c";
All of the symbols exported by dependency.module.c
will become available to modules that import the current module. For Example:
// index.module.c
export * from "a.module.c";
export * from "b.module.c";
export * from "c.module.c";
This allows you to import just the index.module.c
and get all the types and functions.
The generated syntax ends up in the header.
export * from "a.module.c";
-> #include "a.h"
Export a symbol from your module
// without an alias
export void do(void){
...
}
// with alias
export void do_awesome_thing(void){
...
} as do_thing
do_awesome_thing();
Putting export
before a symbol declaration prefixes it with
the module's namespace prefix. This prefix is based on the filename, or can be overwritten using the package
command.
// without aliases.
export void do(void){
...
}
// with alias
export void do_awesome_thing(void){
...
} as do_thing
do_awesome_thing();
which would become
// without aliases
void awesome_do(void){
...
}
// with alias
void awesome_do_thing(void){
...
}
awesome_do_thing();
Change the generated makefile.
/* Set variables in the Makefile */
build set VAR "VALUE"
build add CFLAGS "-g"
build set default LIBRARY_INCLUDE_DIR "/path/to/default"
/* Depend on external c files */
build depends "/path/to/some/file.c"
build (set | set default | add) NAME "VALUE"
will use :=
, ?=
, +=
respectively to set the variables in the
generated makefile whenever the module is included in the build.
build depends "file.c"
adds file.c
to the dependency tree whenever the module is imported. It will be added to the
generated makefile, so you can still just build your whole project with cbuild -m root.modul.c
the example above would result in the following lines being added to the generated makefile.
VAR := "VALUE"
CFLAGS += "-g"
LIBRARY_INCLUDE_DIR ?= "/path/to/default"
build depends
will add the file.o
to the dependencies of the current module, so it will be included in the build of
the final executable.