Skip to content

Commit

Permalink
Write include guards
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 13, 2024
1 parent 1891548 commit 377a338
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/backends/hlsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,26 @@ static void write_bytecode(char *hlsl, char *directory, const char *filename, co
{
sprintf(full_filename, "%s/%s.h", directory, filename);
FILE *file = fopen(full_filename, "wb");

fprintf(file, "#ifndef KONG_%s_HEADER\n", name);
fprintf(file, "#define KONG_%s_HEADER\n\n", name);

fprintf(file, "#include <stddef.h>\n");
fprintf(file, "#include <stdint.h>\n\n");

fprintf(file, "#ifdef __cplusplus\n");
fprintf(file, "extern \"C\" {\n");
fprintf(file, "#endif\n\n");

fprintf(file, "extern uint8_t *%s;\n", name);
fprintf(file, "extern size_t %s_size;\n", name);

fprintf(file, "\n#ifdef __cplusplus\n");
fprintf(file, "}\n");
fprintf(file, "#endif\n\n");

fprintf(file, "#endif\n");

fclose(file);
}

Expand Down
8 changes: 8 additions & 0 deletions Sources/integrations/kope.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ void kope_export(char *directory, api_kind api) {
fprintf(output, "#include <kinc/math/matrix.h>\n");
fprintf(output, "#include <kinc/math/vector.h>\n\n");

fprintf(output, "#ifdef __cplusplus\n");
fprintf(output, "extern \"C\" {\n");
fprintf(output, "#endif\n");

fprintf(output, "\nvoid kong_init(kope_g5_device *device);\n\n");

for (global_id i = 0; get_global(i) != NULL && get_global(i)->type != NO_TYPE; ++i) {
Expand Down Expand Up @@ -437,6 +441,10 @@ void kope_export(char *directory, api_kind api) {
}
}

fprintf(output, "#ifdef __cplusplus\n");
fprintf(output, "}\n");
fprintf(output, "#endif\n\n");

fprintf(output, "#endif\n");

fclose(output);
Expand Down

0 comments on commit 377a338

Please sign in to comment.