fix several build issues

Don't derive compilers from CHOST, instead the ebuild will tell us exactly
which compilers to use.
Don't force -g -O0.
Do make full use of CPPFLAGS, CFLAGS and LDFLAGS that portage might set for us.
Correct name in .pc file.
Moved .pc file generation to configure script - it's simpler that way.
Add copyrights.

BUG=chromium:358029
TEST=emerge hwcplus-drm to device, run rings-gralloc and see something on screen

Change-Id: Ibd2c7a2e22df45e0f3f2593508f9289406cdc883
Reviewed-on: https://chromium-review.googlesource.com/204973
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Commit-Queue: Frank Henigman <fjhenigman@chromium.org>
Tested-by: Frank Henigman <fjhenigman@chromium.org>
diff --git a/src/Makefile b/src/Makefile
index d6cb448..9fed63b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,8 +1,13 @@
+# Copyright 2014 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.
+
 include config
 
 HWC_HDR = $(shell $(PKG_CONFIG) --cflags hwcplus)
 # uncomment to use local source instead instead of installed headers
 #HWC_HDR = -I$(HOME)/chrome_root/src/third_party/hwcplus/include
+#HWC_HDR = -I../../../../chromium/src/third_party/hwcplus/include
 
 LIB_HWCPLUS   = $(shell $(PKG_CONFIG) --libs hwcplus)
 LIB_DRM_INTEL = $(shell $(PKG_CONFIG) --libs libdrm_intel)
@@ -35,31 +40,24 @@
 HALDEST=$(LIBDEST)/hwcplus
 PKGDEST=$(LIBDEST)/pkgconfig
 
-CC = $(CHOST)-gcc
-CXX = $(CHOST)-g++
-
 CFLAGS += $(INC) -fPIC
 CFLAGS += -DCHROMEOS -DANDROID_SMP=0 -DENABLE_INTEL -DHAVE_SYS_UIO_H
-CFLAGS += -O0 -g
 CXXFLAGS := $(CFLAGS)
 CFLAGS += -std=gnu99
 
-all: libgralloc_drm.so gralloc.default.so hwcplus-drm.pc tests/rings-gralloc
+all: libgralloc_drm.so gralloc.default.so tests/rings-gralloc
 
 gralloc.default.so: $(GRALLOC_OBJ) libgralloc_drm.so
-	$(CC) -shared -o $@ $^
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^
 
 libgralloc_drm.so: $(LIBGRALLOC_DRM_OBJ)
-	$(CC) -shared -o $@ $^ $(LIB_DRM_INTEL) -lm
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LIB_DRM_INTEL) -lm
 
 tests/rings-gralloc: tests/rings-gralloc.c
-	$(CC) $(CFLAGS) -o $@ $^ -L. $(LIB_HWCPLUS) -lm -ldl
-
-hwcplus-drm.pc: hwcplus-drm.pc.in
-	sed -e "s/@LIBDIR@/$(LIBDIR)/" < $^ > $@
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^ -L. $(LIB_HWCPLUS) -lm -ldl
 
 clean:
-	rm -f $(OBJ) hwcplus-drm.pc libgralloc_drm.so gralloc.default.so tests/rings-gralloc
+	rm -f $(OBJ) libgralloc_drm.so gralloc.default.so tests/rings-gralloc
 
 install:
 	install -d $(INCDEST)
diff --git a/src/config b/src/config
index bb307b3..88bf53a 100644
--- a/src/config
+++ b/src/config
@@ -1,3 +1,7 @@
+# Copyright 2014 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.
+
 $(warning **)
 $(warning ** USING PRE-PACKAGED CONFIGURATION.  You should edit 'config' to meet your needs.)
 $(warning **)
@@ -8,5 +12,6 @@
 # are libraries in /usr/lib or /usr/lib64?
 LIBDIR = lib64
 
-# cross compilation target
-CHOST = x86_64-cros-linux-gnu
+# cross compilers
+CC = x86_64-cros-linux-gnu-gcc
+CXX = x86_64-cros-linux-gnu-g++
diff --git a/src/configure b/src/configure
index 768615a..9d0a19e 100755
--- a/src/configure
+++ b/src/configure
@@ -1,6 +1,13 @@
 #! /bin/bash
+# Copyright 2014 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.
+
 cat > config <<EOF
 PKG_CONFIG = $PKG_CONFIG
 LIBDIR = $LIBDIR
-CHOST = $CHOST
+CC = $CC
+CXX = $CXX
 EOF
+
+sed -e "s/@LIBDIR@/$LIBDIR/" hwcplus-drm.pc.in > hwcplus-drm.pc
diff --git a/src/hwcplus-drm.pc.in b/src/hwcplus-drm.pc.in
old mode 100644
new mode 100755
index 211663f..69208f0
--- a/src/hwcplus-drm.pc.in
+++ b/src/hwcplus-drm.pc.in
@@ -3,7 +3,7 @@
 libdir=/usr/@LIBDIR@
 includedir=${prefix}/include
 
-Name: libgralloc_drm
+Name: hwcplus-drm
 Description: drm-based implemention of hwcplus
 Version: 0.1
 Libs: -L${libdir} -lgralloc_drm