+2017-10-06  Yao Qi  <yao.qi@linaro.org>
+
+       * Makefile.in (CONFIG_SRC_SUBDIR): New.
+       (ALL_64_TARGET_OBS): Replace amd64.o with arch/amd64.o.
+       (clean): Remove object files and dependency files.
+       (distclean): Remove the directory.
+       * configure.ac: Invoke AC_CONFIG_COMMANDS.
+       * configure: Re-generated.
+       * configure.tgt: Replace amd64.o with arch/amd64.o.
+
 2017-10-05  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        PR build/22188
 
 CONFIG_CLEAN = @CONFIG_CLEAN@
 CONFIG_INSTALL = @CONFIG_INSTALL@
 CONFIG_UNINSTALL = @CONFIG_UNINSTALL@
+CONFIG_SRC_SUBDIR = @CONFIG_SRC_SUBDIR@
 HAVE_NATIVE_GCORE_TARGET = @HAVE_NATIVE_GCORE_TARGET@
 
 # -I. for config files.
        alpha-nbsd-tdep.o \
        alpha-obsd-tdep.o \
        alpha-tdep.o \
-       amd64.o \
        amd64-darwin-tdep.o \
        amd64-dicos-tdep.o \
        amd64-fbsd-tdep.o \
        amd64-sol2-tdep.o \
        amd64-tdep.o \
        amd64-windows-tdep.o \
+       arch/amd64.o \
        ia64-linux-tdep.o \
        ia64-tdep.o \
        ia64-vms-tdep.o \
        rm -f test-cp-name-parser$(EXEEXT)
        rm -f xml-builtin.c stamp-xml
        rm -f $(DEPDIR)/*
+       for i in $(CONFIG_SRC_SUBDIR); do \
+               rm -f $$i/*.o;  \
+               rm -f $$i/$(DEPDIR)/*; \
+       done
 
 # This used to depend on c-exp.c m2-exp.c TAGS
 # I believe this is wrong; the makefile standards for distclean just
        rm -f config.log config.cache
        rm -f Makefile
        rm -rf $(DEPDIR)
+       for i in $(CONFIG_SRC_SUBDIR); do \
+               rmdir $$i/$(DEPDIR); \
+       done
 
 maintainer-clean: local-maintainer-clean do-maintainer-clean distclean
 realclean: maintainer-clean
 # into place if the compile succeeds.  We need this because gcc does
 # not atomically write the dependency output file.
 override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \
-       -MF $(DEPDIR)/$(basename $(@F)).Tpo
-override POSTCOMPILE = @mv $(DEPDIR)/$(basename $(@F)).Tpo \
-       $(DEPDIR)/$(basename $(@F)).Po
+       -MF $(@D)/$(DEPDIR)/$(@F).Tpo
+override POSTCOMPILE = @mv $(@D)/$(DEPDIR)/$(@F).Tpo \
+       $(@D)/$(DEPDIR)/$(@F).Po
 else
 override COMPILE.pre = source='$<' object='$@' libtool=no \
        DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) $(CC)
 
 LIBINTL
 USE_NLS
 CCDEPMODE
+CONFIG_SRC_SUBDIR
 DEPDIR
 am__leading_dot
 CXX_DIALECT
 ac_config_commands="$ac_config_commands depdir"
 
 
+# Create sub-directories for objects and depedencies.
+CONFIG_SRC_SUBDIR="arch"
+
+
+ac_config_commands="$ac_config_commands gdbdepdir"
+
+
 depcc="$CC"   am_compiler_list=
 
 am_depcomp=$ac_aux_dir/depcomp
 # INIT-COMMANDS
 #
 ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR
+ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR CONFIG_SRC_SUBDIR="$CONFIG_SRC_SUBDIR"
 
 _ACEOF
 
   case $ac_config_target in
     "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h:config.in" ;;
     "depdir") CONFIG_COMMANDS="$CONFIG_COMMANDS depdir" ;;
+    "gdbdepdir") CONFIG_COMMANDS="$CONFIG_COMMANDS gdbdepdir" ;;
     "jit-reader.h") CONFIG_FILES="$CONFIG_FILES jit-reader.h:jit-reader.in" ;;
     "$ac_config_links_1") CONFIG_LINKS="$CONFIG_LINKS $ac_config_links_1" ;;
     "gcore") CONFIG_FILES="$CONFIG_FILES gcore" ;;
 
   case $ac_file$ac_mode in
     "depdir":C) $SHELL $ac_aux_dir/mkinstalldirs $DEPDIR ;;
+    "gdbdepdir":C)
+  for subdir in ${CONFIG_SRC_SUBDIR}
+  do
+      $SHELL $ac_aux_dir/mkinstalldirs $subdir/$DEPDIR
+  done ;;
     "gcore":F) chmod +x gcore ;;
     "Makefile":F)
 case x$CONFIG_HEADERS in
 
 
 # Dependency checking.
 ZW_CREATE_DEPDIR
+# Create sub-directories for objects and dependencies.
+CONFIG_SRC_SUBDIR="arch"
+AC_SUBST(CONFIG_SRC_SUBDIR)
+
+AC_CONFIG_COMMANDS([gdbdepdir],[
+  for subdir in ${CONFIG_SRC_SUBDIR}
+  do
+      $SHELL $ac_aux_dir/mkinstalldirs $subdir/$DEPDIR
+  done],
+  [ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR CONFIG_SRC_SUBDIR="$CONFIG_SRC_SUBDIR"])
+
 ZW_PROG_COMPILER_DEPENDENCIES([CC])
 
 gnulib_extra_configure_args=
 
                        i386-darwin-tdep.o solib-darwin.o"
        if test "x$enable_64_bit_bfd" = "xyes"; then
            # Target: GNU/Linux x86-64
-           gdb_target_obs="amd64-tdep.o amd64.o amd64-darwin-tdep.o ${gdb_target_obs}"
+           gdb_target_obs="amd64-tdep.o arch/amd64.o amd64-darwin-tdep.o ${gdb_target_obs}"
        fi
        ;;
 i[34567]86-*-dicos*)
        ;;
 i[34567]86-*-solaris2* | x86_64-*-solaris2*)
        # Target: Solaris x86_64
-       gdb_target_obs="i386-tdep.o i386.o i387-tdep.o amd64-tdep.o amd64.o \
+       gdb_target_obs="i386-tdep.o i386.o i387-tdep.o amd64-tdep.o arch/amd64.o \
                         amd64-sol2-tdep.o i386-sol2-tdep.o sol2-tdep.o \
                         solib-svr4.o"
        ;;
                        linux-tdep.o linux-record.o"
        if test "x$enable_64_bit_bfd" = "xyes"; then
            # Target: GNU/Linux x86-64
-           gdb_target_obs="amd64-tdep.o amd64.o amd64-linux-tdep.o ${gdb_target_obs}"
+           gdb_target_obs="amd64-tdep.o arch/amd64.o amd64-linux-tdep.o ${gdb_target_obs}"
        fi
        build_gdbserver=yes
        ;;
 
 x86_64-*-darwin*)
        # Target: Darwin/x86-64
-       gdb_target_obs="amd64-tdep.o amd64.o i386-tdep.o i386.o i387-tdep.o \
+       gdb_target_obs="amd64-tdep.o arch/amd64.o i386-tdep.o i386.o i387-tdep.o \
                        i386-darwin-tdep.o amd64-darwin-tdep.o \
                         solib-darwin.o"
        ;;
 
 x86_64-*-dicos*)
        # Target: DICOS/x86-64
-       gdb_target_obs="amd64-tdep.o amd64.o i386-tdep.o i386.o i387-tdep.o \
+       gdb_target_obs="amd64-tdep.o arch/amd64.o i386-tdep.o i386.o i387-tdep.o \
                        dicos-tdep.o i386-dicos-tdep.o amd64-dicos-tdep.o"
        ;;
 x86_64-*-elf*)
-       gdb_target_obs="amd64-tdep.o amd64.o i386-tdep.o i386.o i387-tdep.o"
+       gdb_target_obs="amd64-tdep.o arch/amd64.o i386-tdep.o i386.o i387-tdep.o"
        ;;
 x86_64-*-linux*)
        # Target: GNU/Linux x86-64
-       gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o amd64.o i386-tdep.o \
+       gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o arch/amd64.o i386-tdep.o \
                        i387-tdep.o i386.o i386-linux-tdep.o glibc-tdep.o \
                        solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
        build_gdbserver=yes
        ;;
 x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
        # Target: FreeBSD/amd64
-       gdb_target_obs="amd64-tdep.o amd64.o amd64-fbsd-tdep.o i386-tdep.o \
+       gdb_target_obs="amd64-tdep.o arch/amd64.o amd64-fbsd-tdep.o i386-tdep.o \
                        i386.o i387-tdep.o i386-bsd-tdep.o i386-fbsd-tdep.o \
                        fbsd-tdep.o solib-svr4.o"
        ;;
 x86_64-*-mingw* | x86_64-*-cygwin*)
         # Target: MingW/amd64
-       gdb_target_obs="amd64-tdep.o amd64.o amd64-windows-tdep.o \
+       gdb_target_obs="amd64-tdep.o arch/amd64.o amd64-windows-tdep.o \
                         i386-tdep.o i386.o i386-cygwin-tdep.o i387-tdep.o \
                         windows-tdep.o"
        build_gdbserver=yes
         ;;
 x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
        # Target: NetBSD/amd64
-       gdb_target_obs="amd64-tdep.o amd64.o amd64-nbsd-tdep.o i386-tdep.o \
+       gdb_target_obs="amd64-tdep.o arch/amd64.o amd64-nbsd-tdep.o i386-tdep.o \
                        i386.o i387-tdep.o nbsd-tdep.o solib-svr4.o"
        ;;
 x86_64-*-openbsd*)
        # Target: OpenBSD/amd64
-       gdb_target_obs="amd64-tdep.o amd64.o amd64-obsd-tdep.o i386-tdep.o \
+       gdb_target_obs="amd64-tdep.o arch/amd64.o amd64-obsd-tdep.o i386-tdep.o \
                        i387-tdep.o i386-bsd-tdep.o i386-obsd-tdep.o \
                        i386.o obsd-tdep.o bsd-uthread.o solib-svr4.o"
        ;;
 x86_64-*-rtems*)
-       gdb_target_obs="amd64-tdep.o amd64.o i386-tdep.o i386.o i387-tdep.o \
+       gdb_target_obs="amd64-tdep.o arch/amd64.o i386-tdep.o i386.o i387-tdep.o \
                        i386-bsd-tdep.o"
        ;;
 xtensa*-*-linux*)      gdb_target=linux