bin_PROGRAMS = thrift
 
+noinst_LIBRARIES = libparse.a
+
 thrift_OBJDIR = obj
 
-thrift_SOURCES = src/thrifty.yy \
-                 src/thriftl.ll \
-                 src/main.cc \
+thrift_SOURCES = src/main.cc \
                  src/md5.c \
                  src/generate/t_generator.cc \
                  src/generate/t_generator_registry.h \
 thrift_SOURCES += src/generate/t_javame_generator.cc
 endif
 
-thrift_CXXFLAGS = -Wall -I$(srcdir)/src
-thrift_LDFLAGS = -Wall
+thrift_CPPFLAGS = -I$(srcdir)/src
+thrift_CXXFLAGS = -Wall
+thrift_LDADD = @LEXLIB@ libparse.a
+
+libparse_a_CPPFLAGS = -I$(srcdir)/src
+libparse_a_CXXFLAGS = -Wall -Wno-sign-compare -Wno-unused
 
-thrift_LDADD = @LEXLIB@
+libparse_a_SOURCES = src/thrifty.yy \
+                     src/thriftl.ll
 
 EXTRA_DIST = README
 
 
 
 %{
 
+/* This is redundant with some of the flags in Makefile.am, but it works
+ * when people override CXXFLAGS without being careful. The pragmas are
+ * the 'right' way to do it, but don't work on old-enough GCC (in particular
+ * the GCC that ship on Mac OS X 10.6.5, *counter* to what the GNU docs say)
+ *
+ * We should revert the Makefile.am changes once Apple ships a reasonable
+ * GCC.
+ */
 #pragma GCC diagnostic ignored "-Wunused-function"
 #pragma GCC diagnostic ignored "-Wunused-label"
 
 
 # Flags for the various libraries
 libthriftnb_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBEVENT_CPPFLAGS)
 libthriftz_la_CPPFLAGS  = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS)
-
+libthriftnb_la_CXXFLAGS = $(AM_CXXFLAGS)
+libthriftz_la_CXXFLAGS  = $(AM_CXXFLAGS)
 
 include_thriftdir = $(includedir)/thrift
 include_thrift_HEADERS = \
 
        -I$(top_srcdir)/lib/cpp/src
 
 AM_CPPFLAGS = $(BOOST_CPPFLAGS)
+AM_CXXFLAGS = -Wall
 
 clean-local:
        $(RM) -r gen-cpp