[Slackbuilds-users] ARCH determination

B. Watson urchlay at slackware.uk
Wed Jul 15 10:39:03 UTC 2026



On Wed, 15 Jul 2026, Marco Moock wrote:

> Hello!
>
> Various SlackBuilds include something like this:
>
> # Automatically determine the architecture we're building on:
> if [ -z "$ARCH" ]; then
> case "$( uname -m )" in
>   i?86) ARCH=i486 ;;
>   arm*) ARCH=arm ;;
>   # Unless $ARCH is already set, use uname -m for all other archs:
>      *) ARCH=$( uname -m ) ;;
> esac
> fi

That's old template. You can tell because it uses i486. The new template
lives here:

https://git.slackbuilds.org/templates/

> Which purpose does it have?

Mostly, it affects the compiler flags, and the location of the library
directory (/usr/lib/ on 32-bit, /usr/lib64/ on 64-bit).

A bit later in the slackbuild, you should something similar to:

if [ "$ARCH" = "i586" ]; then
   SLKCFLAGS="-O2 -march=i586 -mtune=i686"
   LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
   SLKCFLAGS="-O2 -march=i686 -mtune=i686"
   LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
   SLKCFLAGS="-O2 -fPIC"
   LIBDIRSUFFIX="64"
elif [ "$ARCH" = "aarch64" ]; then
   SLKCFLAGS="-O2 -fPIC"
   LIBDIRSUFFIX="64"
else
   SLKCFLAGS="-O2"
   LIBDIRSUFFIX=""
fi

LIBDIRSUFFIX gets fed to the ./configure (or cmake, meson, etc)
command to tell it where to install shared libraries. SLKCFLAGS
is fed in to set the compiler flags.

For some builds, LIBDIRSUFFIX isn't used, and sometimes it gets removed
from the section of code that sets it.

For some builds, there's no compiled code at all. Those, we get rid
of all the code that sets ARCH, SLKCFLAGS, and LIBDIRSUFFIX... and
put ARCH=noarch at the top of the script. Examples of this would
be software that's just shell scripts (rtirq), or just data files
(e.g. doom_shareware_data).

> I understand that defining an architecture is sometimes used to produce 
> builds specific for a CPU (e.g. to use x86_64-v3 instructions etc.).

We generally don't do that. If you were to set ARCH to a weird value, it
would be caught by the "else" in the code above, and the compiler flags
would be set to -O2, and libraries would go in /usr/lib.

> Although, which purpose do the other values have?
> $ARCH is not set by default.
> If it gets the value of uname -m, that should be fine, or is that guess 
> wrong?

Well, uname -m might be either i586 or i686 on 32-bit platforms. We
allow overriding it in the environment in case you're compiling a
package on an i686 machine, but you're going to install it on an i586
(maybe it's old and slow, or doesn't have enough RAM to do the compile
itself).

Hopefully this explains it.


More information about the SlackBuilds-users mailing list