Project 11A: Compiling and Installing Xmahjongg

 < Day Day Up > 



To get some hands-on experience with compiling a program from source, you will be working with a game called Xmahjongg. Now, you may think that, as you already have a GNOME mahjongg game and a KDE mahjongg game (not listed in the Main menu) installed on your system, having yet another mahjongg game is a tad redundant, to say the least. Maybe so, but in terms of gaming, the Xmahjongg game is easier on the eyes and snappier in performance. It looks prettier too, in my opinion.

More important than these gaming points, though, is the fact that the Xmahjongg package provides a perfect opportunity to learn to compile a program from source and then install it. It is not too big, it doesn’t take too much time to do, and it requires no tinkering.

You can see what the final product will look like in Figure 11-1.

click to expand
Figure 11-1: The Xmahjongg game

As you can see, it is all very simple and clearly laid out. In case you are not already familiar with this genre of mahjongg game, the idea is simple enough. Basically there are four of each tile in the pile. You must match pairs of like tiles that are open to one side. When you click the two matching open tiles, they will dis- appear. The object of the game is, thus, to remove all the tiles from the board. A very simple solitaire game.

To compile and install Xmahjongg, you are going to use seven commands: cd (to get into the xmahjongg folder), ./configure (to configure a makefile, which provides instructions for the next command), make (to translate the source code into object code that the computer can understand), su (to become root), make install (to install the program), exit (to get out of root mode), and make clean (to clean up the mess). I know that sounds like a lot of commands, but as I always say, it is easier to actually do than it looks like on the page, so fear not.

Getting the Xmahjongg Files

To get started, you will first have to download the Xmahjongg file. You can get this from the Xmahjongg project page at: http://www.lcdf.org/~eddietwo/ xmahjongg/. Download the tarball xmahjongg-3.6.1.tar.gz or a newer version if there is one. Do not download any of the RPM files, even those that say they are for Red Hat.

Once you have the file on your hard disk, you are ready to roll.

11A-1: Untarring, Compiling, and Installing

Before you actually compile and install Xmahjongg, you have to extract the tarball’s source files, or untar the tarball.

  1. Untar the xmahjongg-3.6.1.tar.gz file by double-clicking the file icon. This will bring up the File Roller program.

  2. In the File Roller program window, click the Extract button.

  3. When File Roller’s Extract window opens, click the OK button. Once File Roller is done, you can close the File Roller window. A new folder, xmahjongg-3.6.1, will now appear in your Home folder. Figure 11-2 shows the contents of the xmahjongg-3.6.1 folder.

    click to expand
    Figure 11-2: The contents of the folder created by extracting the Xmahjongg tarball

  4. Scroll down through the xmahjongg-3.6.1 folder contents and look for a file called INSTALL. The INSTALL file is actually just a text file with a set of instructions on how to install the program. To read the INSTALL file, just double-click it, and it will open in the same Nautilus window, as shown in Figure 11-3.

    click to expand
    Figure 11-3: Reading a tarball’s INSTALL file in a Nautilus window

    In this case, you can simply close the INSTALL file, as it prescribes the same steps as I’ve listed below. However, in the future, when you install other programs from source, you will need to follow the instructions in the INSTALL files that come with the source files for those programs. With most INSTALL files, the instructions will match those that follow.

  5. Open a Terminal window by clicking the Terminal launcher on the GNOME Panel, and then move into the new folder by typing cd xmahjongg-3.6.1 and pressing ENTER.

    The next step is sort of a setup phase that runs the configure script in the xmahjongg-3.6.1 folder. The configure script checks what files, compilers, and other things it needs, and then it searches your computer to see if those things are there, and if so, where. Based on this information, it then writes a file called makefile, which is a set of instructions that will tell the make command in the subsequent step how to set things up specifically for your system configuration.

    While you are running configure, you will see lots of odd and mysterious things flowing down your Terminal window; this is essentially a running account of what is going on, each step of the way. Depending on the program you are dealing with, this could take a bit of time — a few seconds or a few minutes. Either way, you needn’t worry. As long as the mysterious text keeps flowing and you don’t get an error message at the very end of the whole process, all will be well.

  6. Compile the program by typing ./configure and pressing ENTER.

    When configure has done its thing, you will see your prompt again, and you can go on to the next step, which is the translation step. The make command reads the makefile that configure created to see how things need to be set up on your machine. Then it proceeds to call on the compiler to translate the high-level source code into low-level, machine-readable files that can be installed in the subsequent step.

  7. To perform this translation, type make and press ENTER.

    Again, you will be treated to more mysterious text flowing down the screen and a short wait, usually a tad longer than for the configure process.

    Once make has done its job and you see your prompt again, you are ready to install the program. However, because some of these files created by make must go into places guarded by root permissions, you must first become root by using the su command before doing anything else.

  8. Become root by typing su and pressing ENTER.

  9. Type your root password when prompted to do so, and then press ENTER.

    Up to this point, you have not changed your system in any way. All the changes thus far have taken place in the xmahjongg-3.6.1 folder only. Your system is still as pure as the day you started. Of course, all that is going to end now, as you are about to install into your system the files that make created.

  10. Type make install and then press ENTER.

  11. Once make install is done installing the program, your prompt will reappear. Now type exit and press ENTER to exit root mode.

  12. Type cd and press ENTER to return to user’s Home, and leave your Terminal window open for the time being.

11A-2: Running Xmahjongg

As a general rule, programs compiled from source do not automatically install a launcher in your Main menu. Although you can run a program for the first time by going to the Main menu, selecting Run Program, and then typing the program name in the dialog box, it is better to run the program for the first time by typing the command for the new program in your Terminal window. If anything has gone amiss during installation, the Terminal will tell you what the problem is, whereas the Run Program method would just leave you wondering what’s going on.

Usually the program’s command name is written in the INSTALL file or the README file within the directory that was created when you extracted the source files from the tarball (xmahjongg-3.6.1 in this case). Sometimes you won’t find it there, but you can find it on the project page for that application on the Internet. Other times, however, you can’t find it there either, so you’ll just have to resort to guessing. Sometimes the hardest part of compiling a program from source is not, as you now know, compiling it, but rather finding out what the command to run it is. Usually, it is just the name of the tarball, minus the file endings.

It is time to make sure that all went well with the Xmahjongg program installation. In your Terminal window, type xmahjongg and press ENTER. If all is as it should be, and there is no reason it shouldn’t, the Xmahjongg program will open within seconds and all will be well. You can now goof around with the game for a while, if you like, or get straight back to cleaning up, which is an easy enough process.

11A-3: Cleaning Up

Once you are all done compiling and installing your new application, you will find that you have a lot of extra files in your original source folder that you no longer need. As I mentioned before, the make command created translations of all the source code files, and those low-level language versions of the files were then installed in the make install step. Now that your installation is complete, you don’t need those files anymore; they have all been copied elsewhere. The translated files in your source folder are just sitting there rudely wasting disk space.

Getting rid of these space wasters is simple enough, fortunately. The make clean command will remove all the extraneous translated versions of your source files. However, it sometimes happens that make clean will also clean out your makefile, which is bad, because the makefile often allows you to uninstall the program you’ve installed with it. Before running the make clean command, therefore, it is a good idea to copy the makefile to the desktop. Then, once you are done with make clean, you can check to see if the makefile is still in the project folder or not. If it is, you can trash the makefile on your desktop. If the makefile is not in the project folder, you can move the desktop makefile back into that folder.

Here are the steps:

  1. Type cd xmahjongg-3.6.1 and hit ENTER to return to the xmahjongg-3.6.1 folder.

  2. Type make clean and press ENTER. You needn’t be root to do this.

  3. After make clean is finished with its tidying chores, you are done, and you will have saved a bit of disk space. In the case of the xmahjongg-3.6.1 directory, you will find that it will shrink from 4.2MB to only 867KB (under one megabyte) or thereabouts.

  4. Close your Terminal window by typing exit and then pressing ENTER.

  5. If Xmahjongg is running as it should and you are satisfied with it to the extent that you are sure that you do not want to uninstall it, you can now haul the xmahjongg-3.6.1 folder to the Trash. If you aren’t all that impressed and wouldn’t mind dumping it right away, move on to 11A-4.

And that is that! You have compiled a program from source, installed it, and even cleaned up after yourself. As you can see, there’s really nothing to it! It is most definitely time for a self-administered pat on the back.

11A-4: Second Thoughts — Uninstalling Xmahjongg

Let’s say that you installed a program through this compiling process, and you don’t like or need it — you just want to get it out of there. Usually you can uninstall the program, provided the pesky makefile is still there in the project folder (hence my warning in the previous “Cleaning Up” section), with the make uninstall command. You might first want to check out the INSTALL or README file to see if make uninstall is supported or if there is another uninstall method. Sometimes, however, the uninstall method is not specified, so you will just have to give it a go to find out if make uninstall works or not. There is no danger in this, because if it isn’t supported, nothing will happen.

Anyway, Xmahjongg is a good example. There is no information in either the INSTALL or README files about uninstalling the program, so to find out if you can use make uninstall, you have to go through the more or less standard steps:

  1. Open a Terminal window and become root by typing su and pressing ENTER. Then type your root password and press ENTER.

  2. Use the cd command to move over to the xmahjongg-3.6.1 folder by typing

    cd xmahjongg-3.6.1 and hitting ENTER.
  3. Type make uninstall and press ENTER.

    When you’re done, you should see a stream of text flowing down your Terminal window for a few seconds. If you take a look at the text after it has stopped flowing and you are back at the root prompt, you will see that it actually consists of information that you now more or less understand: a series of cd, rm, and rmdir commands.

  4. To make sure that Xmahjongg really is uninstalled, type exit and press ENTER to get yourself out of root mode, and then type xmahjongg and press ENTER to try to run the program. You should be told that the command cannot be found. If this is the case, you have successfully rid your computer of Xmahjongg.

This is basically the same way you would go about uninstalling any other package that you originally installed in this non-RPM manner. If it works, it works, and if it doesn’t . . . well, then you will have to read the makefile (by double-clicking it) to see where everything was placed, and then trash all the files one by one. That’s a big pain, and you might screw something up in the process, so I recommend you just ignore the program instead, at least at this stage of the game.



 < Day Day Up > 



Linux for Non-Geeks. A Hands-On, Project-Based, Take-It-Slow Guidebook
Linux for Non-Geeks: A Hands-On, Project-Based, Take-It-Slow Guidebook
ISBN: 1593270348
EAN: 2147483647
Year: 2003
Pages: 188

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net