locitest: add Makefile

This greatly speeds up incremental compiles (along with ccache).
diff --git a/Makefile b/Makefile
index 36f73ef..eef6313 100644
--- a/Makefile
+++ b/Makefile
@@ -98,17 +98,9 @@
 	PYTHONPATH=${LOXI_OUTPUT_DIR}/pyloxi:. python py_gen/tests/of12.py
 	PYTHONPATH=${LOXI_OUTPUT_DIR}/pyloxi:. python py_gen/tests/of13.py
 
-CTEST_EXEC = ${LOXI_OUTPUT_DIR}/locitest/locitest
-CTEST_SOURCE = ${LOXI_OUTPUT_DIR}/locitest/src/*.c
-CTEST_SOURCE += ${LOXI_OUTPUT_DIR}/loci/src/*.c
-CTEST_INC = -I ${LOXI_OUTPUT_DIR}/loci/inc
-CTEST_INC += -I ${LOXI_OUTPUT_DIR}/locitest/inc
-CTEST_INC += -I ${LOXI_OUTPUT_DIR}/loci/src
-CTEST_CFLAGS = -Wall -Werror -g
-
 check-c: c
-	gcc ${CTEST_CFLAGS} -o ${CTEST_EXEC} ${CTEST_SOURCE} ${CTEST_INC}
-	${CTEST_EXEC}
+	make -C ${LOXI_OUTPUT_DIR}/locitest
+	${LOXI_OUTPUT_DIR}/locitest/locitest
 
 pylint:
 	pylint -E ${LOXI_PY_FILES}
diff --git a/c_gen/templates/locitest/Makefile b/c_gen/templates/locitest/Makefile
new file mode 100644
index 0000000..ed4ba13
--- /dev/null
+++ b/c_gen/templates/locitest/Makefile
@@ -0,0 +1,12 @@
+SRCS := $(wildcard src/*.c)
+SRCS += $(wildcard ../loci/src/*.c)
+
+OBJS := $(SRCS:.c=.o)
+
+CFLAGS := -Wall -Werror -g
+CFLAGS += -Iinc -I../loci/inc -I ../loci/src
+
+all: locitest
+
+locitest: $(OBJS)
+	$(CC) $^ -o $@
diff --git a/lang_c.py b/lang_c.py
index aae08ea..157339b 100644
--- a/lang_c.py
+++ b/lang_c.py
@@ -107,4 +107,5 @@
     'locitest/src/test_utils.c': static,
     'locitest/src/test_validator.c': static,
     'locitest/src/main.c': static,
+    'locitest/Makefile': static,
 }