<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>SlackWiki - User contributions [en]</title>
		<link>https://www.slackwiki.com/Special:Contributions/Captain-sensible</link>
		<description>User contributions</description>
		<language>en</language>
		<generator>MediaWiki 1.40.0</generator>
		<lastBuildDate>Wed, 08 Apr 2026 13:26:58 GMT</lastBuildDate>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3217</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3217</guid>
			<description>&lt;p&gt;Captain-sensible: /* SlackBuild Script Repositories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
 Those that really know what they are doing are unlikely to need to read this document; as a noob I've read through and  successfully created a slackbuild and package.Some of the text needs updating,which i will have a go at in the knowledge that it should be able to be reversed via the history data. I will update from the perspective that a noob is reading and they may need some spoon feeding!  &lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 $  tar xvzf latex2html-2019.2.tar.gz || exit 1 &lt;br /&gt;
&lt;br /&gt;
 x -extract&lt;br /&gt;
 v -verbose&lt;br /&gt;
 f -file &lt;br /&gt;
 z -basically ungzip&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license.For the sake of brevity an example has been put on discussion page ), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=${VERSION:-2019.2}&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 # Automatically determine the architecture we're building on:&lt;br /&gt;
 if [ -z &amp;quot;$ARCH&amp;quot; ]; then&lt;br /&gt;
  case &amp;quot;$( uname -m )&amp;quot; in&lt;br /&gt;
    i?86) ARCH=i486 ;;&lt;br /&gt;
    arm*) ARCH=arm ;;&lt;br /&gt;
    # Unless $ARCH is already set, use uname -m for all other archs:&lt;br /&gt;
       *) ARCH=$( uname -m ) ;;&lt;br /&gt;
  esac&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
  if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i686&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i686 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;64&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;br /&gt;
;*https://slackbuilds.org/repository/14.2/academic/latex2html/?search=latex2html&lt;br /&gt;
&lt;br /&gt;
the last link is  intended for noobs reading this document and wanting to download a working  slackbuild for latex2html which was based on this tutorial. Its been tested on current stable Slackware 14.2 32 bit&lt;/div&gt;</description>
			<pubDate>Sun, 23 Jun 2019 14:40:54 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3216</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3216</guid>
			<description>&lt;p&gt;Captain-sensible: /* SlackBuild Script Repositories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
 Those that really know what they are doing are unlikely to need to read this document; as a noob I've read through and  successfully created a slackbuild and package.Some of the text needs updating,which i will have a go at in the knowledge that it should be able to be reversed via the history data. I will update from the perspective that a noob is reading and they may need some spoon feeding!  &lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 $  tar xvzf latex2html-2019.2.tar.gz || exit 1 &lt;br /&gt;
&lt;br /&gt;
 x -extract&lt;br /&gt;
 v -verbose&lt;br /&gt;
 f -file &lt;br /&gt;
 z -basically ungzip&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license.For the sake of brevity an example has been put on discussion page ), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=${VERSION:-2019.2}&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 # Automatically determine the architecture we're building on:&lt;br /&gt;
 if [ -z &amp;quot;$ARCH&amp;quot; ]; then&lt;br /&gt;
  case &amp;quot;$( uname -m )&amp;quot; in&lt;br /&gt;
    i?86) ARCH=i486 ;;&lt;br /&gt;
    arm*) ARCH=arm ;;&lt;br /&gt;
    # Unless $ARCH is already set, use uname -m for all other archs:&lt;br /&gt;
       *) ARCH=$( uname -m ) ;;&lt;br /&gt;
  esac&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
  if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i686&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i686 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;64&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;br /&gt;
;*https://github.com/captain-sensible/latex2html.SlackBuild&lt;br /&gt;
&lt;br /&gt;
the last link is intended for noobs reading this document and wanting to download a working  slackbuild for latex2html which was based on this tutorial. Its been tested on current stable Slackware 14.2 32 bit&lt;/div&gt;</description>
			<pubDate>Tue, 18 Jun 2019 13:46:13 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3215</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3215</guid>
			<description>&lt;p&gt;Captain-sensible: /* Initial Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
 Those that really know what they are doing are unlikely to need to read this document; as a noob I've read through and  successfully created a slackbuild and package.Some of the text needs updating,which i will have a go at in the knowledge that it should be able to be reversed via the history data. I will update from the perspective that a noob is reading and they may need some spoon feeding!  &lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 $  tar xvzf latex2html-2019.2.tar.gz || exit 1 &lt;br /&gt;
&lt;br /&gt;
 x -extract&lt;br /&gt;
 v -verbose&lt;br /&gt;
 f -file &lt;br /&gt;
 z -basically ungzip&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license.For the sake of brevity an example has been put on discussion page ), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=${VERSION:-2019.2}&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 # Automatically determine the architecture we're building on:&lt;br /&gt;
 if [ -z &amp;quot;$ARCH&amp;quot; ]; then&lt;br /&gt;
  case &amp;quot;$( uname -m )&amp;quot; in&lt;br /&gt;
    i?86) ARCH=i486 ;;&lt;br /&gt;
    arm*) ARCH=arm ;;&lt;br /&gt;
    # Unless $ARCH is already set, use uname -m for all other archs:&lt;br /&gt;
       *) ARCH=$( uname -m ) ;;&lt;br /&gt;
  esac&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
  if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i686&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i686 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;64&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;/div&gt;</description>
			<pubDate>Tue, 18 Jun 2019 09:48:44 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3214</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3214</guid>
			<description>&lt;p&gt;Captain-sensible: /* Writing the SlackBuild script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
 Those that really know what they are doing are unlikely to need to read this document; as a noob I've read through and  successfully created a slackbuild and package.Some of the text needs updating,which i will have a go at in the knowledge that it should be able to be reversed via the history data. I will update from the perspective that a noob is reading and they may need some spoon feeding!  &lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 $  tar xvzf latex2html-2019.2.tar.gz || exit 1 &lt;br /&gt;
&lt;br /&gt;
 x -extract&lt;br /&gt;
 v -verbose&lt;br /&gt;
 f -file &lt;br /&gt;
 z -basically ungzip&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license.For the sake of brevity an example has been put on discussion page ), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=${VERSION:-2019-2}&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 # Automatically determine the architecture we're building on:&lt;br /&gt;
 if [ -z &amp;quot;$ARCH&amp;quot; ]; then&lt;br /&gt;
  case &amp;quot;$( uname -m )&amp;quot; in&lt;br /&gt;
    i?86) ARCH=i486 ;;&lt;br /&gt;
    arm*) ARCH=arm ;;&lt;br /&gt;
    # Unless $ARCH is already set, use uname -m for all other archs:&lt;br /&gt;
       *) ARCH=$( uname -m ) ;;&lt;br /&gt;
  esac&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
  if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i686&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -march=i686 -mtune=i686&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;64&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
  SLKCFLAGS=&amp;quot;-O2&amp;quot;&lt;br /&gt;
  LIBDIRSUFFIX=&amp;quot;&amp;quot;&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;/div&gt;</description>
			<pubDate>Tue, 18 Jun 2019 09:46:31 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Talk:Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Talk:Writing_A_SlackBuild_Script&amp;diff=3213</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Talk:Writing_A_SlackBuild_Script&amp;diff=3213</guid>
			<description>&lt;p&gt;Captain-sensible: using page mainly as appendix to main slackbuild doc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
 in a recent post on linux.org someone asked how to go about writing a slackbuild script. I thought I would follow this documentation &amp;amp; see how things worked out. I successfully wrote slackbuild and got package visible in /var/log/packages as: /var/log/packages/latex2html-2019.2-i486-1_arb&lt;br /&gt;
&lt;br /&gt;
Example  GNU general public licence &lt;br /&gt;
&lt;br /&gt;
Slackware build script latex2html&lt;br /&gt;
converts latex docs to html &lt;br /&gt;
Copyright (C) 2019  &amp;lt;name&amp;gt;      &amp;lt;email&amp;gt; &lt;br /&gt;
This program is free software: you can redistribute it and/or modify&lt;br /&gt;
it under the terms of the GNU General Public License as published by&lt;br /&gt;
the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
(at your option) any later version.&lt;br /&gt;
This program is distributed in the hope that it will be useful,&lt;br /&gt;
but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
GNU General Public License for more details.&lt;br /&gt;
You should have received a copy of the GNU General Public License&lt;br /&gt;
along with this program.  If not, see &amp;lt;https://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
--[[User:Captain-sensible|Captain-sensible]] ([[User talk:Captain-sensible|talk]]) 09:22, 18 June 2019 (UTC)--[[User:Captain-sensible|Captain-sensible]] ([[User talk:Captain-sensible|talk]]) 09:22, 18 June 2019 (UTC)&lt;/div&gt;</description>
			<pubDate>Tue, 18 Jun 2019 09:22:20 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3212</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3212</guid>
			<description>&lt;p&gt;Captain-sensible: /* Initial Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
 Those that really know what they are doing are unlikely to need to read this document; as a noob I've read through and  successfully created a slackbuild and package.Some of the text needs updating,which i will have a go at in the knowledge that it should be able to be reversed via the history data. I will update from the perspective that a noob is reading and they may need some spoon feeding!  &lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 $  tar xvzf latex2html-2019.2.tar.gz || exit 1 &lt;br /&gt;
&lt;br /&gt;
 x -extract&lt;br /&gt;
 v -verbose&lt;br /&gt;
 f -file &lt;br /&gt;
 z -basically ungzip&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license.For the sake of brevity an example has been put on discussion page ), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=2002-2-1 	&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
 ARCH=${ARCH:-i486} # the architecture on which you want to build your package	&lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
 if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;/div&gt;</description>
			<pubDate>Tue, 18 Jun 2019 09:13:18 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3211</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3211</guid>
			<description>&lt;p&gt;Captain-sensible: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
 Those that really know what they are doing are unlikely to need to read this document; as a noob I've read through and  successfully created a slackbuild and package.Some of the text needs updating,which i will have a go at in the knowledge that it should be able to be reversed via the history data. I will update from the perspective that a noob is reading and they may need some spoon feeding!  &lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 $  tar xvzf latex2html-2019.2.tar.gz || exit 1 &lt;br /&gt;
&lt;br /&gt;
 x -extract&lt;br /&gt;
 v -verbose&lt;br /&gt;
 f -file &lt;br /&gt;
 z -basically ungzip&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=2002-2-1 	&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
 ARCH=${ARCH:-i486} # the architecture on which you want to build your package	&lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
 if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;/div&gt;</description>
			<pubDate>Tue, 18 Jun 2019 08:21:07 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3210</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3210</guid>
			<description>&lt;p&gt;Captain-sensible: /* Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 $  tar xvzf latex2html-2019.2.tar.gz || exit 1 &lt;br /&gt;
&lt;br /&gt;
 x -extract&lt;br /&gt;
 v -verbose&lt;br /&gt;
 f -file &lt;br /&gt;
 z -basically ungzip&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=2002-2-1 	&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
 ARCH=${ARCH:-i486} # the architecture on which you want to build your package	&lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
 if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;/div&gt;</description>
			<pubDate>Mon, 17 Jun 2019 10:36:28 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3209</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Writing_A_SlackBuild_Script&amp;diff=3209</guid>
			<description>&lt;p&gt;Captain-sensible: /* Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
 Originally written by Florian Mueller jjdm@jjdm.org&lt;br /&gt;
 Substantial cleanup and enhancement by Robby Workman (rworkman)&lt;br /&gt;
&lt;br /&gt;
If you use slackware as your main operating system, you have probably wanted to install quite a few applications which are not available in the official slackware.com or even third-party repositories like pkgs.org, or perhaps you just don't like using third-party packages.  In this situation, you have several options on how to install the application:&lt;br /&gt;
&lt;br /&gt;
 * ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
 * use checkinstall&lt;br /&gt;
 * use installwatch&lt;br /&gt;
 * compile and use makepkg by hand&lt;br /&gt;
 * write a SlackBuild script&lt;br /&gt;
&lt;br /&gt;
I will go through the last option: writing [[SlackBuild Scripts]] (which combines the best qualities of all the other aforementioned methods). With a SlackBuild script, you have the build process automated, which will allow you to easily do later upgrades or patches to the package. SlackBuild scripts are also the method by which Patrick Volkerding builds all of the official packages for Slackware. If you look at the various scripts from different sources, you will notice that there is generally an application-independent portion of a script and an application-specific portion of the script.&lt;br /&gt;
&lt;br /&gt;
I cannot teach you how to build the &amp;quot;perfect&amp;quot; package, as reaching that goal requires fairly in-depth knowledge of the Slackware operating system.  You must consider the interactions of your proposed package with all of the other packages within the distribution; they must be integrated seamlessly.  What I can teach you is how to build a package that works and which stays true to the &amp;quot;Slackware Way.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;But it takes so much time!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will take approximately thirty minutes to go through this tutorial and about fifteen minutes to create each package (actual compile process not included), but the time you save in the future (you want to create a newer version of the package) makes the initial time expenditure worth it.&lt;br /&gt;
&lt;br /&gt;
= The Slackware package structure =&lt;br /&gt;
&lt;br /&gt;
See [[Packages#Slackware Package Layout]]&lt;br /&gt;
&lt;br /&gt;
= Setting up your build environment =&lt;br /&gt;
&lt;br /&gt;
See [[Build_Environment]] for examples of how various users do this.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Hopefully, everything is now clear about Slackware package structure, and you have set up a clean build environment, so we'll begin the process of building a package with a SlackBuild script.&lt;br /&gt;
&lt;br /&gt;
For this example, we'll create a package of latex2html - I made my homepage with that tool.&lt;br /&gt;
&lt;br /&gt;
First, you have to create a directory named &amp;lt;build_environment&amp;gt;/latex2html/. Get the most recent source code release of latex2html place it in this directory.  Note that use of wget below to obtain the most recent source code is optional - you can just as well use your favorite web browser to download it, and then move it into the correct directory.&lt;br /&gt;
&lt;br /&gt;
 $ cd &amp;lt;build_environment&amp;gt;&lt;br /&gt;
 $ mkdir latex2html&lt;br /&gt;
 $ cd latex2html&lt;br /&gt;
 $ wget  -O latex2html-2019.2.tar.gz [https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz] #6 th June 2019 release&lt;br /&gt;
 &lt;br /&gt;
Next, we'll create some other needed files with touch.  If you're not familiar with touch, see:&lt;br /&gt;
 man touch&lt;br /&gt;
Note that the *.SlackBuild file will always contain the name of the application for which it's written; for example, gaim would have gaim.SlackBuild.&lt;br /&gt;
&lt;br /&gt;
 $ touch latex2html.SlackBuild&lt;br /&gt;
 $ touch slack-desc&lt;br /&gt;
&lt;br /&gt;
Extract the source code of the application, because we'll need to look at the configure script later on to determine what options we need to pass to it.&lt;br /&gt;
&lt;br /&gt;
 $ tar -xzf latex2html-2002-2-1.tar.gz || exit 1&lt;br /&gt;
&lt;br /&gt;
= Writing the slack-desc file =&lt;br /&gt;
&lt;br /&gt;
See this [[Slack-desc]] page on SlackWiki.org for instructions on how to write a proper slack-desc file.&lt;br /&gt;
&lt;br /&gt;
= Writing the SlackBuild script =&lt;br /&gt;
&lt;br /&gt;
This is the section which takes the most time, and I'll go through it with you step by step.  When you build more packages, you'll probably be able to just copy an existing SlackBuild script and customize it. First, you need to understand that you can write your SlackBuild script in any manner you choose so long as it creates a working package; the method described here is more or less the way Pat Volkerding [[http://slackware.com/~volkerdi]] does it, but even Pat has several different styles for writing the official SlackBuild scripts.  Therefore, if you see something you would do a different way, feel free to do it that way - it's okay.&lt;br /&gt;
&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
Open the file latex2html.SlackBuild with your favourite editor.  What follows below is a piece by piece walk-through of a working SlackBuild script.  You may certainly paste the exact contents of those pieces, but in the author's opinion, you have a better chance of understanding it if you write everything yourself.&lt;br /&gt;
&lt;br /&gt;
First, you'll need to set your shell interpreter.  This should be /bin/sh, as *every* Slackware system is guaranteed to have this shell installed, and you want maximum portability.  For this same reason, be careful not to use any extensions and/or syntax that is customized for your particular shell (bash, zsh, or whatever), as it won't be interpreted correctly.  The '-e' flag tells the shell to exit on any error; this helps with both debugging your script as well as ensuring your script does not proceed in an unknown state.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh -e&lt;br /&gt;
&lt;br /&gt;
You might want to include a license of some sort with your SlackBuild script (preferably a GPL or BSD-style license), but at a minimum, you'll want something like this:&lt;br /&gt;
&lt;br /&gt;
 #&amp;lt;your name&amp;gt; revision date yyyy/mm/dd&lt;br /&gt;
&lt;br /&gt;
With the next few lines, we set some variables that will be used throughout the script. First is the &amp;quot;CWD&amp;quot; variable; in our case, CWD will be &amp;lt;build_environment&amp;gt;/latex2html/. We also test if the TMP variable is set, and if not, we set it to /tmp.&lt;br /&gt;
&lt;br /&gt;
 #Set initial variables:	&lt;br /&gt;
 &lt;br /&gt;
 CWD=$(pwd)&lt;br /&gt;
 if [ &amp;quot;$TMP&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
   TMP=/tmp&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Some people like to build in a subdirectory of /tmp (such as /tmp/build), but that's up to you.&lt;br /&gt;
 &lt;br /&gt;
 # The version which appears in the application's filename&lt;br /&gt;
 VERSION=2002-2-1 	&lt;br /&gt;
 &lt;br /&gt;
 # If the version conflicts with the Slackware package standard&lt;br /&gt;
 # The dash character (&amp;quot;-&amp;quot;) is not allowed in the VERSION string&lt;br /&gt;
 # You can set the PKG_VERSION to something else than VERSION&lt;br /&gt;
 PKG_VERSION=2002.2.1 # the version which appears in the package name. &lt;br /&gt;
 &lt;br /&gt;
 ARCH=${ARCH:-i486} # the architecture on which you want to build your package	&lt;br /&gt;
 &lt;br /&gt;
 # First digit is the build number, which specifies how many times it has been built.	&lt;br /&gt;
 # Second string is the short form of the authors name, typical three initials:w&lt;br /&gt;
 BUILD=${BUILD:-1_rlw}&lt;br /&gt;
 &lt;br /&gt;
 # The application's name&lt;br /&gt;
 APP=latex2html&lt;br /&gt;
 &lt;br /&gt;
 # The installation directory of the package (where its actual directory&lt;br /&gt;
 # structure will be created) &lt;br /&gt;
 PKG=$TMP/package-$APP&lt;br /&gt;
&lt;br /&gt;
Set SLKCFLAGS (which will be used for both CFLAGS and CXXFLAGS).  If you are building on a system with an earlier version of gcc than 3.4.x, then you'll need to use &amp;quot;-mcpu&amp;quot; instead of &amp;quot;-mtune&amp;quot; below.&lt;br /&gt;
&lt;br /&gt;
 if [ &amp;quot;$ARCH&amp;quot; = &amp;quot;i486&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -march=i486 -mtune=i686&amp;quot;&lt;br /&gt;
  elif [ &amp;quot;$ARCH&amp;quot; = &amp;quot;x86_64&amp;quot; ]; then&lt;br /&gt;
   SLKCFLAGS=&amp;quot;-O2 -fPIC&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
The section just finished sets up a few application-specific variables. When you want to create a package of some other application, you can usually just change the variables, and most of the further steps will work automatically.&lt;br /&gt;
&lt;br /&gt;
=== Extract Sources ===&lt;br /&gt;
&lt;br /&gt;
 # Delete the leftover directories if they exist (due to a previous build)&lt;br /&gt;
 # and (re)create the packaging directory&lt;br /&gt;
 rm -rf $PKG &lt;br /&gt;
 mkdir -p $TMP $PKG&lt;br /&gt;
 rm -rf $TMP/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Change to the TMP directory&lt;br /&gt;
 cd $TMP || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Extract the application source in TMP&lt;br /&gt;
 # Note: if your application comes as a tar.bz2, you need tar -jxvf&lt;br /&gt;
 tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1&lt;br /&gt;
 &lt;br /&gt;
 # Change to the application source directory&lt;br /&gt;
 cd $APP-$VERSION || exit 1&lt;br /&gt;
  &lt;br /&gt;
 # Change ownership and permissions if necessary&lt;br /&gt;
 # This may not be needed in some source tarballs, but it never hurts&lt;br /&gt;
 chown -R root:root .&lt;br /&gt;
 chmod -R u+w,go+r-w,a-s .&lt;br /&gt;
&lt;br /&gt;
===Configure and Compile Sources===&lt;br /&gt;
&lt;br /&gt;
 # Set configure options&lt;br /&gt;
 # If your app is written in C++, you'll also need to add a line for CXXFLAGS&lt;br /&gt;
 CFLAGS=&amp;quot;$SLKCFLAGS&amp;quot; \&lt;br /&gt;
   ./configure \&lt;br /&gt;
   --prefix=/usr \&lt;br /&gt;
   --sysconfdir=/etc \&lt;br /&gt;
   --localstatedir=/var \&lt;br /&gt;
   --with-perl=/usr/bin/perl \&lt;br /&gt;
   --enable-eps \&lt;br /&gt;
   --enable-gif \&lt;br /&gt;
   --enable-png \&lt;br /&gt;
   --build=$ARCH-slackware-linux \&lt;br /&gt;
   --host=$ARCH-slackware-linux &lt;br /&gt;
 &lt;br /&gt;
 # compile the source, but exit if anything goes wrong&lt;br /&gt;
 make || exit&lt;br /&gt;
  &lt;br /&gt;
 # Install everything into the package directory, but exit if anything goes wrong&lt;br /&gt;
 make install DESTDIR=$PKG || exit&lt;br /&gt;
&lt;br /&gt;
There are three configure options I always set:&lt;br /&gt;
&lt;br /&gt;
* --prefix=/usr&lt;br /&gt;
* --sysconfdir=/etc&lt;br /&gt;
* --localstatedir=/var&lt;br /&gt;
&lt;br /&gt;
This makes configuration files go to /etc, state files (such as log files) go to /var, and the rest goes to /usr. That's the usual Slackware way, but it's your system, so you can certainly install everything in /usr/local or some other location.  See the Unix Filesystem Hierarchy Standard [[http://www.pathname.com/fhs/]] for more information on &amp;quot;correct&amp;quot; locations of various filetypes.&lt;br /&gt;
&lt;br /&gt;
You notice that there were several other options passed to the configure script, and for each application you compile, you have to figure those out for yourself - that's why you were told to extract the sources earlier in this process.  You simply cd into the source directory and run:&lt;br /&gt;
 ./configure --help&lt;br /&gt;
This will produce a page or two (sometimes more, though) of information about various options that are specific to the application.  Read through this information and figure out what you need (I like to pipe that command through lpr to get a printed copy, but you can certainly use some sort of pager as well:&lt;br /&gt;
 ./configure --help | lpr&lt;br /&gt;
 ./configure --help | less&lt;br /&gt;
&lt;br /&gt;
The DESTDIR variable is very important in this script because it specifies the directory in which the files should be installed.  This should always be our package directory ($PKG).  Unfortunately, some applications' Makefiles will not support the DESTDIR variable, so you can't use it for those apps.  A simple line like this:&lt;br /&gt;
 grep DESTDIR Makefile*&lt;br /&gt;
while inside the source directory should tell you whether it supports DESTDIR or not.  If you get some lines of output with $DESTDIR in them, you're in good shape.  If the command returns no output, then the Makefile does not support the DESTDIR variable.&lt;br /&gt;
&lt;br /&gt;
Here's a piece of advice: ALWAYS go through the ./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install DESTDIR=/somedir process manually and as a NORMAL USER account BEFORE you run your SlackBuild script.  There are quite a few applications out there which try to do &amp;quot;funny stuff&amp;quot; during the installation phase.&lt;br /&gt;
 For example, apcupsd will attempt to patch your /etc/rc.d/rc.6 init script&lt;br /&gt;
 Yes, it's possible to avoid this with a configure option, but it's not obvious that you would need&lt;br /&gt;
 to do so until you look at all of the Makefiles for apcupsd (or watch the install process)&lt;br /&gt;
Anyway, if you go through the process as a normal user, you will get &amp;quot;Permission Denied&amp;quot; errors and such if the install process tries to write anywhere it's not allowed to do so.&lt;br /&gt;
&lt;br /&gt;
=== Install Documentation ===&lt;br /&gt;
&lt;br /&gt;
 # Create a directory for documentation&lt;br /&gt;
 mkdir -p $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 &lt;br /&gt;
 # Copy documentation to the docs directory and fix permissions&lt;br /&gt;
 cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION&lt;br /&gt;
 find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;&lt;br /&gt;
&lt;br /&gt;
I (rworkman) also like to place a copy of my SlackBuild script in this directory&lt;br /&gt;
 cat $CWD/$APP.SlackBuild &amp;gt; $PKG/usr/doc/$APP-$VERSION/$APP.SlackBuild&lt;br /&gt;
&lt;br /&gt;
Make sure you look inside the actual source archive of the application, because some applications won't have all of the documentation files specified above, and some applications will have additional files.  In other words, don't just copy/paste what you see above into your SlackBuild script - you *must* customize this section for each individual application.&lt;br /&gt;
&lt;br /&gt;
=== Final Touches ===&lt;br /&gt;
&lt;br /&gt;
 # Create the ./install directory and copy the slack-desc into it&lt;br /&gt;
 mkdir -p $PKG/install&lt;br /&gt;
 cat $CWD/slack-desc &amp;gt; $PKG/install/slack-desc&lt;br /&gt;
&lt;br /&gt;
NOTE: In some cases, you will have some sort of command or setup that&lt;br /&gt;
needs to run after the package contents are installed - for this, you&lt;br /&gt;
would add a file to $CWD called &amp;quot;doinst.sh&amp;quot; which contains the needed&lt;br /&gt;
commands, and then compress that file with gzip.  The SlackBuild script&lt;br /&gt;
will zcat (which means to gunzip and cat its contents) that file and &lt;br /&gt;
write the output to a doinst.sh file in the $PKG/install directory.&lt;br /&gt;
&lt;br /&gt;
 # Add doinst.sh to package (if it exists)&lt;br /&gt;
 if [ -e $CWD/doinst.sh.gz ]; then&lt;br /&gt;
   zcat $CWD/doinst.sh.gz &amp;gt; $PKG/install/doinst.sh&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Let's conserve space if we can; strip libraries and binaries and compress man pages with gzip&lt;br /&gt;
Note that you might be able to use &amp;quot;make install-strip&amp;quot; instead of &amp;quot;make install&amp;quot; above instead to accomplish the same purpose&lt;br /&gt;
&lt;br /&gt;
 # Strip some libraries and binaries&lt;br /&gt;
 ( cd $PKG&lt;br /&gt;
    find . | xargs file | grep &amp;quot;executable&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
    find . | xargs file | grep &amp;quot;shared object&amp;quot; | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2&amp;gt; /dev/null&lt;br /&gt;
 )&lt;br /&gt;
 &lt;br /&gt;
 # Compress man pages if they exist&lt;br /&gt;
 if [ -d $PKG/usr/man ]; then&lt;br /&gt;
   ( cd $PKG/usr/man&lt;br /&gt;
   find . -type f -exec gzip -9 {} \;&lt;br /&gt;
   for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done&lt;br /&gt;
   ) &lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Compress info pages if they exist (and remove the dir file)&lt;br /&gt;
 if [ -d $PKG/usr/info ]; then&lt;br /&gt;
   gzip -9 $PKG/usr/info/*.info&lt;br /&gt;
   rm -f $PKG/usr/info/dir&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
=== Build the Package ===&lt;br /&gt;
&lt;br /&gt;
 # Build the package&lt;br /&gt;
 cd $PKG&lt;br /&gt;
 /sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz&lt;br /&gt;
&lt;br /&gt;
= Other Concerns =&lt;br /&gt;
&lt;br /&gt;
=== DESTDIR Option Not Available ===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, there are quite a few applications whose Makefiles do not support the DESTDIR option for make install.  On some applications the DESTDIR Makefile variable has another name.  For example, some Qt applications use the variable INSTALL_ROOT for the same purpose.  If you can understand Makefiles, it is probably worth your time to take a look at its contents and try to find out which actions are performed in the install rule.  Sometimes there will be no DESTDIR equivalent at all.  The &amp;lt;strong&amp;gt;best&amp;lt;/strong&amp;gt; thing you can do in this situation is write a patch for the Makefile.in or equivalent, and submit it to the developer(s) for inclusion in the source, but I realize that everyone doesn't have the ability to do that.  The second best thing you can do it write to the developer(s) and ask them to include that functionality in future releases.  In the meantime, here are some thoughts on the subject...&lt;br /&gt;
&lt;br /&gt;
==== Example 1: ====&lt;br /&gt;
Configure the build with:&lt;br /&gt;
 ./configure --prefix=$PKG/usr&lt;br /&gt;
along with your other configure options.  This will install *all* of the package contents in that directory.  If the package creates $PKG/usr/etc and $PKG/usr/var directories (or any other directories that should be elsewhere), you can probably just move them to their correct location within the package directory tree and everything will be fine.  You might also try this along with your other configure options.&lt;br /&gt;
 ./configure --prefix=$PKG/usr \&lt;br /&gt;
    --sysconfdir=$PKG/etc \&lt;br /&gt;
    --localstatedir=$PKG/var &lt;br /&gt;
There are some applications, however, which &amp;quot;hard-code&amp;quot; configuration files based on configure/Makefile parameters.  In those cases, you'll have to figure out a way to patch the config file prior to packaging it, or in worst-case scenario, include instructions for the end user on how to make the necessary changes.&lt;br /&gt;
&lt;br /&gt;
==== Example 2: ====&lt;br /&gt;
This example makes use of the ability to override any Makefile variable, which is called a '''macro''' in the Makefile terminology, on the command line and not have to worry about patching the Makefile to include a '''DESTDIR''' macro in the Makefile.  This approach makes it a bit easier for those not familiar with Makefiles.&lt;br /&gt;
&lt;br /&gt;
If the Makefile does not honor '''DESTDIR''' for the 'make install' command, you can change the prefix macro, instead:&lt;br /&gt;
 make prefix=$PKG/usr install&lt;br /&gt;
This will override the $(prefix) variable inside the Makefile and install to the location you supplied on the command line.  Therefore, you can configure with the standard ''./configure --prefix=/usr'' (or ''./configure --prefix=/usr/local'') syntax, yet install to a different location as if you supplied a ''DESTDIR=$PKG/usr'' for the 'make install' command.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Macro names are case-sensitive (at least for GNU make).  Some Makefiles may use a &amp;quot;'''PREFIX ='''&amp;quot; macro instead of the usual &amp;quot;'''prefix ='''&amp;quot;, so the 'make install' command would look like this:&lt;br /&gt;
 make PREFIX=$PKG/usr install&lt;br /&gt;
Therefore, it's necessary to look inside the Makefile to be sure which form was used for the prefix.  For large, complex makefiles, the easiest way is to 'grep' the Makefile, like so:&lt;br /&gt;
 grep -i '^prefix \?=' Makefile{,.in}&lt;br /&gt;
The ''-i'' option makes the search case-insensitive and the ''{,.in}'' part at the end will search &amp;quot;Makefile&amp;quot; or &amp;quot;Makefile.in&amp;quot; files, the second one being a template for the &amp;quot;configure&amp;quot; script.  Grep's search term is a basic regular expression, so the escaped question mark after the space (\?) means there may or may not be a space in between when searching.&lt;br /&gt;
&lt;br /&gt;
Once in a while, there may be a &amp;quot;'''PREFIX ='''&amp;quot; in a Makefile that is not defined which you are to edit and supply the location. Use the usual ''/usr'' (or ''/usr/local''), in this case, and then use 'make PREFIX=$PKG/usr install' to install to the package's build location.&lt;br /&gt;
&lt;br /&gt;
=== Patching the Sources ===&lt;br /&gt;
&lt;br /&gt;
Sooner or later, there will be some reason to patch the source code prior to building a package, and you'll want to be able to do this automatically.  &lt;br /&gt;
&lt;br /&gt;
===== Obtaining the Patch =====&lt;br /&gt;
&lt;br /&gt;
In most cases, the patch will be provided by the author of the source code, so we're not going to discuss patch *creation* here.  Download the patch and place it in the same directory as the SlackBuild script, slack-desc file, and other related files (in $CWD from above).&lt;br /&gt;
 $ wget http://someapplication.org/files/patches/bigsecuritypatch.diff&lt;br /&gt;
It's not necessary to do the next step, but because developers generally want to conserve space if possible, it's conventional to do this:&lt;br /&gt;
 $ gzip -9 bigsecuritypatch.diff&lt;br /&gt;
This will result in a new file called bigsecuritypatch.diff.gz -- we'll use that in the SlackBuild script in just a moment.&lt;br /&gt;
&lt;br /&gt;
===== Applying the Patch =====&lt;br /&gt;
&lt;br /&gt;
You will now need to edit your &amp;lt;application&amp;gt;.SlackBuild script so that it applies the patch before it runs configure, make, and make install.  To do this, you'll want something like this to run before the configure script, but after extracting the sources:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p1 || exit&lt;br /&gt;
Depending on how the patch was created, you might use a different patchlevel on that line, as in:&lt;br /&gt;
 zcat $CWD/bigsecuritypatch.diff.gz | patch -p0 || exit&lt;br /&gt;
It's a bit beyond the scope of this HOWTO, but essentially, the -p# specifies the number of trailing directories to skip when looking for the file to patch.  You'll often need to skip the top-level directory, but not always (hence the -p0).&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[SlackBuild_Scripts]]&lt;br /&gt;
* [[Different_Approach_To_Buildscripts]]&lt;br /&gt;
* [[Building_A_Package]]&lt;br /&gt;
* [[Slack-desc]]&lt;br /&gt;
* [[Checkinstall]]&lt;br /&gt;
* [[Compiling]]&lt;br /&gt;
&lt;br /&gt;
= SlackBuild Script Repositories =&lt;br /&gt;
&lt;br /&gt;
;* http://slackbuilds.org&lt;br /&gt;
;* http://www.slackware.com/~alien/slackbuilds/&lt;br /&gt;
;* http://slackbuilds.slackadelic.com/&lt;br /&gt;
;* http://slackbuilds.rlworkman.net/&lt;/div&gt;</description>
			<pubDate>Sun, 16 Jun 2019 19:33:45 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
		<item>
			<title>Talk:Writing A SlackBuild Script</title>
			<link>https://www.slackwiki.com/index.php?title=Talk:Writing_A_SlackBuild_Script&amp;diff=3208</link>
			<guid isPermaLink="false">https://www.slackwiki.com/index.php?title=Talk:Writing_A_SlackBuild_Script&amp;diff=3208</guid>
			<description>&lt;p&gt;Captain-sensible: maybe document needs updating&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
 in a recent post on linux.org someone asked how to go about writing a slackbuild script. I thought I would follow this documentation &amp;amp; see how things worked out.&lt;br /&gt;
&lt;br /&gt;
The most recent release on github is v2019.2 release date 6th June 2o19. Thus i edited wget link to that download.&lt;br /&gt;
&lt;br /&gt;
I've tested $ wget   -O   latex2html-2019.2.tar.gz      https://github.com/latex2html/latex2html/archive/v2019.2.tar.gz  and it downloads the tar.gz to my home folder with the name latex2html-2019.2.tar.gz. &lt;br /&gt;
&lt;br /&gt;
Also i have successfully created a package latex2html-2019.2-i486-1_SBo.tgz which launched on my 14.2 32 bit slackware box.&lt;br /&gt;
&lt;br /&gt;
Now when it came to the actual slackbuild file i used, i tried different approaches including Alien slackbuild kit , mksb and another.&lt;br /&gt;
&lt;br /&gt;
Eventually i downloaded latex2html from slackbuild.org for slackware 13 or thereabouts and edited it.&lt;br /&gt;
&lt;br /&gt;
Since this slackbuild document references latex2html  my thinking is that to further help understand a slackbuild maybe the actual slackbuild for latex would be dissected with explanation.&lt;/div&gt;</description>
			<pubDate>Sun, 16 Jun 2019 19:23:43 GMT</pubDate>
			<dc:creator>Captain-sensible</dc:creator>
			<comments>https://www.slackwiki.com/Talk:Writing_A_SlackBuild_Script</comments>
		</item>
</channel></rss>