Refine the makefiles.

* Introduce libbcc.mk which defines the path for makefiles and libbcc
  configuration.
* Introduce libbcc-{device,host}-build.mk which defines the build
  flags for building libbcc itself and/or for building module using
  libbcc.
* Add header guard for generated ConfigFromMk.h.
diff --git a/Android.mk b/Android.mk
index db76dec..e9a3102 100644
--- a/Android.mk
+++ b/Android.mk
@@ -15,8 +15,8 @@
 #
 
 LOCAL_PATH := $(call my-dir)
-include $(LOCAL_PATH)/libbcc-config.mk
-
+LIBBCC_ROOT_PATH := $(LOCAL_PATH)
+include $(LIBBCC_ROOT_PATH)/libbcc.mk
 
 #=====================================================================
 # Whole Static Library to Be Linked In
@@ -64,11 +64,6 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 
-LOCAL_CFLAGS := $(libbcc_CFLAGS)
-LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
-
-LOCAL_SRC_FILES := lib/ExecutionEngine/bcc.cpp
-
 LOCAL_WHOLE_STATIC_LIBRARIES := $(libbcc_WHOLE_STATIC_LIBRARIES)
 
 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm x86))
@@ -158,10 +153,9 @@
 LOCAL_LDFLAGS += -Wl,--exclude-libs=libLLVMARMDisassembler:libLLVMARMAsmPrinter:libLLVMX86Disassembler:libLLVMX86AsmPrinter:libLLVMMCParser:libLLVMARMCodeGen:libLLVMARMDesc:libLLVMARMInfo:libLLVMSelectionDAG:libLLVMAsmPrinter:libLLVMCodeGen:libLLVMLinker:libLLVMTarget:libLLVMMC:libLLVMScalarOpts:libLLVMInstCombine:libLLVMipo:libLLVMipa:libLLVMTransformUtils:libLLVMAnalysis
 
 # Generate build stamp (Build time + Build git revision + Build Semi SHA1)
-include $(LOCAL_PATH)/libbcc-gen-build-stamp.mk
+include $(LIBBCC_ROOT_PATH)/libbcc-gen-build-stamp.mk
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LLVM_ROOT_PATH)/llvm-device-build.mk
+include $(LIBBCC_DEVICE_BUILD_MK)
 include $(BUILD_SHARED_LIBRARY)
 
 
@@ -176,12 +170,6 @@
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 LOCAL_IS_HOST_MODULE := true
 
-LOCAL_CFLAGS := $(libbcc_CFLAGS)
-LOCAL_CFLAGS += -D__HOST__
-LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
-
-LOCAL_SRC_FILES := lib/ExecutionEngine/bcc.cpp
-
 LOCAL_WHOLE_STATIC_LIBRARIES += $(libbcc_WHOLE_STATIC_LIBRARIES)
 
 LOCAL_STATIC_LIBRARIES += librsloader
@@ -239,10 +227,9 @@
 LOCAL_LDLIBS := -ldl -lpthread
 
 # Generate build stamp (Build time + Build git revision + Build Semi SHA1)
-include $(LOCAL_PATH)/libbcc-gen-build-stamp.mk
+include $(LIBBCC_ROOT_PATH)/libbcc-gen-build-stamp.mk
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LLVM_ROOT_PATH)/llvm-host-build.mk
+include $(LIBBCC_HOST_BUILD_MK)
 include $(BUILD_HOST_SHARED_LIBRARY)
 
 
diff --git a/helper/Android.mk b/helper/Android.mk
index 54b408b..3e606e6 100644
--- a/helper/Android.mk
+++ b/helper/Android.mk
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2011 The Android Open Source Project
+# Copyright (C) 2011-2012 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
 #
 
 LOCAL_PATH := $(call my-dir)
-include $(LOCAL_PATH)/../libbcc-config.mk
-
 
 #=====================================================================
 # Device Static Library: libbccHelper
@@ -29,14 +27,11 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
-LOCAL_CFLAGS += $(libbcc_CFLAGS)
-LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
-
 LOCAL_SRC_FILES := sha1.c
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
-include $(LLVM_ROOT_PATH)/llvm-device-build.mk
+include $(LIBBCC_DEVICE_BUILD_MK)
+include $(LIBBCC_GEN_CONFIG_MK)
+include $(LLVM_DEVICE_BUILD_MK)
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -49,17 +44,11 @@
 LOCAL_MODULE := libbccHelper
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
-
-LOCAL_CFLAGS += $(libbcc_CFLAGS)
-LOCAL_CFLAGS += -D__HOST__
-
-LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
   sha1.c
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
-include $(LLVM_ROOT_PATH)/llvm-host-build.mk
+include $(LIBBCC_HOST_BUILD_MK)
+include $(LIBBCC_GEN_CONFIG_MK)
+include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_STATIC_LIBRARY)
diff --git a/lib/Disassembler/Android.mk b/lib/Disassembler/Android.mk
index 1d925ed..3886b33 100644
--- a/lib/Disassembler/Android.mk
+++ b/lib/Disassembler/Android.mk
@@ -16,7 +16,6 @@
 #
 
 LOCAL_PATH := $(call my-dir)
-include $(LOCAL_PATH)/../../libbcc-config.mk
 
 ifeq ($(libbcc_USE_DISASSEMBLER),1)
 
@@ -37,13 +36,12 @@
 LOCAL_MODULE := libbccDisassembler
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_CFLAGS += $(libbcc_CFLAGS)
-LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
+
 LOCAL_SRC_FILES := $(libbcc_disassembler_SRC_FILES)
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
-include $(LLVM_ROOT_PATH)/llvm-device-build.mk
+include $(LIBBCC_DEVICE_BUILD_MK)
+include $(LIBBCC_GEN_CONFIG_MK)
+include $(LLVM_DEVICE_BUILD_MK)
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -58,15 +56,11 @@
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 LOCAL_IS_HOST_MODULE := true
 
-LOCAL_CFLAGS += $(libbcc_CFLAGS)
-LOCAL_CFLAGS += -D__HOST__
-LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
-
 LOCAL_SRC_FILES := $(libbcc_disassembler_SRC_FILES)
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
-include $(LLVM_ROOT_PATH)/llvm-host-build.mk
+include $(LIBBCC_HOST_BUILD_MK)
+include $(LIBBCC_GEN_CONFIG_MK)
+include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 endif # $(libbcc_USE_DISASSEMBLER)
diff --git a/lib/ExecutionEngine/Android.mk b/lib/ExecutionEngine/Android.mk
index 8c78cd0..f3b2c3d 100644
--- a/lib/ExecutionEngine/Android.mk
+++ b/lib/ExecutionEngine/Android.mk
@@ -16,7 +16,6 @@
 #
 
 LOCAL_PATH := $(call my-dir)
-include $(LOCAL_PATH)/../../libbcc-config.mk
 
 #=====================================================================
 # Common: libbccExecutionEngine
@@ -51,8 +50,8 @@
   Source.cpp \
   SymbolResolverProxy.cpp \
   SymbolResolvers.cpp \
-  TargetCompilerConfigs.cpp
-
+  TargetCompilerConfigs.cpp \
+  bcc.cpp
 
 #=====================================================================
 # Device Static Library: libbccExecutionEngine
@@ -64,19 +63,16 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
-LOCAL_CFLAGS += $(libbcc_CFLAGS)
-LOCAL_CFLAGS += -DTARGET_BUILD
-
 LOCAL_C_INCLUDES := \
-  $(libbcc_C_INCLUDES) \
   $(RSLOADER_ROOT_PATH) \
   $(RSLOADER_ROOT_PATH)/include
+
 LOCAL_SRC_FILES := $(libbcc_executionengine_SRC_FILES)
 LOCAL_SHARED_LIBRARIES := libbcinfo
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
-include $(LLVM_ROOT_PATH)/llvm-device-build.mk
+include $(LIBBCC_DEVICE_BUILD_MK)
+include $(LIBBCC_GEN_CONFIG_MK)
+include $(LLVM_DEVICE_BUILD_MK)
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -89,19 +85,15 @@
 LOCAL_MODULE := libbccExecutionEngine
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
 
-LOCAL_CFLAGS += $(libbcc_CFLAGS)
-LOCAL_CFLAGS += -D__HOST__
 LOCAL_C_INCLUDES := \
-  $(libbcc_C_INCLUDES) \
   $(RSLOADER_ROOT_PATH) \
   $(RSLOADER_ROOT_PATH)/include
 
 LOCAL_SRC_FILES := $(libbcc_executionengine_SRC_FILES)
 LOCAL_SHARED_LIBRARIES := libbcinfo
 
-include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
-include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
-include $(LLVM_ROOT_PATH)/llvm-host-build.mk
+include $(LIBBCC_HOST_BUILD_MK)
+include $(LIBBCC_GEN_CONFIG_MK)
+include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_STATIC_LIBRARY)
diff --git a/libbcc-build-rules.mk b/libbcc-build-rules.mk
deleted file mode 100644
index a065ed6..0000000
--- a/libbcc-build-rules.mk
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-
-#=====================================================================
-# Architecture Selection
-#=====================================================================
-
-ifeq ($(LOCAL_IS_HOST_MODULE),) # Target Build
-
-  # Note: We should only use -DFORCE_ARCH_CODEGEN on target build.
-  # For the host build, we will include as many architecture as possible,
-  # so that we can test the execution engine easily.
-
-  ifeq ($(TARGET_ARCH),arm)
-    LOCAL_CFLAGS += -DFORCE_ARM_CODEGEN
-    ifeq ($(ARCH_ARM_HAVE_VFP),true)
-      LOCAL_CFLAGS += -DARCH_ARM_HAVE_VFP
-      ifeq ($(ARCH_ARM_HAVE_VFP_D32),true)
-        LOCAL_CFLAGS += -DARCH_ARM_HAVE_VFP_D32
-      endif
-    endif
-    ifeq ($(ARCH_ARM_HAVE_NEON),true)
-      LOCAL_CFLAGS += -DARCH_ARM_HAVE_NEON
-    endif
-  else
-    ifeq ($(TARGET_ARCH),mips)
-      LOCAL_CFLAGS += -DFORCE_MIPS_CODEGEN
-    else
-      ifeq ($(TARGET_ARCH),x86)
-        LOCAL_CFLAGS += -DFORCE_X86_CODEGEN
-      else
-        $(error Unsupported architecture $(TARGET_ARCH))
-      endif
-    endif
-  endif
-
-endif
diff --git a/libbcc-config.mk b/libbcc-config.mk
index ac5372b..debf929 100644
--- a/libbcc-config.mk
+++ b/libbcc-config.mk
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2011 The Android Open Source Project
+# Copyright (C) 2011-2012 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,15 +16,6 @@
 
 
 #=====================================================================
-# Root Path for Other Projects
-#=====================================================================
-
-LLVM_ROOT_PATH      := external/llvm
-LIBBCC_ROOT_PATH    := frameworks/compile/libbcc
-RSLOADER_ROOT_PATH  := frameworks/compile/linkloader
-
-
-#=====================================================================
 # Configurations
 #=====================================================================
 
@@ -44,21 +35,3 @@
 else
 libbcc_USE_DISASSEMBLER := 1
 endif
-
-
-#=====================================================================
-# Common Variables
-#=====================================================================
-
-libbcc_CFLAGS := -Wall -Wno-unused-parameter -Werror
-ifeq ($(TARGET_BUILD_VARIANT),eng)
-libbcc_CFLAGS += -DANDROID_ENGINEERING_BUILD
-endif
-
-# Include File Search Path
-libbcc_C_INCLUDES := \
-  $(RSLOADER_ROOT_PATH)/android \
-  $(LIBBCC_ROOT_PATH)/lib \
-  $(LIBBCC_ROOT_PATH)/helper \
-  $(LIBBCC_ROOT_PATH)/include \
-  $(LIBBCC_ROOT_PATH)
diff --git a/libbcc-device-build.mk b/libbcc-device-build.mk
new file mode 100644
index 0000000..a3d294a
--- /dev/null
+++ b/libbcc-device-build.mk
@@ -0,0 +1,62 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_CFLAGS := \
+  -Wall \
+  -Wno-unused-parameter \
+  -Werror \
+  -DTARGET_BUILD \
+  $(LOCAL_CFLAGS)
+
+ifeq ($(TARGET_BUILD_VARIANT),eng)
+LOCAL_CFLAGS += -DANDROID_ENGINEERING_BUILD
+endif
+
+#=====================================================================
+# Architecture Selection
+#=====================================================================
+# Note: We should only use -DFORCE_ARCH_CODEGEN on target build.
+# For the host build, we will include as many architecture as possible,
+# so that we can test the execution engine easily.
+
+ifeq ($(TARGET_ARCH),arm)
+  LOCAL_CFLAGS += -DFORCE_ARM_CODEGEN
+  ifeq ($(ARCH_ARM_HAVE_VFP),true)
+    LOCAL_CFLAGS += -DARCH_ARM_HAVE_VFP
+    ifeq ($(ARCH_ARM_HAVE_VFP_D32),true)
+      LOCAL_CFLAGS += -DARCH_ARM_HAVE_VFP_D32
+    endif
+  endif
+  ifeq ($(ARCH_ARM_HAVE_NEON),true)
+    LOCAL_CFLAGS += -DARCH_ARM_HAVE_NEON
+  endif
+else
+  ifeq ($(TARGET_ARCH),mips)
+    LOCAL_CFLAGS += -DFORCE_MIPS_CODEGEN
+  else
+    ifeq ($(TARGET_ARCH),x86)
+      LOCAL_CFLAGS += -DFORCE_X86_CODEGEN
+    else
+      $(error Unsupported architecture $(TARGET_ARCH))
+    endif
+  endif
+endif
+
+LOCAL_C_INCLUDES := \
+  $(LIBBCC_ROOT_PATH) \
+  $(LIBBCC_ROOT_PATH)/helper \
+  $(LIBBCC_ROOT_PATH)/include \
+  $(LOCAL_C_INCLUDES)
diff --git a/libbcc-host-build.mk b/libbcc-host-build.mk
new file mode 100644
index 0000000..b5bc9bd
--- /dev/null
+++ b/libbcc-host-build.mk
@@ -0,0 +1,34 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_CFLAGS := \
+  -Wall \
+  -Wno-unused-parameter \
+  -Werror \
+  -D__HOST__ \
+  $(LOCAL_CFLAGS)
+
+ifeq ($(TARGET_BUILD_VARIANT),eng)
+libbcc_CFLAGS += -DANDROID_ENGINEERING_BUILD
+endif
+
+LOCAL_C_INCLUDES := \
+  $(LIBBCC_ROOT_PATH) \
+  $(LIBBCC_ROOT_PATH)/helper \
+  $(LIBBCC_ROOT_PATH)/include \
+  $(LOCAL_C_INCLUDES)
+
+LOCAL_IS_HOST_MODULE := true
diff --git a/libbcc.mk b/libbcc.mk
new file mode 100644
index 0000000..936573b
--- /dev/null
+++ b/libbcc.mk
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+ifeq ($(LIBBCC_ROOT_PATH),)
+$(error Must set variable LIBBCC_ROOT_PATH before including this! $(LOCAL_PATH))
+endif
+
+#=====================================================================
+# Root Path for Other Projects
+#=====================================================================
+
+LLVM_ROOT_PATH          := external/llvm
+RSLOADER_ROOT_PATH      := frameworks/compile/linkloader
+
+#=====================================================================
+# Related Makefile Paths of libbcc
+#=====================================================================
+
+LIBBCC_HOST_BUILD_MK    := $(LIBBCC_ROOT_PATH)/libbcc-host-build.mk
+LIBBCC_DEVICE_BUILD_MK  := $(LIBBCC_ROOT_PATH)/libbcc-device-build.mk
+LIBBCC_GEN_CONFIG_MK    := $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
+
+#=====================================================================
+# Configuration of libbcc
+#=====================================================================
+include $(LIBBCC_ROOT_PATH)/libbcc-config.mk
+
+#=====================================================================
+# Related Makefile Paths of LLVM
+#=====================================================================
+include $(LLVM_ROOT_PATH)/llvm.mk
diff --git a/runtime/Android.mk b/runtime/Android.mk
index c2051ec..64ce061 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2011 The Android Open Source Project
+# Copyright (C) 2011-2012 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
 #
 
 LOCAL_PATH := $(call my-dir)
-include $(LOCAL_PATH)/../libbcc-config.mk
 
 #=====================================================================
 # Device Static Library: libbccCompilerRT
@@ -88,7 +87,7 @@
   endif
 endif
 
-include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
+include $(LIBBCC_DEVICE_BUILD_MK)
 include $(BUILD_STATIC_LIBRARY)
 
 endif # ifneq($(TARGET_ARCH),mips)
diff --git a/tools/bcc/Android.mk b/tools/bcc/Android.mk
index 373e594..6541fd3 100644
--- a/tools/bcc/Android.mk
+++ b/tools/bcc/Android.mk
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2010 The Android Open Source Project
+# Copyright (C) 2010-2012 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -21,22 +21,15 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := bcc
-
-LOCAL_SRC_FILES := \
-  main.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-  libbcc
-
-LOCAL_C_INCLUDES := \
-  $(LOCAL_PATH)/../../include
-
 LOCAL_MODULE_TAGS := tests eng
+LOCAL_MODULE_CLASS := EXECUTABLES
 
+LOCAL_SRC_FILES := main.cpp
+
+LOCAL_SHARED_LIBRARIES := libbcc
 LOCAL_LDLIBS = -ldl
 
-LOCAL_CFLAGS += -D__HOST__ -Wall -Werror
-
+include $(LIBBCC_HOST_BUILD_MK)
 include $(BUILD_HOST_EXECUTABLE)
 
 # Executable for target
@@ -44,16 +37,13 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := bcc
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := EXECUTABLES
 
-LOCAL_SRC_FILES := \
-  main.cpp
+LOCAL_SRC_FILES := main.cpp
 
 LOCAL_SHARED_LIBRARIES := libdl libstlport libbcinfo libbcc
 
-LOCAL_C_INCLUDES := \
-  $(LOCAL_PATH)/../../include
-
-LOCAL_MODULE_TAGS := optional
-
 include external/stlport/libstlport.mk
+include $(LIBBCC_DEVICE_BUILD_MK)
 include $(BUILD_EXECUTABLE)
diff --git a/tools/bcc/main.cpp b/tools/bcc/main.cpp
index a2492fb..a0d4e5a 100644
--- a/tools/bcc/main.cpp
+++ b/tools/bcc/main.cpp
@@ -65,7 +65,9 @@
 };
 
 // forward declaration of option processing functions
+#if defined(__HOST__)
 static int optSetTriple(int, char **);
+#endif
 static int optSetInput(int, char **);
 static int optSetOutput(int, char **);
 static int optSetIntermediateOutput(int, char **);
diff --git a/tools/build/gen-build-stamp.py b/tools/build/gen-build-stamp.py
index 8a43790..48c0847 100755
--- a/tools/build/gen-build-stamp.py
+++ b/tools/build/gen-build-stamp.py
@@ -1,4 +1,19 @@
 #!/usr/bin/env python
+#
+# Copyright (C) 2011-2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
 import datetime
 import os
diff --git a/tools/build/gen-config-from-mk.py b/tools/build/gen-config-from-mk.py
index 66b5978..5646ee7 100755
--- a/tools/build/gen-config-from-mk.py
+++ b/tools/build/gen-config-from-mk.py
@@ -1,4 +1,21 @@
 #!/usr/bin/env python
+#
+# Copyright (C) 2011-2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import datetime
 
 import re
 import sys
@@ -17,6 +34,8 @@
     for line in f:
         if state == STATE_PRE_CONFIG:
             if conf_patt.match(line.strip()):
+                print '#ifndef BCC_CONFIG_FROM_MK_H'
+                print '#define BCC_CONFIG_FROM_MK_H'
                 state = STATE_FOUND_CONFIG
 
         elif state == STATE_FOUND_CONFIG:
@@ -33,6 +52,7 @@
             elif split_patt.match(line.strip()):
                 # Stop reading the configuration
                 print '/* END USER CONFIG */'
+                print '#endif // BCC_CONFIG_FROM_MK_H'
                 break
 
 def main():
diff --git a/tools/build/gen-sha1-stamp.py b/tools/build/gen-sha1-stamp.py
index ab3dfc7..9f9b728 100755
--- a/tools/build/gen-sha1-stamp.py
+++ b/tools/build/gen-sha1-stamp.py
@@ -1,4 +1,19 @@
 #!/usr/bin/env python
+#
+# Copyright (C) 2011-2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
 import sys