Skip to content

Instantly share code, notes, and snippets.

@aelobdog
Created August 27, 2021 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aelobdog/b643e168600e120682461c6f0478394b to your computer and use it in GitHub Desktop.
Save aelobdog/b643e168600e120682461c6f0478394b to your computer and use it in GitHub Desktop.
My nobuild.c file that I use for hadela. Just a reference for myself :)
#include <stdio.h>
#include <string.h>
#define NOBUILD_IMPLEMENTATION
#include "./my_nobuild.h"
#include <stdlib.h>
#define CFLAGS "-Wall -Wextra -std=c89 -pedantic"
char* getAllCFiles() {
const char** fileList;
char* files;
int numFiles, totalLength, it;
numFiles = 0;
totalLength = 0;
FOREACH_FILE_IN_DIR(cFile, "src", {
if (strlen(cFile) > 2) {
numFiles ++;
totalLength += strlen(cFile) + 5;
}
});
fileList = (const char**)malloc(sizeof(const char**)*numFiles);
files = (char*)calloc(sizeof(char*), totalLength);
it = 0;
FOREACH_FILE_IN_DIR(cFile, "src", {
if (strlen(cFile) > 2) {
fileList[it++] = cFile;
}
});
for (it = 0; it < numFiles; it++) {
char* temp = (char*)fileList[it];
strcat(files, "src/");
strcat(files, temp);
if (it != numFiles - 1) strcat(files, " ");
}
free(fileList);
return files;
}
int main(int argc, char* argv[]) {
const char* cFiles;
const char* cc = "gcc";
int debug = 0;
GO_REBUILD_URSELF(argc, argv);
if (argc > 1) {
for (int i=0; i < argc; i++) {
if (! strcmp(argv[i], "debug")) {
debug = 1;
} else if (! strcmp(argv[i], "-cc")) {
cc = argv[i+1];
i++;
}
}
}
cFiles = getAllCFiles();
// CMD(cc, (debug ? CFLAGS " -ggdb" : CFLAGS), "-o", PATH("bin", "hademac"), cFiles);
// CMD(cc, cFiles, CFLAGS, "-o", PATH("bin", "hademac"));
CMD(cc, cFiles, (debug ? CFLAGS " -ggdb" : CFLAGS), "-o", PATH("bin", "hademac"));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment