From 52fcc57f84bf1c5fbcae1de466ec770c0831a1b7 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 10 Jun 2020 16:29:48 +0200 Subject: Added awesome c boilerplate --- .boilerplates/c/.gitignore | 1 + .boilerplates/c/makefile | 24 ++++++++++++++++++++++++ .boilerplates/c/run | 3 +++ .boilerplates/c/src/main.c | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 .boilerplates/c/.gitignore create mode 100644 .boilerplates/c/makefile create mode 100755 .boilerplates/c/run create mode 100644 .boilerplates/c/src/main.c (limited to '.boilerplates') 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 +#include +#include + +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; +} -- cgit v1.2.3