Support out-of-tree xorg builds and lay groundwork for cross-compatible build using X.org 7.5


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4018 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/unix/build-xorg b/unix/build-xorg
new file mode 100755
index 0000000..a158476
--- /dev/null
+++ b/unix/build-xorg
@@ -0,0 +1,263 @@
+#!/bin/bash
+# -*- mode: shell-script; coding: UTF-8 -*-
+# 
+# Build Xvnc with Xorg 7.4
+#
+
+set -e
+
+if [ "$PREFIX" = "" ]; then
+    PREFIX=`pwd`/xorg.build
+fi
+export ACLOCAL="aclocal -I ${PREFIX}/share/aclocal"
+export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
+MAKE="make"
+STATIC=0
+XORG_VERSION=
+SRCDIR=..
+
+modules="dri2proto \
+    libpthread-stubs \
+    glproto \
+    xf86vidmodeproto \
+    xextproto \
+    xproto \
+    kbproto \
+    inputproto \
+    xcmiscproto \
+    bigreqsproto \
+    fixesproto \
+    damageproto \
+    xf86driproto \
+    randrproto \
+    renderproto \
+    scrnsaverproto \
+    resourceproto \
+    fontsproto \
+    videoproto \
+    compositeproto \
+    xineramaproto \
+    fontcacheproto \
+    libdrm \
+    libXau \
+    xtrans \
+    libXdmcp \
+    libX11 \
+    libXext \
+    libXxf86vm \
+    libICE \
+    libSM \
+    libXt \
+    libXmu \
+    libXfixes \
+    libXdamage \
+    libXi \
+    evieext \
+    libxkbfile \
+    libfontenc \
+    libXfont \
+    libpciaccess \
+    pixman"
+
+
+init()
+{
+    update_modules
+
+    pushd xorg
+    tar jxf ~/.tigervnc-xorg-$XORG_VERSION/util-macros.tar.bz2
+    pushd util-macros-*
+    echo "Building macros"
+    ./configure ${1+"$@"} --prefix=${PREFIX}
+    ($MAKE install)
+    popd
+
+    pushd xserver
+    patch -p1 < $SRCDIR/unix/xserver15.patch
+    popd
+    popd
+
+    pushd $SRCDIR
+    if [ ! -f ./configure ]; then
+        autoreconf -fiv
+    fi
+    popd
+}
+
+
+update_modules()
+{
+    if [ -d xorg ]; then rm -rf xorg; fi
+    mkdir xorg
+    pushd xorg
+    $SRCDIR/unix/download-xorg-$XORG_VERSION
+    for module in ${modules}; do
+        tar jxf ~/.tigervnc-xorg-$XORG_VERSION/${module}.tar.bz2
+    done
+    tar jxf ~/.tigervnc-xorg-$XORG_VERSION/Mesa.tar.bz2
+    tar jxf ~/.tigervnc-xorg-$XORG_VERSION/freetype.tar.bz2
+    tar jxf ~/.tigervnc-xorg-$XORG_VERSION/xorg-server.tar.bz2
+    cp -r $SRCDIR/unix/xserver xserver
+    cp -r xorg-server-1.*/* xserver
+    popd
+}
+
+
+build ()
+{
+    # Build VNC
+    echo "*** Building VNC ***"
+    $SRCDIR/configure ${1+"$@"} --prefix=${PREFIX}
+    ($MAKE)
+
+    # Build Xorg
+    echo "*** Building Xorg ***"
+    pushd xorg
+    for module in ${modules}; do
+        extraoptions=""
+        cd ${module}-*
+        echo ======================
+        echo configuring ${module}
+        echo ======================
+        if [ "${module}" = "libX11" ]; then
+            extraoptions="${extraoptions} --without-xcb"
+        fi
+        if [ "${module}" = "libSM" ]; then
+            extraoptions="${extraoptions} --without-libuuid"
+        fi
+        if [ $STATIC = 1 ]; then
+            extraoptions="${extraoptions} --enable-static --disable-shared"
+            OLD_CFLAGS=${CFLAGS}
+            OLD_CXXFLAGS=${CXXFLAGS}
+            CFLAGS=${CFLAGS}' -fPIC'
+            CXXFLAGS=${CXXFLAGS}' -fPIC'
+            export CFLAGS CXXFLAGS
+        fi
+        ./configure ${1+"$@"} --prefix="${PREFIX}" ${extraoptions}
+        if [ $STATIC = 1 ]; then
+            CFLAGS=${OLD_CFLAGS}
+            CXXFLAGS=${OLD_CXXFLAGS}
+            export CFLAGS CXXFLAGS
+        fi
+        echo ======================
+        echo building ${module}
+        echo ======================
+        if [ $? -ne 0 ]; then
+                echo "Failed to configure ${module}."
+                exit
+        fi
+        ($MAKE install)
+        cd ..
+    done
+
+    # build mesa
+    echo "*** Building Mesa ***"
+    pushd Mesa-*
+    ./configure ${1+"$@"} --prefix=${PREFIX} --with-driver=dri --disable-glut --without-demos
+    if [ $? -ne 0 ]; then
+	echo "Failed to configure Mesa."
+	exit
+    fi
+    ($MAKE install)
+    popd
+
+    # build freetype
+    if [ $STATIC = 1 ]; then
+        echo "*** Building freetype ***"
+        pushd freetype-*
+        ./configure ${1+"$@"} --prefix=${PREFIX} --enable-static --disable-shared
+        if [ $? -ne 0 ]; then
+	    echo "Failed to configure freetype."
+	    exit
+        fi
+        ($MAKE install)
+        popd
+    fi
+
+    popd
+
+    # build xserver
+    echo "*** Building xserver ***"
+    pushd xorg/xserver
+    autoreconf -fiv
+    XORGCFGFLAGS='--disable-xinerama --disable-xvfb --disable-xnest --disable-xorg'
+    if [ $STATIC = 1 ]; then
+        XORGCFGFLAGS="${XORGCFGFLAGS} --disable-shared --enable-static"
+    fi
+    ./configure ${1+"$@"} --prefix=${PREFIX} ${XORGCFGFLAGS}
+    if [ $? -ne 0 ]; then
+	echo "Failed to configure X server."
+	exit
+    fi
+    ($MAKE TIGERVNC_SRCDIR=$SRCDIR install)
+    popd
+}
+
+rebuild ()
+{
+    # Build VNC
+    echo "*** Building VNC ***"
+    ($MAKE ${1+"$@"})
+
+    # build xserver
+    echo "*** Building xserver ***"
+    pushd xorg/xserver
+    ($MAKE TIGERVNC_SRCDIR=$SRCDIR install ${1+"$@"})
+    popd
+}
+
+
+usage ()
+{
+    echo "Usage: $0  init -version <7.4 | 7.5>"
+    echo "       [-srcdir <source dir>]"
+    echo
+    echo "       $0  build -version <7.4 | 7.5>"
+    echo "       [-srcdir <source dir>] [-static] [additional configure flags]"
+    echo
+    echo "       $0  rebuild -version <7.4 | 7.5> "
+    echo "       [additional make options]"
+    echo
+    echo "       $0  update -version <7.4 | 7.5>"
+    echo "       [-srcdir <source dir>]"
+    echo
+    echo "-static = build a stand-alone version of Xvnc which does not depend on"
+    echo "          the shared X11 libraries"
+    echo
+    echo "-srcdir = specify the top directory of the TigerVNC source tree"
+    echo "          (default = ..)"
+    exit 1
+}
+
+
+while [ $# -gt 0 ]
+do
+    case "$1" in
+	init)       MODE=init                ;;
+	build)      MODE=build               ;;
+	rebuild)    MODE=rebuild             ;;
+	update)     MODE=update              ;;
+	-static)    STATIC=1                 ;;
+	-version)   XORG_VERSION=$2;  shift  ;;
+	-srcdir)    SRCDIR=$2;        shift  ;;
+	*)          break                    ;;
+    esac
+    shift
+done
+
+if [ "$XORG_VERSION" = "" -o "$MODE" = "" ]
+then
+    usage
+fi
+
+pushd $SRCDIR
+SRCDIR=`pwd`
+popd
+
+case "$MODE" in
+    init)       init                 ;;
+    build)      build ${1+"$@"}      ;;
+    rebuild)    rebuild ${1+"$@"}    ;;
+    update)     update               ;;
+    *)          usage                ;;
+esac
diff --git a/unix/build-xorg-7.4 b/unix/build-xorg-7.4
deleted file mode 100755
index a783f60..0000000
--- a/unix/build-xorg-7.4
+++ /dev/null
@@ -1,228 +0,0 @@
-#!/bin/bash
-# -*- mode: shell-script; coding: UTF-8 -*-
-# 
-# Build Xvnc with Xorg 7.4
-#
-
-set -e
-
-if [ "$PREFIX" = "" ]; then
-    PREFIX=`pwd`/xorg.build
-fi
-export ACLOCAL="aclocal -I ${PREFIX}/share/aclocal"
-export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
-MAKE="make"
-STATIC=0
-
-modules="dri2proto \
-    libpthread-stubs \
-    glproto \
-    xf86vidmodeproto \
-    xextproto \
-    xproto \
-    kbproto \
-    inputproto \
-    xcmiscproto \
-    bigreqsproto \
-    fixesproto \
-    damageproto \
-    xf86driproto \
-    randrproto \
-    renderproto \
-    scrnsaverproto \
-    resourceproto \
-    fontsproto \
-    videoproto \
-    compositeproto \
-    xineramaproto \
-    fontcacheproto \
-    libdrm \
-    libXau \
-    xtrans \
-    libXdmcp \
-    libX11 \
-    libXext \
-    libXxf86vm \
-    libICE \
-    libSM \
-    libXt \
-    libXmu \
-    libXfixes \
-    libXdamage \
-    libXi \
-    evieext \
-    libxkbfile \
-    libfontenc \
-    libXfont \
-    libpciaccess \
-    pixman"
-
-
-init()
-{
-    mkdir -p xorg
-    update_modules
-
-    pushd xorg
-    tar jxf ~/.tigervnc-build/util-macros.tar.bz2
-    pushd util-macros-*
-    echo "Building macros"
-    ./configure ${1+"$@"} --prefix=${PREFIX}
-    ($MAKE);
-    make install
-    popd
-    popd
-
-    pushd xserver
-    patch -p1 < ../xserver15.patch
-    popd
-
-    cd ..
-    if [ ! -f ./configure ]; then
-        autoreconf -fiv
-    fi
-    cd unix
-}
-
-
-update_modules()
-{
-    pushd xorg
-    ../download-xorg
-    for module in ${modules}; do
-        tar jxf ~/.tigervnc-build/${module}.tar.bz2
-    done
-    tar jxf ~/.tigervnc-build/Mesa.tar.bz2
-    tar jxf ~/.tigervnc-build/freetype.tar.bz2
-    tar jxf ~/.tigervnc-build/xorg-server.tar.bz2
-    cp -r xorg-server-1.*/* ../xserver
-    popd
-}
-
-
-build ()
-{
-    # Build VNC
-    echo "*** Building VNC ***"
-    cd ..
-    make distclean || true
-    ./configure ${1+"$@"} --prefix=${PREFIX}
-    make
-    cd unix
-
-    # Build Xorg
-    echo "*** Building Xorg ***"
-    pushd xorg
-    for module in ${modules}; do
-        extraoptions=""
-        cd ${module}-*
-        echo ======================
-        echo configuring ${module}
-        echo ======================
-        if [ "${module}" = "libX11" ]; then
-            extraoptions="${extraoptions} --without-xcb"
-        fi
-        if [ "${module}" = "libSM" ]; then
-            extraoptions="${extraoptions} --without-libuuid"
-        fi
-        if [ $STATIC = 1 ]; then
-            extraoptions="${extraoptions} --enable-static --disable-shared"
-            OLD_CFLAGS=${CFLAGS}
-            OLD_CXXFLAGS=${CXXFLAGS}
-            CFLAGS=${CFLAGS}' -fPIC'
-            CXXFLAGS=${CXXFLAGS}' -fPIC'
-            export CFLAGS CXXFLAGS
-        fi
-        ./configure ${1+"$@"} --prefix="${PREFIX}" ${extraoptions}
-        if [ $STATIC = 1 ]; then
-            CFLAGS=${OLD_CFLAGS}
-            CXXFLAGS=${OLD_CXXFLAGS}
-            export CFLAGS CXXFLAGS
-        fi
-        echo ======================
-        echo building ${module}
-        echo ======================
-        if [ $? -ne 0 ]; then
-                echo "Failed to configure ${module}."
-                exit
-        fi
-        ($MAKE);
-        make install
-        cd ..
-    done
-
-    # build mesa
-    echo "*** Building Mesa ***"
-    pushd Mesa-*
-    ./configure ${1+"$@"} --prefix=${PREFIX} --with-driver=dri --disable-glut --without-demos
-    if [ $? -ne 0 ]; then
-	echo "Failed to configure Mesa."
-	exit
-    fi
-    ($MAKE)
-    make install
-    popd
-
-    # build freetype
-    if [ $STATIC = 1 ]; then
-        echo "*** Building freetype ***"
-        pushd freetype-*
-        ./configure ${1+"$@"} --prefix=${PREFIX} --enable-static --disable-shared
-        if [ $? -ne 0 ]; then
-	    echo "Failed to configure freetype."
-	    exit
-        fi
-        ($MAKE)
-        make install
-        popd
-    fi
-
-    popd
-
-    # build xserver
-    echo "*** Building xserver ***"
-    cd xserver
-    autoreconf -fiv
-    XORGCFGFLAGS='--disable-xinerama --disable-xvfb --disable-xnest --disable-xorg'
-    if [ $STATIC = 1 ]; then
-        XORGCFGFLAGS="${XORGCFGFLAGS} --disable-shared --enable-static"
-    fi
-    ./configure ${1+"$@"} --prefix=${PREFIX} ${XORGCFGFLAGS}
-    if [ $? -ne 0 ]; then
-	echo "Failed to configure X server."
-	exit
-    fi
-    ($MAKE)
-    make install
-    cd ..
-}
-
-case "$1" in
-    init)
-	shift
-	if [ "$1" = "-static" ]; then
-	    STATIC=1
-	    shift
-	fi
-	init ${1+"$@"}
-	;;
-    build)
-	shift
-	if [ "$1" = "-static" ]; then
-	    STATIC=1
-	    shift
-	fi
-	build ${1+"$@"}
-	;;
-    update)
-	shift
-	if [ "$1" = "-static" ]; then
-	    STATIC=1
-	    shift
-	fi
-	update_modules
-	;;
-    *)
-	echo "Usage: $0 init | build | update [-static] [additional configure flags]"
-	exit 3
-esac
diff --git a/unix/download-xorg b/unix/download-xorg-7.4
similarity index 97%
rename from unix/download-xorg
rename to unix/download-xorg-7.4
index db2b8d2..d72d08b 100755
--- a/unix/download-xorg
+++ b/unix/download-xorg-7.4
@@ -72,7 +72,7 @@
 
 
 def main():
-    dir = os.path.expanduser("~")+"/.tigervnc-build"
+    dir = os.path.expanduser("~")+"/.tigervnc-xorg-7.4"
     cwd = os.getcwd()
     if not os.path.exists(dir):
         os.mkdir(dir)
diff --git a/unix/xserver/hw/vnc/Makefile.am b/unix/xserver/hw/vnc/Makefile.am
index 5845f1e..5245406 100644
--- a/unix/xserver/hw/vnc/Makefile.am
+++ b/unix/xserver/hw/vnc/Makefile.am
@@ -1,5 +1,5 @@
-LIB_DIR=$(top_srcdir)/../../common
-BIN_DIR=$(top_srcdir)/..
+TIGERVNC_SRCDIR=${top_srcdir}/../..
+LIB_DIR=${top_builddir}/../../common
 
 RFB_LIB=$(LIB_DIR)/rfb/librfb.la
 RDR_LIB=$(LIB_DIR)/rdr/librdr.la
@@ -16,8 +16,8 @@
 	Input.cc
 
 libvnccommon_la_CPPFLAGS = -DVENDOR_RELEASE="$(VENDOR_RELEASE)" \
-	-DVENDOR_STRING="\"$(VENDOR_STRING)\"" -I$(LIB_DIR) -UHAVE_CONFIG_H \
-	-I$(BIN_DIR)/vncconfig $(XVNC_CPPFLAGS) -I$(includedir)/pixman-1 -I$(includedir)
+	-DVENDOR_STRING="\"$(VENDOR_STRING)\"" -I$(TIGERVNC_SRCDIR)/common -UHAVE_CONFIG_H \
+	-I$(TIGERVNC_SRCDIR)/unix/vncconfig $(XVNC_CPPFLAGS) -I$(includedir)/pixman-1 -I$(includedir)
 
 bin_PROGRAMS = Xvnc
 
@@ -31,7 +31,7 @@
 
 Xvnc_CPPFLAGS = $(XVNC_CPPFLAGS) -DNO_HW_ONLY_EXTS -DNO_MODULE_EXTS -UHAVE_CONFIG_H \
 	-DXFree86Server -DVENDOR_RELEASE="$(VENDOR_RELEASE)" \
-	-DVENDOR_STRING="\"$(VENDOR_STRING)\"" -I$(LIB_DIR) \
+	-DVENDOR_STRING="\"$(VENDOR_STRING)\"" -I$(TIGERVNC_SRCDIR)/common \
 	-I$(top_srcdir)/include -I$(includedir)/pixman-1 -I$(includedir)
 
 Xvnc_LDADD = $(XVNC_LIBS) libvnccommon.la $(COMMON_LIBS) \
@@ -44,7 +44,7 @@
 
 libvnc_la_SOURCES = xf86vncModule.cc
 
-libvnc_la_CPPFLAGS = $(XVNC_CPPFLAGS) -I$(LIB_DIR) -UHAVE_CONFIG_H \
+libvnc_la_CPPFLAGS = $(XVNC_CPPFLAGS) -I$(TIGERVNC_SRCDIR)/common -UHAVE_CONFIG_H \
 	-I$(top_srcdir)/hw/xfree86/common \
 	-I$(top_srcdir)/hw/xfree86/os-support \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus \