Linux [HowTo] Create packages from source compiled software (unix)

chip_0

Adept
Most users of unix systems will have encountered software that are provided as their source code, and which use a Makefile to automate their build and install process. Now, the problem with this is that uninstalling the software is not so easy, especially if you have deleted the source code directory. It would require hunting and deleting each file manually. Easy enough when the whole software is a single binary, not so trivial if it contains several libraries, shared files, man pages and binaries.

So here are two methods which will not only enable easy uninstallation, but will also integrate the software with your distribution's package manager.

1. checkinstall

This is a very convenient and useful tool which will keep track of all files installed by "make install" (or any other install script), and will create a Slackware tgz, Debian, or RPM package out of them. Get more information, and the program itself, at -

http://asic-linux.com.mx/~izto/checkinstall/

2. The second method

This will do exactly the same thing as checkinstall, so if that doesn't work for you, read on. I find it a more elegant and flexible method, although it makes you do some work.

This method basically will install the files in a temporary directory (say /tmp/pkg) which can later be converted into a package for your distribution. If the files were to go into /usr/local, now they would be placed in /tmp/pkg/usr/local/.

So, here we go ...

1. Compile the software, which can usually done by typing "./configure" followed by "make".

2. Instead of running "make install", type -

make DESTDIR=/tmp/pkg/ install

This should carried out as root user, to make sure that all the files created are owned by root.

3. Check that the directory /tmp/pkg contains the relevant files in their correct locations.

4. Convert the directory /tmp/pkg to a package for your distribution. Here are ways to create popular package formats -

Slackware (tgz) - cd to /tmp/pkg and run "makepkg <name_of_package.tgz>". Read "man makepkg" for more info.
RPM - http://erizo.ucdavis.edu/~dmk/notes/RPMs/Creating_RPMs.html
Debian - http://www.tldp.org/HOWTO/html_single/Debian-Binary-Package-Building-HOWTO
Arch Linux - The Arch Build System does exactly this, in a very elegant manner. Read the Arch package making HOW TO for details.

Notes -

1. Not all makefiles recognise the variable DESTDIR. In this case, you will have to look through the file "Makefile" present in the main source directory, and look about for anything that could be changed for the purpose.

A variable "prefix" is also very commonly used, this controls the exact location of the files to be installed (/usr/local is used by default in most cases), so running

make prefix=/tmp/pkg/usr/local/ install

should give the same result.

In case you don't either variable, search the file for /usr/local (or whatever location the software was to be installed to) and change its occurance to /tmp/pkg/usr/local. This should be done after compiling the program with "make".

2. Of course, all this could have been avoided by simple running the configure script with /tmp/pkg/usr/local as the install location. The problem is that this location would be coded into the binary files, and hence, even after you copy the files to their final location, the binaries would still be looking in /tmp/pkg for some data.

3. If you want to run the make install process as a non-root user, do so, but remember to chown the ownership of all files in /tmp/pkg to root. Basically, you will have to run -

chown -R root:root /tmp/pkg
 
desertwind of the digit forum pointed out a software called GNU Source Installer, which seems to do exactly the second method, but automatically. Get it here.

Unfortunately, I don't think it can create package files in your distributions format, and rather it maintains its own database. For installable binary packages, you still will have to go about from scratch.
 
This is a great HOWTO, I have compiled software before and it can be quite painful. I was unaware of the utilities you have mentioned and have always done it the hard way :( Now I can try some new methods :)

One thing to note for newbies, is that this also assumes that you have all dependencies installed before you try to compile and install new software :D
 
bumping an old thread.

a linux neophyte here. i wish to know can a software be compiled on one Linux box, and then installed on another? i have an Ubuntu VM, and a router with ddwrt interface, running optware. i want to compile a package from source (rtorrent) with xmlrpc, and then take the package to the router and install it on optware. want to do this because the package available in the repositories lacks xmlrpc support. can this be done? i have seen a few guides, detailing the procedures, but they're all for Debian/Ubuntu, ie, compiling as well as installing at the same time in Debian/Ubuntu itself, whereas, i want to compile on Ubuntu, and install on optware.
 
bumping an old thread.

a linux neophyte here. i wish to know can a software be compiled on one Linux box, and then installed on another? i have an Ubuntu VM, and a router with ddwrt interface, running optware. i want to compile a package from source (rtorrent) with xmlrpc, and then take the package to the router and install it on optware. want to do this because the package available in the repositories lacks xmlrpc support. can this be done? i have seen a few guides, detailing the procedures, but they're all for Debian/Ubuntu, ie, compiling as well as installing at the same time in Debian/Ubuntu itself, whereas, i want to compile on Ubuntu, and install on optware.
its called cross compilation. for example you want to compile source for r-pi, you create a toolchain on pc which is x86 to compile source and create binaries for r-pi which is ARM processor.

Cross-compilation itself is a big topic if I start explaining but basically, you will create binary which is meant to run on a different type of processor on a PC. you will need to setup all the gcc and ld and ar options in order to do that. There is a tool called crosstool-ng which will take care of this by selecting the processor profile.

simplest method is if you can find out a toolchain available somewhere, just download it and then use it to compile the source. otherwise, download crosstool-ng and then create the toolchain yourself using the existing profile or modifying a nearest common profile. for this you will need to know the micro architecture characteristics.

The article http://www.dd-wrt.com/wiki/index.php/Compiling_DD-WRT_Sources is explaining the process by downloading a prebuilt toolchain.

Linaro provides toolchains for most of the embedded systems. but at this point, I dont know what processor your router has so cant go further.
 
thanks for the detailed explanation! i had thought that it would be a matter of installing a few utilities and type some commands and then compile, but this seems to be a daunting task. though the want is not so significant to devote much time & efforts into cross-compiling, esp. since i have now figured a well-operating workaround for my objective, but just out of interest & for learning, this indeed looks to be an engrossing 'project' to do. will go ahead with it soon.

here's some info on my router (SoC is Atheros, architecture MIPS):

http://wiki.openwrt.org/toh/tp-link/tl-wdr3600

also, found some info on cross-compiling packages, which i hope to follow:

http://www.nslu2-linux.org/wiki/Optware/AddAPackageToOptware

http://wiki.openwrt.org/doc/howtobuild/single.package

http://wiki.openwrt.org/doc/devel/crosscompile
 
Trust me it can get frustrating some times matching the kernel headers, glibc versions etc... to create the correct toolchain. thats why Linaro distributes most common toolchains in binary formats so that people can concentrate on creating applications rather than figuring out on how to compile things.

seems there is a toolchain available for this... check this thread. http://www.dd-wrt.com/phpBB2/viewtopic.php?t=61112

these seems to be the latest toolchains for aethros that you could try.
Code:
32bit : http://downloads.openwrt.org/kamikaze/8.09.2/atheros/OpenWrt-SDK-atheros-for-Linux-i686.tar.bz2
64bit: http://downloads.openwrt.org/kamikaze/8.09.2/atheros/OpenWrt-SDK-atheros-for-Linux-x86_64.tar.bz2

other related tools and linux kernel image: http://downloads.openwrt.org/kamikaze/8.09.2/atheros/
 
Last edited:
LoL! this looks interesting. thanks for sharing! i have been smashing my head over these packages and this and that since atleast past 2 days. interesting to note that there's more to come. awaiting to tackle the challenge soon!
 
Back
Top