From 7c891b99e8b55fa93d9ed1c16cbeec9e584952fa Mon Sep 17 00:00:00 2001 From: Simon From Jakobsen Date: Fri, 2 Aug 2024 14:07:55 +0000 Subject: [PATCH] add helloworld-c-make --- helloworld-c-make/.clang-format | 14 +++++++++++ helloworld-c-make/.clangd | 5 ++++ helloworld-c-make/.gitignore | 3 +++ helloworld-c-make/Makefile | 41 +++++++++++++++++++++++++++++++++ helloworld-c-make/README.md | 18 +++++++++++++++ helloworld-c-make/src/main.c | 3 +++ 6 files changed, 84 insertions(+) create mode 100644 helloworld-c-make/.clang-format create mode 100644 helloworld-c-make/.clangd create mode 100644 helloworld-c-make/.gitignore create mode 100644 helloworld-c-make/Makefile create mode 100644 helloworld-c-make/README.md create mode 100644 helloworld-c-make/src/main.c diff --git a/helloworld-c-make/.clang-format b/helloworld-c-make/.clang-format new file mode 100644 index 0000000..8ae9b75 --- /dev/null +++ b/helloworld-c-make/.clang-format @@ -0,0 +1,14 @@ +BasedOnStyle: WebKit +IndentWidth: 4 +ColumnLimit: 80 +IndentCaseLabels: true +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + SplitEmptyFunction: false +AlignAfterOpenBracket: BlockIndent +AlignOperands: AlignAfterOperator +BreakBeforeBinaryOperators: true +BinPackArguments: false +BinPackParameters: false + diff --git a/helloworld-c-make/.clangd b/helloworld-c-make/.clangd new file mode 100644 index 0000000..32a3e87 --- /dev/null +++ b/helloworld-c-make/.clangd @@ -0,0 +1,5 @@ +CompileFlags: + CompilationDatabase: build/compile_flags.txt + Remove: + - -Wempty-translation-unit + diff --git a/helloworld-c-make/.gitignore b/helloworld-c-make/.gitignore new file mode 100644 index 0000000..1be61f5 --- /dev/null +++ b/helloworld-c-make/.gitignore @@ -0,0 +1,3 @@ +build/ +.cache/ + diff --git a/helloworld-c-make/Makefile b/helloworld-c-make/Makefile new file mode 100644 index 0000000..5027b45 --- /dev/null +++ b/helloworld-c-make/Makefile @@ -0,0 +1,41 @@ + +EXECUTABLE = helloworld-c-make + +INSTALL_PREFIX = /usr/local + +CFLAGS = -std=c17 -Wall -Wextra -pedantic -pedantic-errors -O2 +LFLAGS = + +LD=gcc +CC=gcc + +SOURCE_FILES = \ + src/main.c + +OBJECT_FILES = $(patsubst src/%.c, build/%.o, $(SOURCE_FILES)) + +HEADER_FILES = $(shell find src/ -name *.h) + +all: build/$(EXECUTABLE) build/compile_flags.txt + +install: build/$(EXECUTABLE) + cp build/$(EXECUTABLE) $(INSTALL_PREFIX)/bin/$(EXECUTABLE) + +build/$(EXECUTABLE): $(OBJECT_FILES) + $(LD) -o $@ $(LFLAGS) $^ + +build/%.o: src/%.c $(HEADER_FILES) build-folder + $(CC) -c -o $@ $(CFLAGS) $< + +build-folder: + mkdir -p build/ + +clean: + $(RM) build/ + +build/compile_flags.txt: + echo -xc $(CFLAGS) \ + | tr ' ' '\n' \ + > $@ + + diff --git a/helloworld-c-make/README.md b/helloworld-c-make/README.md new file mode 100644 index 0000000..5bdbf81 --- /dev/null +++ b/helloworld-c-make/README.md @@ -0,0 +1,18 @@ + +# helloworld-c-make + +``` +make +./build/helloworld-c-make +``` + +``` +make + +sudo make install +# or +sudo make INSTALL_PREFIX=/usr/local install + +helloworld-c-make +``` + diff --git a/helloworld-c-make/src/main.c b/helloworld-c-make/src/main.c new file mode 100644 index 0000000..f1b76e5 --- /dev/null +++ b/helloworld-c-make/src/main.c @@ -0,0 +1,3 @@ +#include + +int main(void) { printf("Hello, world!\n"); }