From 4a6c8bce1923e7a4b322e1137781c922d4493e29 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 5 Dec 2021 00:03:55 +0500 Subject: [PATCH] Improve Makefile --- Makefile | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 006e01d..b375d2f 100644 --- a/Makefile +++ b/Makefile @@ -46,24 +46,38 @@ DWM_HDR = $(DWM_SRC:.c=.h) MAIN_HDR = $(MODULES_HDR) src/main.h src/config.def.h MODULES_OBJ = $(MODULES_SRC:.c=.o) -TEST_OBJ = $(TEST_SRC:.c=.o) tests/main.o -MAIN_OBJ = src/main.o -ALL_OBJ = $(MODULES_OBJ) $(TEST_OBJ) $(MAIN_OBJ) +TEST_OBJ = $(TEST_SRC:.c=.o) +ALL_OBJ = $(MODULES_OBJ) $(TEST_OBJ) tests/main.o src/main.o TEST_EXE = $(TEST_SRC:.c=.test) ALL_EXE = polytreewm $(TEST_EXE) -polytreewm: $(MAIN_OBJ) $(MODULES_OBJ) +############### +# Executables # +############### + +polytreewm: src/main.o $(MODULES_OBJ) $(CC) -o $@ $^ $(LDFLAGS) +%.test: %.o tests/main.o $(MODULES_OBJ) + $(CC) -o $@ $^ $(LDFLAGS) + +################ +# Object files # +################ + %.o: %.c $(CONFIGMKS) $(HDR) $(CC) -c $< -o $@ $(CFLAGS) -%.test: %.o $(MODULES_OBJ) tests/main.o - $(CC) -o $@ $^ $(LDFLAGS) - dwm.o: $(DWM_SRC) $(DWM_HDR) +######### +# Tasks # +######### + +test: $(TEST_EXE) + @echo "$(TEST_EXE)" | awk '{ OFS="\n"; $$1=$$1 } 1' | /bin/sh + clean: rm -f $(ALL_OBJ) $(ALL_EXE) @@ -84,7 +98,4 @@ uninstall: $(DESTDIR)$(BINDIR)/polytreewm \ $(DESTDIR)$(MANDIR)/man1/polytreewm.1 -test: $(TEST_EXE) - @echo "$(TEST_EXE)" | awk '{ OFS="\n"; $$1=$$1 } 1' | sh - .PHONY: all clean distclean install uninstall test