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 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'Makefile') 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 $@ -- cgit