Typo
[linux_from_scratch_hints.git] / OLD / xfree86+freetype.txt
blob28bdbe052f6a66ae46d9af30a8da7d070fffe8b2
1 TITLE:          XFree86 4.2.1, the _friendly_ way.
3 LFS VERSION:    3.x or newer
5 AUTHOR:         Dagmar d'Surreal
7 EMAIL ADDRESS:  Thou shalt not spam. <`echo qntzne@fcrnxrnfl.arg | rot13`>
9 SYNOPSIS:       This hint demonstrates an extremely elegant method for
10                 installing XFree86 4.2.1 that minimizes the chance of
11                 library conflicts.
13 HINT:
15 ChangeLog:
17   2002 Dec 15 - Updated to be current with XFree86 4.2.1
18                 Updated to include shm patch
19                 Added download URLs for all packages
20                 Added a walkthru for using xf86config 
22   2003 Jan 7  - Altered explanation of patent-violating option for Freetype
23                 Minor changes to patch listings for XFree86             
24                 Removed an unneeded setting from sample host.def
25                 Further fine-tuning of the xf86config walkthru
26               - Fixed embarrassing typos spotted by honorable messirs Mark
27                 Hymers and Seth W. Klein.
28                 Removed two gratuitious (and needless) uses of awk.
30 Some Caveats
31 ------------
33 Note...  Do not, I repeat, do _not_ play games with the PKG_CPU and PKG_ARCH
34 variables in the example shell scripts.  I would really recommend you stick
35 with i386 for PKG_ARCH, but try to get PKG_CPU as close to your exact CPU
36 type as possible, which is going to be something like i386, i486, i586, i686,
37 k6, athlon, etc.  If you don't know what you should use, i486 and i586
38 are really good catch-alls.  Using the commented out examples is probably also
39 very safe.  (You could also read the info pages for gcc to learn what all the
40 available targets are...)
42 There are two packages which you must install _before_ you build XFree86 4.2.1
43 and they would be zlib 1.1.4 (or newer) and FreeType2 2.1.3 (or newer).
44 Neither of these are dependent on anything in XFree86 or on each other so this
45 can be easily done on a clean build with no X at all.  You should also
46 _obliterate_ any pre-existing versions of zlib and FreeType2 which might be
47 living in /usr/local, /opt, or even your soon-to-be-destroyed /usr/X11R6
48 directories.  Building these two libraries independently of XFree86, and
49 instructing XFree86 to use our versions of the libraries instead of building
50 it's own stale/dated versions eliminates problems caused by having multiple
51 versions of those packages installed at once, and allows us to capitalize on
52 the benefits of using shared libraries in the first place.
55 Obtaining zlib Source
56 ---------------------
58  http://www.libpng.org/pub/png/src/zlib-1.1.4.tar.bz2
59    md5sum = ea16358be41384870acbdc372f9db152
61 Get the source code for zlib from the location above, and be sure to check the
62 MD5 sum before you do anything with the source.  If you were previously using
63 an older version of zlib, you may need to recompile a lot of applications due
64 to a security issue.  See http://www.gzip.org/zlib/advisory-2002-03-11.txt for
65 more details.
68 Building zlib
69 -------------
71 The short of this is that you need to install zlib in a manner which includes
72 the _shared_ (libz.so) version of the library.  Here is a quick example method
73 for doing it, with optimizations.  (I use PKG_CPU=i686 personally, because
74 I've got a celery and i'm lazy.)
76 Note: the normal LFS way of building zlib should work quite well for this, but
77 just in case you missed it (*ahem*) here's a brief run-down...
79 --------8<---------
80 #!/bin/sh
82 PKG_CPU=i686
83 PKG_ARCH=i386
84 #PKG_ARCH=`uname -m`
85 #PKG_CPU=$PKG_ARCH
87 CFLAGS="-fPIC -O3 -DHAVE_UNISTD_H -DUSE_MMAP -march=$PKG_ARCH -mcpu=$PKG_CPU" \
88 ./configure --prefix=/usr --shared && 
89 make && 
90 make test && 
91 make install
92 -------->8---------
94 The CFLAGS argument given above isn't nearly as fancy as it appears to be.
95 The first three arguments inside it are the same as what the package normally
96 uses.  It is, IMHO, not worth bothering trying to guess at "better" flags
97 for optimization, since the people who develop zlib have already spent a great
98 deal of time looking at the resulting assembly code to determine if any
99 further speedups are possible.
102 Obtaining Freetype2 Sources
103 ---------------------------
105  http://unc.dl.sourceforge.net/freetype/freetype-2.1.3.tar.bz2
106    md5sum = 09775a4111e066f782866d8a57d8481b
108 Get the source tarball for Freetype2 and verify it's md5sum, as usual.  Then
109 uncompress the tarball into a working directory somewhere.  
112 Building Freetype2
113 ------------------
115 The next step is to install FreeType2, and if you don't mind violating a
116 patent in the name of a good-looking desktop, you can make a quick change to
117 include/freetype/config/ftoption.h inside the freetype2 source package
118 before you build it.  Just remove the comment markers from around the line
119 that says:
121 #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER
123 If you decide not to do this, then your freetype library won't do anything
124 about TrueType glyphs that are "hinted", meaning you'll always see the
125 vector-drawn letters, even if the font contains a special set of partially
126 rasterized glyphs for the font size you are using.  If this makes no sense to
127 you, then leave it alone, as it can't cause you any problems.
129 You can use the following shell script below to compile and install the
130 Freetype2 library:
132 ----------8<----------
133 #!/bin/sh
135 PKG_OPT=-O2
136 PKG_ARCH=i386
137 PKG_CPU=i686
138 # Really sane defaults
139 #PKG_ARCH=`uname -m`
140 #PKG_CPU=$PKG_ARCH
142 CFLAGS="$PKG_OPT -march=$PKG_ARCH -mcpu=$PKG_CPU" \
143 ./configure --prefix=/usr && 
144 make && 
145 make install &&
146 ldconfig
147 ---------->8----------
149 There are still a few packages out there that will do something very broken
150 and explicitly search /usr/X11R6/include for the FreeType2 headers,
151 specifically because their maintainers have apparently grown tired of seeing
152 the terrible things that happen when more than one version of FreeType2 is
153 installed.  Eventually these guys will get around to realizing that it's less
154 work to merely demand people fix their installations of Freetype2 than it is
155 to do something almost as broken to get around the problem.  Brokenness is
156 always bad, especially in this case as it requires us to put symlinks under
157 /usr/X11R6 pointing to the Freetype2 files in /usr.  Do so with the following
158 shell script _after_ you have installed the XFree86 binaries:
160 ---------->8----------
161 #!/bin/sh
163 cd /usr/X11R6/lib
164 ln -s ../../lib/libfreetype.* .
165 mkdir -p /usr/X11R6/include
166 cd /usr/X11R6/include
167 ln -s ../../include/freetype2 .
168 ln -s ../../include/ft2build.h .
169 ----------8<----------
171 (This means you can now merrily rm -rf /usr/X11R6 to prepare for the next
172 step--installing XFree86s 4.2.1, instead of having to take partial measures
173 to remove XFree86 without destroying these symlinks.)
176 Before you install XFree86
177 --------------------------
179 I'd like to suggest at this point that you go ahead and make backups of your
180 current XFree86 configuration and any custom app-defaults files you may have
181 had, since you may be able to recycle these between minor revisions and
182 avoid some extra hassle of configuring things again.  To avoid problems with
183 having stale versions of libraries and whatnot lying around, I also recommend
184 that you remove your old XFree86 installation entirely before continuing on.
185 This means deleting /etc/X11, /var/X11, and /usr/X11R6, and then probably
186 running ldconfig to clear the stale things out of the linker cache.
189 Obtaining XFree86 Source
190 ------------------------
192 Note: XFree86 source code is pretty large (around 50Mb compressed), so if you
193 know of a mirror that has these files closer to you, it would behoove you to
194 use it.  You should also be aware that not all three tarballs are necessarily
195 needed to build XFree86, although the third one contains documentation in a
196 number of unusual formats.  Obtain at least the first two tarballs listed and
197 all three of the patches.
199 Source Tarballs:
200  ftp://ftp.xfree86.org/pub/XFree86/4.2.0/source/X420src-1.tgz
201    md5sum = ad43a8e9e39703322005cd6f7145b77f
202  ftp://ftp.xfree86.org/pub/XFree86/4.2.0/source/X420src-2.tgz
203    md5sum = dae33268a9f2735b9678a81fb23e8d3e
204  ftp://ftp.xfree86.org/pub/XFree86/4.2.0/source/X420src-3.tgz
205    md5sum = 560899e175a02ab592185b69756f539e
207 Required Patches:
208  ftp://ftp.xfree86.org/pub/XFree86/4.2.1/patches/4.2.0-4.2.1.diff.gz
209    md5sum = 38adc94a4953a6b29e8619c25dda4887
210  ftp://ftp.xfree86.org/pub/XFree86/4.2.1/fixes/4.2.1-mit-shm-security.patch
211    md5sum = 18eb56110c7f66895111bd9f3513b54e
213 Optional Patch:
214  http://www.jg555.com/cvs/cvsweb.cgi/~checkout~/patches/xfree/xfree-4.2.x.-bison.fixes.patch
215    md5sum = f48429288375f68fdaa3ef010f641e75
217 The md5 values are provided here only as a basic means of determining that
218 the tarballs weren't damaged during the transfer.  These same md5 values are
219 also given in a separate file on the XFree86 site, and should any of them
220 suddenly not match, you should proceed with caution.  There are currently
221 *no* tarballs of 4.2.1, and it doesn't appear that the XFree86 devel team
222 are going to make any available, so don't be suprised that you can't find
223 any.  You will need the 4.2.0 source and patches, as listed above.  If you
224 are using a version of bison newer than 1.35 (which is the case for LFS 4.0
225 users) you will need the last patch listed which was very thoughtfully
226 provided by Jim Gifford.  *Everyone* should use the shm security patch.
229 Preparing the XFree86 Source
230 ----------------------------
232 You will need quite a lot of disk space available to compile XFree86 4.2.1.
233 Use a partition with at _least_ 300-400Mb of space available to compile in,
234 and pick (or create) a work directory.  Untar at least the first two tarballs
235 (X420src-1.tgz and X420src-2.tgz, the third as well if you want the full set
236 documentation installed on the system) and then apply the three patches to the
237 source tree in the order listed to bring it entirely up to date.  You may
238 wish to check ftp://ftp.xfree86.org/pub/XFree86/4.2.1/fixes/ to see if there
239 are any more fixes which have been published since this document was written.
242 Building the Binaries
243 ---------------------
245 Now we move on to the real meat and potatoes of this operation.  Go ahead and
246 untar X420src-1.tgz and X420src-2.tgz (and the third one as well if you like)
247 someplace with about 300-400Mb of space free (for safety's sake).  Cd into
248 the xc/ directory and get ready for the _easy_ part.
250 Note, this is not a shell script, and YOU are expected to put the appropriate
251 values in place of PKG_ARCH and PKG_CPU. 
253 Create the file config/cf/host.def under the xc/ directory to tell XFree86's
254 build system that we want it to use the system-installed versions of zlib
255 and Freetype2 that we just built...
257 ---------->8----------
258 #define HasFreetype2 YES
259 #define BuildFreetype2Library NO
260 #define HasZlib YES
262 #define DefaultGcc2i386Opt -O2 -fno-strength-reduce -march=i386 -mcpu=i686
263 ----------8<----------
265 The last line is entirely optional, and really isn't all that different from
266 the default one XFree86 will use when left to it's own to decide.  I would 
267 strongly recommend that you not attempt to set numerous things in the
268 host.def file unless you are _absolutely_ _positively_ sure that you need to.
269 XFree86's build system is rather crude compared to other packages, but it
270 does manage to autodetect everything correctly in the vast majority of cases
271 (the incorrect minority being mainly esoteric non-x86 hardware).  
273 Once you've written the host.def file, the next step is to (in the xc/ 
274 directory) type the following commands, as given in the README...
276 make World >& world.log
277 make install >& install.log
278 make install.man &>> installman.log
280 The install.man can be skipped if you didn't uncompress the third source
281 tarball.  make World takes a _long_ time, so be patient and just tail the
282 world.log file in another window if you like.  On my machine, it will grow
283 until it reaches approximately 5,900Kb, and generally bores me to death while
284 it does it.
286 At this point, make sure that "/usr/X11R6/lib" appears in your /etc/ld.so.conf
287 file and then run ldconfig one last time.  You may now configure XFree86
288 normally, and/or install any third party drivers for your card that you need.
289 (...as is the case with users of nVidia cards, for example.) 
292 Final Notes
293 -----------
295 Some last tidbits... XFree86 4.2.x comes with a set of Bigelow & Holmes fonts
296 which live under /usr/X11R6/lib/X11/fonts/TTF.  I wouldn't suggest adding any
297 other fonts to this directory, and don't worry about this directory not
298 appearing in the default XF86Config and XftCache files... everything seems to
299 be hard-coded to look there for truetype fonts whether it's been specified or
300 not.  Better to keep _your_ fonts in a directory you can explicitly specify so 
301 you can keep better track of them.  I use /usr/X11R6/lib/X11/fonts/TrueType.
303 Oh, and don't forget to consult the FHS to make sure you have all the symlinks
304 for your filesystem pointing to the right parts of XFree86, just in case
305 XFree86 didn't put them there already.
307 You can also probably go ahead and build Freetype 1.3.1 and ttmkfdir (which
308 are discussed elsewhere) now that you have XFree86 installed.  Between these
309 two versions you will have everything you need to satisfy the requirements of
310 literally every package that can make use of TrueType fonts.
312 There is a newer version of ttfmkdir available which compiles against
313 Freetype 2.x, but frankly, it's just as problematic to compile as the old
314 ttmkfdir, and it will be obsolete with XFree86 4.3.x which is less than a
315 month away, so we're just not going to bother with it.
318 Configuring XFree86
319 -------------------
321 I swore that when I wrote this I wasn't going to get involved in the mess that
322 is configuring XFree86 since the majority of people who are having problems
323 always seem to be trying to do things with only one buttock (to put it
324 politely).  There *is* however, a reliable (the "easy" autoconfiguration some
325 people may recommend of `XFree86 -configure` does not always work properly, if
326 it fails, you will _need_ this method) way to configure XFree86, and it's the
327 one that's still pretty guaranteed to work with just a tiny bit of research
328 on the part of the user.  A walkthru for it is a _large_ amount of typing,
329 which is why it is formally beyond the scope of this document, but I'm
330 including a quick run-down anyway.  It is as follows:
332   1. As root, run `xf86config`.  Hit enter at the first do-nothing prompt.
334   2. At the prompt for the mouse, pick whatever is appropriate, or at least
335     close to the correct value.
337   3. If your mouse has three buttons on it (if your mouse has a wheel, and it
338     clicks when you push down on it--most all do--then it's a third button)
339     then you do not want Emulate3Buttons.  This is only for 2-button mice.
341   4. For the mouse device location, enter /dev/input/mice if you have a USB
342     mouse, /dev/psaux if you have a PS/2 mouse, or /dev/ttyS0 (or whatever)
343     if you have a serial mouse.  We are _long_ past the point where it
344     should be necessary to do weird things like running gpm in repeater mode.
345     For anyone using LFS 3.3 or newer, just trust me and try it.
347   5. The question about keyboards is deceptively simple to answer.  Most US
348     people will say "3" if they have a "Windows" key, and "1" if they don't.
349     Non-US people will be saying "4" or "2" for the same reasons.  Notebook
350     people will REALLY want to pay attention here, but basically if nothing
351     listed matches exactly what they have, they should go with one of the
352     first four generic options depending on the presence of the "Windows" key.
353     You *may* have to use Shift-PgUp as _many_ new keyboard types have been
354     added to the list in 4.3.x.
356   6. Now comes the part where non-US or i18n users should pay attention.  Pick
357     the country your keyboard is localized for, not just the country you are
358     in.  If you have a boring US keyboard, enter 1 no matter where you are.
360   7. You should just hit enter for the default variant of your keyboard unless
361     you already know of a specific other choice you should make.  When in
362     doubt, just choose the defaults.   Overthinking gets people into trouble.
364   8. If you have no idea what "group switcher" and such are, just say no
365     and move on because you clearly do not need them.
367   9. Now comes one of the two questions that will _punish you if you make an
368     unintelligent guess.  The odds are that you _can_ guess, but be smart
369     about it.  If you can find the correct and accurate answers from the web
370     site of your monitor's manufacturer, _do so_.  If you don't know, and
371     you intend to operate your monitor at 1024x768, you can probably enter 7
372     and not worry about it.  If you intend to operate at 1280x1024, you can
373     probably get away with 9 and not have it interlace the image.  If you
374     intent to use something higher than 1280x1024, and you are _certain_
375     your monitor can actually handle it, then you can probably pick the
376     broadest setting shown and only worry about changing it if it doesn't
377     work.  (More expensive monitors tend to be willing to discuss their
378     options with the video card and make intelligent choicess for you.)
380   10. The vertical sync range is the other place where guessing can really
381     burn you.  LCD panels will likely be using a single, fixed value, which
382     they can almost certainly communicate to XFree86 on their own, so whatever
383     value you select will either be ignored, or in some cases you might need
384     to just use 60.   The "safe" choice for monitors and LCD panels here would
385     be answer #3, 50-100, but don't guess if you can easily find out the
386     answer.
388   11. The next answer is just a text string.  Enter whatever you like to
389     describe your monitor.  It won't affect things at all.
391   12. This is the biggie.  You _do_ want to look at the card database unless
392     you like pain.  Hit enter as many times as you need until the exact
393     model of your video card appears, then pick that number.  If you intend
394     to use a different driver later on, you can pick something "close" to 
395     just to get through the massive list of cards.  If you already know
396     which of X's drivers you need to use, 4.3.x has a generic entry for
397     each driver at the top of the list so you don't _have_ to wade through
398     the entire thing if you don't want to.
400   13. The question about the amount of memory your card has is merely used
401     by xf86config to decide what modes to offer you as possible.  It will
402     not affect the configuration file because it will only store the value
403     you enter here as a comment.  If you don't know whether or not your
404     card has 16Mb or 64Mb of RAM, just enter 16384K and be done with it.
405     This is one of the things that XFree86 has become really reliable about
406     detecting properly on it's own.
408   14. Yet another free-form string... Describe your video card any way you
409     like, so long as you don't enter the exact same string as you used to
410     describe your monitor.
412   15. This menu will almost always require you reconfiguring things.  In
413     each color depth, the _first_ value listed will be the default, so
414     if you want 1024x768 as the default for 16bpp, enter 2 to change
415     those values, and then enter "4" as the first number ("432" is a good
416     example).  Keep changing until you have things the way you like them
417     and remember that the largest size for each color depth will control the
418     "virtual" desktop size, which may annoy you.
420     Note: The only time I ever change resolution or color-depth is when 
421     I'm doing something with SDL that changes them both anyway, so I
422     only bother to enter one resolution per color depth.  You might wish
423     to do the same.
425   16. Almost done!  Pick your default color depth.
427   17. Do whatever you like about letting it write out the config you have
428     just created, just be sure that if you use /etc/X11/XF86Config that
429     you don't have a stale /etc/X11/XF86Config-4 file lying in wait.
431   18. You should now have a basic, working X configuration.  Provided nothing
432     went terribly wrong, you should be able to run `startx` and be presented
433     with an extremely primitive window manager called twm.  I recommend
434     Blackbox as a quick replacement (no dependencies other than X) for this
435     before your eyes begin to bleed.
437 One last clue... If you have a mouse wheel, the only thing you need to do
438 to get it working with XFree86 now is to add two lines for the ZAxisMapping
439 and number of buttons to the mouse section so that it looks like this:
441     Identifier  "Mouse1"
442     Driver      "mouse"
443     Option "Protocol"    "IMPS/2"
444     Option "Device"      "/dev/psaux"
445     Option "ZAxisMapping"       "4 5"
446     Option "Buttons"            "5"
448 I'd like to think that the mouse wheel information will be something that
449 xf86config in 4.3.0 will ask about, but considering that it took them years
450 to add the question for DefaultColorDepth, and it has yet to manifest in
451 4.2.99.3 pre-releases, so I doubt it.
453 Peace!