aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile34
1 files changed, 25 insertions, 9 deletions
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 $@