--- /dev/null
+# Utilities
+GCC ?= gcc
+LEX ?= flex
+YACC ?= bison
+CT ?= ct
+
+CFLAGS ?= -Wall -Werror -g --std=c99
+
+ifdef PKGS
+CPPFLAGS += $(shell pkg-config --cflags $(PKGS))
+LDFLAGS += $(shell pkg-config --libs $(PKGS))
+endif
+
+# Targets
+all: $(PROG)
+
+clean:
+ rm -f $(PROG) *.o *.a parse.h parse.c scan.c
+
+# C Rules
+$(PROG): $(SOURCES:%.c=%.o)
+ $(GCC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
+
+%.o: %.c makefile
+ $(GCC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+
+# Lex / Yacc rules
+%.c: %.l parse.h makefile
+ $(LEX) -o $@ $<
+
+%.c %.h: %.y makefile
+ $(YACC) -d -o $*.c $*.y
+
+# CT Rules
+%.c: %.ct makefile
+ $(CT) -o $@ $<
+
+# Miscellaneous
+.SECONDARY:
+
+# vim: ft=make
--- /dev/null
+# Settings
+CT = ../ct
+PROG = main
+SOURCES = main.c html.c
+
+default: main
+ ./main
+
+include ../common.mk
+++ /dev/null
-PROGS=main
-CLEAN=html.c
-
-default:V: run
-main: main.o html.o
-
-<../mkcommon
--- /dev/null
+# Settings
+CT = ../ct
+PROG = gallery
+SOURCES = gallery.c html.c ../lib.c
+CPPFLAGS = -I..
+PKGS = glib-2.0
+
+# Targets
+test: gallery
+ QUERY_STRING=foo ./gallery
+
+# Rules
+../lib.o: CFLAGS += -Wno-format
+
+include ../common.mk
+++ /dev/null
-PROGS = gallery
-PKGS = glib-2.0
-CLEAN = html.c
-CPPFLAGS = -I..
-CFLAGS = --std=c99 -Wall -Wno-format -g
-
-default:V: gallery
- QUERY_STRING=foo ./gallery
-
-gallery: gallery.o html.o ../lib.o
-
-<../mkcommon
--- /dev/null
+# Settings
+CT = ../ct
+PROG = knot
+SOURCES = knot.c html.c
+CPPFLAGS = -I..
+
+# Targets
+test: crown.html hitch.html overhand.html
+
+# Rules
+%.html: %.txt knot makefile
+ ./knot < $< > $@
+
+include ../common.mk
+++ /dev/null
-PROGS=knot
-CLEAN=html.c *.html
-
-knots=`{ls *.txt}
-default:V: ${knots:%.txt=%.html}
-
-knot: knot.o html.o knot.h
-
-%.html: $PROGS %.txt
- ./$PROGS < $stem.txt > $stem.html
-
-<../mkcommon
# Settings
PROG = ct
-CC = gcc
-YACC = bison
-LEX = flex
-
-CFLAGS = -Wall -Werror -g --std=c99
-CPPFLAGS = $(shell pkg-config --cflags glib-2.0)
-LDFLAGS = $(shell pkg-config --libs glib-2.0)
-
-# Targets
-default: test
-
-all: $(PROG)
+SOURCES = ct.o parse.o scan.o
+PKGS = glib-2.0
test: $(PROG)
./$(PROG) example/html.ct
-clean:
- rm -f $(PROG) *.o *.a parse.h parse.c scan.c
-
-# Rules
-$(PROG): ct.o parse.o scan.o
- $(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
-
-%.o: %.c parse.h
- $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
-
-%.c: %.l parse.h
- $(LEX) -o $@ $<
-
-%.c %.h: %.y
- $(YACC) -d -o $*.c $*.y
-
-.SECONDARY:
+include common.mk