Difference between revisions of "Build rpm packages with the rpmbuild command"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
Line 1: Line 1:
 
This article is about how to [[build rpm packages]] with the rpmbuild command and a SPEC file.
 
This article is about how to [[build rpm packages]] with the rpmbuild command and a SPEC file.
  
First, create a SPEC file:
+
= The program =
 +
Here is how we create our program, hello world:
 +
<pre>
 +
cd
 +
mkdir hello
 +
cd hello
 +
cat >main.c <<EOF
 +
#include <stdio.h>
 +
 
 +
int main()
 +
{
 +
  printf("hello world");
 +
}
 +
EOF
 +
</pre>
 +
 
 +
= The Makefile =
 +
To [[build]] our program, we need a [[makefile]]. Here is how we create it:
 +
<pre>
 +
cat >Makefile <<EOF
 +
all:hello
 +
 
 +
hello: main.c
 +
        gcc main.c -o hello
 +
 
 +
install: hello
 +
        cp hello /usr/local/bin
 +
EOF
 +
sed -i "s/        /\t/g" Makefile
 +
</pre>
  
 +
= The SPEC file =
 
<pre>
 
<pre>
Summary: krep allows you to filter text
+
Summary: hello greets the world
Name: krep
+
Name: hello
 
Version: 1.0
 
Version: 1.0
 
Release: 1
 
Release: 1
 
License: GPL
 
License: GPL
 
Group: Applications/Sound
 
Group: Applications/Sound
Source: http://www.staerk.de/files/krep.tar.gz
+
Source: hello.tar.gz
URL: http://www.staerk.de/thorsten/krep
+
URL: http://www.staerk.de/thorsten/
 
Distribution: SUSE Linux
 
Distribution: SUSE Linux
 
Vendor: -
 
Vendor: -
Line 17: Line 47:
  
 
%description
 
%description
krep lets you filter text by regular expressions
+
hello greets the world
  
 
%prep
 
%prep
Line 27: Line 57:
 
%install
 
%install
 
make install
 
make install
mkdir -p /usr/src/packages/BUILDROOT/krep-1.0-1.i386/usr/local/bin
 
cp /usr/local/bin/krep /usr/src/packages/BUILDROOT/krep-1.0-1.i386/usr/local/bin/krep
 
  
 
%files  
 
%files  
 
%doc README
 
%doc README
 
%defattr(-, root, root)
 
%defattr(-, root, root)
/usr/local/bin/krep
+
/usr/local/bin/hello
 
</pre>
 
</pre>
  

Revision as of 18:29, 6 February 2011

This article is about how to build rpm packages with the rpmbuild command and a SPEC file.

The program

Here is how we create our program, hello world:

cd
mkdir hello
cd hello
cat >main.c <<EOF
#include <stdio.h>

int main()
{
  printf("hello world");
}
EOF

The Makefile

To build our program, we need a makefile. Here is how we create it:

cat >Makefile <<EOF
all:hello

hello: main.c
        gcc main.c -o hello

install: hello
        cp hello /usr/local/bin
EOF
sed -i "s/        /\t/g" Makefile 

The SPEC file

Summary: hello greets the world
Name: hello
Version: 1.0
Release: 1
License: GPL
Group: Applications/Sound
Source: hello.tar.gz
URL: http://www.staerk.de/thorsten/
Distribution: SUSE Linux
Vendor: -
Packager: Thorsten Staerk

%description
hello greets the world

%prep
%setup

%build
make 

%install
make install

%files 
%doc README
%defattr(-, root, root)
/usr/local/bin/hello

todo