-# Reading system configuration informations, functions and package versions.
-source ../sysinfos
-source ../functions
-source ../functions-update
-source ../packages-list
-
-# Execute a return statement instead of exit, to be able to continue with
-# downloading other packages
-export RCMD_NO_EXIT=1
-
-update_packages_init
-
-
-fpkg_sf ${FREETYPE}
-fpkg ${FONTCONFIG} "http://fontconfig.org/release"
-###fpkg_hv ${XFREE86}
-
-
-fpkg ${T1LIB} "http://www.ibiblio.org/pub/Linux/libs/graphics"
-fpkg_mis ${TK} "${TK}-src" ${SOURCEFORGE_URL}/tcl
-
-fpkg_gnu ${EMACS}
-
-fpkg ${WINDOWMAKER} "http://windowmaker.info/pub/source/release"
-fpkg ${WINDOWMAKER_EXTRA} "http://windowmaker.info/pub/source/release"
-fpkg_sf ${LESSTIF}
-
-fpkg ${PERL_MOD_XML_SIMPLE} "http://www.cpan.org/modules/by-module/XML"
-fpkg ${PERL_MOD_PARSE_REDESCENT} "http://www.cpan.org/modules/by-module/Parse"
-
-# Gtk
-fpkg_gnome ${GTK_DOC}
-fpkg_gnome ${GLIB}
-fpkg ${PIXMAN} "http://cairographics.org/releases"
-fpkg ${GLITZ} "http://cairographics.org/snapshots"
-fpkg ${CAIRO} "http://cairographics.org/releases"
-fpkg ${CAIROMM} "http://cairographics.org/releases"
-fpkg_gnome ${PANGO}
-fpkg_gnome ${ATK}
-fpkg_gnome ${GTK2}
-fpkg_gnome ${GTK_ENGINES}
-fpkg_gnome ${PYGOBJECT}
-fpkg_gnome ${PYGTK}
-
-fpkg_gnome ${LIBSIGCPP}
-fpkg ${GC} " http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source"
-fpkg_gnome ${GLIBMM}
-fpkg_gnome ${GTKMM}
-
-
-fpkg_hv ${HVCLOCK}
-fpkg_hv ${WMNOTIFY}
-
-fpkg ${DESKTOP_FILE_UTILS} "http://freedesktop.org/software/desktop-file-utils/releases"
-fpkg ${SHARED_MIME_INFO} "http://people.freedesktop.org/~hadess"
-fpkg_gnome ${STARTUP_NOTIFICATION}
-fpkg_gnome ${LIBWNCK}
-fpkg_sf ${LIBXKLAVIER} gswitchit
-fpkg_gnome ${LIBGLADE}
-fpkg_gnome ${LIBSOUP}
-fpkg_gnome ${LIBIDL}
-fpkg_gnome ${LIBRSVG}
-
-fpkg_gnome ${INTLTOOL}
-fpkg_gnu ${GSL}
-
-fpkg_sf ${LIBUSB}
-fpkg_sf ${LIBGPHOTO2} "gphoto"
-
-fpkg ${BABL} "ftp://ftp.gtk.org/pub/babl/$(get_pkg_ver_base ${BABL})"
-fpkg ${GEGL} "ftp://ftp.gimp.org/pub/gegl/$(get_pkg_ver_base ${BABL})"
-fpkg ${GIMP} "ftp://ftp.gimp.org/pub/gimp/v$(get_pkg_ver_base ${GIMP})"
-fpkg_sf ${GUTENPRINT}
-fpkg_hv ${INKSCAPE}
-
-fpkg ${CDRTOOLS} "ftp://ftp.berlios.de/pub/cdrecord"
-fpkg ${DVDRWTOOLS} "http://fy.chalmers.se/~appro/linux/DVD+RW/tools"
-
-fpkg_mis ${CUPS} "${CUPS}-source" "http://ftp.easysw.com/pub/cups/$(get_pkg_ver ${CUPS})"
-fpkg_sf ${SPLIX}
-
-fpkg_mis ${ESPGS} "${ESPGS}-source" "http://ftp.easysw.com/pub/ghostscript/$(get_pkg_ver ${ESPGS})"
-fpkg_sf ${GHOSTSCRIPT_FONTS_STD} "ghostscript"
-fpkg_sf ${GHOSTSCRIPT_FONTS_OTHER} "ghostscript"
-
-fpkg_hv ${IMAGE_MAGICK}
-fpkg ${ICON_NAMING_UTILS} "http://tango.freedesktop.org/releases"
-fpkg ${TANGO_ICON_THEME} "http://tango-project.org/releases"
-fpkg ${TANGO_ICON_THEME_EXTRAS} "http://tango-project.org/releases"
-
-
-fpkg ${TETEX_SRC} "${TETEX_URL}/$(get_pkg_ver ${TETEX_SRC})/distrib"
-fpkg ${TETEX_TEXMF} "${TETEX_URL}/$(get_pkg_ver ${TETEX_TEXMF})/distrib"
-fpkg ${TETEX_TEXMFSRC} "${TETEX_URL}/$(get_pkg_ver ${TETEX_TEXMFSRC})/distrib"
-fpkg ${TETEX_CM_SUPER} "http://anduin.linuxfromscratch.org/sources/BLFS/svn/t"
-# For re-generating fontconfig documentation.
-fpkg_sf ${JADETEX}
-
-fpkg ${POPPLER} "http://poppler.freedesktop.org"
-
-fpkg ${SANE_BACKENDS} "ftp://ftp.sane-project.org/pub/sane/${SANE_BACKENDS}"
-fpkg ${XSANE} "ftp://ftp.sane-project.org/pub/sane/xsane"
-
-fpkg_sf ${JACK} "jackit"
-fpkg ${ALSA_LIB} "ftp://ftp.alsa-project.org/pub/lib"
-fpkg ${ALSA_PLUGINS} "ftp://ftp.alsa-project.org/pub/plugins"
-fpkg ${ALSA_UTILS} "ftp://ftp.alsa-project.org/pub/utils"
-fpkg ${ALSA_OSS} "ftp://ftp.alsa-project.org/pub/oss-lib"
-
-# Multimedia libraries and drivers.
-fpkg ${AUDIOFILE} "http://www.68k.org/~michael/audiofile"
-fpkg_gnome ${ESOUND}
-
-fpkg ${LIBSAMPLERATE} "http://www.mega-nerd.com/SRC"
-fpkg ${LIBOIL} "http://liboil.freedesktop.org/download"
-fpkg ${SPEEX} "http://downloads.xiph.org/releases/speex"
-fpkg ${PULSEAUDIO} "http://0pointer.de/lennart/projects/pulseaudio"
-
-# Temporaire, version beta
-fpkg ${LIBSNDFILE} "http://www.mega-nerd.com/tmp"
-#fpkg ${LIBSNDFILE} "http://www.mega-nerd.com/libsndfile"
-
-fpkg ${LIBOGG} "http://downloads.xiph.org/releases/ogg"
-fpkg ${LIBVORBIS} "http://downloads.xiph.org/releases/vorbis"
-fpkg ${LIBTHEORA} "http://downloads.xiph.org/releases/theora"
-
-fpkg_hv ${FLAC}
-fpkg_hv ${FFMPEG}
-fpkg ${XVIDCORE} "http://downloads.xvid.org/downloads"
-
-# Audio utilities
-fpkg_sf ${LAME}
-fpkg ${VORBIS_TOOLS} "http://downloads.xiph.org/releases/vorbis"
-fpkg_hv ${LIBA52}
-fpkg_hv ${LIBID3TAG}
-fpkg ${LIBMAD} "ftp://ftp.mars.org/pub/mpeg"
-fpkg_sf ${LIBFAAC}
-fpkg ${LIBFAAD2} "http://downloads.sourceforge.net/faac"
-fpkg_sf ${GRIP}
-fpkg_sf ${CDRDAO}
-fpkg_hv ${PORTAUDIO}
-fpkg_hv ${SWEEP}
-fpkg ${LILYPOND} "http://lilypond.org/download/sources/v$(get_pkg_ver_base ${LILYPOND})"
-fpkg ${SYLPHEED} "http://sylpheed.good-day.net/sylpheed/v$(get_pkg_ver_base ${SYLPHEED})"
-
-fpkg_hv ${NSS}
-fpkg ${FIREFOX} "http://releases.mozilla.org/pub/mozilla.org/firefox/releases/$(get_pkg_ver ${FIREFOX})/source"
-
-fpkg_hv ${JAVA}
-fpkg_hv ${AGG}
-fpkg ${GNASH} "http://ftp.gnu.org/pub/gnu/gnash/$(get_pkg_ver ${GNASH})"
-
-fpkg ${DBUS} "http://dbus.freedesktop.org/releases/dbus"
-fpkg ${DBUS_GLIB} "http://dbus.freedesktop.org/releases/dbus-glib"
-fpkg ${HAL} "http://people.freedesktop.org/~david/dist"
-
-fpkg ${SASL2} "ftp://ftp.andrew.cmu.edu/pub/cyrus-mail"
-fpkg_mis ${OPENLDAP} "openldap-stable-20070831" \
- "ftp://ftp.openldap.org/pub/OpenLDAP/openldap-stable"
-fpkg_hv ${KERBEROS5}
-
-fpkg_mis ${SENDMAIL} "sendmail.$(get_pkg_ver ${SENDMAIL})" "ftp://ftp.sendmail.org/pub/sendmail"
-fpkg ${LIBSPF2} "http://libspf2.org/spf"
-fpkg ${MILTER_GREYLIST} "ftp://ftp.espci.fr/pub/milter-greylist"
-fpkg_hv ${MILTER_SPF}
-fpkg ${PROCMAIL} "http://www.procmail.org"
-fpkg ${FETCHMAIL} "http://download.berlios.de/fetchmail"
-fpkg_sf ${MUTT}
-
-fpkg_mis ${FCRON} "${FCRON}.src" "ftp://ftp.seul.org/pub/fcron"
-fpkg_hv ${GETDATE}
-
-fpkg_sf ${CLAMAV}
-
-fpkg ${PERL_MOD_HTML_TAGSET} "http://anduin.linuxfromscratch.org/sources/BLFS/svn/perl-modules"
-fpkg ${PERL_MOD_HTML_PARSER} "http://anduin.linuxfromscratch.org/sources/BLFS/svn/perl-modules"
-fpkg ${PERL_MOD_APACHE_LOGGED_AUTH_DBI} "http://search.cpan.org/CPAN/authors/id/S/SI/SIMKIN"
-fpkg ${PERL_MOD_DB_FILE} "http://search.cpan.org/CPAN/authors/id/P/PM/PMQS"
-fpkg ${PERL_MOD_DIGEST_SHA1} "http://anduin.linuxfromscratch.org/sources/BLFS/svn/perl-modules"
-# URI is needed by LWP
-fpkg ${PERL_MOD_URI} "http://search.cpan.org/CPAN/authors/id/G/GA/GAAS"
-# LWP is Needed by LTSP
-fpkg ${PERL_MOD_LWP} "http://www.linpro.no/lwp"
-
-# ZIP is Needed by OO
-fpkg ${PERL_MOD_ARCHIVE_ZIP} "http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK"
-fpkg ${PERL_MOD_COMPRESS_ZLIB} "http://search.cpan.org/CPAN/authors/id/P/PM/PMQS"
-fpkg ${PERL_MOD_IO_COMPRESS_BASE} "http://search.cpan.org/CPAN/authors/id/P/PM/PMQS"
-fpkg ${PERL_MOD_IO_COMPRESS_ZLIB} "http://search.cpan.org/CPAN/authors/id/P/PM/PMQS"
-fpkg ${PERL_MOD_COMPRESS_RAW_ZLIB} "http://search.cpan.org/CPAN/authors/id/P/PM/PMQS"
-fpkg ${PERL_MOD_NET_DNS} "http://search.cpan.org/CPAN/authors/id/O/OL/OLAF"
-
-fpkg ${SPAMASSASSIN} "http://apache.sunsite.ualberta.ca/spamassassin/source"
-fpkg ${UW_IMAP} "ftp://ftp.cac.washington.edu/imap"
-
-fpkg ${HTTPD} "http://www.apache.org/dist/httpd"
-
-
-
-fpkg_sf ${MAILMAN}
-
-fpkg ${SAMBA} "ftp://ftp.samba.org/pub/samba/old-versions"
-
-fpkg ${PHP} "http://us2.php.net/distributions"
-
-lpkg 2 ${SUBVERSION}
-fpkg_gnu ${INDENT}
-
-fpkg ${LTSP_UTILS} "http://ltsp.mirrors.tds.net/pub/ltsp/utils"
-fpkg ${TFTP_HPA} "http://www.kernel.org/pub/software/network/tftp"
-
-fpkg_sf ${KVM}
-fpkg_hv ${BRIDGE_UTILS}
-fpkg_hv ${UML_UTILITIES}
-
-fpkg_gnu ${GUILE}
-
-fpkg_sf ${LIBBOOST}
-
-fpkg ${TRANSMISSION} "http://mirrors.m0k.org/transmission/files"
-
-fpkg_hv ${CKERMIT}
-
-fpkg ${LIBGAMIN} "ftp://ftp.linux.ee/pub/gentoo/distfiles/distfiles"
-fpkg_sf ${PCMANFM}
-
-fpkg_gnu ${HELP2MAN}
-
-fpkg ${LIBDVDCSS} "ftp://ftp.linux.ee/pub/gentoo/distfiles/distfiles"
-fpkg ${LIBDVDREAD} "ftp://ftp.linux.ee/pub/gentoo/distfiles/distfiles"
-fpkg ${DVDFS} "http://jspenguin.org:81/dvdfs"
-
-
-
-fpkg ${LIBFFI} "ftp://sourceware.org/pub/libffi"
-fpkg_gnome ${GOBJECT_INSTROSPECTION}
-fpkg ${EGGDBUS} "http://hal.freedesktop.org/releases"
-fpkg ${POLKIT} "http://hal.freedesktop.org/releases"
-
-fpkg ${GNUPG} "ftp://ftp.gnupg.org/gcrypt/gnupg"
+source ../functions/main
+
+update_packages_init ${*}
+
+lpkg 3 ${PYTHON}
+
+XORG_MODULES_LIST="${XORG_APP} ${XORG_DRIVER} ${XORG_FONT} ${XORG_LIB} ${XORG_PROTO}"
+
+for module in ${XORG_MODULES_LIST}; do
+ MOD_NAME=$(get_pkg_name ${module})
+ DEST_DIR=${LFS_PKG_DIR}/${MOD_NAME}
+
+ fpkg -d ${DEST_DIR} -e wget -w ${module} ${BLFS_XORG_URL}
+ fpkg -d ${DEST_DIR} -e md5 -w ${module} ${BLFS_XORG_URL}
+
+ if [ "${MOD_NAME}" = "driver" ]; then
+ if [ -n "${XORG_VIDEO_DRIVER}" ]; then
+ # Install only specified video driver
+ for ext in wget md5; do
+ # Comment all xf86-video entries, except for specified driver:
+ sed -e "/xf86-video-${XORG_VIDEO_DRIVER}/!s/\(.*xf86-video.*\)/#\1/" -i ${LFS_PKG_DIR}/${MOD_NAME}/${module}.${ext}
+ done
+ else
+ # Install all drivers, except some unwanted drivers
+ for ext in wget md5; do
+ for excldrv in vmware newport xgixp geode; do
+ sed -i -e "/.*xf86-video-${excldrv}.*/d" \
+ ${LFS_PKG_DIR}/${MOD_NAME}/${module}.${ext}
+ done
+ done
+ fi
+ fi
+ if [ "${MOD_NAME}" = "app" ]; then
+ # Remove unneeded apps
+ for ext in wget md5; do
+ sed -i -e '/.*twm-.*/d' ${LFS_PKG_DIR}/${MOD_NAME}/${module}.${ext}
+ sed -i -e '/.*xclock-.*/d' ${LFS_PKG_DIR}/${MOD_NAME}/${module}.${ext}
+ done
+ fi
+
+ SUBMODS="$(grep -v '^#' ${LFS_PKG_DIR}/${MOD_NAME}/${module}.wget | sed 's!\.tar\.bz2$!!')"
+
+ for submod in ${SUBMODS}; do
+ fpkg -m xorg -s ${MOD_NAME} ${submod}
+ done
+
+ pushd ${DEST_DIR} >> ${LFS_LOG_FILE}
+ # The "driver" md5 file maybe empty if the nouveau driver was selected
+ if cat ${LFS_PKG_DIR}/${MOD_NAME}/${module}.md5 | grep -q "[0-9]"; then
+ md5sum -c ${LFS_PKG_DIR}/${MOD_NAME}/${module}.md5 >> ${LFS_LOG_FILE}
+ if [ $? -ne 0 ]; then
+ echo " md5sum error for ${module}"
+ fi
+ fi
+ popd >> ${LFS_LOG_FILE}
+done
+
+fpkg -m xorg -s util ${XORG_UTIL_MACROS}
+fpkg -m xorg -s util ${XORG_MAKEDEPEND}
+fpkg -m xorg -s lib ${LIBXAU}
+fpkg -m xorg -s lib ${LIBXDMCP}
+fpkg -m sf ${LESSTIF}
+fpkg -m xorg -s data ${XBITMAPS}
+
+fpkg -m fd -o "xcb" -s "dist" ${LIBPTHREAD_STUBS}
+fpkg -m fd -o "xcb" -s "dist" ${XCB_PROTO}
+fpkg -m fd -o "xcb" -s "dist" ${LIBXCB}
+fpkg -m fd -o "xcb" -s "dist" ${XCB_UTIL}
+fpkg -m gnu ${GPERF}
+
+fpkg -m hv ${LIBDRM}
+fpkg -e "tar.gz" ${TALLOC} "http://samba.org/ftp/talloc"
+fpkg -s "$(get_pkg_ver ${MESALIB})" ${MESALIB} \
+ ftp://ftp.freedesktop.org/pub/mesa
+fpkg -m xorg -s data ${XCURSOR_THEMES}
+fpkg -m fd -o "xlibs" -s "xkbdesc" -e "tar.bz2" ${XKEYBOARD_CONFIG}
+
+fpkg -m xorg -s app ${LUIT}
+fpkg -e "tar.gz" ${PIXMAN} ${CAIRO_URL}
+fpkg -e "tar.gz" ${LIBFFI} "ftp://sourceware.org/pub/libffi"
+
+fpkg -m fd -s "releases/dbus" ${DBUS}
+fpkg -m gnome ${GLIB}
+fpkg -m gnome ${GOBJECT_INSTROSPECTION}
+fpkg -m fd -o "dbus" -s "releases/dbus-glib" ${DBUS_GLIB}
+fpkg -m fd -o "hal" ${EGGDBUS}
+fpkg -m fd -o "hal" ${POLKIT}
+fpkg ${CONSOLEKIT} "http://www.freedesktop.org/software/ConsoleKit/dist"
+fpkg -m fd -o "hal" ${POLICYKIT}
+fpkg -m fd ${HAL}
+fpkg -m fd -o "hal" ${HAL_INFO}
+
+if [ "x${XORG_VIDEO_DRIVER}" = "xnouveau" ]; then
+ fpkg -m hv ${XORG_VIDEO_NOUVEAU}
+fi
+fpkg -m xorg -s xserver ${XORG_SERVER}
+fpkg -m xorg -s app ${XDM}
+
+fpkg -e "tgz" ${XTERM} "ftp://invisible-island.net/xterm"
+fpkg -e "tar.gz" ${T1LIB} "http://www.ibiblio.org/pub/Linux/libs/graphics"
+
+fpkg -m sf -s "tcl" ${TK}
+fpkg -m gnu ${EMACS}
+fpkg ${WINDOWMAKER} ${WMAKER_URL}
+fpkg -e "tar.gz" ${WINDOWMAKER_EXTRA} ${WMAKER_URL}