aboutsummaryrefslogtreecommitdiff
path: root/libraries/atlas/atlas.SlackBuild
blob: b6d9977d11a83a7f58d187d8ab224dbfc9ad86d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/bin/bash

# Slackware build script for ATLAS

# Copyright 2010-2016 Serban Udrea <s.udrea@gsi.de>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification,
# is permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=atlas
VERSION=${VERSION:-3.10.3}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH="$( uname -m )" ;;
  esac
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
  BITSize="32" # Specifically for ATLAS
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
  BITSize="32" # Specifically for ATLAS
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
  BITSize="64" # Specifically for ATLAS
fi

# If you don't want to use architectural defaults set the following to
# something like "no".
#
USE_ARCH_DEFAULTS=${USE_ARCH_DEFAULTS:-yes}

# If you decide to use arch defaults and have some custom ones you may
# set the following variable to point to the directory containing these.
#
# If you decide to not use arch defauts and wish to create some after a build
# with full search, set the following variable to point to the directory where
# the file containing them should be placed.
# IMPORTANT: In this case, the file copied to ARCH_DEF_DIR will not be part of
#            the ATLAS package, to avoid problems in case of an upgrade on the
#            same machine. The value of ARCH_DEF_DIR will be written for your
#            reference to the file named ARCH_DEF_DIR within the doc directory
#            of ATLAS.
#
ARCH_DEF_DIR=${ARCH_DEF_DIR:-""}

# If you are on another architecture than x86 and/or don't use gcc you need to
# set the following variable to "yes".
#
USE_DWALL=${USE_DWALL:-no}

# You may wish to set the level 2 cache size to the proper value. The default
# is to deduce it from /proc/cpuinfo
#
L2_CACHE_SIZE=${L2_CACHE_SIZE:-"auto"}

if [ "$L2_CACHE_SIZE" = "auto" ]; then
  L2_CACHE_SIZE="$(cat /proc/cpuinfo |grep "cache size"| head -n 1| cut -d ":" -s -f2| cut -d " " -s -f2)"
  L2_SIZE_UNIT="$(cat /proc/cpuinfo |grep "cache size"| head -n 1| cut -d " " -s -f4)"
  case "$L2_SIZE_UNIT" in
      "KB") L2_CACHE_SIZE=$(($L2_CACHE_SIZE * 1024))
            ;;
      "MB") L2_CACHE_SIZE=$(($L2_CACHE_SIZE * 1024 *  1024))
            ;;
      "GB") L2_CACHE_SIZE=$(($L2_CACHE_SIZE * 1024 *  1024 * 1024))
            ;;
  esac
fi

# Check the value of L2_CACHE_SIZE
#
case "$L2_CACHE_SIZE" in
    ''|'0'|*[!0-9]*) echo "ERROR: The value of L2_CACHE_SIZE is not a strictly positive integer!"
                     exit 1
                     ;;
esac

# Set the (maximum) number of threads. If this is 0 just the serial libs get
# built, even on an SMP machine. By default it's set to -1 for autodetection.
#
NUM_THREADS=${NUM_THREADS:-"-1"}
case "$NUM_THREADS" in
           '-1'|'0') echo -n # Do nothing
                     ;;
                '1') NUM_THREADS="0" # One processor => no threading
                     ;;
        ''|*[!0-9]*) echo "ERROR: NUM_THREADS has an improper value!"
                     exit 1
                     ;;
esac

if [ $NUM_THREADS -gt 1 ]; then
  # On SMP machines one may want to set the processors to be used (see
  # atlas_install.pdf, p. 13). By default the list of processor ID's is empty
  # which means that ATLAS may use whatever is available.
  # NOTE: This is incompatible with the autodetection of the number of threads.
  #       Therefore NUM_THREADS must be greater than 1.
  #
  USE_PROCESSORS=${USE_PROCESSORS:-""}
  if [ -z "$USE_PROCESSORS" ]; then
    MT_SWITCH="-t $NUM_THREADS"
  else
    MT_SWITCH="--force-tids=\"$NUM_THREADS $USE_PROCESSORS\""
  fi
else
  MT_SWITCH="-t $NUM_THREADS"
fi

# Decide upon building full LAPACK or not. Set LAPACK_SOURCE to the empty
# string, if you don't want a full LAPACK build.
#
LAPACK_SOURCE=${LAPACK_SOURCE:-"/usr/share/lapack-atlas/lapack.tgz"}
if [ -z "$LAPACK_SOURCE" ]; then
  echo
  echo "WARNING"
  echo "WARNING: No LAPACK source specified. Just the highly restricted LAPACK"
  echo "         offered by ATLAS will get compiled!"
  echo "WARNING"
  echo
  sleep 3
else
  tar -tf "$LAPACK_SOURCE" > /dev/null 2>&1 || \
  { echo "ERROR: Improper LAPACK source archive!" \
    && echo "       Please check $LAPACK_SOURCE" \
    && echo "       and set it properly! " \
    && exit 1; } # NOTE: Here we just test that we deal with a tar archive.
  LAPACK_SOURCE="--with-netlib-lapack-tarfile=$LAPACK_SOURCE"

  # Change the following to yes if you would like to run the tests for LAPACK.
  #
  TEST_LAPACK="${TEST_LAPACK:-no}"
  # Make Y or N out of yes, Yes, No, no, etc.
  #
  TEST_LAPACK=$(echo "$TEST_LAPACK"|cut -b 1|tr a-z A-Z)
fi

# Decide upon building shared libraries or not. By default we ask for shared
# libs too. If one doesn't want this, she has to just set SHARED_SWITCH to the
# empty string.
#
SHARED_SWITCH=${SHARED_SWITCH:-"--shared"}

# This is the timer to be used for LAPACK. If you stay with gfortran,
# presently the default compiler on Slackware, you can leave the value as is.
# Otherwise, please read LAPACK's make.inc.example for more informations.
#
LAPACK_TIMER="${LAPACK_TIMER:-INT_ETIME}"

# This is the system destination directory. When installing the
# package produced by this script, ATLAS's files will be written to
# $SYS_DESTDIR/include, $SYS_DESTDIR/include/atlas, $SYS_DESTDIR/lib
# or $SYS_DESTDIR/lib64 ond appropriate platforms, etc.
# Nevertheless, by default the documentation files go to
# /usr/doc/$PRGNAM-$VERSION. You may change this through the variable
# DEFAULT_DOCS, see below.
#
SYS_DESTDIR=${SYS_DESTDIR:-/usr}

# Check if SYS_DESTDIR is an absolute path. If not, exit with error.
# NOTE: The $ is used because echo adds a \n at the end of the string.
#
echo $SYS_DESTDIR | grep -vE '/\.\./|/\.\.$' | grep -qE '^/' || \
{ echo "ERROR: The system destination directory has no absolute path!" \
&& echo "       The value of SYS_DESTDIR is $SYS_DESTDIR" \
&& echo "       Please set it properly! " \
&& exit 1; }

# You may want to have the documentation files installed under
# $SYS_DESTDIR/doc/$PRGNAM-$VERSION not /usr/doc/$PRGNAM-$VERSION.
# To achieve this just set the following variable to something like
# "no".
#
DEFAULT_DOCS=${DEFAULT_DOCS:-yes}

# The build directory to be created within the source directory of
# ATLAS.
#
BLDdir="BuildDir"

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT

cd $TMP
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/${PRGNAM}${VERSION}.tar.bz2
mv ATLAS $PRGNAM-$VERSION
cd $PRGNAM-$VERSION
chown -R root:root .
find -L . \
 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  -o -perm 511 \) -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

# Set the proper value to USE_ARCH_DEFAULTS, and the proper value to the
# configure switch needed in case you want to use custom arch defaults.
#
ARCH_DIR_SWITCH=""
case "$USE_ARCH_DEFAULTS" in
  [yY]|[yY][eE]|[yY][eE][sS]) USE_ARCH_DEFAULTS="1"
                              [ -z "$ARCH_DEF_DIR" ] || \
                              ARCH_DIR_SWITCH="-Ss ADdir $ARCH_DEF_DIR"
                              ;;
                           *) USE_ARCH_DEFAULTS="0" ;;
esac

mkdir -p $BLDdir
cd $BLDdir

# Configure atlas.
#
case "$USE_DWALL" in
  [yY]|[yY][eE]|[yY][eE][sS])
                             # Here we assume that we aren't on a x86 machine
                             # and/or gcc isn't the compiler to be used.
                             #
                             ../configure   $SHARED_SWITCH \
                                          --prefix="$SYS_DESTDIR" \
                                            $LAPACK_SOURCE \
                                            $MT_SWITCH \
                                           -Si archdef "$USE_ARCH_DEFAULTS" \
                                            $ARCH_DIR_SWITCH \
                                           -b "$BITSize" -D c -DWALL
                             ;;
                           *)
                             # Here we assume that we are on a x86 machine
                             # (be it 32 or 64 bits) and gcc is the compiler
                             # to be used.
                             #
                             # Get the CPU frequency for good timing.
                             #
                             CPU_FREQ="$(cat /proc/cpuinfo |grep "cpu MHz"| head -n 1| cut -d ":" -s -f2| tr -d [:blank:])"
                             #
                             ../configure   $SHARED_SWITCH \
                                          --prefix="$SYS_DESTDIR" \
                                            $LAPACK_SOURCE \
                                            $MT_SWITCH \
                                           -Si archdef "$USE_ARCH_DEFAULTS" \
                                            $ARCH_DIR_SWITCH \
                                           -b "$BITSize" \
                                           -D c -DPentiumCPS="$CPU_FREQ"
                             ;;
esac

# NOTES ON SOME FLAGS FOR CONFIGURE
#
#  SHARED_SWITCH = "--shared" asks for building the shared libraries too
# -Si archdef "$USE_ARCH_DEFAULTS" means that we ignore or not architectural defaults depending
#   upon the value of "$USE_ARCH_DEFAULTS".
# -b "$BITSize" tells ATLAS about the platform's bitsize, 32 or 64.
# -D c -DPentiumCPS="$CPU_FREQ" is for achieving good timing on x86 platforms with gcc.
# -D c -DWALL is for achieving good timing on non x86 platforms and/or non gcc compilers

# Write the value of L2_CACHE_SIZE to Make.inc
#
sed -i -r Make.inc -e \
    "s%L2SIZE = -DL2SIZE=[0-9]+%L2SIZE = -DL2SIZE=$L2_CACHE_SIZE%"

# Allow for deprecated LAPACK routines to get build in case of a full LAPACK
# installation. Also set the LAPACK timer to the desired value and add
# -frecursive to the compile flags, since this should help avoid problems
# with some functions which seem otherwise to not be thread safe.
#
if [ "$LAPACK_SOURCE" ]; then
  sed -i  ./src/lapack/reference/make.inc.example -e \
      "s%^#MAKEDEPRECATED *=.*Yes%MAKEDEPRECATED = Yes%"
  sed -i  ./interfaces/lapack/F77/src/Makefile -e \
      "s%NONE%$LAPACK_TIMER%" -e \
      "s%F77FLAGS)@%F77FLAGS) -frecursive@%" -e \
      "s%F77NOOPT)@%F77NOOPT) -frecursive@%"
fi

make build
make check

# If parallel libraries have been compiled check them too.
#
if [ -f lib/libptcblas.a ]; then
  make ptcheck
fi

# If the full LAPACK got build one may wish to test it too.
#
if [ "$LAPACK_SOURCE" ]; then
  if [ "$TEST_LAPACK" = "Y" ]; then
    ( cd src/lapack/reference
      [ -e ./libtmglib.a ] || make tmglib
      # Some testers segfault when build with -frecursive if one doesn't
      # increase the stack size limit, thus it's better to remove this flag
      # from make.inc
      #
      sed -i make.inc -e "s%-frecursive%%"

      # Now we have to set the proper library paths. Here for the serial libs.
      #
      ATLAS_LIBS="../../../../../lib/libf77blas.a ../../../../../lib/libcblas.a"
      ATLAS_LIBS="$ATLAS_LIBS ../../../../../lib/libatlas.a"
      LAPACK_LIB="../../../lib/liblapack.a"

      sed -i make.inc -e \
      "s%^BLASLIB *=.*%BLASLIB = $ATLAS_LIBS%" -e \
      "s%^CBLASLIB *=.*%CBLASLIB =%" -e \
      "s%^LAPACKLIB *=.*%LAPACKLIB = $LAPACK_LIB%"

      # Perform the tests.
      #
      make lapack_testing

      # Put the test results together
      #
      tar czf TEST_SERIAL_RESULTS.tgz TESTING/*.out

      # If threaded libs got build, we repeat the tests with them.
      #
      if [ -e ../../../lib/libptlapack.a ]; then
        make cleantesting
        ATLAS_LIBS="../../../../../lib/libptf77blas.a"
        ATLAS_LIBS="$ATLAS_LIBS ../../../../../lib/libptcblas.a"
        ATLAS_LIBS="$ATLAS_LIBS ../../../../../lib/libatlas.a -lpthread"
        LAPACK_LIB="../../../lib/libptlapack.a"
        sed -i make.inc -e \
        "s%^BLASLIB *=.*%BLASLIB = $ATLAS_LIBS%" -e \
        "s%^LAPACKLIB *=.*%LAPACKLIB = $LAPACK_LIB%"
        make lapack_testing
        tar czf TEST_PT_RESULTS.tgz TESTING/*.out
      fi
    )
  fi
fi

make install DESTDIR=${PKG}${SYS_DESTDIR}

# The install script (sometimes) "forgets" about libptlapack.a
#
cp -ua lib/libptlapack.a ${PKG}${SYS_DESTDIR}/lib/ || true

find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true

# This is probably the easiest way to make sure that we install in the
# proper place.
#
if [ "$LIBDIRSUFFIX" ]; then
  mv ${PKG}${SYS_DESTDIR}/lib ${PKG}${SYS_DESTDIR}/lib${LIBDIRSUFFIX}
fi

# Create the doc directory for atlas and populate it.
#
case "$DEFAULT_DOCS" in
 [nN]|[nN][oO]) DOC_DIR="$PKG$SYS_DESTDIR/doc/$PRGNAM-$VERSION" ;;
             *) DOC_DIR="$PKG/usr/doc/$PRGNAM-$VERSION" ;;
esac
mkdir -p ${DOC_DIR}
cp -a ../INSTALL.txt ../README ../doc ${DOC_DIR}

# Add the Slackbuild script and README.SLACKWARE to the docs.
#
cat $CWD/$PRGNAM.SlackBuild > $DOC_DIR/$PRGNAM.SlackBuild
cat $CWD/README.SLACKWARE > $DOC_DIR/README.SLACKWARE

# Create custom arch defaults if appropriate.
#
if [ "$USE_ARCH_DEFAULTS" = "0"  ]; then
  if [ "$ARCH_DEF_DIR" ]; then
    ( cd ARCHS
    make ArchNew
    make tarfile
    cp -ua *.tar.* "$ARCH_DEF_DIR"
    )
    echo "$ARCH_DEF_DIR" > $DOC_DIR/ARCH_DEF_DIR
  fi
fi

# If the full LAPACK got installed add also some relevant files from its source
# tree.
#
if [ "$LAPACK_SOURCE" ]; then
  ( cd src/lapack/reference
    LAPACK_VER=$(./INSTALL/testversion | sed -e "s% *LAPACK *%%" -e "s% *%%g")
    LAPACK_DOC_DIR="${DOC_DIR}/lapack-$LAPACK_VER"
    mkdir "$LAPACK_DOC_DIR"
    cp -a LICENSE README "$LAPACK_DOC_DIR"

    # Copy the test results if present (getting around "set -e" with "echo -n").
    #
    cp -a TEST_* "$LAPACK_DOC_DIR" 2>/dev/null || echo -n
  )
fi

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd "$PKG"
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}