12.07.2015 Views

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Building RPM Packages 143Creating the MakefileThe Makefile is similar to a script. It contains variables that define values such as thename of the package. It also contains stanzas called targets. Each target has a unique namethat represents an action such as install for installing the software or rpm for buildingthe RPM file. Each target contains a list of commands to run to perform the action.Listing 5.10 contains a simple Makefile for our example startvpn program.CAUTIONWhen creating the Makefile, be sure to use tabs instead of spaces to indent thelines for each target. Also, the commands for each target must be started on the nextline as shown in Listing 5.10.LISTING 5.10Example MakefilePKGNAME=startvpnVERSION=$(shell awk ‘/Version:/ { print $$2 }’ ${PKGNAME}.spec)default: install5install:echo “hello”echo $(INSTROOT)mkdir -p $(INSTROOT)/usr/local/bininstall ${PKGNAME} $(INSTROOT)/usr/local/bin/${PKGNAME}srpm:@rpmbuild -ts ${PKGNAME}-${VERSION}.tar.gzrpm:@rpmbuild -tb ${PKGNAME}-${VERSION}.tar.gzThe example Makefile starts off by defining the name of the package as the PKGNAME variableand the version of the package as the VERSION variable. Notice that the version numberis retrieved from the package spec file using an awk command. Using this commandprevents you from getting the package versions listed in the spec file and Makefile out ofsync. Because the Makefile retrieves the version number from the spec file, you just need tochange the version number in the spec file each time it needs to be incremented.Because our example program is only one file, the install target creates the directory forthe file and then installs the file into the directory. The srpm and rpm targets execute thecorresponding rpmbuild commands.Creating the Source TarballCreating the source tarball is as easy as creating a directory with the package name andversion in it such as startvpn-1.1, copying all the source files including the Makefile

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!