StormC Build System
What is it?
The StormC Build System is my C build system for, obviously, building C, as you'd imagine.
A look into what the scbuild.c file looks like (which is generated in the cwd, by running the following command: stormc init):
#include <storm/scbuild.h>
int main(int argc, char *argv[])
{
build.in = make_string("main.c");
build.out = make_string("main");
SET_FLAGS(WALL, STD_C89, OPTIM_2);
}
The SET_FLAGS is a macro and it looks like this:
#define SET_FLAGS(...) \
do{ \
StormC_Commands cmds[] = {__VA_ARGS__, INVALID}; \
set_flags(cmds); \
}while(0)\
For a full view of the scbulid.h file, go here
For documentation on the build system, go here
But...why?
Every single time I see a framework / solution that is, ostensibly, trying to solve a problem, it's always some
absolute bloated, endless configuration / API / syntax learning curve. With this, I can just write C that writes C! Perfect!
There are no dependencies other than having a compiler.
More than just flags
The general idea behind the build system is to parse commands and feed it into the compiler input line.
There are actually two binaries at play here, as you can probably see. There is stormc
and there is scbuild.c, both working as a "main" entry point.
Reason for this being that stormc is meant to do more than just passing compiler flags, for example
it also helps me setting up ctags, using this as input:
stormc ctags /usr/include/storm
Which allows me to use functionality like jump to defninition, jump back, and so on, without much configuration typing
and without having to use ( and remember ) multiple tool names.
Linking with the linker
Additionally, setting link flag path and linked files is also possible and trivial.
You literally just write them as you normally would. Example:
#include <storm/scbuild.h>
int main(int argc, char *argv[])
{
build.in = make_string("main.c");
build.out = make_string("main");
SET_FLAGS(WALL, ALLSAN, STD_C89, OPTIM_2);
SET_LINK_PATH("-L.");
SET_LINKED_FILES("-lraylib", "-lGL", "-lX11", "-lpthread", "-ldl", "-lm");
stormc_build(argc, argv);
}
The arguments argc and argv are being passed into scbuiild.c by stormc,
hence the reason why I pass them into the stormc_build() function
Hello, StormC!
Here's a "hello world" example:
riri@storm:~/for_show_code$ stormc init
riri@storm:~/for_show_code$ ls
scbuild.c
riri@storm:~/for_show_code$ cat scbuild.c
#include <storm/scbuild.h>
int main(int argc, char *argv[])
{
build.in = make_string("main.c");
build.out = make_string("main");
SET_FLAGS(WALL, WPEDANTIC, ALLSAN, STD_C89, OPTIM_2);
stormc_build(argc, argv);
}
riri@storm:~/for_show_code$ nvim main.c
#include <storm/storm.h>
int main(void)
{
printf("Hello, StormC!\n");
}
riri@storm:~/for_show_code$ stormc build run
Hello, StromC!
riri@storm:~/for_show_code$
The command stormc build can be ran independently and so can stormc run.
The build argument will compile the binary according to the instructions in scbuild.c
and the run will execute the binary ( if it exists ).