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 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
|
#! /bin/bash
# This script will configure and build Gnuastro in parallel inside another
# directory (to keep the source and build directories separate). By default
# it is in the tmpfs directory of the RAM. Run with '--help' for a more
# complete description.
#
# Original author:
# Mohammad Akhlaghi <mohammad@akhlaghi.org>
# Contributing author(s):
# Mosè Giordano <mose@gnu.org>
# Raul Infante-Sainz <infantesainz@gmail.com>
# Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
# Copyright (C) 2016-2024 Free Software Foundation, Inc.
#
# Gnuastro is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Gnuastro is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
# Exit the script if any of the commands fail
set -e
# Default values for variables.
jobs=0
dist=0
debug=0
clean=0
check=0
reconf=0
upload=0
install=0
valgrind=0
compression=lzip
prefix=/usr/local
# Check and set the temporary directory
if [ -d /dev/shm ]; then
top_build_dir=/dev/shm
elif [ -d /tmp ]; then
top_build_dir=/tmp
else
top_build_dir=.
fi
if [ -f .version ]; then
version=$(cat .version)
else
version=""
fi
# Output of help.
me=$0 # Executable file name.
help_print() {
# See if autoreconf is enabled or not.
if [ $reconf = "0" ]; then
reconf_status="DISABLED"
else
reconf_status="ENABLED"
fi
# See if debug is enabled or not.
if [ $debug = "0" ]; then
debug_status="DISABLED"
else
debug_status="ENABLED"
fi
# See if valgrind is enabled or not.
if [ $valgrind = "0" ]; then
valgrind_status="DISABLED"
else
valgrind_status="ENABLED"
fi
# See if clean is enabled or not.
if [ $clean = "0" ]; then
clean_status="DISABLED"
else
clean_status="ENABLED"
fi
# See if check is enabled or not.
if [ $check = "0" ]; then
check_status="DISABLED"
else
check_status="ENABLED"
fi
# See if install is enabled or not.
if [ $install = "0" ]; then
install_status="DISABLED"
else
install_status="ENABLED"
fi
# See dist is enabled or not.
if [ $dist = "0" ]; then
dist_status="DISABLED"
else
dist_status="ENABLED"
fi
# See if upload is enabled or not.
if [ $upload = "0" ]; then
upload_status="DISABLED"
else
upload_status="ENABLED"
fi
# Print the output.
cat <<EOF
Usage: $me [OPTION]...
Configure and make the package in a separate directory and put a symbolic
link to that directory in the current directory. A top build directory must
be given to host the build directory for this script (see 'top-build-dir'
option below). The symbolic link to the build directory in this directory
will be called 'build'.
Through the options, it also possible to request further operations after
the build (for example checking, making distribution files or
installing). See the "Separate build and source directories" section of the
Gnuastro manual for a more complete introduction to this script.
Options:
-b, --top-build-dir STR Address to host the top build directory.
Current value: $top_build_dir
-o, --prefix STR Install architecture-independent files here.
Current value: $prefix
-O, --confopts "STR" Add extra configure options manually.
Please note that all of the options must
be wrapped between double quotations '"',
so that the script does not confuse them
with 'developer-build' options.
-V, --version Print current version to be used in absolute
build directory name.
Current value: $version
-a, --autoreconf Run 'autoreconf -f' (to set the version and
update the build system) before anything else.
Current status: $reconf_status
-c, --clean Delete (with 'rm') all its contents of the build
directory before starting new configuration.
Current status: $clean_status
-d, --debug Build Gnuastro with debugging information,
no optimization flags, and without shared
libraries.
Current status: $debug_status
-v, --valgrind Build with '--enable-check-with-valgrind'.
Current status: $valgrind_status
-j, --jobs INT Number of threads to use in 'make'.
Current value: $jobs
-C, --check Run 'make check' after the build.
Current status: $check_status
-i, --install Run 'sudo make install' after the build.
Current status: $install_status
-D, --dist Build a compressed tarball and PDF manual.
Current status: $dist_status
-z, --compression=STR Compression algorithm to use: 'lz' or 'xz'.
Current value: $compression
-u, --upload STR First run '--dist', then upload tarball and PDF
manual to the given 'server:folder'.
For example: -u my-server:folder
Current status: $upload_status
-p, --publish STR Short for '-a -c -d -C -u STR'. '-d' is added
because it will greatly speed up the build. It
will have no effect on the produced tarball.
-I, --install-archive Short for '-a -c -C -i -D'.
-P, --printparams Another name for '--help', for similarity with
Gnuastro's programs. Note that the output of
'--help' also includes the variable values.
-h, --help Print this help list.
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
GNU Astronomy Utilities home page: http://www.gnu.org/software/gnuastro/
Report bugs to bug-gnuastro@gnu.org.
EOF
}
# Parse the arguments.
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-O|--confopts)
confopts="$2"
if [ x"$confopts" = x ]; then
echo "No argument given to '--confopts'."
exit 1;
fi
shift # past argument
shift # past value
;;
-o|--prefix)
prefix="$2"
if [ x"$prefix" = x ]; then
echo "No argument given to '--prefix' ('-o')."
exit 1;
fi
shift # past argument
shift # past value
;;
-b|--top-build-dir)
top_build_dir="$2"
if [ x"$top_build_dir" = x ]; then
echo "No argument given to '--top-build-dir' ('-b')."
exit 1;
fi
shift # past argument
shift # past value
;;
-V|--version)
echo $version
exit 0
;;
-a|--autoreconf)
reconf=1
shift # past argument
;;
-c|--clean)
clean=1
shift # past argument
;;
-d|--debug)
debug=1
shift # past argument
;;
-v|--valgrind)
valgrind=1
shift # past argument
;;
-j|--jobs)
jobs="$2"
if [ x"$jobs" = x ]; then
echo "No argument given to '--jobs' ('-j')."
exit 1;
fi
shift # past argument
shift # past value
;;
-C|--check)
check=1
shift # past argument
;;
-i|--install)
install=1
shift # past argument
;;
-D|--dist)
dist=1
shift # past argument
;;
-z|--compression)
compression="$2"
if [ x"$compression" = x ]; then
echo "No argument given to '--compression' ('-z')."
exit 1;
fi
shift # past argument
shift # past value
;;
-u|--upload)
dist=1
upload=1
url="$2"
if [ x"$url" = x ]; then
echo "No SERVER:DIR given to '--upload' ('-u') ."
exit 1;
fi
shift # past argument
shift # past value
;;
-p|--publish)
dist=1
clean=1
debug=1
check=1
reconf=1
upload=1
url="$2"
if [ x"$url" = x ]; then
echo "No SERVER:DIR given to '--publish' ('-p') ."
exit 1;
fi
shift # past argument
shift # past value
;;
-I|--install-archive)
dist=1
clean=1
check=1
reconf=1
install=1
shift # past argument
;;
-h|-P|--help|--printparams)
help_print
exit 0
;;
*) # unknown option
echo "'$1' isn't a recognized option. Aborted."
echo
echo "Recall that for this script, options and their values must be"
echo "separated by atleast one white-space character."
exit 1
;;
esac
done
# Check if the configure script already exists. If not, let the user know
# what to do.
if ! [ -f configure ]; then
echo "The 'configure' script doesn't exist!"
echo "It is created after bootstrapping Gnuastro."
echo;
echo "The dependencies to bootstrap Gnuastro are described here:"
echo " https://www.gnu.org/software/gnuastro/manual/html_node/Bootstrapping-dependencies.html"
echo;
echo "Afterwards, the bootstrapping process is described here:"
echo " https://www.gnu.org/software/gnuastro/manual/html_node/Bootstrapping.html"
echo;
echo "If you don't want to develop Gnuastro, but just build, install and use it, you don't need to bootstrap, please use the tarball:"
echo " https://ftp.gnu.org/gnu/gnuastro/"
exit 1
fi
# Make sure a reasonable value is given to '--compression':
if [ x"$compression" = xlzip ]; then compsuff=lz;
elif [ x"$compression" = xxz ]; then compsuff=xz;
else
echo "$compression: value of '--compression' ('-z') not recognized. It should be either 'lzip' or 'xz'"; exit 1
fi
# Keep the address of this source directory (where this script is being run
# from) which we will need later.
srcdir=$(pwd)
# Set the number of jobs
# ----------------------
#
# If the user hasn't manually specified the number of threads, see if we
# can deduce it from the host:
# - On systems with GNU Coreutils we have 'nproc'.
# - On BSD-based systems (for example FreeBSD and macOS), we have a
# 'hw.ncpu' in the output of 'sysctl'.
# - When none of the above work, just set the number of threads to 1.
if [ $jobs = 0 ]; then
if type nproc > /dev/null 2> /dev/null; then
jobs=$(nproc --all);
else
jobs=$(sysctl -a | awk '/^hw\.ncpu/{print $2}')
if [ x"$jobs" = x ]; then jobs=1; fi
fi
fi
# Check if top_build_dir exists
if [ ! -d $top_build_dir ]; then
echo "$top_build_dir doesn't exist. Aborted."
exit 1
fi
# Set the build directory name in tmpfs. If the .version file exists, use
# it to allow multiple version builds there (which might happen during
# development).
basedir=$(basename -- "$srcdir")
if [ -f .version ]; then
build_dir=$top_build_dir/"$basedir"-$version
else
build_dir=$top_build_dir/"$basedir"
fi
# Make the build directory (if it doesn't already exist).
if [ ! -d $build_dir ]; then
mkdir $build_dir
fi
# If reconfiguration was requested, do it.
if [ $reconf = 1 ]; then
autoreconf -f
fi
# Make a symbolic link to the tmpfs build directory for users to easily
# access the built files and also follow the progress. We are first
# deleting any existing symbolic link and remaking it since the possible
# deletion of $build_dir during the development can complicate the
# pre-existing symbolic link.
build_sym=build
if [ -h $build_sym ]; then
# Delete a harmless symbolic link, if present.
rm $build_sym
fi
# Create the link only if the symbolic link doesn't exist.
if [ ! -e $build_sym ]; then
ln -s $build_dir $build_sym
else
echo "$build_sym already exists here and is not a symbolic link."
echo "Aborted."
exit 1
fi
# Clean the contents of the build directory if requested.
if [ x$clean = x1 ]; then
rm -rf $build_sym/*
fi
# Go into the build directory to start the configure and/or build:
cd $build_dir
# If a 'Makefile' doesn't exist, then configure Gnuastro.
if [ ! -f Makefile ]; then
# Set the proper flags.
if [ x$debug = x1 ]; then
confopts="$confopts --enable-debug"
fi
if [ x$valgrind = x1 ]; then
confopts="$confopts --enable-check-with-valgrind"
fi
# Run the configure script.
$srcdir/configure --srcdir=$srcdir $confopts --prefix=$prefix
fi
# Build Gnuastro in that directory with the specified number of threads
make -k -j$jobs
# If requested, also run 'make check'.
if [ x$check = x1 ]; then
make check -k -j$jobs
fi
# Make the tarball and PDF for distribution. Then put a copy of the PDF in
# the top build directory for easy usage later.
if [ x$dist = x1 ]; then
make dist-$compression pdf
cp doc/gnuastro.pdf ./
fi
# Upload the tarball to the requested server.
if [ x$upload = x1 ]; then
# Get the base package name, and use it to make a generic tarball
# name. Note that with the '--upload' option, '--dist' is also
# activated, so the tarball is already built and ready by this
# step.
tarball=$(ls *.tar.$compsuff)
base=$(echo $tarball | sed -e's/-/ /' | awk '{print $1}')
# File names:
pdf=$base.pdf
latest=$base"-latest.tar.$compsuff"
# Copy the files to the subdirectories of the given URL (must include
# folders).
scp $tarball $url/src
scp $pdf $url/pdf
# Make the symbolic links on the server.
server=$(echo "$url" | sed -e's/:/ /' | awk '{print $1}')
sdir=$(echo "$url" | sed -e's/:/ /' | awk '{print $2}')
ssh $server 'cd '"$sdir"' && rm -f '$latest' && ln -s src/'$tarball $latest ' && exit'
echo; echo "On $url:"
echo " $latest -> src/$tarball"
fi
# If requested, run 'sudo make install'.
if [ x$install = x1 ]; then
# Check if user has permission to write in $prefix, if not, use 'sudo'.
if [ -w $prefix ]; then
make install -kj$jobs
else
sudo make install -kj$jobs
fi
fi
|