We are hiring ! See our job offers.
https://hal.archives-ouvertes.fr/hal-02128878
Raw File
Tip revision: 4201397494d9af8b687117e8ff4d85a8944f5c5a authored by Software Heritage on 11 June 2019, 10:15:02 UTC
hal: Deposit 298 in collection hal
Tip revision: 4201397
incremente-versions
#!/bin/csh -f
# Copyright (c) 2011 FFLAS-FFPACK
# written by Brice Boyer (briceboyer) <boyer.brice@gmail.com>
# adapted from LinBox configuration
#
# ========LICENCE========
# This file is part of the library FFLAS-FFPACK.
#
# FFLAS-FFPACK is free software: you can redistribute it and/or modify
# it under the terms of the  GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
# ========LICENCE========
#/



set conf = configure.ac
set ver  = Makefile.am

#verbatim second argument of AC_INIT
set verb = `grep ^AC_INIT $conf | cut -d',' -f2`
#removes spaces and brackets
set vern = `echo "$verb" | sed 's/ //g;s/\[//;s/\]//'`
echo "Current version is $vern."


echo -n "Increment library version ? (y/n)"
set answ = $<
if ("$answ" == "y") then
	set line = `fgrep -n  ^AC_INIT $conf  | cut -d':' -f1`  #gets the line
    set macro = `echo "$vern" | cut -d'.' -f1` #a version number is macro.minor.micro
    set minor = `echo "$vern" | cut -d'.' -f2`
	set micro = `echo "$vern" | cut -d'.' -f3`
	set tmpfile = `mktemp` #tempfile
	set sedfile = `mktemp` #temp sed file
	set pmicro = `echo $micro`
    @ pmicro ++
	set pminor = `echo $minor`
    @ pminor ++
	set pmacro = `echo $macro`
    @ pmacro ++
	echo "Increment micro revision number ($vern -> $macro.$minor.$pmicro) ? press '0' "
	echo "Increment minor revision number ($vern -> $macro.$pminor.0) ? press '1' "
	echo -n "Increment macro revision number ($vern -> $pmacro.0.0) ? press '2' "
	set increm = $<
	switch ($increm)
		case 0:
			set newv = "[$macro.$minor.$pmicro]"
			breaksw
		case 1:
			set newv = "[$macro.$pminor.0]"
			breaksw
		case 2:
			set newv = "[$pmacro.0.0]"
			breaksw
		default:
			set newv = "$verb"
			echo "'$increm' read. Not incrementing anything."
			breaksw
	endsw

	#replacing [ ] and . with escaped version for sed would understand them as 'operators'
	echo "$line s/$verb/$newv/" | sed 's/\./\\\./g;s/\[/\\\[/g;s/\]/\\\]/g' > $sedfile
	sed -f $sedfile $conf > $tmpfile
	#clean up
	\rm -f $sedfile
	#diff for changes
	diff -u0 $conf $tmpfile
	#if something was changed, confirm incrementation :
    if ("$newv" != "$verb") then
		echo -n "Confirmation of incrementation ? (yes/no)"
		set answ = $<
        set backupconf = $conf.back$$
		if ("$answ" == "yes") then
			\cp -p $conf $backupconf
            echo "Back-up of $conf made in $backupconf. Now overwriting $conf."
			\mv -f $tmpfile $conf
		else
			echo "'$answ' read. Not incrementing anything."
			\rm -f $tmpfile
			exit 0 ;
		endif
		#now change Makefile accordingly
		echo -n "Incrementing Makefile revision accordingly"
		set tmpfile = `mktemp` #tempfile
		set sedfile = `mktemp` #tempfile
		switch ($increm)
			case 0:
				echo -n "s/VERSION.*/VERSION=$macro.$minor.$pmicro/"  >> $sedfile
				breaksw
			case 1:
				echo "s/VERSION.*/VERSION=$macro.$pminor.0/"  > $sedfile
				breaksw
			case 2:
				echo "s/VERSION.*/VERSION=$pmacro.0.0/"  > $sedfile
				breaksw
			default:
				echo "Something abnormal happened"
				exit 1
				breaksw
		endsw
		sed -f $sedfile $ver > $tmpfile
		\rm -f $sedfile
		diff -u0 $ver $tmpfile
		echo -n "Confirmation of incrementation ? (yes/no) "
		set answ = $<
		if ("$answ" == "yes") then
			\mv -f $tmpfile $ver
			echo " your old $conf is destroyed..."
			\rm -f $backupconf
		else
			echo "'$answ' read. Not incrementing anything."
			echo " your old $conf is restored..."
			\rm -f $tmpfile
			\mv -f $backupconf $conf
			exit 0
		endif

	endif
else
	echo "'$answ' read. Not doing anything."
endif

exit 0

back to top