-casl2.o comet2.o $(COMMONSRC) $(ASSRC) $(EXECSRC): $(INCLUDE)/casl2.h $(INCLUDE)/word.h $(INCLUDE)/hash.h $(INCLUDE)/cerr.h
-casl2.o $(ASSRC): $(INCLUDE)/assemble.h
-comet2.o $(EXECSRC): $(INCLUDE)/exec.h
-TAGS: $(INCLUDE)/*.h *.c
- @if test `which etags`; then etags $^; fi
-clean:
- @rm -f *.o
+
+%.d: %.c
+ @$(CC) -MM -I $(INCLUDE) $< | sed 's/\($*\.o\):/\1 $@:/g' >$@
+
+-include $(subst .c,.d,casl2.c comet2.c dumpword.c $(COMMONSRC) $(CASL2SRC) $(ASSRC) $(EXECSRC))
+
+ctags: $(INCLUDE)/*.h *.c
+ @($(WHICH) $(CTAGS) && $(CTAGS) $^) >/dev/null
+
+etags: $(INCLUDE)/*.h *.c
+ @($(WHICH) $(ETAGS) && $(ETAGS) $^) >/dev/null
+
+clean: clean_cmd clean_build clean_tags
+
+clean_cmd:
+ @$(RMF) ../casl2 ../comet2 ../dumpword
+
+clean_build:
+ @$(RMF) *.o *.d
+
+clean_tags:
+ @$(RMF) TAGS tags