Code/build-experimental-X

From ThinkWiki
Revision as of 23:49, 26 July 2006 by Thinker (Talk | contribs) (moved from How to compile an experimental X server)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  1. !/bin/bash
  2. Script to fetch and build X.org, DRI and Mesa from CVS and GIT.
  3. If you want to skip some tasks, comment them out at the bottom of the script.
  4. Source: http://thinkwiki.org/wiki/How_to_compile_an_experimental_X_server
  5. See also:
  6. http://wiki.x.org/wiki/ModularDevelopersGuide
  7. http://wiki.x.org/wiki/GitPage
  8. http://gitweb.freedesktop.org
  9. http://dri.freedesktop.org/wiki/Building
  10. http://www.mesa3d.org/cvs_access.html
  11. http://www.mesa3d.org/install.html
  1. Init

PIT=$HOME/3d-pit # Download and build here DEST=$PIT/install # Install here

  1. MESA_DATE=2006-06-29 # Set this to get a historical Mesa CVS snapshot

FLAGS='-O2 -g -march=pentium-m'

trap "echo Aborting.; exit 1" ERR

die() {

 echo "$*"
 exit 1

} run() {

 echo "@ $@"
 "$@" || { echo "ERROR: Command \"$*\" failed in `pwd`"; exit 1; }

}

fetch_from_git() {

 PARENT_DIR="$1"
 GIT_REP="$2"
 MODULE="$3"
 if [ -d "$PARENT_DIR/$MODULE" ]; then 
   run cd "$PARENT_DIR/$MODULE"
   run git pull
 else
   run cd "$PARENT_DIR"
   run git clone "$GIT_REP/$MODULE" "$MODULE"
 fi

}

  1. Fetching and building libDRM and DRM kernel drivers

fetch_drm() {

 echo "########### Fetch DRM ###########"
 DRM_GIT=git://anongit.freedesktop.org/git/mesa
 fetch_from_git "$PIT" "$DRM_GIT" drm

}

build_libdrm() {

 echo "########### Build libdrm ###########"
 run cd $PIT/drm
 run ./autogen.sh
 CFLAGS="$FLAGS" run ./configure --prefix=$DEST --quiet
 run make clean
 run make
 run make install

}

build_drm_modules() {

 echo "########### Build DRM kernel modules ###########"
 run cd $PIT/drm/linux-core
 run make DRM_MODULES="radeon"
 run sudo sh -c \
   'rm -fv /lib/modules/`uname -r`/kernel/drivers/char/drm/*.ko; \
    cp -v *.ko /lib/modules/`uname -r`/extra/; \
    /sbin/depmod -a'

}

  1. Fetching Mesa

fetch_mesa() {

 echo "########### Fetching Mesa ###########"
 MESA_CVS=:pserver:anonymous@anoncvs.freedesktop.org:2401/cvs/mesa
 run mkdir -p $PIT
 run cd $PIT
 grep -qF $MESA_CVS ~/.cvspass || run cvs -d $MESA_CVS login
 [ -d Mesa ] || run cvs -z3 -d $MESA_CVS co ${MESA_DATE:+-D $MESA_DATE} Mesa
 run cd $PIT/Mesa
 run cvs -z3 update -ACPd ${MESA_DATE:+-D $MESA_DATE}

}

patch_mesa() {

 # patch to make Google Earth use acceleration:
 run perl -i -pe 'print "//DISABLE " if m/^\s*FALLBACK_IF.*Line\.SmoothFlag/' \
   $PIT/Mesa/src/mesa/drivers/dri/r300/r300_render.c

}

  1. Building Mesa (do this *after* installing X.org)

build_mesa() { (

 echo "########### Building Mesa ###########"
 # This uses both old-style and new-style vars, to support older Mesa snapshots.
 run cd $PIT/Mesa
 export DRM_SOURCE_PATH=$PIT/drm
 export PKG_CONFIG_PATH="$DEST/lib/pkgconfig:$PKG_CONFIG_PATH"
 export DRM_SOURCE_PATH="$PIT/drm"
 export DESTDIR=$DEST  INSTALL_DIR=$DEST
 export DRI_DRIVER_INSTALL_DIR=$DEST/lib/dri
 export DRI_DIRS='r300 r200 r128 radeon'
 export OPT_FLAGS="$FLAGS"
 export PATH="$DEST/bin:$PATH"
 run mkdir -p $DRI_DRIVER_INSTALL_DIR
 run make -e linux-dri-x86
 run make -e install
 run cp -v lib/*_dri.so $DRI_DRIVER_INSTALL_DIR

) }

  1. X.org setup
  2. This is a list of modules that are in flux and likely to be related to
  3. whatever you're testing (or are required for the build), sorted by
  4. build order (see util/modular/build.sh for dependencies).
  5. Check CVS and the above URLs for other modules.

XORG_DIRS=(

 util/macros
 proto/{bigreqs,composite,fixes,damage,gl,input,kb,pm,randr,resource}proto
 proto/{render,scrnsaver,video}proto
 proto/{x11,xf86dga,xf86dri,xf86misc,xf86vidmode,xinerama}proto
 lib/lib{xtrans,X11,Xt,Xmu,Xcomposite,Xrender,Xdamage,Xcursor,Xi,Xinerama}
 lib/lib{xkbui,Xrandr,Xv,XvMC,Xxf86dga,Xxf86misc,Xxf86vm}
 xserver
 driver/xf86-video-ati
 driver/xf86-input-mouse driver/xf86-input-keyboard

)

  1. Fetching X.org

fetch_xorg() {

 echo "########### Fetching (selected) X.org modules ###########"
 XORG_GIT=git://anongit.freedesktop.org/git/xorg
 run mkdir -p $PIT/xorg
 for D in "${XORG_DIRS[@]}"; do
   fetch_from_git $PIT/xorg "$XORG_GIT" "$D"
 done

}

  1. Building and installing X.org
  2. (On repeated runs we avoid rerunning autotools if nothing changed.)

LAST_HASH=last_dir_hash dir_hash() {

 find . \( -path ./$LAST_HASH -o -path ./.git -prune \) -o -ls | sort | md5sum

} should_autogen() {

 [ ! -f $LAST_HASH ] || [ "`dir_hash`" != "`cat $LAST_HASH`" ]

} done_build() {

 dir_hash > $LAST_HASH

} build_x_module() { (

 D=$1
 echo "########### Building xorg/$D ###########"
 export PATH="$DEST/bin:$PATH"
 export PKG_CONFIG_PATH="$DEST/lib/pkgconfig:$PKG_CONFIG_PATH"
 export ACLOCAL="${AC_LOCAL:-aclocal} -I $DEST/share/aclocal"
 export LD_LIBRARY_PATH="$DEST/lib:$LD_LIBRARY_PATH"
 if [ $D == "xserver" ]; then
   CONF_OPT="--with-mesa-source=$PIT/Mesa --enable-xorg --disable-dmx --disable-xvfb --disable-xnest"
 elif [ $D == "lib/libX11" ]; then
   CONF_OPT="--with-xcb=no"
 else
   CONF_OPT=
 fi
 run cd $PIT/xorg/$D
 if should_autogen; then
   CFLAGS="$FLAGS" run sh autogen.sh --prefix=$DEST --quiet --cache-file=$PIT/xorg/autoconf.cache $CONF_OPT
 fi
 run make
 done_build
 run make install

) }

build_xorg() {

 run cd $PIT/xorg
 run mkdir -p $DEST/share/aclocal
 run mkdir -p $DEST/var/log
 for D in "${XORG_DIRS[@]}"; do 
   build_x_module $D || return 1
 done
 run sudo sh -c "chown -v root $DEST/bin/Xorg; \
                 chmod -v 4711 $DEST/bin/Xorg"

}

  1. Creating a script which sets env vars

create_xsetenv() {

 cat <<EOF > $DEST/bin/xsetenv || die "Can't create $DEST/bin/xsetenv"

export PATH="$DEST/bin:$PATH" export LD_LIBRARY_PATH="$DEST/lib:$LD_LIBRARY_PATH" export LIBGL_DRIVERS_PATH=$DEST/lib/dri EOF

 echo -e "\nRun '. $DEST/bin/xsetenv' to point env vars to this installation."

}

  1. Do it:

fetch_drm build_libdrm build_drm_modules fetch_mesa

  1. patch_mesa

fetch_xorg build_xorg build_mesa create_xsetenv

echo 'Done.'