diff options
author | zachir <zachir@librem.one> | 2024-03-11 01:34:22 -0500 |
---|---|---|
committer | zachir <zachir@librem.one> | 2024-03-11 01:34:22 -0500 |
commit | 2b135d87f5c1f1f307984f5fd78e151f5ee99dae (patch) | |
tree | 6e9e089326ea40badd6dab25a3ed5a7cef61dcbd | |
parent | 42b5d719a0207a56b482a4e0298d72b628b93fa0 (diff) |
Replace build system with zig
Zig is actually handling the building and such, now the Makefile is
here just as a wrapper for it.
-rw-r--r-- | .gitignore | 8 | ||||
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | build.zig | 28 | ||||
-rw-r--r-- | include/main.h (renamed from main.h) | 0 | ||||
-rw-r--r-- | src/main.c (renamed from main.c) | 8 |
5 files changed, 40 insertions, 20 deletions
@@ -1,5 +1,5 @@ -# Ignore object files -*.o +# Ignore Zig build dirs +zig-cache/ -#Ignore the compiled binary -even +# Ignore the compiled binary +zig-out/ @@ -1,16 +1,8 @@ -C_SRC := main.c -C_OBJ := main.o -B_NAM := even -CC := gcc -C_FLG := -Os -Wall -Wpedantic -Werror -O_FLG := ${C_FLG} +ZIG_ARGS := -Doptimize=ReleaseSmall -${B_NAM}: ${C_OBJ} - ${CC} ${O_FLG} -o ${B_NAM} ${C_OBJ} - -main.o: main.c main.h - ${CC} ${C_FLG} -c main.c +all: + zig build ${ZIG_ARGS} clean: - rm -f ${B_NAM} ${C_OBJ} + rm -rf zig-out/ zig-cache/ diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..4fba9b6 --- /dev/null +++ b/build.zig @@ -0,0 +1,28 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const exe = b.addExecutable(.{ + .name = "even", + .target = target, + .optimize = optimize, + }); + exe.addIncludePath(.{ + .path = "include", + }); + exe.linkLibC(); + exe.addCSourceFiles(&.{ + "src/main.c", + }, &.{ + "-pedantic", + "-Wall", + "-Werror", + "-W", + "-Wno-missing-field-initializers", + "--std=c11", + }); + + b.installArtifact(exe); +} @@ -1,6 +1,6 @@ #include "./main.h" -void printhelp() { +void printhelp(void) { fprintf(stderr, "even: a binary by ZachIR to check if a number is even or "); fprintf(stderr, "odd.\n"); fprintf(stderr, "even [-hcv]\n"); @@ -15,14 +15,14 @@ void printhelp() { return; } -void printcopyright() { +void printcopyright(void) { fprintf(stderr, "Copyright (c) 2024 Zachary Smith\n"); fprintf(stderr, "even is Free software under the MIT license, and is "); fprintf(stderr, "provided without warranty of any kind.\n"); return; } -void printversion() { +void printversion(void) { fprintf(stderr, "even version %s, 2024\n", VERSION); return; } @@ -38,7 +38,7 @@ int main(int argc, char **argv) { char *output; if (argc > 1) { - for (size_t i = 1; i < argc; i++) { + for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'h': |