- Create a simple hello.cpp
- Create a Makefile
- Put hello.cpp and the Makefile in a directory structure like this
- Create a tarball of hello project
- Create an rpmbuild directory
- Create BUILD BUILDROOT RPMS SOURCES SPECS SRPMS directories inside the /home/foobar/rpmbuild directory BUILD --> the source files are unpacked and compiled here
- Create a spec file in the /hom/foobar/rpmbuild/SPECS/hello.spec
- Build the source and binary RPMs
- Install the newly created binary RPM
- Test if hello program was successfully installed
- Remove the hello package
#include <iostream> using namespace std; int main() { cout << "Hello World" << endl; return 0; }
CC = g++ CCFLAGS = -g -Wall SRC = hello.cpp TARGET = hello .PHONY: clean install all: hello install: $(TARGET) if [ -d ${DESTDIR} ]; then rm -rf ${DESTDIR}; fi mkdir -p ${DESTDIR} cp $(TARGET) ${DESTDIR} hello: $(CC) $(CCFLAGS) -o $(TARGET) $(SRC) clean: rm -rf $(TARGET)
/home/foobar/hello/Makefile /hello.cpp
cd /home/foobar tar czvf hello-0.1.tar.gz hello/
mkdir -p /home/foobar/rpmbuild
BUILDROOT --> files are installed here
RPMS --> binary RPMs are created here
SOURCES --> source tarballs
SPECS --> spec files
SRPMS --> source RPMs
Summary : Hello World program Name : hello Version : 0.1 Release : 1%{?dist} License : GPLv3+ Source : %{name}-%{version}.tar.gz %description A simple Hello World program %prep %setup -q -n %{name} %build make %install make install DESTDIR="%{buildroot}%{_bindir}" %files %{_bindir}/hello%prep --> this stage calls %setup to unpack hello-0.1.tar.gz to /home/foobar/rpmbuild/BUILD/hello. %{name} is a macro variable that substitutes to hello %build --> this stage calls "make" in the /home/foobar/rpmbuild/BUILD/hello to create a hello executable %install --> this stage calls "make install" to install the files into /home/foobar/rpmbuild/BUILDROOT/usr/bin. %{buildroot} is a macro variable that substitutes to /home/foobar/rpmbuild/BUILDROOT. Make sure the Makefile supports DESTDIR argument %files --> lists all the files to be installed. %{_bindir} is a macro variablesubstitutes to /usr/bin. In this example, only hello executable needs to be installed into /usr/bin
rpmbuild -ba /home/foobar/SPECS/hello.spec-ba option means build all (prep, build, install)
The binary RPM will be created in /home/foobar/rpmbuild/RPMS
The source RPM will be created in /home/foobar/rpmbuild/SRPMS
sudo rpm -ivh hello-0.1-1.fc16.i686.rpm
helloYou should see "Hello World" output
sudo rpm -e hello
Step # 8 doesn't work for me.
ReplyDeleteI try this:
$ rpmbuild -ba ./home/ec2-user/foobar/rpmbuild/SPECS/hello.spec
I get this:
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.r47lfF
+ umask 022
+ cd /home/ec2-user//BUILD
+ cd /home/ec2-user/BUILD
+ rm -rf hello
+ /usr/bin/gzip -dc /home/ec2-user/SOURCES/hello-0.1.tar.gz
+ /usr/bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd hello
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.pHBGef
+ umask 022
+ cd /home/ec2-user//BUILD
+ cd hello
+ make
makefile:11: *** missing separator. Stop.
error: Bad exit status from /var/tmp/rpm-tmp.pHBGef (%build)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.pHBGef (%build)
What should I do?