-# set some compiler flags
-CFLAGS=-lncurses
-
-# find *.c in the current directory
-SOURCES=$(wildcard *.c)
-TESTS=$(wildcard test/*.c)
-
-# define the output objects by replacing .c with .o
-TARGETS=$(SOURCES:.c=)
-TEST_TARGETS=$(TESTS:.c=)
-
-# this will make all objects
-all: $(TEST_TARGETS) $(TARGETS)
-test: $(TEST_TARGETS)
-
-# each objects will be build by a *.c file
-#%.o: %.c
-%: %.c
- cc $(CFLAGS) -o $@ $^
-
-# this will delete all objects
-# if not all objects are there, they will be compiled first
-clean: $(TARGETS) $(TEST_TARGETS)
- rm -f $^
+CFLAGS=-g -Wall -lncurses
+
+tmp: tmp.c cstring.o markdown.o parser.o viewer.o
+ cc $(CFLAGS) -o tmp tmp.c cstring.o markdown.o parser.o viewer.o
+
+viewer.o: viewer.c
+ cc $(CFLAGS) -c viewer.c
+
+parser.o: parser.c
+ cc $(CFLAGS) -c parser.c
+
+markdown.o: markdown.c
+ cc $(CFLAGS) -c markdown.c
+
+cstring.o: cstring.c
+ cc $(CFLAGS) -c cstring.c
+
+all: tmp
+
+.PHONY: test
+
+test:
+ $(MAKE) -C test
+
+clean:
+ rm -f tmp *.o