diff options
author | Marvin Borner | 2020-06-10 16:29:48 +0200 |
---|---|---|
committer | Marvin Borner | 2020-06-10 16:29:48 +0200 |
commit | 52fcc57f84bf1c5fbcae1de466ec770c0831a1b7 (patch) | |
tree | 5a0cb9f2dfdcdb740a09187c4ea141bb973464f4 /.boilerplates | |
parent | 2a15a328c424eca5ede8280501c19145ea68efd0 (diff) |
Added awesome c boilerplate
Diffstat (limited to '.boilerplates')
-rw-r--r-- | .boilerplates/c/.gitignore | 1 | ||||
-rw-r--r-- | .boilerplates/c/makefile | 24 | ||||
-rwxr-xr-x | .boilerplates/c/run | 3 | ||||
-rw-r--r-- | .boilerplates/c/src/main.c | 18 |
4 files changed, 46 insertions, 0 deletions
diff --git a/.boilerplates/c/.gitignore b/.boilerplates/c/.gitignore new file mode 100644 index 0000000..89f9ac0 --- /dev/null +++ b/.boilerplates/c/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/.boilerplates/c/makefile b/.boilerplates/c/makefile new file mode 100644 index 0000000..b3f9b64 --- /dev/null +++ b/.boilerplates/c/makefile @@ -0,0 +1,24 @@ +TARGET=out/name +CC=gcc +CFLAGS=-Iinc -Wall -Wextra -g + +SRC=$(wildcard src/*.c) +OBJ=$(patsubst src/%.c,out/%.o,$(SRC)) +MAKEFLAGS+=--silent + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CC) $(CFLAGS) -o $@ $^ + +out/%.o: src/%.c + @mkdir -p "$(@D)" + $(CC) $(CFLAGS) -MD -o $@ -c $< + + +clean: + rm -rf out/ $(TARGET) + +-include $(OBJECTS:.o=.d) + +.PHONY: all clean run diff --git a/.boilerplates/c/run b/.boilerplates/c/run new file mode 100755 index 0000000..50bf221 --- /dev/null +++ b/.boilerplates/c/run @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +make && ./out/name "$@" diff --git a/.boilerplates/c/src/main.c b/.boilerplates/c/src/main.c new file mode 100644 index 0000000..10ea279 --- /dev/null +++ b/.boilerplates/c/src/main.c @@ -0,0 +1,18 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void print_help() +{ + printf("Help\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + if (argc == 2 && (strcmp(argv[1], "--help") == 0)) + print_help(); + + printf("Hello, world!\n"); + return 0; +} |