You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by hu...@apache.org on 2016/05/25 02:06:54 UTC

incubator-hawq git commit: HAWQ-751. Add plr, pgcrypto, gporca into Apache HAWQ

Repository: incubator-hawq
Updated Branches:
  refs/heads/master 14cb8e091 -> 72f5302b0


HAWQ-751. Add plr, pgcrypto, gporca into Apache HAWQ


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/72f5302b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/72f5302b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/72f5302b

Branch: refs/heads/master
Commit: 72f5302b0aa93e93800ccc595da912e6cfc6f97d
Parents: 14cb8e0
Author: Paul Guo <pa...@gmail.com>
Authored: Mon May 23 17:59:00 2016 +0800
Committer: Ruilong Huo <rh...@pivotal.io>
Committed: Wed May 25 10:07:16 2016 +0800

----------------------------------------------------------------------
 .gitmodules                |  15 +++++
 GNUmakefile.in             |  40 ++++---------
 configure                  |  68 ++++++++++++++++++----
 configure.in               |  34 ++++++++---
 contrib/.gitignore         |   1 +
 contrib/Makefile           |  26 ++++++++-
 contrib/pgcrypto           |   1 +
 contrib/pgcrypto.patch     |  32 +++++++++++
 src/.gitignore             |   2 +
 src/Makefile.global.in     |  23 +++++---
 src/backend/.gitignore     |   4 ++
 src/backend/Makefile       | 123 ++++++++++++++++++++++++++++++++++++----
 src/backend/gp-xerces      |   1 +
 src/backend/gpopt/Makefile |  29 +++++-----
 src/backend/gpopt/gpopt.mk |  16 ++++--
 src/backend/gporca         |   1 +
 src/backend/gpos           |   1 +
 src/bin/Makefile           |   2 +-
 src/pl/Makefile            |  22 ++++++-
 src/pl/plr                 |   1 +
 src/pl/plr.patch           |  28 +++++++++
 src/postgres               |   1 +
 22 files changed, 378 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/.gitmodules
----------------------------------------------------------------------
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..40ab4f3
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,15 @@
+[submodule "src/backend/gp-xerces"]
+	path = src/backend/gp-xerces
+	url = https://github.com/greenplum-db/gp-xerces.git
+[submodule "src/backend/gpos"]
+	path = src/backend/gpos
+	url = https://github.com/greenplum-db/gpos.git
+[submodule "src/backend/gporca"]
+	path = src/backend/gporca
+	url = https://github.com/greenplum-db/gporca.git
+[submodule "src/pl/plr"]
+	path = src/pl/plr
+	url = https://github.com/jconway/plr.git
+[submodule "src/postgres"]
+	path = src/postgres
+	url = https://github.com/postgres/postgres.git

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/GNUmakefile.in
----------------------------------------------------------------------
diff --git a/GNUmakefile.in b/GNUmakefile.in
index 78a3524..6875cf6 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -9,20 +9,16 @@ top_builddir = .
 include $(top_builddir)/src/Makefile.global
 
 all:
-#	$(MAKE) -C doc all
+#	$(MAKE) -C doc $@
 # waiting for higher version of gcc ready
-#$(MAKE) -C depends/thirdparty/googletest all
-	$(MAKE) -C depends/thirdparty/thrift/hawqbuild all
-	$(MAKE) -C depends/libhdfs3 all
-	$(MAKE) -C depends/libyarn all
-	$(MAKE) -C src all
-	$(MAKE) -C config all
-	$(MAKE) -C contrib/formatter_fixedwidth all
-	$(MAKE) -C contrib/extprotocol all
-	$(MAKE) -C contrib/orafce all
-	$(MAKE) -C contrib/gp_cancel_query all
-	$(MAKE) -C contrib/hawq-hadoop all
-	$(MAKE) -C tools all
+#$(MAKE) -C depends/thirdparty/googletest $@
+	$(MAKE) -C depends/thirdparty/thrift/hawqbuild $@
+	$(MAKE) -C depends/libhdfs3 $@
+	$(MAKE) -C depends/libyarn $@
+	$(MAKE) -C src $@
+	$(MAKE) -C config $@
+	$(MAKE) -C contrib $@
+	$(MAKE) -C tools $@
 	@echo "All of HAWQ successfully made. Ready to install."
 
 install:
@@ -34,11 +30,7 @@ install:
 	$(MAKE) -C depends/libyarn $@
 	$(MAKE) -C src $@
 	$(MAKE) -C config $@
-	$(MAKE) -C contrib/formatter_fixedwidth $@
-	$(MAKE) -C contrib/extprotocol $@
-	$(MAKE) -C contrib/orafce $@
-	$(MAKE) -C contrib/gp_cancel_query $@
-	$(MAKE) -C contrib/hawq-hadoop $@
+	$(MAKE) -C contrib $@
 	$(MAKE) -C tools $@
 	@echo "HAWQ installation complete."
 
@@ -46,11 +38,7 @@ installdirs uninstall:
 #	$(MAKE) -C doc $@
 	$(MAKE) -C src $@
 	$(MAKE) -C config $@
-	$(MAKE) -C contrib/formatter_fixedwidth $@
-	$(MAKE) -C contrib/extprotocol $@
-	$(MAKE) -C contrib/orafce $@
-	$(MAKE) -C contrib/gp_cancel_query $@
-	$(MAKE) -C contrib/hawq-hadoop $@
+	$(MAKE) -C contrib $@
 
 distprep:
 #	$(MAKE) -C doc $@
@@ -76,11 +64,7 @@ clean:
 	-$(MAKE) -C depends/libyarn $@
 	$(MAKE) -C src $@
 	$(MAKE) -C config $@
-	$(MAKE) -C contrib/formatter_fixedwidth $@
-	$(MAKE) -C contrib/extprotocol $@
-	$(MAKE) -C contrib/orafce $@
-	$(MAKE) -C contrib/gp_cancel_query $@
-	$(MAKE) -C contrib/hawq-hadoop $@
+	$(MAKE) -C contrib $@
 	$(MAKE) -C tools $@
 	-$(MAKE) -C src feature-test-clean
 # Garbage from autoconf:

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/configure
----------------------------------------------------------------------
diff --git a/configure b/configure
index 0c2fe9c..5aa3d6a 100755
--- a/configure
+++ b/configure
@@ -665,6 +665,7 @@ CXX
 CURL_LIBS
 CURL_CFLAGS
 CURL_CONFIG
+R_HOME
 ZIC
 JAVAC_FLAGS
 JAVADOC
@@ -728,14 +729,13 @@ with_pam
 krb_srvtab
 with_krb5
 with_gssapi
+with_pgcrypto
 with_r
 with_java
 with_python
 with_perl
 with_tcl
 enable_thread_safety
-ORCA_DEPENDS_OBJDIR_DEFAULT
-ORCA_DEPENDS_DIR_INTER
 enable_orca
 enable_email
 enable_gphdfs
@@ -856,6 +856,7 @@ with_perl
 with_python
 with_java
 with_r
+with_pgcrypto
 with_gssapi
 with_krb5
 with_krb_srvnam
@@ -1545,7 +1546,8 @@ Optional Packages:
   --with-perl             build Perl modules (PL/Perl)
   --with-python           build Python modules (PL/Python)
   --with-java             build Java modules (PL/Java)
-  --with-r             build R modules (PL/R)
+  --with-r                build R modules (PL/R)
+  --with-pgcrypto         build with pgcrypto
   --with-gssapi           build with GSSAPI support
   --with-krb5             build with Kerberos 5 support
   --with-krb-srvnam=NAME  default service principal name in Kerberos [postgres]
@@ -5502,14 +5504,6 @@ fi
 
 
 
-if test "$enable_orca" = yes ; then
-    ORCA_DEPENDS_DIR_INTER="$ORCA_DEPENDS_DIR"
-    ORCA_DEPENDS_OBJDIR_DEFAULT="$ORCA_OBJDIR_DEFAULT"
-fi
-
-
-
-
 #
 # Enable thread-safe client libraries
 #
@@ -5774,6 +5768,41 @@ fi
 $as_echo "$with_r" >&6; }
 
 
+
+#
+# Optionally build with pgcrypto.
+#
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build pgcrypto modules" >&5
+$as_echo_n "checking whether to build pgcrypto modules... " >&6; }
+
+pgac_args="$pgac_args with_pgcrypto"
+
+
+# Check whether --with-pgcrypto was given.
+if test "${with_pgcrypto+set}" = set; then :
+  withval=$with_pgcrypto;
+  case $withval in
+    yes)
+      :
+      ;;
+    no)
+      :
+      ;;
+    *)
+      as_fn_error $? "no argument expected for --with-pgcrypto option" "$LINENO" 5
+      ;;
+  esac
+
+else
+  with_pgcrypto=no
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_pgcrypto" >&5
+$as_echo "$with_pgcrypto" >&6; }
+
+
 #
 # GSSAPI
 #
@@ -8997,6 +9026,23 @@ fi
 
 fi
 
+if test "$with_r" = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking R_HOME" >&5
+$as_echo_n "checking R_HOME... " >&6; }
+  if test "x${R_HOME}" = x; then
+    r_home_guess=`pkg-config --variable=rhome libR 2>/dev/null`
+	if test "x${r_home_guess}" != "x"; then
+      R_HOME=$r_home_guess
+	else
+      as_fn_error $? "Failed to Set R_HOME. R is not installed? R_HOME is not set
+or pkg-config is not installed to find R_HOME automatically." "$LINENO" 5
+    fi
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${R_HOME}" >&5
+$as_echo "${R_HOME}" >&6; }
+
+fi
+
 if test "$enable_spinlocks" = yes; then
 
 $as_echo "#define HAVE_SPINLOCKS 1" >>confdefs.h

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/configure.in
----------------------------------------------------------------------
diff --git a/configure.in b/configure.in
index 3a6e8d3..ee04770 100644
--- a/configure.in
+++ b/configure.in
@@ -643,14 +643,6 @@ PGAC_ARG_BOOL(enable, orca, no, [  --enable-orca        enable Pivotal Query Opt
                          [Define to 1 to build with Pivotal Query Optimizer. (--enable-orca)])])
 AC_SUBST(enable_orca)
 
-if test "$enable_orca" = yes ; then
-    ORCA_DEPENDS_DIR_INTER="$ORCA_DEPENDS_DIR"
-    ORCA_DEPENDS_OBJDIR_DEFAULT="$ORCA_OBJDIR_DEFAULT"
-fi
-
-AC_SUBST(ORCA_DEPENDS_DIR_INTER)
-AC_SUBST(ORCA_DEPENDS_OBJDIR_DEFAULT)
-
 #
 # Enable thread-safe client libraries
 #
@@ -711,10 +703,19 @@ AC_SUBST(with_java)
 # Optionally build R modules (PL/R)
 #
 AC_MSG_CHECKING([whether to build R modules])
-PGAC_ARG_BOOL(with, r, no, [  --with-r             build R modules (PL/R)])
+PGAC_ARG_BOOL(with, r, no, [  --with-r                build R modules (PL/R)])
 AC_MSG_RESULT([$with_r])
 AC_SUBST(with_r)
 
+
+#
+# Optionally build with pgcrypto.
+#
+AC_MSG_CHECKING([whether to build pgcrypto modules])
+PGAC_ARG_BOOL(with, pgcrypto, no, [  --with-pgcrypto         build with pgcrypto ])
+AC_MSG_RESULT([$with_pgcrypto])
+AC_SUBST(with_pgcrypto)
+
 #
 # GSSAPI
 #
@@ -1077,6 +1078,21 @@ failure.  It is possible the compiler isn't looking in the proper directory.
 Use --without-zlib to disable zlib support.])])
 fi
 
+if test "$with_r" = yes; then
+  AC_MSG_CHECKING([R_HOME])
+  if test "x${R_HOME}" = x; then
+    r_home_guess=`pkg-config --variable=rhome libR 2>/dev/null`
+	if test "x${r_home_guess}" != "x"; then
+      R_HOME=$r_home_guess
+	else
+      AC_MSG_ERROR([Failed to Set R_HOME. R is not installed? R_HOME is not set
+or pkg-config is not installed to find R_HOME automatically.])
+    fi
+  fi
+  AC_MSG_RESULT(${R_HOME})
+  AC_SUBST(R_HOME)
+fi
+
 if test "$enable_spinlocks" = yes; then
   AC_DEFINE(HAVE_SPINLOCKS, 1, [Define to 1 if you have spinlocks.])
 else

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/contrib/.gitignore
----------------------------------------------------------------------
diff --git a/contrib/.gitignore b/contrib/.gitignore
new file mode 100644
index 0000000..2971e1e
--- /dev/null
+++ b/contrib/.gitignore
@@ -0,0 +1 @@
+pgcrypto_prepare_timestamp

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/contrib/Makefile
----------------------------------------------------------------------
diff --git a/contrib/Makefile b/contrib/Makefile
index 92df392..1701b23 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -8,20 +8,40 @@ WANTED_DIRS = \
 		orafce \
 		extprotocol \
 		gp_cancel_query \
+		formatter_fixedwidth \
 		hawq-hadoop
 
+ifeq ($(with_pgcrypto), yes)
+WANTED_DIRS += pgcrypto
+
+# fixme: depend on pgcrypto.patch also.
+pgcrypto_prepare: pg_prepare
+	if [ ! -e $(abs_top_builddir)/$(subdir)/pgcrypto_prepare_timestamp ]; then \
+		(cd $(abs_top_srcdir)/src/postgres/contrib/pgcrypto; git apply $(abs_top_srcdir)/$(subdir)/pgcrypto.patch) && \
+		touch $(abs_top_builddir)/$(subdir)/pgcrypto_prepare_timestamp; \
+	fi
+else
+pgcrypto_prepare:
+endif
+
+.PHONY: pgcrypto_prepare
+
 # Missing:
 #		start-scripts	\ (does not have a makefile)
 #		xml2		\ (requires libxml installed)
 
-
-all install installdirs uninstall distprep clean distclean maintainer-clean:
+all install installdirs uninstall distprep: pgcrypto_prepare
 	@for dir in $(WANTED_DIRS); do \
 		$(MAKE) -C $$dir $@ || exit; \
 	done
 
+clean distclean maintainer-clean:
+	@for dir in $(WANTED_DIRS); do \
+		$(MAKE) -C $$dir $@ || true; \
+	done
+
 # We'd like check operations to run all the subtests before failing.
-check installcheck:
+check installcheck: pgcrypto_prepare
 	@CHECKERR=0; for dir in $(WANTED_DIRS); do \
 		$(MAKE) -C $$dir $@ || CHECKERR=$$?; \
 	done; \

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/contrib/pgcrypto
----------------------------------------------------------------------
diff --git a/contrib/pgcrypto b/contrib/pgcrypto
new file mode 120000
index 0000000..8c4adfc
--- /dev/null
+++ b/contrib/pgcrypto
@@ -0,0 +1 @@
+../src/postgres/contrib/pgcrypto
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/contrib/pgcrypto.patch
----------------------------------------------------------------------
diff --git a/contrib/pgcrypto.patch b/contrib/pgcrypto.patch
new file mode 100644
index 0000000..3b2a633
--- /dev/null
+++ b/contrib/pgcrypto.patch
@@ -0,0 +1,32 @@
+diff --git a/contrib/pgcrypto/.gitignore b/contrib/pgcrypto/.gitignore
+index 5dcb3ff..dd80948 100644
+--- a/contrib/pgcrypto/.gitignore
++++ b/contrib/pgcrypto/.gitignore
+@@ -1,4 +1,9 @@
+ # Generated subdirectories
+-/log/
+-/results/
+-/tmp_check/
++libpgcrypto.a
++libpgcrypto.so
++libpgcrypto.so.0
++libpgcrypto.so.0.0
++pgcrypto.sql
++log
++results
++tmp_check
+diff --git a/contrib/pgcrypto/Makefile b/contrib/pgcrypto/Makefile
+index dadec95..3ec597d 100644
+--- a/contrib/pgcrypto/Makefile
++++ b/contrib/pgcrypto/Makefile
+@@ -41,8 +41,8 @@ PG_CONFIG = pg_config
+ PGXS := $(shell $(PG_CONFIG) --pgxs)
+ include $(PGXS)
+ else
+-subdir = contrib/pgcrypto
+-top_builddir = ../..
++subdir = src/postgresql/contrib/pgcrypto
++top_builddir = ../../../..
+ include $(top_builddir)/src/Makefile.global
+ include $(top_srcdir)/contrib/contrib-global.mk
+ endif

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/.gitignore
----------------------------------------------------------------------
diff --git a/src/.gitignore b/src/.gitignore
index 512464f..8b5553c 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -2,3 +2,5 @@ Makefile.global
 Makefile.port
 Makefile.custom
 VERSIONS.mk
+pg_prepare_timestamp
+pl/plr_prepare_timestamp

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/Makefile.global.in
----------------------------------------------------------------------
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index cf27bdc..dc09653 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -45,6 +45,7 @@ ADDON_DIR = @ADDON_DIR@
 # Support for VPATH builds
 vpath_build = @vpath_build@
 abs_top_srcdir = @abs_top_srcdir@
+abs_top_builddir = @abs_top_builddir@
 
 ifneq ($(vpath_build),yes)
 top_srcdir = $(top_builddir)
@@ -170,6 +171,7 @@ with_perl	= @with_perl@
 with_python	= @with_python@
 with_tcl	= @with_tcl@
 with_r		= @with_r@
+with_pgcrypto = @with_pgcrypto@
 with_java   = @with_java@
 with_openssl	= @with_openssl@
 with_system_tzdata = @with_system_tzdata@
@@ -266,13 +268,6 @@ LD = @LD@
 with_gnu_ld = @with_gnu_ld@
 ld_R_works = @ld_R_works@
 
-# Dependencies
-ORCA_DEPENDS_DIR_INTER = @ORCA_DEPENDS_DIR_INTER@
-ORCA_DEPENDS_OBJDIR_DEFAULT = @ORCA_DEPENDS_OBJDIR_DEFAULT@
-ORCA_DEPENDS_XERCES_VER = @ORCA_DEPENDS_XERCES_VER@
-ORCA_DEPENDS_LIBGPOS_VER = @ORCA_DEPENDS_LIBGPOS_VER@
-ORCA_DEPENDS_OPTIMIZER_VER = @ORCA_DEPENDS_OPTIMIZER_VER@
-
 # We want -L for libpgport.a to be first in LDFLAGS.  We also need LDFLAGS
 # to be a "recursively expanded" variable, else adjustments to rpathdir
 # don't work right.  So we must NOT do LDFLAGS := something, meaning this has
@@ -329,6 +324,11 @@ else
 	JAVADOC     = $(missing) javadoc
 endif
 
+# R
+ifeq ($(with_r), yes)
+	R_HOME		= "@R_HOME@"
+endif
+
 # Miscellaneous
 
 AWK	= @AWK@
@@ -695,6 +695,14 @@ include $(top_srcdir)/src/nls-global.mk
 endif # nls.mk
 endif # enable_nls
 
+pg_prepare:
+ifneq "$(findstring yes, $(with_pgcrypto))" ""
+	if [ ! -e $(abs_top_builddir)/pg_prepare_timestamp ]; then \
+		cd $(abs_top_srcdir); \
+		git submodule update --init src/postgres && \
+		touch $(abs_top_builddir)/src/pg_prepare_timestamp; \
+	fi
+endif
 
 ##########################################################################
 #
@@ -728,7 +736,6 @@ lcov.info: $(gcda_files)
 %.c.gcov: %.gcda | lcov.info
 	$(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
 
-
 # hook for clean-up
 clean distclean maintainer-clean: clean-coverage
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/backend/.gitignore
----------------------------------------------------------------------
diff --git a/src/backend/.gitignore b/src/backend/.gitignore
index e26100d..00b1901 100644
--- a/src/backend/.gitignore
+++ b/src/backend/.gitignore
@@ -1,2 +1,6 @@
 postgres
 postgres.def
+*timestamp
+gporca/
+gpos/
+gp-xerces/

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/backend/Makefile
----------------------------------------------------------------------
diff --git a/src/backend/Makefile b/src/backend/Makefile
index f89c24d..bc8c178 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -56,12 +56,18 @@ LIBS := -lprotobuf -lboost_system -lboost_date_time -lstdc++ -lhdfs3 -lgsasl -lx
 
 # adding orca libraries
 ifeq ($(enable_orca),yes)
-LIBS := $(LIBS) -L$(ORCA_DEPENDS_DIR_INTER)/libgpos/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpos
-LIBS := $(LIBS) -L$(ORCA_DEPENDS_DIR_INTER)/lib -lxerces-c
-LIBS := $(LIBS) -L$(ORCA_DEPENDS_DIR_INTER)/libnaucrates/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lnaucrates
-LIBS := $(LIBS) -L$(ORCA_DEPENDS_DIR_INTER)/libgpdbcost/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpdbcost
-LIBS := $(LIBS) -L$(ORCA_DEPENDS_DIR_INTER)/libgpopt/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpopt
-LIBS := $(LIBS) -L$(top_builddir)/src/backend/gpopt -ldxltranslators
+LIBGPOS_DIR = $(abs_top_builddir)/$(subdir)/gpos/build/install/$(prefix)/lib
+LIBXERCES_DIR = $(abs_top_builddir)/$(subdir)/gp-xerces/build/install/$(prefix)/lib
+LIBNAUCRATES_DIR = $(abs_top_builddir)/$(subdir)/gporca/build/install/$(prefix)/lib
+LIBGPDBCOST_DIR = $(abs_top_builddir)/$(subdir)/gporca/build/install/$(prefix)/lib
+LIBGPOPT_DIR = $(abs_top_builddir)/$(subdir)/gporca/build/install/$(prefix)/lib
+
+LIBS := $(LIBS) -L$(LIBGPOS_DIR) -lgpos
+LIBS := $(LIBS) -L$(LIBXERCES_DIR) -lxerces-c
+LIBS := $(LIBS) -L$(LIBNAUCRATES_DIR) -lnaucrates
+LIBS := $(LIBS) -L$(LIBGPDBCOST_DIR) -lgpdbcost
+LIBS := $(LIBS) -L$(LIBGPOPT_DIR) -lgpopt
+LIBS := $(LIBS) -L$(abs_top_builddir)/$(subdir)/gpopt -ldxltranslators
 endif
 
 # HAWQ uses threads in the backend
@@ -74,19 +80,111 @@ SNAPPYLIB = -lsnappy
 LIBS := $(LIBS) $(SNAPPYLIB)
 ##########################################################################
 
-submake-libdxltranslators: 
 ifeq ($(enable_orca),yes)
-	$(MAKE) -C gpopt all
+
+ifeq ($(PORTNAME), darwin)
+XERCES_LIB_FILE=libxerces-c.dylib
+GPOS_LIB_FILE=libgpos.dylib
+else
+XERCES_LIB_FILE=libxerces-c.so
+GPOS_LIB_FILE=libgpos.so
+endif
+
+GPORCA_SRC_PATH := $(abs_top_srcdir)/$(subdir)/gporca
+GPOS_SRC_PATH := $(abs_top_srcdir)/$(subdir)/gpos
+GP_XERCES_SRC_PATH := $(abs_top_srcdir)/$(subdir)/gp-xerces
+
+submake-gporca: submake-gpos submake-gp-xerces gporca_prepare
+ifneq ($(prefix),)
+	if [ ! -f gporca_build_timestamp ]; then \
+		rm -rf gporca/build; mkdir -p gporca/build; cd gporca/build; \
+		cmake $(GPORCA_SRC_PATH) -DCMAKE_INSTALL_PREFIX=$(prefix) \
+			-DXERCES_INCLUDE_DIR=$(abs_top_builddir)/$(subdir)/gp-xerces/build/install/$(prefix)/include \
+			-DXERCES_LIBRARY=$(abs_top_builddir)/$(subdir)/gp-xerces/build/install/$(prefix)/lib/$(XERCES_LIB_FILE) \
+			-DGPOS_INCLUDE_DIR=$(abs_top_builddir)/$(subdir)/gpos/build/install/$(prefix)/include \
+			-DGPOS_LIBRARY=$(abs_top_builddir)/$(subdir)/gpos/build/install/$(prefix)/lib/$(GPOS_LIB_FILE) && \
+		$(MAKE) DESTDIR=$(abs_top_builddir)/$(subdir)/gporca/build/install install && \
+		touch ../../gporca_build_timestamp; \
+	fi
+else
+	if [ ! -f gporca_build_timestamp ]; then \
+		rm -rf gporca/build; mkdir -p gporca/build; cd gporca/build; \
+ 		cmake $(ORCA_SRC_PATH) \
+			-DXERCES_INCLUDE_DIR=$(abs_top_builddir)/$(subdir)/gp-xerces/build/install/$(prefix)/include \
+			-DXERCES_LIBRARY=$(abs_top_builddir)/$(subdir)/gp-xerces/build/install/$(prefix)/lib/$(XERCES_LIB_FILE) \
+			-DGPOS_INCLUDE_DIR=$(abs_top_builddir)/$(subdir)/gpos/build/install/$(prefix)/include \
+			-DGPOS_LIBRARY=$(abs_top_builddir)/$(subdir)/gpos/build/install/$(prefix)/lib/$(GPOS_LIB_FILE) && \
+		$(MAKE) DESTDIR=$(abs_top_builddir)/$(subdir)/gporca/build/install install && \
+		touch ../../gporca_build_timestamp; \
+	fi
+endif
+
+submake-gpos: gporca_prepare
+ifneq ($(prefix),)
+	if [ ! -f gpos_build_timestamp ]; then \
+		rm -rf gpos/build; mkdir -p gpos/build; cd gpos/build; mkdir -p install; \
+		cmake $(GPOS_SRC_PATH) -DCMAKE_INSTALL_PREFIX=$(prefix) && \
+		$(MAKE) DESTDIR=$(abs_top_builddir)/$(subdir)/gpos/build/install install && \
+		touch ../../gpos_build_timestamp; \
+	fi
+else
+	if [ ! -f gpos_build_timestamp ]; then \
+		rm -rf gpos/build; mkdir -p gpos/build; cd gpos/build; mkdir -p install; \
+		cmake $(GPOS_SRC_PATH) && \
+		$(MAKE) DESTDIR=$(abs_top_builddir)/$(subdir)/gpos/build/install install && \
+		touch ../../gpos_build_timestamp; \
+	fi
 endif
 
-all: submake-libpgport submake-libdxltranslators  postgres $(POSTGRES_IMP)
+submake-gp-xerces: submake-gpos gporca_prepare
+ifneq ($(prefix),)
+	if [ ! -f gp-xerces_build_timestamp ]; then \
+		rm -rf gp-xerces/build; mkdir -p gp-xerces/build; cd gp-xerces/build; mkdir -p install; \
+		$(GP_XERCES_SRC_PATH)/configure --prefix=$(prefix); \
+		$(MAKE) DESTDIR=$(abs_top_builddir)/$(subdir)/gp-xerces/build/install install && \
+		touch ../../gp-xerces_build_timestamp; \
+	fi
+else
+	if [ ! -f gp-xerces_build_timestamp ]; then \
+		rm -rf gp-xerces/build; mkdir -p gp-xerces/build; cd gp-xerces/build; mkdir -p install; \
+		$(GP_XERCES_SRC_PATH)/configure --prefix=$(prefix); \
+		$(MAKE) DESTDIR=$(abs_top_builddir)/$(subdir)/gp-xerces/build/install install && \ 
+		touch ../../gp-xerces_build_timestamp; \
+	fi
+endif
+
+gporca_prepare:
+	if [ ! -f $(abs_top_builddir)/$(subdir)/gporca_prepare_timestamp ]; then \
+			cd $(abs_top_srcdir); \
+			git submodule update --init $(subdir)/gporca && \
+			git submodule update --init $(subdir)/gp-xerces && \
+			git submodule update --init $(subdir)/gpos && \
+			touch $(abs_top_builddir)/$(subdir)/gporca_prepare_timestamp; \
+	fi
+
+submake-libdxltranslators: submake-gporca
+	$(MAKE) -C gpopt all
+
+# No distclean for gpor & gpos by now.
+distclean_gporca:
+	rm -rf gporca/build gporca_*_timestamp
+	rm -rf gpos/build gpos_*_timestamp
+	rm -rf gp-xerces/build gp-xerces_*_timestamp
+
+.PHONY: submake-gporca submake-gpos submake-gp-xerces distclean_gporca gporca_prepare
+
+else
+submake-libdxltranslators distclean_gporca:
+endif # enable_orca
+
+all: submake-libpgport postgres $(POSTGRES_IMP)
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
 ifneq ($(PORTNAME), aix)
 
-postgres: $(OBJS)
-	$(CXX) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
+postgres: $(OBJS) submake-libdxltranslators
+	$(CXX) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys, $(filter-out submake-libdxltranslators, $^)) $(LIBS) -o $@
 
 endif
 endif
@@ -227,6 +325,7 @@ endif
 	${INSTALL_DATA} $(srcdir)/utils/misc/etc/gpcheck.cnf ${sysconfdir}
 ifeq ($(enable_orca), yes)
 	$(MAKE) -C gpopt $@ INSTLOC=$(DESTDIR)$(libdir)
+	$(MAKE) -C gporca/build $@
 endif
 
 install-bin: postgres $(POSTGRES_IMP) installdirs
@@ -303,7 +402,7 @@ endif
 	find gpopt -name *.so | xargs rm -rf
 	find gpopt -name *.dylib | xargs rm -rf
 
-distclean: clean
+distclean: clean distclean_gporca
 	rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
 
 maintainer-clean: distclean

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/backend/gp-xerces
----------------------------------------------------------------------
diff --git a/src/backend/gp-xerces b/src/backend/gp-xerces
new file mode 160000
index 0000000..f07c17d
--- /dev/null
+++ b/src/backend/gp-xerces
@@ -0,0 +1 @@
+Subproject commit f07c17da813f44d8da17067a76491ca4b1deb02f

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/backend/gpopt/Makefile
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/Makefile b/src/backend/gpopt/Makefile
index b587ffd..58d97fa 100644
--- a/src/backend/gpopt/Makefile
+++ b/src/backend/gpopt/Makefile
@@ -39,29 +39,30 @@ else
 	GPOPT_UDF_FLAGS := -shared
 endif
 
-LIBGPOS_DIR = $(ORCA_DEPENDS_DIR_INTER)/libgpos
-LIBNAUCRATES_DIR = $(ORCA_DEPENDS_DIR_INTER)/libnaucrates
-LIBGPDBCOST_DIR = $(ORCA_DEPENDS_DIR_INTER)/libgpdbcost
-LIBGPOPT_DIR = $(ORCA_DEPENDS_DIR_INTER)/libgpopt
+LIBGPOS_DIR = ../gpos/build/install/$(prefix)/lib
+LIBXERCES_DIR = ../gp-xerces/build/install/$(prefix)/lib
+LIBNAUCRATES_DIR = ../gporca/build/install/$(prefix)/lib
+LIBGPDBCOST_DIR = ../gporca/build/install/$(prefix)/lib
+LIBGPOPT_DIR = ../gporca/build/install/$(prefix)/lib
 
 include $(top_srcdir)/src/backend/common.mk
 
 libdxltranslators.$(LDSFX): $(SUBDIROBJS) $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDLIBFLAGS) \
-	  -L$(LIBGPOS_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpos \
-	  -L$(ORCA_DEPENDS_DIR_INTER)/lib -lxerces-c \
-	  -L$(LIBNAUCRATES_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lnaucrates \
-	  -L$(LIBGPDBCOST_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpdbcost \
-	  -L$(LIBGPOPT_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpopt -lpthread -o $@ \
+	  -L$(LIBGPOS_DIR) -lgpos \
+	  -L$(LIBXERCES_DIR) -lxerces-c \
+	  -L$(LIBNAUCRATES_DIR) -lnaucrates \
+	  -L$(LIBGPDBCOST_DIR) -lgpdbcost \
+	  -L$(LIBGPOPT_DIR) -lgpopt -lpthread -o $@ \
 	  $(SUBDIROBJS) $(OBJS)
 
 libgpoptudf.$(LDSFX): $(SUBDIROBJS)
 	$(CXX) $(CXXFLAGS) $(GPOPT_UDF_FLAGS) \
-	  -L$(ORCA_DEPENDS_DIR_INTER)/lib -lxerces-c \
-	  -L$(LIBGPOS_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpos \
-	  -L$(LIBNAUCRATES_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lnaucrates \
-	  -L$(LIBGPDBCOST_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpdbcost \
-	  -L$(LIBGPOPT_DIR)/$(ORCA_DEPENDS_OBJDIR_DEFAULT) -lgpopt \
+	  -L$(LIBXERCES_DIR) -lxerces-c \
+	  -L$(LIBGPOS_DIR) -lgpos \
+	  -L$(LIBNAUCRATES_DIR) -lnaucrates \
+	  -L$(LIBGPDBCOST_DIR) -lgpdbcost \
+	  -L$(LIBGPOPT_DIR) -lgpopt \
 	  -o $@ ./utils/funcs.o
 
 install:

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/backend/gpopt/gpopt.mk
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/gpopt.mk b/src/backend/gpopt/gpopt.mk
index 1fa7d81..c21f27e 100644
--- a/src/backend/gpopt/gpopt.mk
+++ b/src/backend/gpopt/gpopt.mk
@@ -60,14 +60,20 @@ XERCES_VER  = $(shell grep "\"xerces-c\""   $(GREP_SED_VAR))
 LIBGPOS_VER = $(shell grep "\"libgpos\""    $(GREP_SED_VAR))
 OPTIMIZER_VER = $(shell grep "\"optimizer\""  $(GREP_SED_VAR))
 
+LIBGPOS_DIR = $(abs_top_builddir)/src/backend/gpos/build/install/$(prefix)
+LIBXERCES_DIR = $(abs_top_builddir)/src/backend/gp-xerces/build/install/$(prefix)
+LIBNAUCRATES_DIR = $(abs_top_builddir)/src/backend/gporca/build/install/$(prefix)
+LIBGPDBCOST_DIR = $(abs_top_builddir)/src/backend/gporca/build/install/$(prefix)
+LIBGPOPT_DIR = $(abs_top_builddir)/src/backend/gpopt/build/install/$(prefix)
+
 BLD_FLAGS = $(ARCH_FLAGS) -D$(ARCH_BIT) -D$(ARCH_CPU) -D$(ARCH_OS) $(GPOPT_flags)
 override CPPFLAGS := -fPIC $(CPPFLAGS)
 override CPPFLAGS := $(BLD_FLAGS)  $(CPPFLAGS)
 override CPPFLAGS := -DGPOS_VERSION=\"$(LIBGPOS_VER)\" $(CPPFLAGS)
 override CPPFLAGS := -DGPOPT_VERSION=\"$(OPTIMIZER_VER)\" $(CPPFLAGS)
 override CPPFLAGS := -DXERCES_VERSION=\"$(XERCES_VER)\" $(CPPFLAGS)
-override CPPFLAGS := -I $(ORCA_DEPENDS_DIR_INTER)/include $(CPPFLAGS)
-override CPPFLAGS := -I $(ORCA_DEPENDS_DIR_INTER)/libgpos/include $(CPPFLAGS)
-override CPPFLAGS := -I $(ORCA_DEPENDS_DIR_INTER)/libgpopt/include $(CPPFLAGS)
-override CPPFLAGS := -I $(ORCA_DEPENDS_DIR_INTER)/libnaucrates/include $(CPPFLAGS)
-override CPPFLAGS := -I $(ORCA_DEPENDS_DIR_INTER)/libgpdbcost/include $(CPPFLAGS)
+override CPPFLAGS := -I $(LIBGPOS_DIR)/include $(CPPFLAGS)
+override CPPFLAGS := -I $(LIBXERCES_DIR)/include $(CPPFLAGS)
+override CPPFLAGS := -I $(LIBGPOPT_DIR)/include $(CPPFLAGS)
+override CPPFLAGS := -I $(LIBNAUCRATES_DIR)/include $(CPPFLAGS)
+override CPPFLAGS := -I $(LIBGPDBCOST_DIR)/include $(CPPFLAGS)

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/backend/gporca
----------------------------------------------------------------------
diff --git a/src/backend/gporca b/src/backend/gporca
new file mode 160000
index 0000000..f0532b1
--- /dev/null
+++ b/src/backend/gporca
@@ -0,0 +1 @@
+Subproject commit f0532b19c22c86e6959ae35fb9568096b7d666f9

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/backend/gpos
----------------------------------------------------------------------
diff --git a/src/backend/gpos b/src/backend/gpos
new file mode 160000
index 0000000..91fa636
--- /dev/null
+++ b/src/backend/gpos
@@ -0,0 +1 @@
+Subproject commit 91fa636d53ad71d56a4beae55e3ed1fb6d6f8f92

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/bin/Makefile
----------------------------------------------------------------------
diff --git a/src/bin/Makefile b/src/bin/Makefile
index 04d412d..46243cf 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -16,7 +16,7 @@ include $(top_builddir)/src/Makefile.global
 DIRS = initdb ipcclean pg_ctl pg_dump pgbench \
 	psql scripts pg_config pg_controldata pg_resetxlog \
 	gpfilesystem/hdfs gpmirrortransition gpupgrade \
-	gpfusion gp_workfile_mgr gpcheckhdfs gpfdist gpoptutils
+	gpfusion gp_workfile_mgr gpcheckhdfs gpoptutils
 
 all install installdirs uninstall distprep clean distclean maintainer-clean:
 	@for dir in $(DIRS); do echo "build $$dir"; $(MAKE) -C $$dir $@ || exit; done

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/pl/Makefile
----------------------------------------------------------------------
diff --git a/src/pl/Makefile b/src/pl/Makefile
index 31d9bb9..49f2a9b 100644
--- a/src/pl/Makefile
+++ b/src/pl/Makefile
@@ -30,11 +30,29 @@ ifeq ($(with_perl), yes)
 DIRS += plperl
 endif
 
-all install installdirs uninstall distprep:
+ifeq ($(with_r), yes)
+DIRS += plr
+
+# fixme: depend on plr.patch also.
+plr_prepare:
+	if [ ! -e $(abs_top_builddir)/$(subdir)/plr_prepare_timestamp ]; then \
+		cd $(abs_top_srcdir); \
+		git submodule update --init $(subdir)/plr && \
+		(cd $(abs_top_srcdir)/$(subdir)/plr; git apply ../plr.patch) && \
+		touch $(abs_top_builddir)/$(subdir)/plr_prepare_timestamp; \
+	fi
+else
+plr_prepare:
+endif
+
+.PHONY: plr_prepare
+
+# We need to fetch plrr if needed.
+all install installdirs uninstall distprep: plr_prepare
 	@for dir in $(DIRS); do $(MAKE) -C $$dir $@ || exit 1; done
 
 clean distclean maintainer-clean:
-	@for dir in $(DIRS); do $(MAKE) -C $$dir $@; done
+	@for dir in $(DIRS); do $(MAKE) -C $$dir $@ || true; done
 
 # We'd like check operations to run all the subtests before failing;
 # also insert a sleep to ensure the previous test backend exited before

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/pl/plr
----------------------------------------------------------------------
diff --git a/src/pl/plr b/src/pl/plr
new file mode 160000
index 0000000..33a90a9
--- /dev/null
+++ b/src/pl/plr
@@ -0,0 +1 @@
+Subproject commit 33a90a9a098fe7bf56256e231b9d0142016cb9f5

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/pl/plr.patch
----------------------------------------------------------------------
diff --git a/src/pl/plr.patch b/src/pl/plr.patch
new file mode 100644
index 0000000..1350fbd
--- /dev/null
+++ b/src/pl/plr.patch
@@ -0,0 +1,28 @@
+diff --git a/Makefile b/Makefile
+index 65c6bbe..29f04cd 100755
+--- a/Makefile
++++ b/Makefile
+@@ -35,8 +35,8 @@ endif
+ PGXS := $(shell $(PG_CONFIG) --pgxs)
+ include $(PGXS)
+ else
+-subdir = contrib/plr
+-top_builddir = ../..
++subdir = src/pl/plr
++top_builddir = ../../..
+ include $(top_builddir)/src/Makefile.global
+ include $(top_srcdir)/contrib/contrib-global.mk
+ endif
+diff --git a/plr.h b/plr.h
+index 67f8dbe..9a457ee 100755
+--- a/plr.h
++++ b/plr.h
+@@ -366,7 +366,7 @@ extern void R_RunExitFinalizers(void);
+ 		tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod); \
+ 		tuple->t_len = HeapTupleHeaderGetDatumLength(tuple_hdr); \
+ 		ItemPointerSetInvalid(&(tuple->t_self)); \
+-		tuple->t_tableOid = InvalidOid; \
++		/* tuple->t_tableOid = InvalidOid; */ \
+ 		tuple->t_data = tuple_hdr; \
+ 		PROTECT(el = pg_tuple_get_r_frame(1, &tuple, tupdesc)); \
+ 		ReleaseTupleDesc(tupdesc); \

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/72f5302b/src/postgres
----------------------------------------------------------------------
diff --git a/src/postgres b/src/postgres
new file mode 160000
index 0000000..ca59dfa
--- /dev/null
+++ b/src/postgres
@@ -0,0 +1 @@
+Subproject commit ca59dfa6f727fe3bf3a01904ec30e87f7fa5a67e