extract_files: Add ODM partition blob support

Change-Id: Id94bbef879b6f4bcc20645c259981f9d163649c9
diff --git a/build/tools/extract_utils.sh b/build/tools/extract_utils.sh
index d335307..fae3936 100644
--- a/build/tools/extract_utils.sh
+++ b/build/tools/extract_utils.sh
@@ -283,6 +283,10 @@
                 local OUTTARGET=$(truncate_file $TARGET)
                 printf '    %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
                     "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
+            elif prefix_match_file "odm/" $TARGET ; then
+                local OUTTARGET=$(truncate_file $TARGET)
+                printf '    %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
+                    "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
             else
                 printf '    %s/proprietary/%s:system/%s%s\n' \
                     "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
@@ -299,7 +303,7 @@
 # write_packages:
 #
 # $1: The LOCAL_MODULE_CLASS for the given module list
-# $2: /product or /vendor partition
+# $2: /odm, /product, or /vendor partition
 # $3: type-specific extra flags
 # $4: Name of the array holding the target list
 #
@@ -341,6 +345,8 @@
             SRC+="/vendor"
         elif [ "$PARTITION" = "product" ]; then
             SRC+="/product"
+        elif [ "$PARTITION" = "odm" ]; then
+            SRC+="/odm"
         fi
 
         printf 'include $(CLEAR_VARS)\n'
@@ -422,6 +428,8 @@
             printf 'LOCAL_VENDOR_MODULE := true\n'
         elif [ "$PARTITION" = "product" ]; then
             printf 'LOCAL_PRODUCT_MODULE := true\n'
+        elif [ "$PARTITION" = "odm" ]; then
+            printf 'LOCAL_ODM_MODULE := true\n'
         fi
         printf 'include $(BUILD_PREBUILT)\n\n'
     done
@@ -494,6 +502,22 @@
         write_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDMK"
     fi
 
+    local T_O_LIB32=( $(prefix_match "odm/lib/") )
+    local T_O_LIB64=( $(prefix_match "odm/lib64/") )
+    local O_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) )
+    local O_LIB32=( $(comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
+    local O_LIB64=( $(comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
+
+    if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then
+        write_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDMK"
+    fi
+    if [ "${#O_LIB32[@]}" -gt "0" ]; then
+        write_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDMK"
+    fi
+    if [ "${#O_LIB64[@]}" -gt "0" ]; then
+        write_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDMK"
+    fi
+
     # Apps
     local APPS=( $(prefix_match "app/") )
     if [ "${#APPS[@]}" -gt "0" ]; then
@@ -519,6 +543,14 @@
     if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then
         write_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDMK"
     fi
+    local O_APPS=( $(prefix_match "odm/app/") )
+    if [ "${#O_APPS[@]}" -gt "0" ]; then
+        write_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDMK"
+    fi
+    local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") )
+    if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then
+        write_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDMK"
+    fi
 
     # Framework
     local FRAMEWORK=( $(prefix_match "framework/") )
@@ -533,6 +565,10 @@
     if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then
         write_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDMK"
     fi
+    local O_FRAMEWORK=( $(prefix_match "odm/framework/") )
+    if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then
+        write_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDMK"
+    fi
 
     # Etc
     local ETC=( $(prefix_match "etc/") )
@@ -547,6 +583,10 @@
     if [ "${#P_ETC[@]}" -gt "0" ]; then
         write_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDMK"
     fi
+    local O_ETC=( $(prefix_match "odm/etc/") )
+    if [ "${#O_ETC[@]}" -gt "0" ]; then
+        write_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDMK"
+    fi
 
     # Executables
     local BIN=( $(prefix_match "bin/") )
@@ -561,6 +601,10 @@
     if [ "${#P_BIN[@]}" -gt "0" ]; then
         write_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDMK"
     fi
+    local O_BIN=( $(prefix_match "odm/bin/") )
+    if [ "${#O_BIN[@]}" -gt "0" ]; then
+        write_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDMK"
+    fi
     local SBIN=( $(prefix_match "sbin/") )
     if [ "${#SBIN[@]}" -gt "0" ]; then
         write_packages "EXECUTABLES" "" "sbin" "SBIN" >> "$ANDROIDMK"