(Answer) (Category) Linux on PowerPC FAQ-O-Matic : (Category) Applications : (Category) RPM :
How do I compile a package that I downloaded as a source RPM?
Compiling packages from source RPMs can vary from simple to difficult. In the
simplest case, where the package has been "ported" to your platform, a single
command can unpack sources, apply patches, rebuild and install complete
packages - whew! In the harder case, one where your platform isn't yet ported
or there are new code pieces to incorporate, the task becomes more difficult.

Here's how I go about it (and I've done quite a few...) for a package
XYZ-1.1-1.src.rpm.

Step 1. "Install the sources, patches, etc."

   cd /usr/src/redhat/SPECS
   rpm -iv .../XYZ-1.1-1.src.rpm
      -- This unpacks the sources and patches and the 'spec'
      -- file which is what tells RPM how to function

Step 2. Look at the 'spec' file. Quite often there are platform specifics in
this file. These are outlined by lines such as '%ifarch sparc'. Try to get a
feel for which ones might need adjusting.

Step 3. After you think the 'spec' file is close (or even before), give it a
try - you can't really hurt anything.

   rpm -bc XYZ-1.1.spec

This will stage the sources (typically into /usr/src/redhat/BUILD/XYZ) and
apply any patches. This is where you'll find most platform changes. There are
quite often patches which are applied only for a given platform. The "-bc"
command will attempt to compile the package and most likely will not work. The
best thing is to let it try and see what the problems are.

Step 4. [Assuming that step 3 failed] Go fix up the sources and get it to
compile. This may involve some effort! Go ahead and modify the files in
"/usr/src/BUILD/XYZ" - I'll explain later how to update the patches.

Some things to watch out for:
   
   o Many packages use 'configure'. Look at the 'spec' file to
     see if this is the case. If so, you may have to modify files
     which configure uses, typically they end in ".in". E.g. the
     file "Makefile" may really be generated from "Makefile.in".
     You'll have to figure out how to modify the configure script,
     or "Makefile.in" or some combo. ** Beware - black art!! **

   o Be sure you call 'make' (or whatever) the same way RPM did.
     Make note of it when you do the "-bc" command or look in the 
     spec file.

Step 5. Now you've gotten it to build, modified whatever you had to, etc. Time
to "package" the result. If you had to make changes to get this far, you'll
want to make up a set of patches. The best way is to compute the differences
between what you have now and what RPM started with (which may already have
been patched). Here's how I do it.

   cd /usr/src/redhat/BUILD
   mv XYZ XYZ.NEW
   cd /usr/src/redhat/SPECS
   rpm -bp XYZ-1.1.spec                -- only stages sources, no compile
   cd /usr/src/redhat/BUILD
   diff -uNr XYZ XYZ.NEW >../SOURCES/XYZ-1.1.mypatch

You may want to edit  "../SOURCES/XYZ-1.1.mypatch" to take out any junk like
backup files (*~) or stuff you created while trying to get things to compile.

Time to integrate your patches into the 'spec' file. 

   cd /usr/src/redhat/SPECS
   XYZ-1.1.spec

Change the release #. I typically just add a letter suffix if I'm modifying
somebody elses package. That way, I know it's been changed, but also which
"release" I started with in case the originator comes up with changes of their
own.

Add a line to incorporate your patch:

   %Patch99 XYZ-1.1.mypatch

In the '%prep' stage, get your patch included. Make sure it goes at the end
since the diffs assumed that!

   %ifarch ppc
   %patch99 -p1                    -- always use these options
   %endif

Note: you should number the patches consecutively. I just used 99 as an example
number. Take the highest numbered patch + 1.

Step 6. See if it works.

   rpm -bc XYZ-1.1.spec

If it all compiles then you're ready to try installing and building the result
RPM package files. If there was some problem, go back to steps 4-5 and fix it
up.

Step 7. Install and Package.
This part is [normally] very straight forward. You may have to change the
'%files' section if you added/removed any result files.

   rpm -ba XYZ-1.1.spec

When this completes, you will have built the appropriate XYZ.ppc.rpm (binary)
and .src.rpm (source) packages.

[Martien     m10@xs4all.nl    adds]

I noticed that at this point the executable and all are in place but the
package is not yet registered in the rpm databases.
To do this install the XYZ.ppc.rpm over the current situation

  rpm -ihv XYZ-1.1-1a.ppc.rpm

and use

  rpm -q XYZ

to see if it is installed according to rpm.

[end addition by M10]

---

There you have it!  Give it a try and see how it goes.

[Excellent advice provided by Gary Thomas, g.thomas@opengroup.org.
Posted to FAQ-O-Matic by sjohnson@datadungeon.com.]
m10@xs4all.nl, g.thomas@opengroup.org., sjohnson@datadungeon.com.
Note that you when you edit spec file to incorporate your patch, 
the first line you want to add is "Patch99: XYZ-1.1.mypatch"
and that goes up towards the top of the spec file, where it says
"Source0:" and "Version:", etc.
sarac@mit.edu
[Append to This Answer]
Next: (Answer) I can't install software because my copy of rpm is too old.
This document is: http://www.jonh.net/cgi-bin/lppcfom/fom?file=100
[Search] [Appearance]
This is a Faq-O-Matic 2.717d.
Hosted by anduin.org and SourceForge Logo