#! /bin/sh # # Necessary preparations/configurations for the reproduction pipeline. # # Original author: # Mohammad Akhlaghi # Contributing author(s): # Your name # Copyright (C) 2018, Your Name. # # This script 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. # # This script 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. # # A copy of the GNU General Public License is available at # . # Script settings # --------------- # Stop the script if there are any errors. set -e # Important internal locations # ---------------------------- # # These are defined to help make this script more readable. topdir=$(pwd) installedlink=.local lbdir=reproduce/build cdir=reproduce/config optionaldir="/optional/path" pdir=$cdir/pipeline pconf=$pdir/LOCAL.mk ptconf=$pdir/LOCAL_tmp.mk poconf=$pdir/LOCAL_old.mk # --------- Delete for no Gnuastro --------- glconf=$cdir/gnuastro/gnuastro-local.conf # ------------------------------------------ # Delete final target of configuration # ------------------------------------ # # Without the top-level `Makefile' the user can't run `make' in this # directory. But we only want to make it available when we know everything # else is set up. So we'll delete it at the start of this configuration and # reset the link in the absolute end. rm -f Makefile # Notice for top of generated files # --------------------------------- # # In case someone opens the files output from the configuration scripts in # a text editor and wants to edit them, it is important to let them know # that their changes are not going to be permenant. function create_file_with_notice() { if echo "# IMPORTANT: file can be RE-WRITTEN after './configure'" > $1 then echo "#" >> $1 echo "# This file was created during the reproduction" >> $1 echo "# pipeline's configuration ('./configure'). Therefore," >> $1 echo "# it is not under version control and any manual " >> $1 echo "# changes to it will be over-written if the pipeline " >> $1 echo "# is re-configured." >> $1 echo "#" >> $1 else echo; echo "Can't write to $1"; echo; exit 1 fi } # Get absolute address # -------------------- # # Since the build directory will go into a symbolic link, we want it to be # an absolute address. With this function we can make sure of that. function absolute_dir() { echo "$(cd "$(dirname "$1")" && pwd )/$(basename "$1")" } # Inform the user # --------------- # # Print some basic information so the user gets a feeling of what is going # on and is prepared on what will happen next. cat < /dev/null 2>/dev/null; then wgetname=$(which wget) downloader="$wgetname --no-use-server-timestamps -O"; else cat < /dev/null; then bdir=$(absolute_dir $inbdir) echo " -- Build directory: '$bdir'" rm -rf $inbdir/$junkname else echo " -- Can't write in '$inbdir'" fi else if mkdir $inbdir 2> /dev/null; then bdir=$(absolute_dir $inbdir) echo " -- Build directory set to (the newly created): '$bdir'" else echo " -- Can't create '$inbdir'" fi fi done fi # Input directory # --------------- indir=$optionaldir wfpc2name=$(awk '!/^#/ && $1=="WFPC2IMAGE" {print $3}' $pdir/INPUTS.mk) wfpc2md5=$(awk '!/^#/ && $1=="WFPC2MD5" {print $3}' $pdir/INPUTS.mk) wfpc2size=$(awk '!/^#/ && $1=="WFPC2SIZE" {print $3}' $pdir/INPUTS.mk) wfpc2url=$(awk '!/^#/ && $1=="WFPC2URL" {print $3}' $pdir/INPUTS.mk) if [ $rewritepconfig = yes ]; then cat <> $pconf else # Read the values from existing configuration file. inbdir=$(awk '$1=="BDIR" {print $3}' $pconf) downloader=$(awk '$1=="DOWNLOADER" {print $3}' $pconf) # Make sure all necessary variables have a value err=0 verr=0 novalue="" if [ x"$inbdir" = x ]; then novalue="BDIR, "; fi if [ x"$downloader" = x ]; then novalue="$novalue"DOWNLOADER; fi if [ x"$novalue" != x ]; then verr=1; err=1; fi # Make sure `bdir' is an absolute path and it exists. berr=0 ierr=0 bdir=$(absolute_dir $inbdir) if ! [ -d $bdir ]; then if ! mkdir $bdir; then berr=1; err=1; fi; fi if [ $err = 1 ]; then cat <> $glconf echo " minmapsize $minmapsize" >> $glconf echo >> $glconf echo "# Version of Gnuastro that must be used." >> $glconf echo " onlyversion $gversion" >> $glconf else ingversion=$(awk '$1=="onlyversion" {print $NF}' $glconf) if [ x$ingversion != x$gversion ]; then echo "______________________________________________________" echo "!!!!!!!!!!!!!!!!!!CONFIGURATION ERROR!!!!!!!!!!!!!!!!!" echo echo "Gnuastro's version in '$glconf' ($ingversion) doesn't match the tarball version that this pipeline was designed to use in '$depverfile' ($gversion). Please re-run after removing the former file:" echo echo " $ rm $glconf" echo " $ ./configure" echo echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo exit 1 fi fi # ------------------------------------------ # Setup the top-level directories # ------------------------------- rm -f $lbdir ln -s $bdir $lbdir depdir=$bdir/dependencies if ! [ -d $depdir ]; then mkdir $depdir; fi tardir=$depdir/tarballs if ! [ -d $tardir ]; then mkdir $tardir; fi instdir=$depdir/installed if ! [ -d $instdir ]; then mkdir $instdir; fi rm -f $installedlink ln -s $instdir $installedlink # --------- Delete for no Gnuastro --------- rm -f .gnuastro ln -s $(pwd)/reproduce/config/gnuastro .gnuastro # ------------------------------------------ # See if the C compiler can build static libraries # ------------------------------------------------ oprog=$depdir/static-test cprog=$depdir/static-test.c echo "#include " > $cprog echo "int main(void) {return 0;}" >> $cprog if [ x$CC = x ]; then CC=gcc; fi; if $CC $cprog -o$oprog -static &> /dev/null; then export static_build="yes" else export static_build="no" fi rm -f $oprog $cprog if [ $printnotice = yes ] && [ $static_build = "no" ]; then cat <