Skip to content

Commit

Permalink
new update-mak.sh tool to help keep Makefile.mak updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vedaldi committed Jan 12, 2010
1 parent 255b1db commit b27e204
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions update-mak.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# file: update-mak.sh
# description: Helper script to update Makefile.mak
# author: Andrea Vedaldi

# This script updates Makefile.mak based on the current source tree
# and version in vl/generic.h. It saves the new version to
# Makefile.mak.new.

function make
{
# sed below removes the trailing '\' from the last entry
(
printf '%-69s\\\n' "$1 ="
find "$2" -name '*.c' | tr '/' '\' | while read -r x
do
printf ' %-66s \\\n' "$x"
done
) | sed '$s/ *\\$//'
echo
}

function sub
{
# Put substitution text at the beginning. Then sed puts the
# beginning in its hold buffer, finds the paragraph starting with
# "$2 =", deletes all but the last lines of it and substititue the
# last line with the hold buffer. It also removes trailing
# whitespaces.
(make "$2" "$3" ; echo "$1") | \
sed -e '1{h;d;}' \
-e '2,/^$/{H;d;}' \
-e "/$2 =/,/^$/{/^$/!d;g;}" \
-e 's/ *$//'
}

function subv
{
# Substitutes VER = x.x.x with the new version string.
echo "$1" | sed -e "/VER *=/s/\(\([0-9][0-9]*\.\{0,1\}\)\{3\}\)/$2/"
}

# source version string from vl/generic.h
ver=$(cat vl/generic.h | sed -n \
's/.*VL_VERSION_STRING.*\(\([0-9][0-9]*\.\{0,1\}\)\{3\}\).*/\1/p')

# source current nmake script
a=$(cat Makefile.mak)

# updaetes version string
a=$(subv "$a" "$ver")

# updates hard-wired list of source code files in the nmake script
a=$(sub "$a" libsrc vl)
a=$(sub "$a" cmdsrc src)
a=$(sub "$a" mexsrc toolbox)

echo "$a" > Makefile.mak.new

0 comments on commit b27e204

Please sign in to comment.