add helloworld-c-make

This commit is contained in:
Simon From Jakobsen 2024-08-02 14:07:55 +00:00
parent 2d29797403
commit 7c891b99e8
6 changed files with 84 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,5 @@
CompileFlags:
CompilationDatabase: build/compile_flags.txt
Remove:
- -Wempty-translation-unit

3
helloworld-c-make/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build/
.cache/

View File

@ -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' \
> $@

View File

@ -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
```

View File

@ -0,0 +1,3 @@
#include <stdio.h>
int main(void) { printf("Hello, world!\n"); }