add build for pdk1/pdk2
- pdk1: minimal UI
- pdk2: PDK only build + binaries from pdk1 build
- copy_pdk1_bins.py: script to copy pdk1 build result for pdk2 build
- create_source_tree.py: script to generate minimal build source tree
                         for pdk2 build
- copy_pdk_data.py: script to copy necessary headers / data for pdk build
- setup_pdk2.py : script to copy pdk binaries from vendor to out

Bug: 6079146

Change-Id: I4a6bf78783c1f1f1a8f945b372066d83d01bea78
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2f836aa
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*~
+*.pyc
diff --git a/build/copy_pdk1_bins.py b/build/copy_pdk1_bins.py
new file mode 100755
index 0000000..0c30d11
--- /dev/null
+++ b/build/copy_pdk1_bins.py
@@ -0,0 +1,270 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+# script to copy PDK1 build result into a dir for PDK2 build
+
+import os, string, sys, shutil
+import copy_utils as cu
+
+
+# currently javalib.jar is not used and target jar is just copied in raw copy process
+def copy_jar(src_jar_dir, dest_dir, jar_name):
+  """copy classes.jar and javalib.jar to dest_dir/jar_name dir"""
+  cu.copy_file_if_exists(src_jar_dir, dest_dir + "/" + jar_name, "classes.jar")
+  cu.copy_file_if_exists(src_jar_dir, dest_dir + "/" + jar_name, "javalib.jar")
+
+def copy_classes_or_javalib(src_jar_dir, dest_dir, jar_name):
+  """For host, either classes.jar or javalib.jar is enough.
+     Use javalib only when there is no classes.jar"""
+  if cu.copy_file_new_name_if_exists(src_jar_dir + "/classes.jar", dest_dir + "/" + jar_name,
+                                     jar_name + ".jar"):
+    return
+  cu.copy_file_new_name_if_exists(src_jar_dir + "/javalib.jar", dest_dir + "/" + jar_name,
+                                  jar_name + ".jar")
+
+class DependencyMk(object):
+  def __init__(self, file_full_name):
+    self.f = open(file_full_name, "a+")
+
+  def __del__(self):
+    self.f.flush()
+    self.f.close()
+
+  def addHostA(self, a_name):
+    self.f.write("include $(CLEAR_VARS)\n")
+    self.f.write("LOCAL_PREBUILT_LIBS := " + "host/lib/" + a_name + ".a\n")
+    self.f.write("LOCAL_MODULE_TAGS := optional\n")
+    self.f.write("include $(BUILD_HOST_PREBUILT)\n")
+
+  def addHostSo(self, so_name):
+    # same as .a in makefile, distinguished by extension in build/core/multi_prebuilt.mk
+    self.f.write("include $(CLEAR_VARS)\n")
+    self.f.write("LOCAL_PREBUILT_LIBS := " + "host/lib/" + so_name + ".so\n")
+    self.f.write("LOCAL_MODULE_TAGS := optional\n")
+    self.f.write("include $(BUILD_HOST_PREBUILT)\n")
+
+  def addHostJar(self, jar_name):
+    self.f.write("include $(CLEAR_VARS)\n")
+    self.f.write("LOCAL_MODULE_TAGS := optional\n")
+    self.f.write("LOCAL_PREBUILT_JAVA_LIBRARIES := " + "host/java_lib/" + jar_name
+                 + "/" + jar_name + ".jar\n")
+    self.f.write("include $(BUILD_HOST_PREBUILT)\n")
+
+  def addTargetA(self, a_name):
+    self.f.write("include $(CLEAR_VARS)\n")
+    self.f.write("LOCAL_MODULE := " + a_name + "\n")
+    self.f.write("LOCAL_SRC_FILES := target/lib/" + a_name + ".a\n")
+    self.f.write("LOCAL_MODULE_TAGS := optional\n")
+    self.f.write("LOCAL_MODULE_SUFFIX := .a\n")
+    self.f.write("LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n")
+    self.f.write("include $(BUILD_PREBUILT)\n")
+
+  def addTargetSo(self, so_name):
+    self.f.write("include $(CLEAR_VARS)\n")
+    self.f.write("LOCAL_MODULE := " + so_name + "\n")
+    self.f.write("LOCAL_SRC_FILES := target/lib/" + so_name + ".so\n")
+    self.f.write("LOCAL_MODULE_TAGS := optional\n")
+    self.f.write("LOCAL_MODULE_SUFFIX := .so\n")
+    self.f.write("LOCAL_MODULE_CLASS := SHARED_LIBRARIES\n")
+    self.f.write("LOCAL_MODULE_PATH := $(TARGET_OUT)/lib\n")
+    self.f.write("OVERRIDE_BUILT_MODULE_PATH := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)\n")
+    self.f.write("include $(BUILD_PREBUILT)\n")
+
+  def addTargetJar(self, jar_name):
+    self.f.write("include $(CLEAR_VARS)\n")
+    self.f.write("LOCAL_MODULE_TAGS := optional\n")
+    self.f.write("LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := " + jar_name + ":target/java_lib/" +
+                 jar_name + "/classes.jar\n")
+    self.f.write("include $(BUILD_MULTI_PREBUILT)\n")
+
+  def addString(self, message):
+    self.f.write(message)
+
+# individual files top copy as it is
+# product/maguro will be substituted into product/target_name later
+raw_file_list = [
+# "target/common/obj/PACKAGING/public_api.txt",
+  "host/linux-x86/bin/dx",
+  "host/linux-x86/bin/aapt",
+  # necessary for bootstrapping in host as the path is always assumed
+  "host/common/obj/JAVA_LIBRARIES/core-hostdex_intermediates/classes.jar",
+  "host/common/obj/JAVA_LIBRARIES/core-hostdex_intermediates/javalib.jar",
+  "host/common/obj/JAVA_LIBRARIES/core-junit-hostdex_intermediates/classes.jar",
+  "host/common/obj/JAVA_LIBRARIES/core-junit-hostdex_intermediates/javalib.jar",
+  # these permission stuffs are not copied as frameworks is not built
+  "target/product/maguro/system/etc/permissions/com.android.location.provider.xml",
+  "target/product/maguro/system/etc/permissions/platform.xml",
+  ]
+
+# the whole dir to copy as it is
+raw_dir_list = [
+  "target/product/maguro/system/etc/dhcpcd",
+  "target/product/maguro/system/etc/ppp",
+  "target/product/maguro/system/app",
+  "target/product/maguro/system/bin",
+  "target/product/maguro/system/etc/security",
+  "target/product/maguro/system/framework",
+  "target/product/maguro/system/lib",
+  # tools for debugging, not all of them are built in pdk2 build
+  "target/product/maguro/system/xbin"
+  ]
+
+# from host/linux-x86/obj/STATIC_LIBRARIES/XYZ_intermediates
+host_a_list = [
+  "libandroidfw"
+  ]
+
+# from host/linux-x86/obj/lib
+host_so_list = [
+  "libbcc"
+  ]
+
+# from host/commom/JAVA_LIBRARIES/XYZ_intermediates
+host_jar_list = [
+  "core-hostdex",
+  "dx",
+  "core-junit-hostdex"
+  ]
+
+# from target/product/product_name/obj/STATIC_LIBRARIES/XYZ_intermediates
+target_a_list = [
+  "libdrmframeworkcommon",
+  "libcpustats",
+  "libv8"
+  ]
+
+# from target/product/product_name/obj/lib
+target_so_list = [
+  "libandroid",
+  "libandroidfw",
+  "libandroid_runtime",
+  "libandroid_servers",
+  "libjnigraphics",
+  "libnativehelper",
+  "libemoji",
+  "libdrmframework",
+  "libbcc",
+  "libdvm",
+  "libchromium_net",
+  "libcamera_client",
+  ]
+
+
+# from target/common/obj/JAVA_LIBRARIES
+target_jar_list = [
+  "core",
+  "core-junit",
+  "ext",
+  "framework",
+  "android.test.runner",
+  "android_stubs_current"
+  ]
+
+# files unnecessarily built for PDK. remove after copy
+raw_target_files_to_remove = [
+  # redundant
+  "target/product/maguro/system/app/Home.apk",
+  # stingray build included due to wrong mk file
+  "target/product/maguro/system/app/StingrayProgramMenu*.apk",
+  "target/product/maguro/system/app/SprintMenu.apk",
+  "target/product/maguro/system/app/WiMAX*.apk",
+  # wallpaper, not necessary
+  "target/product/maguro/system/app/Microbes.apk",
+  # H/W depedent anyway
+  "target/procuct/maguro/system/hw",
+  "target/product/maguro/system/lib/hw",
+  "target/product/maguro/system/lib/libOMX.SEC.*.so",
+  "target/product/maguro/system/lib/libSEC_OMX*.so",
+  "target/product/maguro/system/lib/libWiMAX*.so",
+  "target/product/maguro/system/lib/libOMX.TI.*.so",
+  "target/product/maguro/system/lib/libOMX_Core.so",
+  ]
+
+def main(argv):
+  if len(argv) != 4:
+    print "Usage: copy_pdk1_bins.py src_top_dir dest_top_dir src_target_device"
+    print "   ex: copy_pdk1_bins.py ../master vendor/pdk_bin_j_arm maguro"
+    sys.exit(1)
+  src_top_dir = argv[1]
+  src_out_dir = argv[1] + "/out/"
+  dest_top_dir = argv[2]
+  target_name = argv[3]
+
+  # now replace product/maguro to product/target_name for all lists
+  replacement_list = [
+    raw_file_list,
+    raw_dir_list,
+    raw_target_files_to_remove
+    ]
+  for dir_list in replacement_list:
+    for i in xrange(len(dir_list)):
+      replacement = dir_list[i].replace("product/maguro", "product/" + target_name)
+      dir_list[i] = replacement
+
+  src_target_top_dir = src_out_dir + "/target/product/" + target_name + "/"
+  # delete existing binaries
+  os.system("rm -rf " + dest_top_dir + "/host")
+  os.system("rm -rf " + dest_top_dir + "/raw_copy")
+  os.system("rm -rf " + dest_top_dir + "/target")
+  # copy template for mk
+  cu.copy_file_if_exists(src_top_dir + "/pdk/build", dest_top_dir, "pdk_prebuilt.mk")
+  mkFile = DependencyMk(dest_top_dir + "/pdk_prebuilt.mk")
+  mkFile.addString("\n\n\n")
+  mkFile.addString("PDK_BIN_ORIGINAL_TARGET := " + target_name + "\n")
+
+  for file_name in raw_file_list:
+    cu.copy_file_if_exists(src_out_dir, dest_top_dir + "/raw_copy", file_name)
+
+  for raw_dir in raw_dir_list:
+    cu.copy_dir(src_out_dir, dest_top_dir + "/raw_copy", raw_dir)
+
+  for host_a in host_a_list:
+    cu.copy_file_if_exists(src_out_dir + "/host/linux-x86/obj/STATIC_LIBRARIES/" + host_a +
+                           "_intermediates", dest_top_dir + "/host/lib", host_a + ".a")
+    mkFile.addHostA(host_a)
+
+  for host_so in host_so_list:
+    cu.copy_file_if_exists(src_out_dir + "/host/linux-x86/obj/lib/",
+                           dest_top_dir + "/host/lib", host_so + ".so")
+    mkFile.addHostSo(host_so)
+
+  src_host_jar_top = src_out_dir + "/host/common/obj/JAVA_LIBRARIES/"
+  for host_jar in host_jar_list:
+    src_host_jar_dir = src_host_jar_top + host_jar + "_intermediates/"
+    copy_classes_or_javalib(src_host_jar_dir, dest_top_dir + "/host/java_lib/", host_jar)
+    mkFile.addHostJar(host_jar)
+
+  for target_a in target_a_list:
+    cu.copy_file_if_exists(src_target_top_dir + "obj/STATIC_LIBRARIES/" + target_a +
+                           "_intermediates", dest_top_dir + "/target/lib", target_a + ".a")
+    mkFile.addTargetA(target_a)
+
+  for target_so in target_so_list:
+    cu.copy_file_if_exists(src_target_top_dir + "obj/lib/",
+                           dest_top_dir + "/target/lib", target_so + ".so")
+    mkFile.addTargetSo(target_so)
+
+  src_target_jar_top = src_out_dir + "/target/common/obj/JAVA_LIBRARIES/"
+  for target_jar in target_jar_list:
+    src_target_jar_dir = src_target_jar_top + target_jar + "_intermediates/"
+    copy_jar(src_target_jar_dir, dest_top_dir + "/target/java_lib", target_jar)
+    mkFile.addTargetJar(target_jar)
+
+  for file_to_remove in raw_target_files_to_remove:
+    os.system("rm -rf " + dest_top_dir + "/raw_copy/" + file_to_remove)
+
+if __name__ == '__main__':
+  main(sys.argv)
diff --git a/build/copy_pdk_data.py b/build/copy_pdk_data.py
new file mode 100755
index 0000000..88a00bb
--- /dev/null
+++ b/build/copy_pdk_data.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+# script to copy necessary data / source for PDK build from
+# the current and the previous branch
+
+import os, string, sys, shutil
+import copy_utils as cu
+import create_source_tree as tree
+
+
+def main(argv):
+  if len(argv) != 4:
+    print "Usage: copy_pdk_data.py current previous dest_top_dir"
+    print "   ex: copy_pdk_data.py ../jb_master ../ics_master ."
+    sys.exit(1)
+  current_branch = argv[1]
+  previous_branch = argv[2]
+  dest_top = argv[3]
+
+  for dir_name in tree.prev_copy_dir_list:
+    cu.copy_dir(previous_branch, dest_top + "/vendor/pdk_data", dir_name)
+
+  for dir_name in tree.prev_copy_dir_pdk1_list:
+    cu.copy_dir(previous_branch, dest_top + "/vendor/pdk_data_internal", dir_name)
+
+  for dir_name in tree.additional_dir_pdk2_list:
+    cu.copy_dir(current_branch, dest_top + "/vendor/pdk_data", dir_name)
+
+  for file_name in tree.copy_files_pdk2_list:
+    cu.copy_files(current_branch, dest_top + "/vendor/pdk_data", file_name)
+
+if __name__ == '__main__':
+  main(sys.argv)
diff --git a/build/copy_utils.py b/build/copy_utils.py
new file mode 100755
index 0000000..d9876f9
--- /dev/null
+++ b/build/copy_utils.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+# copy relared utils for all PDK scripts
+
+import os, string, sys, shutil
+
+def copy_dir(src_top, dest_top, dir_name):
+  """copy all the files under src_top/dir_name to dest_top/dir_name."""
+  src_full_path = src_top + "/" + dir_name
+  # do not create the leaf dir as cp will create it
+  [mid_path, leaf_path] = dir_name.rsplit("/", 1)
+  dest_full_path = dest_top + "/" + mid_path
+  if not os.path.isdir(dest_full_path):
+    os.makedirs(dest_full_path)
+  print "copy dir ", src_full_path, " to ", dest_full_path
+  os.system("cp -a " + src_full_path + " " + dest_full_path)
+
+
+def copy_dir_only_file(src_top, dest_top, dir_name):
+  """copy only files directly under the given dir_name"""
+  src_full_path = src_top + "/" + dir_name
+  dest_full_path = dest_top + "/" + dir_name
+  if not os.path.isdir(dest_full_path):
+    os.makedirs(dest_full_path)
+  children = os.listdir(src_full_path)
+  for child in children:
+    child_full_name = src_full_path + "/" + child
+    if os.path.isfile(child_full_name):
+      print "copy file ", child_full_name, " to ", dest_full_path
+      os.system("cp -a " + child_full_name + " " + dest_full_path)
+
+
+def copy_files(src_top, dest_top, files_name):
+  """copy files from src_top to dest_top.
+     Note that files_name can include directories which will be created
+     under dest_top"""
+  src_full_path = src_top + "/" + files_name
+  # do not create the leaf dir as cp will create it
+  [mid_path, leaf_path] = files_name.rsplit("/", 1)
+  dest_full_path = dest_top + "/" + mid_path
+  if not os.path.isdir(dest_full_path):
+    os.makedirs(dest_full_path)
+  print "copy files ", src_full_path, " to ", dest_full_path
+  os.system("cp -a " + src_full_path + " " + dest_full_path)
+
+
+def copy_file_if_exists(src_top, dest_top, file_name):
+  """copy file src_top/file_name to dest_top/file_name
+     returns false if such file does not exist in source."""
+  src_full_name = src_top + "/" + file_name
+  if not os.path.isfile(src_full_name):
+    print "file " + src_full_name + " not found"
+    return False
+  dest_file = dest_top + "/" + file_name
+  dest_dir = os.path.dirname(dest_file)
+  if not os.path.isdir(dest_dir):
+    os.makedirs(dest_dir)
+  print "copy file ", src_full_name, " to ", dest_file
+  os.system("cp -a " + src_full_name + " " +  dest_file)
+  return True
+
+
+def copy_file_new_name_if_exists(src_full_name, dest_dir, dest_file):
+  """copy src_full_name (including dir + file name) to dest_dir/dest_file
+     will be used when renaming is necessary"""
+  if not os.path.isfile(src_full_name):
+    print "file " + src_full_name + " not found"
+    return False
+  dest_full_name = dest_dir + "/" + dest_file
+  if not os.path.isdir(dest_dir):
+    os.makedirs(dest_dir)
+  print "copy file ", src_full_name, " to ", dest_full_name
+  os.system("cp -a " + src_full_name + " " + dest_full_name)
+  return True
diff --git a/build/create_source_tree.py b/build/create_source_tree.py
new file mode 100755
index 0000000..c35f723
--- /dev/null
+++ b/build/create_source_tree.py
@@ -0,0 +1,213 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+# script to create minimal source tree for pdk2 build
+# pdk/build/pdk.mk file will be checked to detect necessary files
+# together with additional addition in this script for build dependency
+
+import os, string, sys, shutil
+import copy_utils as cu
+
+
+def get_one_var_occurrence(f, dir_list_var):
+  dir_list = []
+  for line in f:
+    start = line.find(dir_list_var)
+    if (start != -1) and (line[0] != "#"): # found the pattern
+      break
+  # it can be eof, but the next for-loop will filter it out
+  for line in f:
+    words = line.split()
+    #print words
+    if len(words) > 0:
+      dir_list.append(words[0])
+    if len(words) != 2:
+      break
+  return dir_list
+
+def extract_build_dir(makefile, dir_list_var):
+  f = open(makefile, "r")
+  dir_list = []
+  while 1:
+    list_found = get_one_var_occurrence(f, dir_list_var)
+    if len(list_found) == 0:
+      break;
+    dir_list += list_found
+  f.close();
+  return dir_list
+
+def create_symbolic_link(src_top, dest_top, dir_name):
+  src_full = src_top + "/" + dir_name
+  dest_full = dest_top + "/" + dir_name
+  print "create symbolic link from " + dest_full + " to " + src_full
+  os.system("ln -s " + src_full + " " + dest_full)
+
+
+# when these dirs are copied as a whlole, only symbolic link will be created
+# instead of full copying. These dirs should not be overwritten or replaced by copy
+symbolic_link_list = [
+  "bionic",
+  "dalvik",
+  "development",
+  "external",
+  "libcore",
+  "pdk",
+  "prebuilt",
+  "prebuilts",
+  "sdk",
+  "system"
+]
+
+# the whole dir copied
+additional_dir_list = [
+  "pdk"
+  ]
+
+# these dirs will be direcly pulled as the whole git.
+# so these files will not go under vendor/pdk_data
+additional_dir_pdk2_list_git = [
+  "external/chromium",
+  "external/libnl-headers",
+  "external/proguard",
+]
+
+additional_dir_pdk2_list = [
+  "frameworks/base/build",
+  "frameworks/base/cmds/dumpstate",
+  "frameworks/base/drm/libdrmframework/plugins/common/include",
+  "frameworks/base/include/androidfw",
+  "frameworks/base/include/android_runtime",
+  "frameworks/base/include/camera",
+  "frameworks/base/include/cpustats",
+  "frameworks/base/include/drm",
+  "frameworks/base/include/media",
+  "frameworks/base/include/private",
+  "frameworks/media/libvideoeditor/include",
+  "frameworks/base/native/include",
+  "dalvik/libnativehelper/include",
+  "external/v8/include",
+  "external/safe-iop/include",
+  "external/skia/include"
+
+  ]
+
+# only files under the dir is copied, not subdirs
+dir_copy_only_files_list = [
+  ]
+
+copy_files_list = [
+  "Makefile"
+  ]
+
+copy_files_pdk2_list = [
+  "frameworks/base/media/libeffects/data/audio_effects.conf",
+  "development/data/etc/apns-conf_sdk.xml",
+  "development/data/etc/vold.conf"
+  ]
+
+prev_copy_dir_list = [
+  "frameworks/base/data"
+  ]
+
+# for PDK1 build only, use old version
+prev_copy_dir_pdk1_list = [
+  "packages/apps/Bluetooth",
+  "packages/inputmethods/LatinIME",
+  "packages/providers/ApplicationsProvider",
+  "packages/providers/CalendarProvider",
+  #"packages/providers/DownloadProvider", old version does not build
+  "packages/providers/GoogleContactsProvider",
+  "packages/providers/TelephonyProvider",
+  "packages/providers/ContactsProvider",
+  "packages/providers/DrmProvider",
+  "packages/providers/MediaProvider",
+  "packages/providers/UserDictionaryProvider"
+  ]
+
+# not necessary although copied due to the dir list from pdk.mk
+files_to_remove = [
+  "vendor/moto/olympus",
+  "vendor/samsung/manta",
+  "vendor/samsung/mysidspr",
+  "vendor/samsung/toro",
+  "vendor/nvidia/proprietary-tegra3",
+  "packages/providers/BrowserProvider",
+  ]
+
+def main(argv):
+  if len(argv) < 5:
+    print "Usage: create_source_tree.py pdk_type(1 or 2) current_src_top_dir prev_src_top_tree dest_top_dir"
+    print "   ex: create_source_tree.py 1 ../jb_master ../ics_master /pdk1_source"
+    sys.exit(1)
+  pdk1 = (argv[1] == "1")
+  src_top_dir = os.path.abspath(argv[2])
+  prev_src_top_dir = os.path.abspath(argv[3])
+  dest_top_dir = os.path.abspath(argv[4])
+
+  full_copy = True
+  # hidden command for initial testing of manually added parts
+  if len(argv) == 6:
+    if argv[5] == "0":
+      full_copy = False
+  dir_list = []
+  if full_copy:
+    dir_list += extract_build_dir(src_top_dir + "/pdk/build/pdk.mk", "BUILD_PDK_SUBDIRS")
+    dir_list += extract_build_dir(src_top_dir + "/pdk/build/pdk_google.mk", "BUILD_PDK_SUBDIRS")
+    if pdk1:
+      dir_list += extract_build_dir(src_top_dir + "/pdk/build/pdk.mk", "BUILD_PDK1_SUBDIRS")
+    else:
+      dir_list += extract_build_dir(src_top_dir + "/pdk/build/pdk.mk", "BUILD_PDK2_SUBDIRS")
+
+  dir_list += additional_dir_list
+  if not pdk1:
+    dir_list += additional_dir_pdk2_list_git
+    dir_list += additional_dir_pdk2_list
+  print "copy list", dir_list
+
+  os.system("mkdir -p " + dest_top_dir)
+  for dir_name in dir_list:
+    if dir_name in symbolic_link_list:
+      create_symbolic_link(src_top_dir, dest_top_dir, dir_name)
+    else:
+      cu.copy_dir(src_top_dir, dest_top_dir, "/" + dir_name)
+
+  for dir_name in dir_copy_only_files_list:
+    cu.copy_dir_only_file(src_top_dir, dest_top_dir, "/" + dir_name)
+
+  copy_files_list_ = copy_files_list
+  if not pdk1:
+    copy_files_list_ += copy_files_pdk2_list
+  for file_name in copy_files_list_:
+    cu.copy_files(src_top_dir, dest_top_dir, "/" + file_name)
+
+  # overwrite files
+  cu.copy_files(src_top_dir + "/vendor/pdk_data_internal/overwrite", dest_top_dir, "/*")
+
+  for file_name in files_to_remove:
+    os.system("rm -rf " + dest_top_dir + "/" + file_name)
+
+  prev_copy_dir_list_ = []
+  prev_copy_dir_list_ += prev_copy_dir_list
+  if pdk1:
+    prev_copy_dir_list_ += prev_copy_dir_pdk1_list
+  print "use ICS version for ", prev_copy_dir_list_
+  for dir_name in prev_copy_dir_list_:
+    os.system("rm -rf " + dest_top_dir + "/" + dir_name)
+    cu.copy_dir(prev_src_top_dir, dest_top_dir, "/" + dir_name)
+
+if __name__ == '__main__':
+  main(sys.argv)
diff --git a/build/pdk.mk b/build/pdk.mk
new file mode 100644
index 0000000..caa7571
--- /dev/null
+++ b/build/pdk.mk
@@ -0,0 +1,167 @@
+#
+# 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.
+#
+
+# common build dirs for pdk1 and pdk2
+# this list should be minimal to make pdk2 build fast
+
+# BUILD_PDK_SUBDIRS is parsed by a script to extract source tree list automatically.
+# To make that parsing simple, the first line should not include any explicit directory name.
+BUILD_PDK_SUBDIRS := \
+	abi \
+	bionic \
+	bootable \
+	build \
+	device \
+	hardware \
+	prebuilt \
+	prebuilts \
+	system
+
+
+# if pdk_vendor.mk exist, do not include pdk_google.mk
+# pdk_vendor.mk should add more dirs for pdk2 build
+# that is, it should include BUILD_PDK_SUBDIRS += \ to add additional dir for build
+ifneq (,$(wildcard $(TOPDIR)pdk/build/pdk_vendor.mk))
+include $(TOPDIR)pdk/build/pdk_vendor.mk
+else
+include $(TOPDIR)pdk/build/pdk_google.mk
+endif
+
+ifeq ($(PDK_BUILD_TYPE), pdk1)
+# addition for pdk1
+BUILD_PDK1_SUBDIRS := \
+	dalvik \
+	development \
+	external \
+	frameworks \
+	libcore \
+	packages/apps/Bluetooth \
+	packages/apps/Launcher2 \
+	packages/apps/Settings \
+	packages/inputmethods/LatinIME \
+	packages/providers \
+	sdk
+
+
+
+BUILD_PDK_SUBDIRS += $(BUILD_PDK1_SUBDIRS)
+
+ifeq ($(TARGET_CPU_SMP), true)
+PDK_BIN_NAME := pdk_bin_$(TARGET_ARCH_VARIANT)_true
+else # !SMP
+PDK_BIN_NAME := pdk_bin_$(TARGET_ARCH_VARIANT)_false
+endif # !SMP
+
+.PHONY: pdk_bin_zip
+pdk_bin_zip: $(OUT_DIR)/target/$(PDK_BIN_NAME).zip
+
+
+$(OUT_DIR)/target/$(PDK_BIN_NAME).zip: $(OUT_DIR)/target/$(PDK_BIN_NAME)
+	$(info Creating $(OUT_DIR)/target/$(PDK_BIN_NAME).zip)
+	$(hide) cd $(dir $@) && rm -rf $(notdir $@) && zip -rq $(notdir $@) $(PDK_BIN_NAME)
+
+# explicitly put dependency on two final images to avoid copying every time
+# It is too early and INSTALLED_SYSTEMIMAGE is not defined yet.
+$(OUT_DIR)/target/$(PDK_BIN_NAME): $(OUT_DIR)/target/product/$(TARGET_DEVICE)/boot.img \
+                                   $(OUT_DIR)/target/product/$(TARGET_DEVICE)/system.img
+	python $(TOPDIR)pdk/build/copy_pdk1_bins.py . $(OUT_DIR)/target/$(PDK_BIN_NAME) $(TARGET_DEVICE)
+
+else # pdk2
+
+# overwrite the definition from conflig.mk, no package build in pdk2
+BUILD_PACKAGE :=
+
+# addition for pdk2
+BUILD_PDK2_SUBDIRS := \
+	external/antlr \
+	external/bluetooth \
+	external/bsdiff \
+	external/bzip2 \
+	external/dbus \
+	external/doclava \
+	external/expat \
+	external/fdlibm \
+	external/flac \
+	external/freetype \
+	external/gcc-demangle \
+	external/giflib \
+	external/gtest \
+	external/guava \
+	external/icu4c \
+	external/jhead \
+	external/jpeg \
+	external/jsilver \
+	external/jsr305 \
+	external/liblzf \
+	external/libpng \
+	external/libvpx \
+	external/mksh \
+	external/openssl \
+	external/protobuf \
+	external/sonivox \
+	external/speex \
+	external/stlport \
+	external/tinyalsa \
+	external/tremolo \
+	external/wpa_supplicant \
+	external/wpa_supplicant_6 \
+	external/wpa_supplicant_8 \
+	external/yaffs2 \
+	external/zlib \
+	frameworks/native \
+	frameworks/base/media/libmedia \
+	frameworks/base/media/libstagefright
+
+
+BUILD_PDK_SUBDIRS += $(BUILD_PDK2_SUBDIRS)
+
+# naming convention for bin repository: pdk_bin_CPUArch_SMPSupport
+# ex: pdk_bin_armv7-a_true (armv7-a with SMP support)
+ifeq ($(TARGET_CPU_SMP), true)
+PDK_BIN_PRIMARY := pdk_bin_$(TARGET_ARCH_VARIANT)_true
+# this dir will not exist, so SMP CPU requires SMP version
+PDK_BIN_SECONDARY := pdk_bin_no_such_dir
+else # !SMP
+PDK_BIN_PRIMARY := pdk_bin_$(TARGET_ARCH_VARIANT)_false
+# if non-SMP binary does not exist, use SMP version
+PDK_BIN_SECONDARY := pdk_bin_$(TARGET_ARCH_VARIANT)_true
+endif # !SMP
+
+ifneq (,$(wildcard $(TOPDIR)vendor/$(PDK_BIN_PRIMARY)))
+PDK_BIN_REPOSITORY := $(TOPDIR)vendor/$(PDK_BIN_PRIMARY)
+else # !PRIMARY
+ifneq (,$(wildcard $(TOPDIR)vendor/$(PDK_BIN_SECONDARY)))
+$(info PDK_BIN using secondary option $(PDK_BIN_SECONDARY) for build)
+PDK_BIN_REPOSITORY := $(TOPDIR)vendor/$(PDK_BIN_SECONDARY)
+else # !SECONDARY
+$(error Neither vendor/$(PDK_BIN_PRIMARY) nor $(TOPDIR)vendor/$(PDK_BIN_SECONDARY) exists.)
+endif # !SECONDARY
+endif # !PRIMARY
+
+
+include $(PDK_BIN_REPOSITORY)/pdk_prebuilt.mk
+
+ifeq ($(PDK_BIN_ORIGINAL_TARGET), )
+$(error PDK_BIN_ORIGINAL_TARGET not set in $(PDK_BIN_REPOSITORY)/pdk_prebuilt.mk)
+endif
+
+ifeq (,$(wildcard $(OUT_DIR)/target/product/$(TARGET_DEVICE)/PDK_BIN_COPIED))
+$(error PDK binaries necessary for pdk2 build are not there! Did you run setup_pdk2_bin.py? )
+endif # PDK_BIN_COPIED
+
+PRODUCT_PACKAGES += core core-junit
+
+endif # pdk2
diff --git a/build/pdk_google.mk b/build/pdk_google.mk
new file mode 100644
index 0000000..ea0da7f
--- /dev/null
+++ b/build/pdk_google.mk
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+
+# subdirs for building pdk1/pdk2 for maruro/crespo
+BUILD_PDK_SUBDIRS += \
+	vendor/broadcom \
+	vendor/invensense \
+	vendor/khronos \
+	vendor/nxp/pn544 \
+	vendor/samsung \
+	vendor/ti \
+	vendor/widevine
+
diff --git a/build/pdk_prebuilt.mk b/build/pdk_prebuilt.mk
new file mode 100644
index 0000000..e0bb8ed
--- /dev/null
+++ b/build/pdk_prebuilt.mk
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+
+# build list for PDK1
+# This build filters out most applications
+# The outcome of this build is to create a binary release to allow chipset vendors
+# to create a minimum UI image to bring up their H/W
+
+# This file under pdk/build is the template for the same file under vendor/pdk_XYZ
+# The file under vendor is automatically generated, and do not edit.
+
+LOCAL_PATH := $(call my-dir)
+
diff --git a/build/setup_pdk2_bin.py b/build/setup_pdk2_bin.py
new file mode 100755
index 0000000..31fea1d
--- /dev/null
+++ b/build/setup_pdk2_bin.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+# script to prepare pdk2 branches for build.
+# This should be run after every make clean as necessary files will be deleted
+
+import os, re, string, sys
+
+PDK_BIN_PREFIX = "pdk_bin_"
+
+def list_available_pdk_bins(path):
+  """returns the list of pdk_bin_* dir under the given path"""
+  pdk_bin_list = list()
+  file_list = os.listdir(path)
+  for file_name in file_list:
+    if file_name.startswith(PDK_BIN_PREFIX) and os.path.isdir(path + "/" + file_name):
+        pdk_bin_list.append(file_name)
+  return pdk_bin_list
+
+def get_target_name_from_pdk_bin(path):
+  """returns the original target name from the given pdk_bin_* dir"""
+  product_dir = path + "/raw_copy/target/product"
+  file_list = os.listdir(product_dir)
+  for file_name in file_list:
+    if os.path.isdir(product_dir + "/" + file_name):
+        return file_name
+  assert False, "target not found from product dir"
+
+def main(argv):
+  if len(argv) != 4:
+    print "Usage: setup_pdk2_bin.py top_dir cpu_conf target_hw"
+    print "   ex: setup_pdk2_bin.py pdk2_source armv7-a-neon_true maguro"
+    sys.exit(1)
+  top_dir = argv[1]
+  cpu_conf = argv[2]
+  target_hw = argv[3]
+
+  pdk_bin_dirs = list_available_pdk_bins(top_dir + "/vendor")
+  arch_list = []
+  for pdk_bin_dir in pdk_bin_dirs:
+    arch_list.append(pdk_bin_dir[len(PDK_BIN_PREFIX): ])
+
+  if not (cpu_conf in arch_list):
+    print "Specified cpu_conf", cpu_conf, "not avaialble under", top_dir + "/vendor/"
+    print "Avaiable configurations are ", arch_list
+    sys.exit(1)
+
+  print "copy pdk bins"
+  os.system("mkdir -p " + top_dir + "/out/host")
+  os.system("mkdir -p " + top_dir + "/out/target/common")
+  os.system("mkdir -p " + top_dir + "/out/target/product/" + target_hw)
+  pdk_bin_path = top_dir + "/vendor/" + PDK_BIN_PREFIX + cpu_conf
+  pdk_bin_target_name = get_target_name_from_pdk_bin(pdk_bin_path)
+  os.system("cp -a " + pdk_bin_path + "/raw_copy/host/* " + top_dir + "/out/host")
+  os.system("cp -a " + pdk_bin_path + "/raw_copy/target/common/* " + top_dir +
+            "/out/target/common")
+  os.system("cp -a " + pdk_bin_path + "/raw_copy/target/product/" + pdk_bin_target_name + "/* "
+            + top_dir + "/out/target/product/" + target_hw)
+  os.system("touch " + top_dir + "/out/target/product/" + target_hw + "/PDK_BIN_COPIED")
+
+if __name__ == '__main__':
+  main(sys.argv)