From 5069b41630f706391827b2de22779d88a8347085 Mon Sep 17 00:00:00 2001 From: Imbus Date: Sat, 2 Dec 2023 07:12:56 +0100 Subject: [PATCH] Initial --- .gitignore | 2 ++ Justfile | 39 +++++++++++++++++++++++++++++++++++++++ lib/fib.h | 3 +++ lib/greet.h | 3 +++ src/fib.c | 7 +++++++ src/greet.c | 8 ++++++++ src/main.c | 7 +++++++ 7 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100644 Justfile create mode 100644 lib/fib.h create mode 100644 lib/greet.h create mode 100644 src/fib.c create mode 100644 src/greet.c create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ad324d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.tar.gz +build \ No newline at end of file diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..8403115 --- /dev/null +++ b/Justfile @@ -0,0 +1,39 @@ +run: build + ./build/main + +build: mkdir objects + gcc build/*.o -o build/main -O3 + du -h build/main + +objects: mkdir + cd build && gcc -c -I ../lib -Wall -Werror -fpic ../src/*.c -O3 + du -h build/*.o + +asm: mkdir + cd build && gcc -S -masm=intel -I ../lib -Wall -Werror -fpic ../src/*.c -O3 + +release: mkdir build + strip build/main + tar -czvf build.tar.gz build + +mkdir: + mkdir build -p + +clean: + rm *.tar.gz -f + rm -rf build + +hex: build + objdump -M intel -d build/main + +symbols: build + nm build/main + +symbols2: build + readelf -s build/main + +rodata: build + objdump -s -j .rodata build/main + +fmt: + fd -e c -e h -x clang-format --verbose -i {} \ No newline at end of file diff --git a/lib/fib.h b/lib/fib.h new file mode 100644 index 0000000..54c0ae4 --- /dev/null +++ b/lib/fib.h @@ -0,0 +1,3 @@ +#pragma once + +int fib(int n); \ No newline at end of file diff --git a/lib/greet.h b/lib/greet.h new file mode 100644 index 0000000..4101e80 --- /dev/null +++ b/lib/greet.h @@ -0,0 +1,3 @@ +#pragma once + +void greet(const char *name); \ No newline at end of file diff --git a/src/fib.c b/src/fib.c new file mode 100644 index 0000000..8170a9b --- /dev/null +++ b/src/fib.c @@ -0,0 +1,7 @@ +#include "fib.h" + +int fib(int n) { + if (n < 2) + return n; + return fib(n - 1) + fib(n - 2); +} \ No newline at end of file diff --git a/src/greet.c b/src/greet.c new file mode 100644 index 0000000..e87af9f --- /dev/null +++ b/src/greet.c @@ -0,0 +1,8 @@ +#include "greet.h" +#include "fib.h" +#include + +void greet(const char *name) { + printf("Hello %s!\n", name); + printf("Fibonacci of 10 is %d\n", fib(10)); +} \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..b55d6c9 --- /dev/null +++ b/src/main.c @@ -0,0 +1,7 @@ +#include "greet.h" +#include + +int main(void) { + greet("Template"); + return 0; +} \ No newline at end of file