Merge "Make gdbclient smarter for gdb[server] setup."
diff --git a/core/64_bit_blacklist.mk b/core/64_bit_blacklist.mk
index 99db95d..4302c47 100644
--- a/core/64_bit_blacklist.mk
+++ b/core/64_bit_blacklist.mk
@@ -19,8 +19,8 @@
 # misc build errors
 _64_bit_directory_blacklist += \
 	external/bluetooth/bluedroid \
+	external/oprofile/daemon \
 	external/oprofile/opcontrol \
-	external/tcpdump \
 	frameworks/av \
 	frameworks/base \
 	frameworks/ex \
@@ -30,11 +30,6 @@
 	device/generic/goldfish/opengl \
 	device/generic/goldfish/camera \
 
-# depends on libnl_2
-_64_bit_directory_blacklist += \
-	external/android-clat \
-	external/wpa_suplicant_8
-
 # depends on frameworks/av
 _64_bit_directory_blacklist += \
 	external/srec \
diff --git a/core/Makefile b/core/Makefile
index d76aca6..71eeb2e 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -1430,7 +1430,7 @@
 	@echo "Package apps: $@"
 	$(hide) rm -rf $@
 	$(hide) mkdir -p $(dir $@)
-	$(hide) zip -qj $@ $(TARGET_OUT_APPS)/*
+	$(hide) zip -qj $@ $(TARGET_OUT_APPS)/* $(TARGET_OUT_APPS_PRIVILEGED)/*
 
 
 #------------------------------------------------------------------
diff --git a/core/definitions.mk b/core/definitions.mk
index 6c65bc5..399eb42 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1240,11 +1240,11 @@
 	-Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
 	-Wl,-rpath,\$$ORIGIN/../lib \
 	-shared -Wl,-soname,$(notdir $@) \
-	$(PRIVATE_LDFLAGS) \
 	$(HOST_GLOBAL_LD_DIRS) \
 	$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
 	   $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
 	) \
+	$(PRIVATE_LDFLAGS) \
 	$(PRIVATE_ALL_OBJECTS) \
 	-Wl,--whole-archive \
 	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
@@ -1395,11 +1395,11 @@
 	-Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
 	-Wl,-rpath,\$$ORIGIN/../lib \
 	$(HOST_GLOBAL_LD_DIRS) \
-	$(PRIVATE_LDFLAGS) \
 	$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
 		$(PRIVATE_HOST_GLOBAL_LDFLAGS) \
 		-fPIE -pie \
 	) \
+	$(PRIVATE_LDFLAGS) \
 	-o $@ \
 	$(PRIVATE_LDLIBS)
 endef
@@ -2145,6 +2145,13 @@
 $(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
 endef
 
+## Return the arch for the source file of a prebuilt
+# $(1) the list of archs supported by the prebuilt
+define get-prebuilt-src-arch
+$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\
+  $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH))))
+endef
+
 ###########################################################
 ## Other includes
 ###########################################################
diff --git a/core/executable_internal.mk b/core/executable_internal.mk
index 1edcd2c..a1ce7f2 100644
--- a/core/executable_internal.mk
+++ b/core/executable_internal.mk
@@ -17,7 +17,7 @@
 skip_build_from_source :=
 ifdef LOCAL_PREBUILT_MODULE_FILE
 ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH)))
-include $(BUILD_PREBUILT)
+include $(BUILD_SYSTEM)/prebuilt_internal.mk
 skip_build_from_source := true
 endif
 endif
diff --git a/core/host_executable.mk b/core/host_executable.mk
index ab0f8f3..ffb35d2 100644
--- a/core/host_executable.mk
+++ b/core/host_executable.mk
@@ -18,7 +18,7 @@
 skip_build_from_source :=
 ifdef LOCAL_PREBUILT_MODULE_FILE
 ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH)))
-include $(BUILD_PREBUILT)
+include $(BUILD_SYSTEM)/prebuilt_internal.mk
 skip_build_from_source := true
 endif
 endif
diff --git a/core/host_shared_library.mk b/core/host_shared_library.mk
index a608251..56ced01 100644
--- a/core/host_shared_library.mk
+++ b/core/host_shared_library.mk
@@ -27,7 +27,7 @@
 skip_build_from_source :=
 ifdef LOCAL_PREBUILT_MODULE_FILE
 ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH)))
-include $(BUILD_PREBUILT)
+include $(BUILD_SYSTEM)/prebuilt_internal.mk
 skip_build_from_source := true
 endif
 endif
diff --git a/core/main.mk b/core/main.mk
index d568f8a..2399d2e 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -1004,6 +1004,7 @@
 
 .PHONY: lintall
 
+ifneq (,$(filter samplecode, $(MAKECMDGOALS)))
 .PHONY: samplecode
 sample_MODULES := $(sort $(call get-tagged-modules,samples))
 sample_APKS_DEST_PATH := $(TARGET_COMMON_OUT_ROOT)/samples
@@ -1017,6 +1018,7 @@
 	@echo "Collect sample code apks: $^"
 	# remove apks that are not intended to be installed.
 	rm -f $(sample_ADDITIONAL_INSTALLED)
+endif  # samplecode in $(MAKECMDGOALS)
 
 .PHONY: findbugs
 findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 18bddc5..51440c4 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -20,9 +20,13 @@
 LOCAL_DONT_CHECK_MODULE := true
 
 ifdef LOCAL_PREBUILT_MODULE_FILE
-my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE)
+  my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE)
 else
-my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
+  ifdef LOCAL_SRC_FILES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
+    my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
+  else
+    my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
+  endif
 endif
 
 ifdef LOCAL_IS_HOST_MODULE
@@ -86,12 +90,13 @@
 # of the shared libraries are determined.
 ifdef LOCAL_INSTALLED_MODULE
 ifdef LOCAL_SHARED_LIBRARIES
-$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += $(LOCAL_MODULE):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(LOCAL_SHARED_LIBRARIES))
+$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
+  $(LOCAL_MODULE):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(LOCAL_SHARED_LIBRARIES))
 
 # We also need the LOCAL_BUILT_MODULE dependency,
 # since we use -rpath-link which points to the built module's path.
 built_shared_libraries := \
-    $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
+    $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
     $(addsuffix $($(my_prefix)SHLIB_SUFFIX), \
         $(LOCAL_SHARED_LIBRARIES)))
 $(LOCAL_BUILT_MODULE) : $(built_shared_libraries)
@@ -213,5 +218,3 @@
 $(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES)
 
 my_prebuilt_src_file :=
-
-LOCAL_2ND_ARCH_VAR_PREFIX :=
diff --git a/core/shared_library_internal.mk b/core/shared_library_internal.mk
index c42cf37..b5ac32a 100644
--- a/core/shared_library_internal.mk
+++ b/core/shared_library_internal.mk
@@ -25,7 +25,7 @@
 skip_build_from_source :=
 ifdef LOCAL_PREBUILT_MODULE_FILE
 ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH)))
-include $(BUILD_PREBUILT)
+include $(BUILD_SYSTEM)/prebuilt_internal.mk
 skip_build_from_source := true
 endif
 endif
diff --git a/target/board/generic_mips/BoardConfig.mk b/target/board/generic_mips/BoardConfig.mk
index e16374b..85bf7d7 100644
--- a/target/board/generic_mips/BoardConfig.mk
+++ b/target/board/generic_mips/BoardConfig.mk
@@ -56,3 +56,17 @@
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
+
+BOARD_SEPOLICY_DIRS += build/target/board/generic/sepolicy
+BOARD_SEPOLICY_UNION += \
+        adbd.te \
+        bootanim.te \
+        device.te \
+        domain.te \
+        file.te \
+        file_contexts \
+        mediaserver.te \
+        qemud.te \
+        rild.te \
+        surfaceflinger.te \
+        system_server.te
diff --git a/target/board/generic_x86/BoardConfig.mk b/target/board/generic_x86/BoardConfig.mk
index 5da767e..a34804a 100644
--- a/target/board/generic_x86/BoardConfig.mk
+++ b/target/board/generic_x86/BoardConfig.mk
@@ -10,7 +10,6 @@
 TARGET_ARCH := x86
 TARGET_ARCH_VARIANT := x86
 TARGET_PRELINK_MODULE := false
-TARGET_USES_64_BIT_BINDER := true
 
 # The IA emulator (qemu) uses the Goldfish devices
 HAVE_HTC_AUDIO_DRIVER := true
diff --git a/target/board/generic_x86/sepolicy/domain.te b/target/board/generic_x86/sepolicy/domain.te
index 0bc8d87..c17950d 100644
--- a/target/board/generic_x86/sepolicy/domain.te
+++ b/target/board/generic_x86/sepolicy/domain.te
@@ -1 +1,3 @@
+# For /sys/qemu_trace files in the emulator.
+allow domain sysfs_writable:file rw_file_perms;
 allow domain cpuctl_device:dir search;
diff --git a/target/product/core_minimal.mk b/target/product/core_minimal.mk
index 17000ac..eb8d653 100644
--- a/target/product/core_minimal.mk
+++ b/target/product/core_minimal.mk
@@ -53,6 +53,7 @@
     libfilterfw \
     libsqlite_jni \
     libwilhelm \
+    logd \
     make_ext4fs \
     screencap \
     sensorservice \