Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, April 13, 2008

How to Build a Typical Linux Project

How to Build a Typical Linux Project

If you are using Linux, it makes a lot of sense to download and use various Free and Open Source software. While frequently you will be able to download and install various RPMs, there are a lot of projects that do not provide any user friendly installers. Some projects even do not have the explicit releases. From the other side, building from the source may produce an application that is much better optimized to your processor and operating system. Surely, you must also be able to build a Free / Open Source project if you want to master it enough to join as developer later. This article explains how to build a typical, correctly managed Linux project from the source code.

Steps
If the project has no explicit releases, you may need to pull the source code directly from its CVS or SVN repository. The websites of the most such projects will have the corresponding command line which you only need to copy-paste to your system, for instance cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/classpath co classpath. The similar command usually downloads a large number of project files in a current folder.

Look into the files README and INSTALL that should be at the top folder in the downloaded project. They may contain valuable information that will save you a lot of time.

Some projects provide the build script as a shell script (usually named build.sh). This is not very frequent, but happens for very old projects and also for new projects that try to provide a "user friendly" build procedure. If you find such file, try to use it first (the installation may be placed in a separate script that is usually names install.sh). If you find these scripts, just run them. Otherwise, proceed to the following steps.

Search for the file called configure which also must be present in a project top folder. It is usually a .sh script that will tune the project build system to your machine. If you find it, type ./configure or sh configure to run this script. ./configure usually has a lot of options that may help if the "default" run fails with error messages. Run the script with the key --help to see the options. If there is no configure script, it may be an old - style project which only uses makefiles, so you can proceed directly to the next step.

Search for the file called makefile which may be initially present or appear after you run configure. If you find it, type the command make. It should find the makefile in the current directory and build the project for you.

If there is no configure nor makefile in the project tree, it may be an ant - powered project with the build.xml file instead. In this case, type ant in the project root folder. While make is more popular for C and C++ projects, ant is popular for java projects.

If ant doesn't work either, or the project is C or C++, try running ./autogen.sh to create the configure and makefile files. THis uses autoconf, automake and libtool to create these files.
After you succeeded to compile the makefile - based project, try make install to place the project files into appropriate locations (to install the project). The default locations like /usr/lib or /usr/bin are usually only root-writeable, so this step usually needs administrator rights.
After the installation succeeds, try to type the short project name. This usually invokes the newly compiled and installed program which is now ready to use.


Tips
If the build fails, paste the error message into Google or other web search engine. You will frequently find the description of the same problem together with explanation, how to solve it.

The frequent reason is the absence or the wrong version of some required library. In this case all you need is to find and build this library which is usually a similar project on its own.

If you still cannot understand that is going wrong, try to update your build tools and the existing C/C++/java or other libraries (depending on which programming languages are used in the project). It is usually easy to update tools and libraries using the system software updater.

After you tried the earlier steps (but after, not before), send a question to the project mailing list. Tell all you think may be relevant about your operating system, describe the problem in details and include all error messages. Hackers should understand that you have done enough from you side and really deserve some help.

If you succeeded to build a program from the source, make use of this. Try to understand how does the program work and improve it!

Warnings
Always try to solve the problem yourself, search the web for a solution and check the mailing list archive before asking any question to the mailing list. Otherwise you may get something like RTFM in response which is rather frustrating and not very helpful.

If the project has the official releases, try to use them before pulling the source code from repository. The repository version may contain the recently introduced bugs and be very unstable.
From the other side, if the official release has problem, this problem may be already fixed on the CVS/SVN and in such case it may be worth to try the newest version.

Some projects may be very difficult to build if you operating system is old and a lot of libraries are obsolete. In such case think about migrating to another Linux distribution that is under active development and should have the more recent versions of these libraries.

How to Boot a Floppy Image Using the Grub Bootloader

How to Boot a Floppy Image Using the Grub Bootloader

Say you want/need to boot your computer from a floppy, but your computer has no floppy drive. You can boot your computer from a floppy disk image if you have the GRUB bootloader installed (found on many Linux distributions).

Steps
Install the syslinux package on your system. Instructions vary by distro. For a Debian/Ubuntu/MEPIS system, for instance, you would either choose it from Synaptic, or from the command line with "apt-get install syslinux".
Copy the memdisk file from /usr/lib/syslinux to the /boot directory.
Copy the floppy disk image (ie. image.img) to the /boot directory.
Add an entry to /boot/grub/menu.lst that looks like:

title My Floppy Disk
root (hd0,0)
kernel /boot/memdisk
initrd /boot/image.img

Run update-grub
Reboot

Tips
It is not really necessary to copy the floppy image and the memdisk kernel to the boot directory (but it makes things a lot easier to remember).
The floppy image will be read-only; all changes will be lost when the computer is rebooted. It might be handy to create a small partition on your hard drive that the operating system can write to.

How to Assign An IP Address on a Linux Computer

How to Assign an IP Address on a Linux Computer

Linux is the free, open-source alternative to Microsoft Windows and Mac. The operating system itself can be chopped down entirely to a raw text console, or it can utilize a window manager such as Gnome or KDE. This guide will explain how to assign a static IP address on a Linux system through the use of a text console. Although this can usually be accomplished within the system settings of a window manager, different window managers may differ in this process; therefore, by using a simple step-by-step console guide, someone using almost any distribution of Linux can follow this guide. This guide assumes that you know a little bit about Linux, and you know how networks, IP addresses, and DNS servers work.

Steps
Switching to Root
If you are not already logged in as 'root' (the Linux counterpart of 'Administrator'), open a console program and type 'su' (without quote) and press enter.
Note: *buntu Linux distributions usually have the root password the same as the account created when the operating system was installed.
Enter your root password when prompted, and press enter.

Debian / Ubuntu / Kubuntu
Make a backup of your /etc/network/interfaces file by typing the following in the console: 'cp /etc/network/interfaces /etc/network/interfaces.backup'
Type 'vim /etc/network/interfaces' and press enter. Press 'i' to enter into insert (editing) mode.
Scroll down until you find your network interface card in the file (usually named eth0 for an ethernet connection, or wlan0 or wifi0 for a wifi connection).
Change 'iface eth0 inet dhcp' to 'iface eth0 inet static'
Add the following lines, substituting the IP address numbers with your desired configuration:

address 192.168.0.10
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 216.10.119.241
Save and exit by pressing escape, then typing: ':wq' (including the colon)
Type 'ifdown eth0' and press enter.
Type 'ifup eth0' and press enter.

Red Hat or Slackware
The easiest method in Red Hat or Slackware is to type 'netconfig' in a console as the root user. A text-based menu will guide you through its configuration settings.
Use tab to move between fields. Use the spacebar to uncheck or check checkboxes.
When you have input the desired settings, press OK.
To make these settings take effect, type 'service network restart' in the console and press enter (this step is not necessary under Slackware, where the changes are immediate).

Note: There are numerous distributions based on Red Hat Linux (Fedora Core, CentOS, White Box, et cetera); many of them are likely to avail one the same method.

Dynamic IP address (DHCP)

Dynamic addresses are obtained automatically and usually do not any attention from the user. However there are several specific cases:
If the network has not been available all the time while the system was starting, the internet connection may stay disabled even after fixing the network problems. To revive it instantly, run dhclient as root. This will set the dynamic address.
The previous situation may happed if the network is accessed by separate hardware that starts at the same time as your machine. In some cases Linux boots faster than the network router and finds no network at startup. Find dhclient.conf (for instance, /etc/dhcp3/dhclient.cof for Debian) and add/correct the line reboot nn;, where nn is the delay for which the system must wait after booting, for the router to start.