summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md30
-rw-r--r--src/utils/utils.c20
2 files changed, 45 insertions, 5 deletions
diff --git a/README.md b/README.md
index 2a54c26..2827662 100644
--- a/README.md
+++ b/README.md
@@ -435,6 +435,36 @@ fn add(a: int, b: int) -> int {
> **Note:** When using Intel syntax (via `-masm=intel`), you must ensure your build is configured correctly (for example, `//> cflags: -masm=intel`). TCC does not support Intel syntax assembly.
+### 14. Build Directives
+
+Zen C supports special comments at the top of your source file to configure the build process without needing a complex build system or Makefile.
+
+| Directive | Arguments | Description |
+|:---|:---|:---|
+| `//> link:` | `-lfoo` or `path/to/lib.a` | Link against a library or object file. |
+| `//> lib:` | `path/to/libs` | Add a library search path (`-L`). |
+| `//> include:` | `path/to/headers` | Add an include search path (`-I`). |
+| `//> cflags:` | `-Wall -O3` | Pass arbitrary flags to the C compiler. |
+| `//> define:` | `MACRO` or `KEY=VAL` | Define a preprocessor macro (`-D`). |
+| `//> pkg-config:` | `gtk+-3.0` | Run `pkg-config` and append `--cflags` and `--libs`. |
+| `//> shell:` | `command` | Execute a shell command during the build. |
+| `//> get:` | `http://url/file` | Download a file if specific file does not exist. |
+| `//> immutable-by-default` | None | Make variables immutable unless declared `mut`. |
+
+#### Examples
+
+```zc
+//> include: ./include
+//> lib: ./libs
+//> link: -lraylib -lm
+//> cflags: -Ofast
+//> pkg-config: gtk+-3.0
+
+import "raylib.h"
+
+fn main() { ... }
+```
+
---
## Compiler Support & Compatibility
diff --git a/src/utils/utils.c b/src/utils/utils.c
index 4af811f..5f41f44 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -537,24 +537,30 @@ void scan_build_directives(ParserContext *ctx, const char *src)
if (0 == strncmp(line, "link:", 5))
{
+ char *val = line + 5;
+ while (*val == ' ') val++;
if (strlen(g_link_flags) > 0)
{
strcat(g_link_flags, " ");
}
- strcat(g_link_flags, line + 5);
+ strcat(g_link_flags, val);
}
else if (0 == strncmp(line, "cflags:", 7))
{
+ char *val = line + 7;
+ while (*val == ' ') val++;
if (strlen(g_cflags) > 0)
{
strcat(g_cflags, " ");
}
- strcat(g_cflags, line + 7);
+ strcat(g_cflags, val);
}
else if (0 == strncmp(line, "include:", 8))
{
+ char *val = line + 8;
+ while (*val == ' ') val++;
char flags[2048];
- sprintf(flags, "-I%s", line + 8);
+ sprintf(flags, "-I%s", val);
if (strlen(g_cflags) > 0)
{
strcat(g_cflags, " ");
@@ -563,8 +569,10 @@ void scan_build_directives(ParserContext *ctx, const char *src)
}
else if (strncmp(line, "lib:", 4) == 0)
{
+ char *val = line + 4;
+ while (*val == ' ') val++;
char flags[2048];
- sprintf(flags, "-L%s", line + 4);
+ sprintf(flags, "-L%s", val);
if (strlen(g_link_flags) > 0)
{
strcat(g_link_flags, " ");
@@ -573,8 +581,10 @@ void scan_build_directives(ParserContext *ctx, const char *src)
}
else if (strncmp(line, "define:", 7) == 0)
{
+ char *val = line + 7;
+ while (*val == ' ') val++;
char flags[2048];
- sprintf(flags, "-D%s", line + 7);
+ sprintf(flags, "-D%s", val);
if (strlen(g_cflags) > 0)
{
strcat(g_cflags, " ");