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"); }