#!/bin/sh

# This program was written by Bartłomiej Gędziorowski.

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


license () {
cat <<EOF

		    GNU GENERAL PUBLIC LICENSE
		       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS

	    How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) year name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type 'show c' for details.

The hypothetical commands 'show w' and 'show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than 'show w' and 'show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  'Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

EOF
}

#teść pomocy wyświetlanej po wydaniu polecenia "--help"
pomoc () {
cat <<EOF

	x11-pinkybuild.sh, Copyright (C) 2006 Bartłomiej Gędziorowski.
	x11-pinkybuild.sh comes with ABSOLUTELY NO WARRANTY; for details use "--howto" 
	option. This is free software, and you are welcome to redistribute it under 
	certain conditions; use "--license" option for details.

	Program for automatic compilation of Xorg 7.2 dedicated for Slackware Linux.
	 
	Options:			Default values or description:
	--list				Shows modules list.
	--howto				Shows usage intruction of the script. It's important to read it!

	--prefix=PREFIX                 [/usr/X11R7] WARNING! Do not set "/usr" or "/usr/local". It is safe
					to use default prefix.
	--localstatedir=DIR	        [PREFIX/var]
	--sysconfdir=DIR                [/etc]
	--tmp-install-dir=DIR	        [/tmp/x11-build]
	--source-dir=DIR		Allows to build xorg from sources from local directory (disables
					downloading modules from net).
	--only-download			Script will only download xorg components.
	--build=BUILD			Sets release name. [1]
	--disable-debug			All modules will be compiled without debuging.
	--without-modules="MODULE1- MODULE2- etc." Exludes modules from compilation. Use --list option
					to see full modules list.
	--continue			Script will continue previous compilation.
	--license			Shows "GNU General Public License"
	--set-links			Allows setting links by the user.

	CFLAGS="FLAGS"			[system default]
	CXXFLAGS="FLAGS"		[system default]
EOF
}

howto () {
cat <<EOF

This program automaticaly downloads, compiles and creates packages of Xorg 7.2 for Slackware Linux.


!!!WARNING!!!
If you used packages (not the script) you only need to read "II" section. Remember that you need
fontconfig and freetype from official Slackware repositories.


I. Compilation

1. Enter the text mode.
2. Uninstall old version of Xorg.
3. If you used previous version of script or packages you need to run following commands:

test -L /usr/include/freetype && rm /usr/include/freetype
test -L /usr/include/freetype2 && rm /usr/include/freetype2
test -L /usr/X11R6 && rm /usr/X11R6
test -L /usr/X11 && rm /usr/X11

Reinstalling fluxbox, glut and lesstif also might be needed.

4. Download and install fontconfig and freetype from official Slackware repositories.
5. Run the script with --help option to see available options.
6. Run the script with chosen options.
7. If compialtion fails see the /tmp/x11-build/error file or error file in directory pointed by
   --tmp-install-dir option (if used) for details.

!!!WARNING!!! kernel-headers from 2.6 series are required for proper compilation.


II. Instalation and configuration.

1. Uninstall old version of Xorg.
2. Install new Xorg. Packages created by the script should be in /tmp/x11-build or other directory
   pointed by --tmp-install-dir option (if used).
3. Add /usr/X11R7/lib directory (or other pointed by --prefix option) to /etc/ld.so.conf
4. Add /usr/X11R7/bin directory (or other pointed by --prefix option) to PATH variable.
5. Reinstall graphic drivers
6. Change fontpaths in /etc/X11/xorg.conf
7. Change fontpaths in /etc/fonts/fonts.conf. For instance:

<dir>/usr/X11R6/lib/X11/fonts/TTF</dir>
might be changed to
<dir>/usr/X11R7/lib/X11/fonts/TTF</dir>

8. Run '/usr/X11R6/bin/fc-cache -f' command from root and user.
9. Be happy with new Xorg!

EOF
}


#UWAGA!!! Tablica o nawie "lista" zachowuje kolejność wymaganą do poprwnej kompilacji xorg. Nie zmieniać!!!
#Na liście znajdują się rownież paczki libdrm oraz xterm.
LISTA="libdrm- util-macros- xorg-sgml-doctools- xorg-docs- applewmproto- bigreqsproto- \
compositeproto- damageproto- dmxproto- evieext- fixesproto- fontcacheproto- fontsproto- glproto- \
inputproto- kbproto- printproto- randrproto- recordproto- renderproto- resourceproto- \
scrnsaverproto- trapproto- videoproto- windowswmproto- xcmiscproto- xextproto- xf86bigfontproto- \
xf86dgaproto- xf86driproto- xf86miscproto- xf86rushproto- xf86vidmodeproto- xineramaproto- xproto- \
xproxymanagementprotocol- xtrans- libXau- libXdmcp- libX11- libXext- libAppleWM- libWindowsWM- \
libdmx- libfontenc- libFS- libICE- liblbxutil- liboldX- libSM- libXt- libXtst- libXmu- libXpm- \
libXp- libXprintUtil- libXaw- libXfixes- libXcomposite- libXrender- libXdamage- libXcursor- \
libXevie- libXfont- libXfontcache- libXft- libXi- libXinerama- libxkbfile- libxkbui- libXrandr- \
libXres- libXScrnSaver- libXTrap- libXv- libXvMC- libXxf86misc- libXxf86vm- libXprintAppUtil- \
libXxf86dga- xbitmaps- appres- bdftopcf- beforelight- bitmap- editres- fonttosfnt- fslsfonts- \
fstobdf- iceauth- ico- lbxproxy- listres- luit- mkfontdir- mkfontscale- oclock- rgb- rstart- \
scripts- sessreg- setxkbmap- showfont- proxymngr- smproxy- twm- viewres- x11perf- xauth- xbiff- \
xcalc- xclipboard- xclock- xcmsdb- xconsole- xcursorgen- xdbedizzy- xditview- xdm- xdpyinfo- \
xdriinfo- xedit- xev- xeyes- xf86dga- xfd- xfindproxy- xfontsel- xfs- xfsinfo- xfwp- xgamma- xgc- \
xhost- xinit- xkbcomp- xkbevd- xkbprint- xkbutils- xkill- xload- xlogo- xlsatoms- xlsclients- \
xlsfonts- xmag- xman- xmessage- xmh- xmodmap- xmore- xphelloworld- xplsprinters- xpr- \
xprehashprinterlist- xprop- xrandr- xrdb- xrefresh- xrx- xset- xsetmode- xsetpointer- xsetroot- \
xsm- xstdcmap- xtrap- xvidtune- xvinfo- xwd- xwininfo- xwud- xorg-server- xf86-input-aiptek- \
xf86-input-evdev- xf86-input-ur98- xf86-input-acecad- xf86-input-calcomp- xf86-input-citron- \
xf86-input-digitaledge- xf86-input-dmc- xf86-input-dynapro- xf86-input-elo2300- \
xf86-input-elographics- xf86-input-fpit- xf86-input-hyperpen- xf86-input-jamstudio- \
xf86-input-joystick- xf86-input-keyboard- xf86-input-magellan- xf86-input-magictouch- \
xf86-input-microtouch- xf86-input-mouse- xf86-input-mutouch- xf86-input-palmax- \
xf86-input-penmount- xf86-input-spaceorb- xf86-input-summa- xf86-input-tek4957- xf86-input-void- \
xf86-input-vmmouse- xf86-input-acecad- xf86-video-sisusb- xf86-video-sunffb- xf86-video-v4l- \
xf86-video-apm- xf86-video-ark- xf86-video-ati- xf86-video-chips- xf86-video-cirrus- \
xf86-video-cyrix- xf86-video-dummy- xf86-video-fbdev- xf86-video-glint- xf86-video-i128- \
xf86-video-i740- xf86-video-i810- xf86-video-imstt- xf86-video-mga- xf86-video-neomagic- \
xf86-video-newport- xf86-video-nsc- xf86-video-nv- xf86-video-rendition- xf86-video-s3- \
xf86-video-s3virge- xf86-video-savage- xf86-video-siliconmotion- xf86-video-sis- xf86-video-sunbw2- \
xf86-video-suncg14- xf86-video-suncg3- xf86-video-suncg6- xf86-video-sunleo- xf86-video-suntcx- \
xf86-video-tdfx- xf86-video-tga- xf86-video-trident- xf86-video-tseng- xf86-video-vesa- \
xf86-video-vga- xf86-video-via- xf86-video-vmware- xf86-video-voodoo- xf86-video-ast- \
xcursor-themes- font-util- encodings- font-adobe-100dpi- font-adobe-75dpi- \
font-adobe-utopia-100dpi-  font-adobe-utopia-75dpi- font-adobe-utopia-type1- font-arabic-misc- \
font-bh-100dpi- font-bh-75dpi- font-bh-lucidatypewriter-100dpi- font-bh-lucidatypewriter-75dpi- \
font-bh-ttf- font-bh-type1- font-bitstream-100dpi- font-bitstream-75dpi- font-bitstream-speedo- \
font-bitstream-type1- font-cronyx-cyrillic- font-cursor-misc- font-daewoo-misc- font-dec-misc- \
font-ibm-type1- font-isas-misc- font-jis-misc- font-micro-misc- font-misc-cyrillic- \
font-misc-ethiopic- font-misc-meltho- font-misc-misc- font-mutt-misc- font-schumacher-misc- \
font-screen-cyrillic- font-sony-misc- font-sun-misc- font-winitzki-cyrillic- font-xfree86-type1- \
font-alias- xorg-cf-files- imake- makedepend- gccmakedep- lndir- xterm Mesa- xkbdata-"


##########Konfiguracja##########

#tak na wszelki wypadek, gdyby w systemie istniały juz zmienne o podobnej nazwie.
EXCLUDE=""
DISABLE_DEBUG=""
SOURCES="net"
ONLY_DOWNLOAD=""
CONTINUE_BUILDING=""
SET_LINKS=""
while [ "$1" != "" ]; do
case $1 in
	--help) pomoc; exit 0;;
	--howto) howto; exit 0;;
	--list) echo "${LISTA}"; exit 0;;
	--continue) CONTINUE_BUILDING="yes";;
	--license) license; exit 0;;
	--set-links) SET_LINKS="yes";;
	--prefix*) XORG_PREFIX=${1#*--prefix=};;
	--localstatedir*) LOCALSTATEDIR="$1";;
	--sysconfdir*) SYSCONFDIR="$1";;
	--build*) BUILD=${1#*--build=};;
	--tmp-install-dir*) BLOC=${1#*--tmp-install-dir=};;
	--without-modules*) EXCLUDE=${1#*--without-modules=};;
	--disable-debug) DISABLE_DEBUG="--disable-debug";;
	--source-dir=*) SOURCES=${1#*--source-dir=};;
	--only-download) ONLY_DOWNLOAD="yes";;
	*) echo "Nie znana opcja $1"; exit 1;;
esac
shift
done

BUILD=${BUILD:-1}
BLOC=${BLOC:-"/tmp/x11-build"}
XORG_PREFIX=${XORG_PREFIX:-"/usr/X11R7"}
LOCALSTATEDIR=${LOCALSTATEDIR:-"--localstatedir=/var"}
SYSCONFDIR=${SYSCONFDIR:-"--sysconfdir=/etc"}

#określenie architektury na podstawie użytych flag
for file in $CFLAGS
do
	if [ "`echo ${file} | grep march`" != "" ]
	then
	ARCH=${file##*-march=}
	fi
done

ARCH=${ARCH:-"noarch"}

#wartości stałe, użytkownik nie może ich zmienić.
VERSION="7.2"
MESA_VER="6.5.2"
INST_DIR=${BLOC}/inst-x11

XORG_CONFIG="--prefix=${XORG_PREFIX} --datadir=${XORG_PREFIX}/lib ${LOCALSTATEDIR} ${SYSCONFDIR} ${DISABLE_DEBUG}"


##########przygotowanie środowiska do kompilacji##########
#kontynuacja kompilacji
if [ "${CONTINUE_BUILDING}" = "yes" ]
then
. ${BLOC}/continue_file
compilation_options
compilation_links
exclude_packages
else
	if [ -d "${BLOC}" ]
	then

cat <<EOF
Directory ${BLOC} has been found but you haven't used "--continue" option. What you want to do?

1. To continue previous compilation press "c".
2. To start new compilation press "n". Warning! All previous data will be lost!
3. To exit press "e".
EOF

	read answer
		case $answer in
			c)  . ${BLOC}/continue_file
			    compilation_options
			    compilation_links
			    exclude_packages ;;
			n) rm -rf ${BLOC};;
			e) exit 0;;
			
		esac
	fi
fi

#Sprawdzanie zależności w przypadku, gdy się tylko ściąga komponenty jest bezcelowe.
if [ "${ONLY_DOWNLOAD}" != "yes" ]; then

	#sprawdzenie zależnośći
	QUIT_PROGRAM="no"
	pkg-config fontconfig --atleast-version=2.2.3
	if [ "$?" != "0" ]; then
	echo 'fontconfig >= 2.2.3 needed'
	QUIT_PROGRAM="yes"
	fi

	pkg-config freetype2 --atleast-version=2.1.9
	if [ "$?" != "0" ]; then
	echo 'freetype >= 2.1.9 needed'
	QUIT_PROGRAM="yes"
	fi

	pkg-config libpng --atleast-version=1.2.8
	if [ "$?" != "0" ]; then
	echo 'libpng >= 1.2.8 needed'
	QUIT_PROGRAM="yes"
	fi

	[ "$QUIT_PROGRAM" = "yes" ] && exit 1
fi

#ustawienie linków używanych podczas kompilacji
if [ "${SET_LINKS}" = "yes" ]; then

	echo "Podaj adres libdrm. Aby pozostawić domyślny wciśnij 'enter'"
	echo "[http://dri.freedesktop.org/libdrm]"
	read answer1

	echo "Podaj adres xterm. Aby pozostawić domyślny wciśnij 'enter'"
	echo "[ftp://invisible-island.net/xterm]"
	read answer2

	echo "Podaj adres xorg. Aby pozostawić domyślny wciśnij 'enter'"
	echo "[ftp://ftp.freedesktop.org/pub/xorg]"
	read answer3

	echo "Podaj adres Mesa'y. Aby pozostawić domyślny wciśnij 'enter'"
	echo "[http://switch.dl.sourceforge.net/sourceforge/mesa3d]"
	read answer4
fi

LIBDRM_LINK=${answer1:-"http://dri.freedesktop.org/libdrm"}
XTERM_LINK=${answer2:-"ftp://invisible-island.net/xterm"}
XORG_LINK=${answer3:-"ftp://ftp.freedesktop.org/pub/xorg"}
MESA_LINK=${answer4:-"http://switch.dl.sourceforge.net/sourceforge/mesa3d"}


mkdir -p ${BLOC}

#wykonanie ponizsztch operacji jest bezcelowe, jesli się wyłącznie sciaga komponenty.
if [ "${ONLY_DOWNLOAD}" != "yes" ]; then

	#utworzenie miejsca tymczasowej instalacji
	mkdir -p ${INST_DIR}${XORG_PREFIX}

	#utorzenie pliku, do którego skierowywane będą ew. komunikaty o błędach podczas kompilacji
	echo "#PLIK BLĘDÓW" > ${BLOC}/error
	
	#utorzenie pliku, do którego skierowywane będą dane o obecnej kompilacji, potrzebne do jej ew. wznowienia w razie
	#przerwania z powodu błędu.

cat <<EOF > ${BLOC}/continue_file
#DANE KOMPILACJI
compilation_options () {
XORG_PREFIX="${XORG_PREFIX}"
XORG_CONFIG="${XORG_CONFIG}"
ARCH="${ARCH}"
BUILD="${BUILD}"
SOURCES="${SOURCES}"
CFLAGS="${CFLAGS}"
CXXFLAGS="${CXXFLAGS}"
}

compilation_links () {
LIBDRM_LINK="${LIBDRM_LINK}"
XTERM_LINK="${XTERM_LINK}"
XORG_LINK="${XORG_LINK}"
MESA_LINK="${MESA_LINK}"
}
EOF

	# jeśli istnieje katalog lub plik okreslony prefiksem, yo należy go przenieść w bezpieczne miejsce, aby skrypt 
	# mogł utworzyć dowiązanie o tej samej nazwie. Skrypt wykonuje to automatycznie, jednak zaleca się, aby uzytkownik 
	# wykonał tą operacje samodzielnie, a skrypt uruchamiał wyłacznie z trybu tekstowego.
	
	if [ -d ${XORG_PREFIX} ]
	then
	mkdir -p /tmp/x11-backup
	mv ${XORG_PREFIX} /tmp/x11-backup
	fi
	
	
	#to dowiązanie jest jest wymagane do prawidłowej kompilacji
	ln -s ${INST_DIR}${XORG_PREFIX} ${XORG_PREFIX}
	
	#ustawienie zmiennych środowskowych
	export CFLAGS="$CFLAGS"
	export CXXFLAGS="$CXXFLAGS"
	export LDFLAGS="-s -L${INST_DIR}${XORG_PREFIX}/lib -I${INST_DIR}${XORG_PREFIX}/include"
	export PKG_CONFIG_PATH="${INST_DIR}${XORG_PREFIX}/lib/pkgconfig"
	export PATH="${PATH}:${INST_DIR}${XORG_PREFIX}/bin"
fi


###funkcje
	
#ta funkcja zostanie użyta po kompilacji, aby przywrócić stare ustawienia systemu
returning_system () {
[ -L ${XORG_PREFIX} ] && rm ${XORG_PREFIX}

if
[ -d /tmp/x11-backup ]; then
mv /tmp/x11-backup/* ${XORG_PREFIX}
rm -rf /tmp/x11-backup
fi
}

#ta funkcja sprawdza, czy użytkownik nie wykluczył bierzącej paczki z kompilacji
exclude () {
exclude_module="no"
	
	for file in ${EXCLUDE}
	do
		if [ ${module} = "${file}" ]
		then
		exclude_module="yes"
		break
		fi
	done
	
	if [ "$exclude_module" = "yes" ]
	then
	echo "kompilacja ${module} pominięta" >> ${BLOC}/error
	continue
	fi
}

#ta funkcja ściąga źrodła z serverów.
downloading () {
#jeśli któryś moduł instnieje w $BLOC, to nie będzie on sciągany ponownie.
if [ ! -e ${module}* ]
then
	case ${module} in
	#ściągnięcie libdrm, Mesa'y oraz xterm
	libdrm-) wget ${LIBDRM_LINK}/libdrm-2.3.0.tar.bz2;;
	xterm) wget ${XTERM_LINK}/xterm.tar.gz;;
	#Mesa zostanie ściągnięta podczas kompilacji modułu xorg-server-
	Mesa-) echo "skipping downloading Mesa now";;
	xkbdata-) wget ${XORG_LINK}/X11R7.2/src/deprecated/xkbdata-X11R7.0-1.0.1.tar.bz2;;
	*) #śćiągnięcie komponentów xorg.
		wget ${XORG_LINK}/X11R7.2/src/everything/${module}*bz2
	
		if [ -L ${module}* ]; then
		wget ${XORG_LINK}/X11R7.2/src/everything/`readlink ${module}*`
		fi;;
	esac

fi

if [ ${module} = "xorg-server-" ]; then
    if [ ! -d ${BLOC}/${MESA_VER} ]; then
	wget ${MESA_LINK}/MesaLib-${MESA_VER}.tar.bz2
	wget ${MESA_LINK}/MesaDemos-${MESA_VER}.tar.bz2
	wget ${MESA_LINK}/MesaGLUT-${MESA_VER}.tar.bz2
    fi
fi
}

#ta funkcja sprawdza, czy żródla mają zostać sciągniete z sieci. 
getting_sources () {
if [ ${SOURCES} = "net" ]; then
downloading
else
	if [ "${SOURCES}" != "${BLOC}" ]; then
		cp ${SOURCES}/${module}* ${BLOC}

		if [ ${module} = "xorg-server-" ]; then
			cp ${SOURCES}/MesaLib-${MESA_VER}.tar.bz2 ${BLOC}
			cp ${SOURCES}/MesaDemos-${MESA_VER}.tar.bz2 ${BLOC}
			cp ${SOURCES}/MesaGLUT-${MESA_VER}.tar.bz2 ${BLOC}
		fi
	fi
fi
}

#ta funkcja rozpakowuje paczki. Zakładamy, żę ściągnięte zostały tylko pliki w formatach "tar.bz2" oraz "tar.gz"
unpacking () {
	if [ -f ${module}*.bz2 ]; then
	tar jxf ${module}*tar.bz2
	elif [ -f ${module}*.gz ]; then
	tar zxf ${module}*tar.gz
	fi

	rm -f ${BLOC}/${module}*

	if [ ${module} = "xorg-server-" ]; then
	tar jxf MesaLib*tar.bz2
	tar jxf MesaDemos*tar.bz2
	tar jxf MesaGLUT*tar.bz2
	rm -f Mesa*tar.bz2
	fi

}

#konfiguracja. Niektore paczki wymagają specyficznych ustawień przed kompilacją
configuring () {

chown -R root:root ${BLOC}/${module}*

#ten modul wymaga spatchowania
if [ "${module}" = "xf86-video-sis-" ]; then
patch -p0 <<EOF
diff -ur xorg-video-7.2.orig/xf86-video-sis-0.9.3/src/sis_dri.h xorg-video-7.2/xf86-video-sis-0.9.3/src/sis_dri.h
--- src/sis_dri.h	2006-11-30 16:09:43.000000000 +0200
+++ src/sis_dri.h	2006-12-19 20:03:30.000000000 +0200
@@ -115,12 +115,12 @@
   int dummy;
 } SISDRIContextRec, *SISDRIContextPtr;
 
+void SISDRICloseScreen(ScreenPtr pScreen);
 #ifdef XFree86Server
 
 #include "screenint.h"
 
 Bool SISDRIScreenInit(ScreenPtr pScreen);
-void SISDRICloseScreen(ScreenPtr pScreen);
 Bool SISDRIFinishScreenInit(ScreenPtr pScreen);
 
 #endif
EOF
fi

case ${module} in
	libX11-)
	./configure ${XORG_CONFIG} --without-xcb 2>> ${BLOC}/error;;
	xorg-server-)
	./configure ${XORG_CONFIG} --with-mesa-source="${BLOC}/Mesa-${MESA_VER}" 2>> ${BLOC}/error;;
	#konfiguracja mesy odbywa sie w odmienny sposób, dlatego tutaj zostaje pominięta
	Mesa-) echo "skipping configuring Mesa now";;


	*)
	./configure ${XORG_CONFIG} 2>> ${BLOC}/error;;
esac

}

#ta funkcja sprawdza, czy kompilacja się powiodła. Jeśli nie, to zapisuje ustawienia do odpowiedniego pliku,
#a następnie przerywa dziłanie całego skryptu.
checking_compilation () {
if [ "$?" = "0" ]
	then
	EXCLUDE="$EXCLUDE ${module}"
	else

	echo "KOMPILACJA PRZERWANA Z POWODU BŁĘDU!!!"

cat <<EOF  >> ${BLOC}/continue_file
exclude_packages ()
{
EXCLUDE="${EXCLUDE}"
}
EOF

	returning_system
	exit 1
	fi
}


#ta funkcja kompiluje paczki, instaluje je do tymczasowego katalogu, a następnie usuwa niepotrzebne źródła
building_and_clearing () {

if [ ${module} != "Mesa-" ]; then
	make 2>> ${BLOC}/error

	checking_compilation

	make DESTDIR=${INST_DIR} install
	ldconfig ${INST_DIR}${XORG_PREFIX}/lib

else
	#kompilacja Mesa'y
	make realclean
	make OPT_FLAGS="-march=$ARCH -Os -fno-strict-aliasing" X11_INCLUDES="-I${XORG_PREFIX}/include" \
	EXTRA_LIB_PATH="-L${XORG_PREFIX}/lib" linux-dri-x86 2>> ${BLOC}/error

	checking_compilation

	mkdir -v -p ${INST_DIR}${XORG_PREFIX}/lib/X11/modules/dri
	make INSTALL_DIR=${INST_DIR}${XORG_PREFIX} \
	DRI_DRIVER_INSTALL_DIR=${INST_DIR}${XORG_PREFIX}/lib/X11/modules/dri install

	cd ${BLOC}/Mesa-${MESA_VER}/progs/xdemos
	make OPT_FLAGS="-march=$ARCH -Os -fno-strict-aliasing" X11_INCLUDES="-I${XORG_PREFIX}/include" \
	EXTRA_LIB_PATH="-L${XORG_PREFIX}/lib" PROGS='glxinfo glxgears' 2>> ${BLOC}/error
	install -v -m755 glxinfo glxgears ${INST_DIR}${XORG_PREFIX}/bin

	ldconfig ${INST_DIR}${XORG_PREFIX}/lib

fi

#czyszczenie
rm -rf ${BLOC}/${module}*
}


##########Kompilacja##########

 for module in ${LISTA}
 do
	exclude
	echo "Kompilacja ${module} rozpoczęta" >> ${BLOC}/error
	cd ${BLOC}
	getting_sources
	[ "${ONLY_DOWNLOAD}" = "yes" ] && continue
	unpacking
	cd ${BLOC}/${module}*
	configuring
	building_and_clearing
 done

[ "${ONLY_DOWNLOAD}" = "yes" ] && rm -f ${BLOC}/error && exit 0

#########Ustawienia pokompilacyjne##########

returning_system

#usunięcię niepotrzebnych, statycznych bibliotek
( cd ${INST_DIR}${XORG_PREFIX}/lib
for file in *.a; do
   test -f ${file%a}so && rm ${file}
done
)

#stripowanie
( cd ${INST_DIR}
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

#komperesowanie manuali
( cd ${INST_DIR}${XORG_PREFIX}/man
find . -type f -exec gzip -9 {} \;

for i in `find . -type l`
do 
ln -s $( readlink $i ).gz $i.gz ; rm $i
done
)

if [ -d ${INST_DIR}${XORG_PREFIX}/info ]; then
gzip -9 ${INST_DIR}${XORG_PREFIX}/info/*.info
gzip -9f ${INST_DIR}${XORG_PREFIX}/info/*.info*
fi


#########Przygotowania do stworzenia paczek#########

mkdir -p ${BLOC}/2 ${BLOC}/3 ${BLOC}/4 ${BLOC}/5 ${BLOC}/6 ${BLOC}/7 ${BLOC}/8 ${BLOC}/9 ${BLOC}/10


#pliki slack-desc oraz doinst.sh

slack_desc_x11 () {
cat <<EOF
		|-----handy-ruler------------------------------------------------------|
x11: x11 (X11 base module)
x11:
x11: This is the base module for X11, and provides the required binaries,
x11: shared libraries, and support files (except fonts) to run X on Linux.
x11:
x11:
x11:
x11:
x11:
x11:
x11:
EOF
}

slack_desc_fonts_misc () {
cat <<EOF
               |-----handy-ruler------------------------------------------------------|
x11-fonts-misc: x11-fonts-misc (fonts for the X Window System)
x11-fonts-misc:
x11-fonts-misc: This is a minimal set of fonts needed to run X.
x11-fonts-misc:
x11-fonts-misc:
x11-fonts-misc:
x11-fonts-misc:
x11-fonts-misc:
x11-fonts-misc:
x11-fonts-misc:
x11-fonts-misc:
EOF
}

slack_desc_fonts_100dpi () {
cat <<EOF
             |-----handy-ruler------------------------------------------------------|
x11-fonts-100dpi: x11-fonts-100dpi (100dpi screen fonts for the X Window System)
x11-fonts-100dpi:
x11-fonts-100dpi: These extra fonts are useful on high-resolution monitors.
x11-fonts-100dpi:
x11-fonts-100dpi:
x11-fonts-100dpi:
x11-fonts-100dpi:
x11-fonts-100dpi:
x11-fonts-100dpi:
x11-fonts-100dpi:
x11-fonts-100dpi:
EOF
 }
 
slack_desc_fonts_cyrillic () {
cat <<EOF
               |-----handy-ruler------------------------------------------------------|
x11-fonts-cyrillic: x11-fonts-cyrillic (Cyrillic fonts for the X Window System)
x11-fonts-cyrillic:
x11-fonts-cyrillic: A set of Cyrillic fonts for X.
x11-fonts-cyrillic:
x11-fonts-cyrillic:
x11-fonts-cyrillic:
x11-fonts-cyrillic:
x11-fonts-cyrillic:
x11-fonts-cyrillic:
x11-fonts-cyrillic:
x11-fonts-cyrillic:
EOF
}

slack_desc_fonts_scale () {
cat <<EOF
            |-----handy-ruler------------------------------------------------------|
x11-fonts-scale: x11-fonts-scale (scalable screen fonts for the X Window System)
x11-fonts-scale:
x11-fonts-scale: Speedo, Type 1, and TrueType scalable fonts for X.
x11-fonts-scale:
x11-fonts-scale:
x11-fonts-scale:
x11-fonts-scale:
x11-fonts-scale:
x11-fonts-scale:
x11-fonts-scale:
x11-fonts-scale:
EOF
}

slack_desc_docs () {
cat <<EOF
         |-----handy-ruler------------------------------------------------------|
x11-docs: x11-docs (text documentation for X)
x11-docs:
x11-docs: Documentation and release notes for X11 that you can find in
x11-docs: ${XORG_PREFIX}/lib/X11/doc/.
x11-docs:
x11-docs:
x11-docs:
x11-docs:
x11-docs:
x11-docs:
x11-docs:
EOF
}

slack_desc_xnest () {
cat <<EOF
          |-----handy-ruler------------------------------------------------------|
x11-xnest: x11-xnest (a nested X server)
x11-xnest:
x11-xnest: Xnest is an experimental nested server for X that acts as both a 
x11-xnest: client and a server.  Xnest is a client of the real server which
x11-xnest: manages windows and graphics requests on its behalf.  Xnest is a
x11-xnest: server to its own clients.  Xnest manages windows and graphics 
x11-xnest: requests on their behalf.  To these clients Xnest appears to be a 
x11-xnest: conventional server.
x11-xnest:
x11-xnest:
x11-xnest:
EOF
}

slack_desc_xvfb () {
cat <<EOF
         |-----handy-ruler------------------------------------------------------|
x11-xvfb: x11-xvfb (virtual framebuffer X server)
x11-xvfb:
x11-xvfb: Xvfb is an X server that can run on machines with no display hardware
x11-xvfb: and no physical input devices.  It emulates a dumb framebuffer using 
x11-xvfb: virtual memory.  The primary use of this server is intended to be 
x11-xvfb: server testing.  The mfb or cfb code for any depth can be exercised
x11-xvfb: with this server without the need for real hardware that supports the
x11-xvfb: desired depths.  A secondary use is testing clients against unusual
x11-xvfb: depths and screen configurations.
x11-xvfb:
x11-xvfb:
EOF
}

slack_desc_devel () {
cat <<EOF
          |-----handy-ruler------------------------------------------------------|
x11-devel: x11-devel (Libraries and other files for X programming)
x11-devel:
x11-devel: This is a set of include files (found in ${XORG_PREFIX}/include), static
x11-devel: libraries (found in ${XORG_PREFIX}/lib/*.a) and configuration files
x11-devel: (found in ${XORG_PREFIX}/lib/X11/config/) needed to compile X programs.
x11-devel:
x11-devel:
x11-devel:
x11-devel:
x11-devel:
x11-devel:
EOF
}
 
slack_desc_xdmx () {
cat <<EOF
         |-----handy-ruler------------------------------------------------------|
x11-xdmx: x11-xdmx (Distributed Multi-head X server)
x11-xdmx:
x11-xdmx: Xdmx is a proxy X server that uses one or more other X servers as its
x11-xdmx: display devices.  It provides multi-head X functionality for displays
x11-xdmx: that might be located on different machines.
x11-xdmx:
x11-xdmx:
x11-xdmx:
x11-xdmx:
x11-xdmx:
x11-xdmx:
EOF
}
 
doinst_x11 (){
cat <<EOF
rm /usr/X11
ln -s ${XORG_PREFIX} /usr/X11

#The following test commands repairs a liitle bug, wich has been in x11-7.1-i686-pinki1 package.
test ! -L ${XORG_PREFIX}/lib/X11/app-defaults && rm -rf ${XORG_PREFIX}/lib/X11/app-defaults
test ! -L ${XORG_PREFIX}/lib/X11/fs && rm -rf ${XORG_PREFIX}/lib/X11/fs
test ! -L ${XORG_PREFIX}/lib/X11/lbxproxy && rm -rf ${XORG_PREFIX}/lib/X11/lbxproxy
test ! -L ${XORG_PREFIX}/lib/X11/proxymngr && rm -rf ${XORG_PREFIX}/lib/X11/proxymngr
test ! -L ${XORG_PREFIX}/lib/X11/rstart && rm -rf ${XORG_PREFIX}/lib/X11/rstart
test ! -L ${XORG_PREFIX}/lib/X11/xdm && rm -rf ${XORG_PREFIX}/lib/X11/xdm
test ! -L ${XORG_PREFIX}/lib/X11/xinit && rm -rf ${XORG_PREFIX}/lib/X11/xinit
test ! -L ${XORG_PREFIX}/lib/X11/xkb && rm -rf ${XORG_PREFIX}/lib/X11/xkb
test ! -L ${XORG_PREFIX}/lib/X11/xserver && rm -rf ${XORG_PREFIX}/lib/X11/xserver
test ! -L ${XORG_PREFIX}/lib/X11/xsm && rm -rf ${XORG_PREFIX}/lib/X11/xsm
 
ln -s /etc/X11/app-defaults ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/fs ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/lbxproxy ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/proxymngr ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/rstart ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/xdm ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/xinit ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/xkb ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/xserver ${XORG_PREFIX}/lib/X11 2>> /dev/null
ln -s /etc/X11/xsm ${XORG_PREFIX}/lib/X11 2>> /dev/null
rm /usr/bin/X11
ln -s ${XORG_PREFIX}/bin /usr/bin/X11
rm /usr/lib/X11
ln -s ${XORG_PREFIX}/lib/X11 /usr/lib/X11
${XORG_PREFIX}/bin/lndir ${XORG_PREFIX}/lib/aclocal /usr/share/aclocal 1>> /dev/null
ln -s ${XORG_PREFIX}/lib/xorg/modules ${XORG_PREFIX}/lib/modules 2>> /dev/null
EOF
}

doinst_devel () {
cat <<EOF
rm /usr/include/X11
ln -s ${XORG_PREFIX}/include/X11 /usr/include/X11
ln -s /usr/lib/pkgconfig ${XORG_PREFIX}/lib/pkgconfig
EOF
}



#x11 package:

chmod 4711 ${INST_DIR}${XORG_PREFIX}/bin/Xorg
chmod u+s ${INST_DIR}${XORG_PREFIX}/bin/Xorg

mv ${INST_DIR} ${BLOC}/1

mkdir ${BLOC}/1/install

mkdir -p ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/app-defaults ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fs ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/lbxproxy ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/proxymngr ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/rstart ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/xdm ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/xinit ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/xkb ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/xserver ${BLOC}/1/etc/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/xsm ${BLOC}/1/etc/X11
slack_desc_x11 > ${BLOC}/1/install/slack-desc
#utworzenie pliku doinst.sh
doinst_x11 > ${BLOC}/1/install/doinst.sh


# x11-fonts-misc package:
mkdir -p ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts ${BLOC}/2/install
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/75dpi ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/encodings ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/misc ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/util ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts
#Utworzenie pozostałych katalogów pozwoli uniknąć ostrzeżeń programu fontpath
mkdir -p \
  ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts/TTF \
  ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts/Type1 \
  ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts/local \
  ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts/Speedo \
  ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts/100dpi \
  ${BLOC}/2${XORG_PREFIX}/lib/X11/fonts/cyrillic
slack_desc_fonts_misc > ${BLOC}/2/install/slack-desc


# x11-fonts-100dpi package:
mkdir -p ${BLOC}/3${XORG_PREFIX}/lib/X11/fonts ${BLOC}/3/install
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/100dpi ${BLOC}/3${XORG_PREFIX}/lib/X11/fonts
slack_desc_fonts_100dpi > ${BLOC}/3/install/slack-desc


# x11-fonts-cyrillic package:
mkdir -p ${BLOC}/4${XORG_PREFIX}/lib/X11/fonts ${BLOC}/4/install
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/cyrillic ${BLOC}/4${XORG_PREFIX}/lib/X11/fonts
slack_desc_fonts_cyrillic > ${BLOC}/4/install/slack-desc


# x11-fonts-scale package:
mkdir -p ${BLOC}/5${XORG_PREFIX}/lib/X11/fonts ${BLOC}/5/install
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/TTF ${BLOC}/5${XORG_PREFIX}/lib/X11/fonts
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/Type1 ${BLOC}/5${XORG_PREFIX}/lib/X11/fonts
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/fonts/Speedo ${BLOC}/5${XORG_PREFIX}/lib/X11/fonts
slack_desc_fonts_scale > ${BLOC}/5/install/slack-desc


# x11-docs package:
mkdir -p ${BLOC}/6${XORG_PREFIX}/lib/X11 ${BLOC}/6/install
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/doc ${BLOC}/6${XORG_PREFIX}/lib/X11
slack_desc_docs > ${BLOC}/6/install/slack-desc


# x11-xnest package:
mkdir -p ${BLOC}/7${XORG_PREFIX}/bin ${BLOC}/7/install
mv ${BLOC}/1${XORG_PREFIX}/bin/Xnest ${BLOC}/7${XORG_PREFIX}/bin
slack_desc_xnest > ${BLOC}/7/install/slack-desc


# x11-xvfb package:
mkdir -p ${BLOC}/8${XORG_PREFIX}/bin ${BLOC}/8/install
mv ${BLOC}/1${XORG_PREFIX}/bin/Xvfb ${BLOC}/8${XORG_PREFIX}/bin
slack_desc_xvfb > ${BLOC}/8/install/slack-desc

 
#x11-devel package:
mkdir -p ${BLOC}/9${XORG_PREFIX}/lib/X11 ${BLOC}/9/usr/lib ${BLOC}/9${XORG_PREFIX}/man ${BLOC}/9/install ${BLOC}/9/usr/include
mv ${BLOC}/1${XORG_PREFIX}/lib/pkgconfig ${BLOC}/9/usr/lib
chmod 644 ${BLOC}/9/usr/lib/pkgconfig/*
mv ${BLOC}/1${XORG_PREFIX}/lib/X11/config ${BLOC}/9${XORG_PREFIX}/lib/X11
mv ${BLOC}/1${XORG_PREFIX}/lib/*.a ${BLOC}/9${XORG_PREFIX}/lib
mv ${BLOC}/1${XORG_PREFIX}/man/man3 ${BLOC}/9${XORG_PREFIX}/man
mv ${BLOC}/1${XORG_PREFIX}/include ${BLOC}/9${XORG_PREFIX}
mkdir -p ${BLOC}/1${XORG_PREFIX}/include/X11
mv ${BLOC}/9${XORG_PREFIX}/include/X11/bitmaps ${BLOC}/1${XORG_PREFIX}/include/X11
mv ${BLOC}/9${XORG_PREFIX}/include/X11/pixmaps ${BLOC}/1${XORG_PREFIX}/include/X11
slack_desc_devel > ${BLOC}/9/install/slack-desc
#utworzenie pliku doinst.sh
doinst_devel > ${BLOC}/9/install/doinst.sh


# x11-xdmx package:
mkdir -p ${BLOC}/10${XORG_PREFIX}/bin ${BLOC}/10${XORG_PREFIX}/man/man1 ${BLOC}/10/install
mv ${BLOC}/1${XORG_PREFIX}/bin/Xdmx ${BLOC}/10${XORG_PREFIX}/bin
mv ${BLOC}/1${XORG_PREFIX}/man/man1/Xdmx.1x ${BLOC}/10${XORG_PREFIX}/man/man1
mv ${BLOC}/1${XORG_PREFIX}/man/man1/dmxtodmx.1x ${BLOC}/10${XORG_PREFIX}/man/man1
mv ${BLOC}/1${XORG_PREFIX}/man/man1/vdltodmx.1x ${BLOC}/10${XORG_PREFIX}/man/man1
mv ${BLOC}/1${XORG_PREFIX}/man/man1/xdmxconfig.1x ${BLOC}/10${XORG_PREFIX}/man/man1
slack_desc_xdmx > ${BLOC}/10/install/slack-desc


# Bodowa paczek
cd ${BLOC}/1
makepkg -l y -c n ../x11-$VERSION-$ARCH-$BUILD.tgz
rm -rf ${BLOC}/1

cd ${BLOC}/2
makepkg -l y -c n ../x11-fonts-misc-$VERSION-noarch-$BUILD.tgz
rm -rf ${BLOC}/2

cd ${BLOC}/3
makepkg -l y -c n ../x11-fonts-100dpi-$VERSION-noarch-$BUILD.tgz
rm -rf ${BLOC}/3

cd ${BLOC}/4
makepkg -l y -c n ../x11-fonts-cyrillic-$VERSION-noarch-$BUILD.tgz
rm -rf ${BLOC}/4

cd ${BLOC}/5
makepkg -l y -c n ../x11-fonts-scale-$VERSION-noarch-$BUILD.tgz
rm -rf ${BLOC}/5

cd ${BLOC}/6
makepkg -l y -c n ../x11-docs-$VERSION-noarch-$BUILD.tgz
rm -rf ${BLOC}/6

cd ${BLOC}/7
makepkg -l y -c n ../x11-xnest-$VERSION-$ARCH-$BUILD.tgz
rm -rf ${BLOC}/7

cd ${BLOC}/8
makepkg -l y -c n ../x11-xvfb-$VERSION-$ARCH-$BUILD.tgz
rm -rf ${BLOC}/8

cd ${BLOC}/9
makepkg -l y -c n ../x11-devel-$VERSION-$ARCH-$BUILD.tgz
rm -rf ${BLOC}/9

cd ${BLOC}/10
makepkg -l y -c n ../x11-xdmx-$VERSION-$ARCH-$BUILD.tgz
rm -rf ${BLOC}/10

echo "Budowa paczek xorg $VERSION dla Slackware zakończona!"
