Difference between revisions of "Build rpm packages with the rpmbuild command"
imported>ThorstenStaerk |
imported>ThorstenStaerk |
||
Line 66: | Line 66: | ||
EOF | EOF | ||
</pre> | </pre> | ||
+ | '''''License''''' is a free-text field. You can enter what you want. Same goes for '''''Group'''''. '''''Source''''' is the file that will be stored in /usr/src/packages/SOURCES. | ||
= Build the rpm = | = Build the rpm = |
Revision as of 15:56, 13 February 2011
This article is about how to build rpm packages with the rpmbuild command and a SPEC file. The example is based on SuSE 11.3 x86_64. However, other distributions should work same or similar.
The program
Here is how we create our program, hello world:
cd mkdir hello-1.0 cd hello-1.0 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 mkdir -p \${prefix}/usr/local/bin cp hello \${prefix}/usr/local/bin EOF sed -i "s/ /\t/g" Makefile
The SPEC file
Your SPEC file will be named hello.spec and reside in the folder /root/hello-1.0. Create it like this:
cat >hello.spec<<EOF 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 prefix=\$RPM_BUILD_ROOT %files %defattr(-, root, root) "/usr/local/bin/hello" EOF
License is a free-text field. You can enter what you want. Same goes for Group. Source is the file that will be stored in /usr/src/packages/SOURCES.
Build the rpm
Now we have the SPEC file and the software. First we store the source in the "appropriate" place:
cd tar cvzf hello.tar.gz hello-1.0 cp hello.tar.gz /usr/src/packages/SOURCES
Then, build it with the command
rpmbuild -ba hello-1.0/hello.spec
You will find your ready RPM under /usr/src/packages/RPMS.
Clean up
To clean up, run
rm /usr/src/packages/SOURCES/hello.tar.gz rm -rf /usr/src/packages/BUILD/hello-1.0