From 5d7c2925c4ef268413363f0eab01132a6254087e Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Fri, 18 Oct 2024 02:37:49 +0100 Subject: Refactor main to source & header files, & update Makefile --- Makefile | 34 +++++++++++++++++++++++++--------- src/main.c | 13 ++----------- src/tdo.c | 15 +++++++++++++++ src/tdo.h | 8 ++++++++ 4 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 src/tdo.c create mode 100644 src/tdo.h diff --git a/Makefile b/Makefile index ed6b098..79be005 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,42 @@ -# Compiler to options +proj=tdo + +# Compiler options CC=gcc CFLAGS=-std=c17 -Wall -Werror -g # Directory paths -src=src -bin=bin +src:=src +bin:=bin +obj:=obj + +# Files +srcs=$(filter-out $(src)/main.c, $(wildcard $(src)/*.c)) +objs=$(patsubst $(src)/%.c, $(obj)/%.o, $(srcs)) # Directives .PHONY: build -build: $(bin)/tdo +build: $(bin)/$(proj) .PHONY: clean clean: -rm -r $(bin) $(obj) -# Build executable -$(bin)/tdo: $(bin) $(src)/main.c +.PHONY: info +info: + @echo srcs: $(srcs) + @echo objs: $(objs) + +# Make object files +$(obj)/%.o: $(srcs) $(obj) + $(CC) $(CFLAGS) -o $@ -c $< + +# Build executable including any object files +$(bin)/$(proj): $(bin) $(objs) $(src)/main.c $(CC) $(CFLAGS) -o $@ $(filter-out $<,$^) -# Make bin directory +# Make directories $(bin): mkdir $@ - - +$(obj): + mkdir $@ diff --git a/src/main.c b/src/main.c index bc6b673..e50b7ae 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,9 @@ #include // for input/output #include // for STD macros #include // for getopt +#include "tdo.h" +// for debugging void print_args(int argc, char* argv[]) { printf("There are %i arguments\n",argc); printf("Those arguments are:\n"); @@ -11,17 +13,6 @@ void print_args(int argc, char* argv[]) { } } -void new_tdo(int argc, char** argv) { - printf("New todo: "); - // just in case not using quotes - for (int i=2; i +#include "tdo.h" + +void print_version() { + printf("tdo version 0.0.1\n"); +} + +void new_tdo(int argc, char** argv) { + printf("New todo: "); + // just in case not using quotes + for (int i=2; i + +// Print version +void print_version(); + +// Create a new todo item +void new_tdo(int argc, char** argv); + -- cgit