[speech_synthesis] rewrite makefile

This fixes a bunch of issues:
 - drop hardcoded x86_generic -I/-L paths for all targets
 - use standard flag namings (CXXFLAGS/CPPFLAGS/LDLIBS)
 - split compiler flags into CXXFLAGS and preprocessor flags into CPPFLAGS
 - execute pkg-config twice per *make*, not per *file compile*
 - use pkg-config for all libraries were possible (alsa/libchrome)
 - fix link order -- we need flags, then objects, then libraries
 - fix build dependencies -- make sure dirs are created before they are
   needed, and make them an order-only depend; this should allow us to
   build in parallel again rather than forcing -j1
 - drop -fPIC hardcode -- we're creating an executable, not a library
 - drop the -I.. and -Iobjs flags -- there are no headers in either place

BUG=None
TEST=`emerge-x86-alex speech_synthesis` still works

Change-Id: I46f076927f1d0ce0dfb9f261310f32b4461cd22a
Reviewed-on: https://gerrit.chromium.org/gerrit/15987
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: Scott James Remnant <keybuk@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/Makefile b/Makefile
index bea7820..5920a79 100644
--- a/Makefile
+++ b/Makefile
@@ -1,21 +1,18 @@
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
 CXX ?= g++
 PKG_CONFIG ?= pkg-config
 
-LDFLAGS = -lpthread -lm -lasound -lpico -lresample -lchromeos -lrt -lbase
+PC_DEPS = alsa dbus-1 dbus-glib-1 gobject-2.0 libchrome libchromeos
+PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
+PC_LIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))
 
-CCFLAGS = $(CFLAGS) \
-	-Wall -Werror \
-	-I. \
-	-I/build/x86_generic/usr/include \
-	-L/build/x86_generic/usr/lib
-
-PC_DEPS = dbus-1 dbus-glib-1 gobject-2.0 libchromeos
-INCLUDE_DIRS=-I.. $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
-LIB_DIRS=$(shell $(PKG_CONFIG) --libs $(PC_DEPS))
+CXXFLAGS += -Wall -Werror
+CPPFLAGS += -I. $(PC_CFLAGS)
+LDLIBS = -lpico -lresample
+LDLIBS += $(PC_LIBS)
 
 DBUS_SOURCE=speech_synthesizer.xml
 DBUS_SERVER=bindings/server.h
@@ -29,31 +26,26 @@
 threading.h tts_engine.h tts_receiver.h tts_service.h log.h \
 speech_synthesizer_service.h interface.h
 
-all: dirs speech_synthesizer
-	@echo "Done building."
+all: speech_synthesizer
 
 clean:
 	rm -rf libttspico.so objs/
 
 dirs:
-	test -d objs/pico || mkdir -p objs/pico
-	test -d objs/linux || mkdir -p objs/linux
+	mkdir -p objs/pico objs/linux
 
 CC_OBJS = $(CC_SRCS:%.cc=objs/%.o)
 OBJS = $(CC_OBJS)
 
-$(CC_OBJS): objs/%.o: %.cc $(HEADERS) $(DBUS_SERVER)
-	$(CXX) -c $(CCFLAGS) $(INCLUDE_DIRS) $(LIB_DIRS) -fPIC -Iobjs/ $< -o $@
+$(CC_OBJS): objs/%.o: %.cc $(HEADERS) $(DBUS_SERVER) | dirs
+	$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
 
 speech_synthesizer: $(OBJS)
-	$(CXX) \
-	$(CCFLAGS) $(INCLUDE_DIRS) $(LIB_DIRS) \
-	-o $@ $^ \
-	$(LDFLAGS)
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
 $(BINDINGS_DIR):
 	mkdir -p $(BINDINGS_DIR)
 
-$(DBUS_SERVER): $(DBUS_SOURCE) $(BINDINGS_DIR)
+$(DBUS_SERVER): $(DBUS_SOURCE) | $(BINDINGS_DIR)
 	dbus-binding-tool --mode=glib-server \
 	 --prefix=`basename $(DBUS_SOURCE) .xml` $(DBUS_SOURCE) > $(DBUS_SERVER)