Different Approach To Buildscripts: Difference between revisions

From SlackWiki
Jump to navigation Jump to search
(Migrated from old wiki)
 
m (Reverted edits by Esmapebb (talk) to last revision by Dugan)
 
(One intermediate revision by one other user not shown)
(No difference)

Latest revision as of 14:11, 9 December 2011

Pretty much everyone can have their own way of writing Slackware buildscripts. I also have mine, which just makes it easier for me to package software.

In here, I'm going to explain mine. To start, let's look at one I wrote this morning while drinking coffee cup #1:

   #!/bin/bash
   
   #############################################################################
   ## Name: jpilot                                                            ##
   ## Version: 0.99.8                                                         ##
   ## Packager: Martin Lefebvre (dadexter@gmail.com)                          ##
   ## Homepage: http://www.jpilot.org                                         ##
   #############################################################################
   
   PKGNAME=jpilot
   VERSION=0.99.8
   LOC="http://jpilot.org/$PKGNAME-$VERSION.tar.gz"
   ARCH=`uname -m`
   
   START=`pwd`
   PKG=$START/pkg
   SRC=$START/work
   
   build() {
           mkdir -p $PKG $SRC
           cd $SRC
           wget $LOC
           tar -zxvf $PKGNAME-$VERSION.tar.gz
           cd $PKGNAME-$VERSION
           ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
           --enable-gtk2 --enable-prometheon
           
           patch -p0 < patch.0.99.8-memory
           patch -p0 < patch.jpilot-sync
           make
           make DESTDIR=$PKG install
           mkdir -p $PKG/usr/doc/$PKGNAME-$VERSION
           cp -r ABOUT-NLS AUTHORS BUGS COPYING ChangeLog ChangeLog.cvs INSTALL \
           NEWS README TODO UPGRADING docs $PKG/usr/doc/$PKGNAME-$VERSION
           
           cp KeyRing/README.txt $PKG/usr/doc/$PKGNAME-$VERSION/README.keyring
           cp dialer/README $PKG/usr/doc/$PKGNAME-$VERSION/README.dialer
           cp icons/README $PKG/usr/doc/$PKGNAME-$VERSION/README.icons
   }
   
   package() {
           cd $PKG
           find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : \
           | xargs strip --strip-unneeded 2> /dev/null
           find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : \
           | xargs strip --strip-unneeded 2> /dev/null
           find . | xargs file | grep "current ar archive" | cut -f 1 -d : | \
           xargs strip --strip-debug 2> /dev/null
           chown -R root:root usr/bin
           gzip -p $PKG/usr/man/man*/*
           mkdir $PKG/install
           cp $START/slack-desc $PKG/install/slack-desc
           cd $PKG
           makepkg -l y -c n $START/$PKGNAME-$VERSION-$ARCH-1.tgz
   }
   
   build
   package


The top section is just comments identifying the piece of software we're going to build, and the name of the script's author. Then we have the following lines:

   PKGNAME=jpilot
   VERSION=0.99.8
   LOC="http://jpilot.org/$PKGNAME-$VERSION.tar.gz"
   ARCH=`uname -m`
   
   START=`pwd`
   PKG=$START/pkg
   SRC=$START/work

They set the program's name, version, download URL, build and package directories. Since I usually don't specify anything related to the cpu or architecture, it auto detects the architecture. So, the $ARCH variable *should be* accurate.

   build() {
           mkdir -p $PKG $SRC
           cd $SRC
           wget $LOC
           tar -zxvf $PKGNAME-$VERSION.tar.gz
           cd $PKGNAME-$VERSION
           ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
           --enable-gtk2 --enable-prometheon
           
           patch -p0 < patch.0.99.8-memory
           patch -p0 < patch.jpilot-sync
           make
           make DESTDIR=$PKG install
           mkdir -p $PKG/usr/doc/$PKGNAME-$VERSION
           cp -r ABOUT-NLS AUTHORS BUGS COPYING ChangeLog ChangeLog.cvs INSTALL \
           NEWS README TODO UPGRADING docs $PKG/usr/doc/$PKGNAME-$VERSION
           
           cp KeyRing/README.txt $PKG/usr/doc/$PKGNAME-$VERSION/README.keyring
           cp dialer/README $PKG/usr/doc/$PKGNAME-$VERSION/README.dialer
           cp icons/README $PKG/usr/doc/$PKGNAME-$VERSION/README.icons
   }

The is the main build function. This contains the code required to build the software. First, we create the build and package directories. The next 3 lines change to the building diirectory, uses wget to fetch the source file and extracts it.

The lines after that are what you would normally type at your command line to build the software:

  • Change to the source directory.
  • Run ./configure with all the options you want.
  • Apply two patches required (in this case) to fix bugs with the software.
  • Run make
  • Install the software in the package directory defined by $PKG
  • Create the standard Slackware Software Documentation directory in the package
  • Copy the standard documentation.


The next section is the packaging part:

   package() {
           cd $PKG
           find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : \
           | xargs strip --strip-unneeded 2> /dev/null
           find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : \
           | xargs strip --strip-unneeded 2> /dev/null
           find . | xargs file | grep "current ar archive" | cut -f 1 -d : | \
           xargs strip --strip-debug 2> /dev/null
           chown -R root:root usr/bin
           gzip -p $PKG/usr/man/man*/*
           mkdir $PKG/install
           cp $START/slack-desc $PKG/install/slack-desc
           cd $PKG
           makepkg -l y -c n $START/$PKGNAME-$VERSION-$ARCH-1.tgz
   }
  • We change to the package directory
  • Strip executables and libraries in order to decrease size.
  • As a Slackware standard, we change the ownership of the executables to root:root (to be done for every bin/ and sbin/ directory)
  • We compress the manpages
  • Create install/ and copy the slack-desc file from the start directory
  • Finally, change back to the package folder and create the package tarball.


In this example, the slack-desc and some patch files are distributed with the SlackBuild. This also makes it easier to ship the build script with patches that might be required for the software to work on Slackware (patch to remove PAM stuff).

The slack-desc file format is described here: LinuxPackages.net


Additional files:

Some people use slapt-get (like me). slapt-get supports additional features such as

  • Dependencies
  • Conflicts
  • Suggestions

Not everyone wants those features, so building a package with those files will not interfere with the normal pkgtools process. For more info on these optional files, go here: LinuxPackages.net

If you decide to use those files, you will then have to repeat these lines:

   cp $START/slack-desc $PKG/install/slack-desc

for slack-required, slack-conflicts, and slack-suggests.



See also SlackBuild_Scripts and Writing A SlackBuild Script