By thomas, Mon, 09/21/2009 - 16:11
The %build section is where anything that needs to be compiled should be compiled. Any file that has to be made on the machine or is architecture dependant should be created here. RPM provides convenient macros for this section. If your software is configure;make;make install (autoconf/automake) compliant, then this section will be very small also.
%build
%configure
make
For many packages, this is it. %configure is a macro that sends the appropriate defaults to configure. You can see what %configure expands to by stopping rpmbuild in the middle of the build and looking at the temp file in /var that rpm runs. Each section of the spec file is first parsed and expanded then cut up by rpm and placed into an executable file in /var/tmp. We'll run rpmbuild and look for a line that starts with Executing(%build). This will tell us the filename of the file in /var/tmp.
[build@client11 SPECS]$ rpmbuild -bb tar.spec 
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.61921
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ cd /home/build/rpmbuild/BUILD
+ rm -rf tar-1.22
+ /usr/bin/bzip2 -dc /home/build/rpmbuild/SOURCES/tar-1.22.tar.bz2
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd tar-1.22
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.21166
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ cd tar-1.22
+ CFLAGS='-O2 -g'
+ export CFLAGS
+ CXXFLAGS='-O2 -g'
+ export CXXFLAGS
+ FFLAGS='-O2 -g'
+ export FFLAGS
+ ./configure --host=x86_64-redhat-linux-gnu --build=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/usr/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/usr/var --sharedstatedir=/usr/com --mandir=/usr/man --infodir=/usr/info
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... 
[1]+  Stopped                 rpmbuild -bb tar.spec
[build@client11 SPECS]$ cat /var/tmp/rpm-tmp.21166 
#!/bin/sh

  RPM_SOURCE_DIR="/home/build/rpmbuild/SOURCES"
  RPM_BUILD_DIR="/home/build/rpmbuild/BUILD"
  RPM_OPT_FLAGS="-O2 -g"
  RPM_ARCH="x86_64"
  RPM_OS="linux"
  export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
  RPM_DOC_DIR="/usr/doc"
  export RPM_DOC_DIR
  RPM_PACKAGE_NAME="tar"
  RPM_PACKAGE_VERSION="1.22"
  RPM_PACKAGE_RELEASE="1"
  export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
  
  
  
  set -x
  umask 022
  cd /home/build/rpmbuild/BUILD
cd tar-1.22

  CFLAGS="${CFLAGS:--O2 -g}" ; export CFLAGS ; 
  CXXFLAGS="${CXXFLAGS:--O2 -g}" ; export CXXFLAGS ; 
  FFLAGS="${FFLAGS:--O2 -g}" ; export FFLAGS ; 
  ./configure --host=x86_64-redhat-linux-gnu --build=x86_64-redhat-linux-gnu \
	--target=x86_64-redhat-linux-gnu \
	--program-prefix= \
 	--prefix=/usr \
	--exec-prefix=/usr \
	--bindir=/usr/bin \
	--sbindir=/usr/sbin \
	--sysconfdir=/usr/etc \
	--datadir=/usr/share \
	--includedir=/usr/include \
	--libdir=/usr/lib \
	--libexecdir=/usr/libexec \
	--localstatedir=/usr/var \
	--sharedstatedir=/usr/com \
	--mandir=/usr/man \
	--infodir=/usr/info
make
Ok, let rpmbuild complete or kill it, it won't do anything useful yet, because we didn't install any files, we need an %install section next.