-# test the strutils stuff
-PROGRAM = StrUtil${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = strutil_test.cc
-include $(PROGRAM_H)
+# All Google Test headers. Usually you shouldn't change this definition.
+GTEST_HEADERS = /usr/include/gtest/*.h \
+ /usr/include/gtest/internal/*.h
+
+# House-keeping build targets.
+.PHONY: clean/gtest veryclean/gtest
+clean: clean/gtest
+clean/gtest:
+ rm -f $(gtest-OBJS)
+veryclean: veryclean/gtest
+veryclean/gtest: clean/gtest
+ rm -f $(LIB)/gtest.a
+
+# Usually you shouldn't tweak such internal variables, indicated by a
+# trailing _.
+GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
+
+# Builds gtest.a
+# For simplicity and to avoid depending on Google Test's
+# implementation details, the dependencies specified below are
+# conservative and not optimized. This is fine as Google Test
+# compiles fast and for ordinary users its source rarely changes.
+$(gtest-OBJS): $(GTEST_SRCS_)
+ echo Compiling $@
+ $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $(GTEST_DIR)/src/$(notdir $(basename $@)).cc
+
+$(LIB)/gtest.a: $(OBJ)/gtest-all.o
+ echo Building static library $@
+ -rm -f $@
+ $(AR) $(ARFLAGS) $@ $^